Fix crash when UaProfUrlTagName is null
This change fixes a silent MMS lib crash when the UaProfUrlTagName is
empty.
Test: Tested manually by modifying the configs and using temporary log
lines
Bug: 128510421
Change-Id: I3500a5988d1b50e79599846cce641ec3bca923ca
(cherry picked from commit d7bdbde7a3b103589c1915e3333e66f998a3bfac)
diff --git a/src/com/android/mms/service/MmsHttpClient.java b/src/com/android/mms/service/MmsHttpClient.java
index 1e77134..7ca012c 100644
--- a/src/com/android/mms/service/MmsHttpClient.java
+++ b/src/com/android/mms/service/MmsHttpClient.java
@@ -28,6 +28,7 @@
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
+
import com.android.mms.service.exception.MmsHttpException;
import java.io.BufferedInputStream;
@@ -74,6 +75,9 @@
"application/vnd.wap.mms-message";
private static final String HEADER_CONNECTION_CLOSE = "close";
+ // Used for configs that specify a UA_PROF_URL, but not a name
+ private static final String UA_PROF_TAG_NAME_DEFAULT = "x-wap-profile";
+
private static final int IPV4_WAIT_ATTEMPTS = 15;
private static final long IPV4_WAIT_DELAY_MS = 1000; // 1 seconds
@@ -83,9 +87,9 @@
/**
* Constructor
- * @param context The Context object
+ *
+ * @param context The Context object
* @param network The Network for creating an OKHttp client
- * @param connectivityManager
*/
public MmsHttpClient(Context context, Network network,
ConnectivityManager connectivityManager) {
@@ -99,16 +103,16 @@
/**
* Execute an MMS HTTP request, either a POST (sending) or a GET (downloading)
*
- * @param urlString The request URL, for sending it is usually the MMSC, and for downloading
- * it is the message URL
- * @param pdu For POST (sending) only, the PDU to send
- * @param method HTTP method, POST for sending and GET for downloading
+ * @param urlString The request URL, for sending it is usually the MMSC, and for downloading
+ * it is the message URL
+ * @param pdu For POST (sending) only, the PDU to send
+ * @param method HTTP method, POST for sending and GET for downloading
* @param isProxySet Is there a proxy for the MMSC
- * @param proxyHost The proxy host
- * @param proxyPort The proxy port
- * @param mmsConfig The MMS config to use
- * @param subId The subscription ID used to get line number, etc.
- * @param requestId The request ID for logging
+ * @param proxyHost The proxy host
+ * @param proxyPort The proxy port
+ * @param mmsConfig The MMS config to use
+ * @param subId The subscription ID used to get line number, etc.
+ * @param requestId The request ID for logging
* @return The HTTP response body
* @throws MmsHttpException For any failures
*/
@@ -144,11 +148,18 @@
LogUtil.i(requestId, "HTTP: User-Agent=" + userAgent);
connection.setRequestProperty(HEADER_USER_AGENT, userAgent);
// Header: x-wap-profile
- final String uaProfUrlTagName =
+ String uaProfUrlTagName =
mmsConfig.getString(SmsManager.MMS_CONFIG_UA_PROF_TAG_NAME);
final String uaProfUrl = mmsConfig.getString(SmsManager.MMS_CONFIG_UA_PROF_URL);
- if (uaProfUrl != null) {
- LogUtil.i(requestId, "HTTP: UaProfUrl=" + uaProfUrl);
+
+ if (!TextUtils.isEmpty(uaProfUrl)) {
+ if (TextUtils.isEmpty(uaProfUrlTagName)) {
+ uaProfUrlTagName = UA_PROF_TAG_NAME_DEFAULT;
+ }
+
+ LogUtil.i(requestId,
+ "HTTP: UaProfUrl=" + uaProfUrl + ", UaProfUrlTagName=" + uaProfUrlTagName);
+
connection.setRequestProperty(uaProfUrlTagName, uaProfUrl);
}
// Header: Connection: close (if needed)
@@ -350,8 +361,8 @@
* macros like "##LINE1##" or "##NAI##" which is resolved with methods in this class
*
* @param connection The HttpURLConnection that we add headers to
- * @param mmsConfig The MmsConfig object
- * @param subId The subscription ID used to get line number, etc.
+ * @param mmsConfig The MmsConfig object
+ * @param subId The subscription ID used to get line number, etc.
*/
private void addExtraHeaders(HttpURLConnection connection, Bundle mmsConfig, int subId) {
final String extraHttpParams = mmsConfig.getString(SmsManager.MMS_CONFIG_HTTP_PARAMS);
@@ -374,6 +385,7 @@
}
private static final Pattern MACRO_P = Pattern.compile("##(\\S+)##");
+
/**
* Resolve the macro in HTTP param value text
* For example, "something##LINE1##something" is resolved to "something9139531419something"
@@ -413,9 +425,6 @@
/**
* Redact the URL for non-VERBOSE logging. Replace url with only the host part and the length
* of the input URL string.
- *
- * @param urlString
- * @return
*/
public static String redactUrlForNonVerbose(String urlString) {
if (LogUtil.isLoggable(Log.VERBOSE)) {
@@ -450,13 +459,14 @@
private static final String MACRO_LINE1NOCOUNTRYCODE = "LINE1NOCOUNTRYCODE";
// NAI (Network Access Identifier), used by Sprint for authentication
private static final String MACRO_NAI = "NAI";
+
/**
* Return the HTTP param macro value.
* Example: "LINE1" returns the phone number, etc.
*
- * @param macro The macro name
+ * @param macro The macro name
* @param mmsConfig The MMS config which contains NAI suffix.
- * @param subId The subscription ID used to get line number, etc.
+ * @param subId The subscription ID used to get line number, etc.
* @return The value of the defined macro
*/
private static String getMacroValue(Context context, String macro, Bundle mmsConfig,