Merge Android R

Bug: 168057903
Merged-In: Ida0d85395e88f56b278d69373edaed5d0421d9b4
Change-Id: Ifa482b474843ff704f8f1c3310a9717cded6274b
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e033528..87e7947 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -25,8 +25,6 @@
     <uses-permission android:name="android.permission.WRITE_SMS"/>
     <uses-permission android:name="android.permission.BROADCAST_WAP_PUSH"/>
     <uses-permission android:name="android.permission.BIND_CARRIER_SERVICES"/>
-    <!-- BIND_CARRIER_MESSAGING_SERVICE has been deprecated in favor of BIND_CARRIER_SERVICES. -->
-    <uses-permission android:name="android.permission.BIND_CARRIER_MESSAGING_SERVICE"/>
     <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
 
     <protected-broadcast android:name="android.settings.ENABLE_MMS_DATA_REQUEST"/>
diff --git a/OWNERS b/OWNERS
index e2a657c..cc5e6a3 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1,7 @@
 amitmahajan@google.com
 rgreenwalt@google.com
-sanketpadawe@google.com
+tomtaylor@google.com
+afurtado@google.com
+jianxiangp@google.com
+stephshi@google.com
+bellavicevh@google.com
diff --git a/src/com/android/mms/service/ApnSettings.java b/src/com/android/mms/service/ApnSettings.java
index 5f923c9..7e4a0fc 100644
--- a/src/com/android/mms/service/ApnSettings.java
+++ b/src/com/android/mms/service/ApnSettings.java
@@ -21,9 +21,9 @@
 import android.net.NetworkUtils;
 import android.net.Uri;
 import android.provider.Telephony;
+import android.telephony.data.ApnSetting;
 import android.text.TextUtils;
 
-import com.android.internal.telephony.PhoneConstants;
 import com.android.mms.service.exception.ApnException;
 
 import java.net.URI;
@@ -33,6 +33,7 @@
  * APN settings used for MMS transactions
  */
 public class ApnSettings {
+
     // MMSC URL
     private final String mServiceCenter;
     // MMSC proxy address
@@ -126,7 +127,7 @@
         while (cursor.moveToNext()) {
             // Read values from APN settings
             if (isValidApnType(
-                    cursor.getString(COLUMN_TYPE), PhoneConstants.APN_TYPE_MMS)) {
+                    cursor.getString(COLUMN_TYPE), ApnSetting.TYPE_MMS_STRING)) {
                 String mmscUrl = trimWithNullCheck(cursor.getString(COLUMN_MMSC));
                 if (TextUtils.isEmpty(mmscUrl)) {
                     continue;
@@ -203,13 +204,13 @@
     }
 
     private static boolean isValidApnType(String types, String requestType) {
-        // If APN type is unspecified, assume APN_TYPE_ALL.
+        // If APN type is unspecified, assume TYPE_ALL_STRING.
         if (TextUtils.isEmpty(types)) {
             return true;
         }
         for (String type : types.split(",")) {
             type = type.trim();
-            if (type.equals(requestType) || type.equals(PhoneConstants.APN_TYPE_ALL)) {
+            if (type.equals(requestType) || type.equals(ApnSetting.TYPE_ALL_STRING)) {
                 return true;
             }
         }
diff --git a/src/com/android/mms/service/DownloadRequest.java b/src/com/android/mms/service/DownloadRequest.java
index 8079fa4..e4d386e 100644
--- a/src/com/android/mms/service/DownloadRequest.java
+++ b/src/com/android/mms/service/DownloadRequest.java
@@ -59,8 +59,8 @@
 
     public DownloadRequest(RequestManager manager, int subId, String locationUrl,
             Uri contentUri, PendingIntent downloadedIntent, String creator,
-            Bundle configOverrides, Context context) {
-        super(manager, subId, creator, configOverrides, context);
+            Bundle configOverrides, Context context, long messageId) {
+        super(manager, subId, creator, configOverrides, context, messageId);
         mLocationUrl = locationUrl;
         mDownloadedIntent = downloadedIntent;
         mContentUri = contentUri;
@@ -72,8 +72,9 @@
         final String requestId = getRequestId();
         final MmsHttpClient mmsHttpClient = netMgr.getOrCreateHttpClient();
         if (mmsHttpClient == null) {
-            LogUtil.e(requestId, "MMS network is not ready!");
-            throw new MmsHttpException(0/*statusCode*/, "MMS network is not ready");
+            LogUtil.e(requestId, "MMS network is not ready! messageId: " + mMessageId);
+            throw new MmsHttpException(0/*statusCode*/, "MMS network is not ready. messageId: "
+                    + mMessageId);
         }
         return mmsHttpClient.execute(
                 mLocationUrl,
@@ -106,9 +107,9 @@
         if (!mRequestManager.getAutoPersistingPref()) {
             return null;
         }
-        LogUtil.d(requestId, "persistIfRequired");
+        LogUtil.d(requestId, "persistIfRequired. messageId: " + mMessageId);
         if (response == null || response.length < 1) {
-            LogUtil.e(requestId, "persistIfRequired: empty response");
+            LogUtil.e(requestId, "persistIfRequired: empty response. messageId: " + mMessageId);
             return null;
         }
         final long identity = Binder.clearCallingIdentity();
@@ -117,13 +118,15 @@
                     mMmsConfig.getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION);
             final GenericPdu pdu = (new PduParser(response, supportMmsContentDisposition)).parse();
             if (pdu == null || !(pdu instanceof RetrieveConf)) {
-                LogUtil.e(requestId, "persistIfRequired: invalid parsed PDU");
+                LogUtil.e(requestId, "persistIfRequired: invalid parsed PDU. messageId: "
+                        + mMessageId);
                 return null;
             }
             final RetrieveConf retrieveConf = (RetrieveConf) pdu;
             final int status = retrieveConf.getRetrieveStatus();
             if (status != PduHeaders.RETRIEVE_STATUS_OK) {
-                LogUtil.e(requestId, "persistIfRequired: retrieve failed " + status);
+                LogUtil.e(requestId, "persistIfRequired: retrieve failed " + status
+                        + ", messageId: " + mMessageId);
                 // Update the retrieve status of the NotificationInd
                 final ContentValues values = new ContentValues(1);
                 values.put(Telephony.Mms.RETRIEVE_STATUS, status);
@@ -148,7 +151,8 @@
                     true/*groupMmsEnabled*/,
                     null/*preOpenedFiles*/);
             if (messageUri == null) {
-                LogUtil.e(requestId, "persistIfRequired: can not persist message");
+                LogUtil.e(requestId, "persistIfRequired: can not persist message. messageId: "
+                        + mMessageId);
                 return null;
             }
             // Update some of the properties of the message
@@ -167,7 +171,8 @@
                     values,
                     null/*where*/,
                     null/*selectionArg*/) != 1) {
-                LogUtil.e(requestId, "persistIfRequired: can not update message");
+                LogUtil.e(requestId, "persistIfRequired: can not update message. messageId: "
+                        + mMessageId);
             }
             // Delete the corresponding NotificationInd
             SqliteWrapper.delete(context,
@@ -181,11 +186,14 @@
 
             return messageUri;
         } catch (MmsException e) {
-            LogUtil.e(requestId, "persistIfRequired: can not persist message", e);
+            LogUtil.e(requestId, "persistIfRequired: can not persist message. messageId: "
+                    + mMessageId, e);
         } catch (SQLiteException e) {
-            LogUtil.e(requestId, "persistIfRequired: can not update message", e);
+            LogUtil.e(requestId, "persistIfRequired: can not update message. messageId: "
+                    + mMessageId, e);
         } catch (RuntimeException e) {
-            LogUtil.e(requestId, "persistIfRequired: can not parse response", e);
+            LogUtil.e(requestId, "persistIfRequired: can not parse response. messageId: "
+                    + mMessageId, e);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -277,9 +285,11 @@
                 CarrierDownloadCompleteCallback carrierDownloadCallback) {
             mCarrierDownloadCallback = carrierDownloadCallback;
             if (bindToCarrierMessagingService(context, carrierMessagingServicePackage)) {
-                LogUtil.v("bindService() for carrier messaging service succeeded");
+                LogUtil.v("bindService() for carrier messaging service succeeded. messageId: "
+                        + mMessageId);
             } else {
-                LogUtil.e("bindService() for carrier messaging service failed");
+                LogUtil.e("bindService() for carrier messaging service failed. messageId: "
+                        + mMessageId);
                 carrierDownloadCallback.onDownloadMmsComplete(
                         CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK);
             }
@@ -291,7 +301,8 @@
                 downloadMms(mContentUri, mSubId, Uri.parse(mLocationUrl),
                         mCarrierDownloadCallback);
             } catch (RuntimeException e) {
-                LogUtil.e("Exception downloading MMS using the carrier messaging service: " + e, e);
+                LogUtil.e("Exception downloading MMS for messageId " + mMessageId
+                        + " using the carrier messaging service: " + e, e);
                 mCarrierDownloadCallback.onDownloadMmsComplete(
                         CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK);
             }
@@ -315,12 +326,14 @@
 
         @Override
         public void onSendMmsComplete(int result, byte[] sendConfPdu) {
-            LogUtil.e("Unexpected onSendMmsComplete call with result: " + result);
+            LogUtil.e("Unexpected onSendMmsComplete call with result: " + result
+                    + ", messageId: " + mMessageId);
         }
 
         @Override
         public void onDownloadMmsComplete(int result) {
-            LogUtil.d("Carrier app result for download: " + result);
+            LogUtil.d("Carrier app result for download: " + result
+                    + ", messageId: " + mMessageId);
             mCarrierDownloadManager.disposeConnection(mContext);
 
             if (!maybeFallbackToRegularDelivery(result)) {
diff --git a/src/com/android/mms/service/MmsRequest.java b/src/com/android/mms/service/MmsRequest.java
index 9f3e620..baf9292 100644
--- a/src/com/android/mms/service/MmsRequest.java
+++ b/src/com/android/mms/service/MmsRequest.java
@@ -83,15 +83,17 @@
     protected Bundle mMmsConfigOverrides;
     // Context used to get TelephonyManager.
     protected Context mContext;
+    protected long mMessageId;
 
     public MmsRequest(RequestManager requestManager, int subId, String creator,
-            Bundle configOverrides, Context context) {
+            Bundle configOverrides, Context context, long messageId) {
         mRequestManager = requestManager;
         mSubId = subId;
         mCreator = creator;
         mMmsConfigOverrides = configOverrides;
         mMmsConfig = null;
         mContext = context;
+        mMessageId = messageId;
     }
 
     public int getSubId() {
@@ -133,7 +135,7 @@
      * @param networkManager The network manager to use
      */
     public void execute(Context context, MmsNetworkManager networkManager) {
-        final String requestId = this.toString();
+        final String requestId = this.getRequestId();
         LogUtil.i(requestId, "Executing...");
         int result = SmsManager.MMS_ERROR_UNSPECIFIED;
         int httpStatusCode = 0;
@@ -206,7 +208,7 @@
     /**
      * Process the result of the completed request, including updating the message status
      * in database and sending back the result via pending intents.
-     *  @param context The context
+     * @param context The context
      * @param result The result code of execution
      * @param response The response body
      * @param httpStatusCode The optional http status code in case of http failure
@@ -214,6 +216,14 @@
     public void processResult(Context context, int result, byte[] response, int httpStatusCode) {
         final Uri messageUri = persistIfRequired(context, result, response);
 
+        final String requestId = this.getRequestId();
+        // As noted in the @param comment above, the httpStatusCode is only set when there's
+        // an http failure. On success, such as an http code of 200, the value here will be 0.
+        // It's disconcerting in the log to see httpStatusCode: 0 when the mms succeeded. That
+        // is why an httpStatusCode of zero is now reported in the log as "success".
+        LogUtil.i(requestId, "processResult: " + result + ", httpStatusCode: "
+                + (httpStatusCode != 0 ? httpStatusCode : "success (0)"));
+
         // Return MMS HTTP request result via PendingIntent
         final PendingIntent pendingIntent = getPendingIntent();
         if (pendingIntent != null) {
@@ -235,7 +245,7 @@
                 }
                 pendingIntent.send(context, result, fillIn);
             } catch (PendingIntent.CanceledException e) {
-                LogUtil.e(this.toString(), "Sending pending intent canceled", e);
+                LogUtil.e(requestId, "Sending pending intent canceled", e);
             }
         }
 
@@ -251,7 +261,8 @@
                 == CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK
                 || carrierMessagingAppResult
                         == CarrierMessagingService.DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK) {
-            LogUtil.d(this.toString(), "Sending/downloading MMS by IP failed.");
+            LogUtil.d(this.toString(), "Sending/downloading MMS by IP failed. messageId: "
+                    + mMessageId);
             mRequestManager.addSimRequest(MmsRequest.this);
             return true;
         } else {
@@ -275,7 +286,8 @@
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + '@' + Integer.toHexString(hashCode());
+        return getClass().getSimpleName() + '@' + Integer.toHexString(hashCode())
+                + " messageId: " + mMessageId;
     }
 
 
@@ -344,17 +356,20 @@
     protected abstract class CarrierMmsActionCallback extends CarrierMessagingCallbackWrapper {
         @Override
         public void onSendSmsComplete(int result, int messageRef) {
-            LogUtil.e("Unexpected onSendSmsComplete call with result: " + result);
+            LogUtil.e("Unexpected onSendSmsComplete call for messageId " + mMessageId
+                    + " with result: " + result);
         }
 
         @Override
         public void onSendMultipartSmsComplete(int result, int[] messageRefs) {
-            LogUtil.e("Unexpected onSendMultipartSmsComplete call with result: " + result);
+            LogUtil.e("Unexpected onSendMultipartSmsComplete call for messageId " + mMessageId
+                    + " with result: " + result);
         }
 
         @Override
         public void onFilterComplete(int result) {
-            LogUtil.e("Unexpected onFilterComplete call with result: " + result);
+            LogUtil.e("Unexpected onFilterComplete call for messageId " + mMessageId
+                    + " with result: " + result);
         }
     }
 }
diff --git a/src/com/android/mms/service/MmsService.java b/src/com/android/mms/service/MmsService.java
index 410ef70..eb0fd88 100644
--- a/src/com/android/mms/service/MmsService.java
+++ b/src/com/android/mms/service/MmsService.java
@@ -39,6 +39,7 @@
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.provider.Telephony;
+import android.security.NetworkSecurityPolicy;
 import android.service.carrier.CarrierMessagingService;
 import android.telephony.SmsManager;
 import android.telephony.SubscriptionInfo;
@@ -186,8 +187,9 @@
     private IMms.Stub mStub = new IMms.Stub() {
         @Override
         public void sendMessage(int subId, String callingPkg, Uri contentUri,
-                String locationUrl, Bundle configOverrides, PendingIntent sentIntent) {
-            LogUtil.d("sendMessage");
+                String locationUrl, Bundle configOverrides, PendingIntent sentIntent,
+                long messageId) {
+            LogUtil.d("sendMessage messageId: " + messageId);
             enforceSystemUid();
 
             // Make sure the subId is correct
@@ -207,7 +209,8 @@
             }
 
             final SendRequest request = new SendRequest(MmsService.this, subId, contentUri,
-                    locationUrl, sentIntent, callingPkg, configOverrides, MmsService.this);
+                    locationUrl, sentIntent, callingPkg, configOverrides, MmsService.this,
+                    messageId);
 
             final String carrierMessagingServicePackage =
                     getCarrierMessagingServicePackageIfExists(subId);
@@ -237,11 +240,12 @@
         @Override
         public void downloadMessage(int subId, String callingPkg, String locationUrl,
                 Uri contentUri, Bundle configOverrides,
-                PendingIntent downloadedIntent) {
+                PendingIntent downloadedIntent, long messageId) {
             // If the subId is no longer active it could be caused by an MVNO using multiple
             // subIds, so we should try to download anyway.
             // TODO: Fail fast when downloading will fail (i.e. SIM swapped)
-            LogUtil.d("downloadMessage: " + MmsHttpClient.redactUrlForNonVerbose(locationUrl));
+            LogUtil.d("downloadMessage: " + MmsHttpClient.redactUrlForNonVerbose(locationUrl) +
+                    ", messageId: " + messageId);
 
             enforceSystemUid();
 
@@ -274,7 +278,8 @@
             }
 
             final DownloadRequest request = new DownloadRequest(MmsService.this, subId, locationUrl,
-                    contentUri, downloadedIntent, callingPkg, configOverrides, MmsService.this);
+                    contentUri, downloadedIntent, callingPkg, configOverrides, MmsService.this,
+                    messageId);
 
             final String carrierMessagingServicePackage =
                     getCarrierMessagingServicePackageIfExists(subId);
@@ -612,6 +617,9 @@
         LogUtil.d("onCreate");
         // Load mms_config
         MmsConfigManager.getInstance().init(this);
+
+        NetworkSecurityPolicy.getInstance().setCleartextTrafficPermitted(true);
+
         // Initialize running request state
         for (int i = 0; i < mRunningRequestExecutors.length; i++) {
             mRunningRequestExecutors[i] = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
diff --git a/src/com/android/mms/service/SendRequest.java b/src/com/android/mms/service/SendRequest.java
index 8446646..e4d1d55 100644
--- a/src/com/android/mms/service/SendRequest.java
+++ b/src/com/android/mms/service/SendRequest.java
@@ -57,8 +57,9 @@
     private final PendingIntent mSentIntent;
 
     public SendRequest(RequestManager manager, int subId, Uri contentUri, String locationUrl,
-            PendingIntent sentIntent, String creator, Bundle configOverrides, Context context) {
-        super(manager, subId, creator, configOverrides, context);
+            PendingIntent sentIntent, String creator, Bundle configOverrides, Context context,
+            long messageId) {
+        super(manager, subId, creator, configOverrides, context, messageId);
         mPduUri = contentUri;
         mPduData = null;
         mLocationUrl = locationUrl;
@@ -71,8 +72,9 @@
         final String requestId = getRequestId();
         final MmsHttpClient mmsHttpClient = netMgr.getOrCreateHttpClient();
         if (mmsHttpClient == null) {
-            LogUtil.e(requestId, "MMS network is not ready!");
-            throw new MmsHttpException(0/*statusCode*/, "MMS network is not ready");
+            String notReady = "MMS network is not ready! messageId: " + mMessageId;
+            LogUtil.e(requestId, notReady);
+            throw new MmsHttpException(0/*statusCode*/, notReady);
         }
         final GenericPdu parsedPdu = parsePdu();
         notifyIfEmergencyContactNoThrow(parsedPdu);
@@ -93,14 +95,14 @@
         final String requestId = getRequestId();
         try {
             if (mPduData == null) {
-                LogUtil.w(requestId, "Empty PDU raw data");
+                LogUtil.w(requestId, "Empty PDU raw data. messageId: " + mMessageId);
                 return null;
             }
             final boolean supportContentDisposition =
                     mMmsConfig.getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION);
             return new PduParser(mPduData, supportContentDisposition).parse();
         } catch (final Exception e) {
-            LogUtil.w(requestId, "Failed to parse PDU raw data");
+            LogUtil.w(requestId, "Failed to parse PDU raw data. messageId: " + mMessageId);
         }
         return null;
     }
@@ -113,7 +115,7 @@
         try {
             notifyIfEmergencyContact(parsedPdu);
         } catch (Exception e) {
-            LogUtil.w(getRequestId(), "Error in notifyIfEmergencyContact", e);
+            LogUtil.w(getRequestId(), "Error in notifyIfEmergencyContact. messageId: " + mMessageId, e);
         }
     }
 
@@ -122,16 +124,18 @@
             SendReq sendReq = (SendReq) parsedPdu;
             for (EncodedStringValue encodedStringValue : sendReq.getTo()) {
                 if (isEmergencyNumber(encodedStringValue.getString())) {
-                    LogUtil.i(getRequestId(), "Notifying emergency contact");
+                    LogUtil.i(getRequestId(), "Notifying emergency contact. messageId: "
+                            + mMessageId);
                     new AsyncTask<Void, Void, Void>() {
                         @Override
                         protected Void doInBackground(Void... voids) {
                             try {
                                 BlockedNumberContract.SystemContract
-                                    .notifyEmergencyContact(mContext);
+                                        .notifyEmergencyContact(mContext);
                             } catch (Exception e) {
                                 LogUtil.e(getRequestId(),
-                                    "Exception notifying emergency contact: " + e);
+                                    "Exception notifying emergency contact. messageId: "
+                                            + mMessageId + e);
                             }
                             return null;
                         }
@@ -168,9 +172,9 @@
             // Not required to persist
             return null;
         }
-        LogUtil.d(requestId, "persistIfRequired");
+        LogUtil.d(requestId, "persistIfRequired. messageId: " + mMessageId);
         if (mPduData == null) {
-            LogUtil.e(requestId, "persistIfRequired: empty PDU");
+            LogUtil.e(requestId, "persistIfRequired: empty PDU. messageId: " + mMessageId);
             return null;
         }
         final long identity = Binder.clearCallingIdentity();
@@ -180,11 +184,12 @@
             // Persist the request PDU first
             GenericPdu pdu = (new PduParser(mPduData, supportContentDisposition)).parse();
             if (pdu == null) {
-                LogUtil.e(requestId, "persistIfRequired: can't parse input PDU");
+                LogUtil.e(requestId, "persistIfRequired: can't parse input PDU. messageId: "
+                        + mMessageId);
                 return null;
             }
             if (!(pdu instanceof SendReq)) {
-                LogUtil.d(requestId, "persistIfRequired: not SendReq");
+                LogUtil.d(requestId, "persistIfRequired: not SendReq. messageId: " + mMessageId);
                 return null;
             }
             final PduPersister persister = PduPersister.getPduPersister(context);
@@ -195,7 +200,8 @@
                     true/*groupMmsEnabled*/,
                     null/*preOpenedFiles*/);
             if (messageUri == null) {
-                LogUtil.e(requestId, "persistIfRequired: can not persist message");
+                LogUtil.e(requestId, "persistIfRequired: can not persist message. messageId: "
+                        + mMessageId);
                 return null;
             }
             // Update the additional columns based on the send result
@@ -233,13 +239,16 @@
             values.put(Telephony.Mms.SUBSCRIPTION_ID, mSubId);
             if (SqliteWrapper.update(context, context.getContentResolver(), messageUri, values,
                     null/*where*/, null/*selectionArg*/) != 1) {
-                LogUtil.e(requestId, "persistIfRequired: failed to update message");
+                LogUtil.e(requestId, "persistIfRequired: failed to update message. messageId: "
+                        + mMessageId);
             }
             return messageUri;
         } catch (MmsException e) {
-            LogUtil.e(requestId, "persistIfRequired: can not persist message", e);
+            LogUtil.e(requestId, "persistIfRequired: can not persist message. messageId: "
+                    + mMessageId, e);
         } catch (RuntimeException e) {
-            LogUtil.e(requestId, "persistIfRequired: unexpected parsing failure", e);
+            LogUtil.e(requestId, "persistIfRequired: unexpected parsing failure. messageId: "
+                    + mMessageId, e);
         } finally {
             Binder.restoreCallingIdentity(identity);
         }
@@ -254,11 +263,12 @@
     private void updateDestinationAddress(final GenericPdu pdu) {
         final String requestId = getRequestId();
         if (pdu == null) {
-            LogUtil.e(requestId, "updateDestinationAddress: can't parse input PDU");
+            LogUtil.e(requestId, "updateDestinationAddress: can't parse input PDU. messageId: "
+                    + mMessageId);
             return ;
         }
         if (!(pdu instanceof SendReq)) {
-            LogUtil.i(requestId, "updateDestinationAddress: not SendReq");
+            LogUtil.i(requestId, "updateDestinationAddress: not SendReq. messageId: " + mMessageId);
             return;
         }
 
@@ -391,9 +401,11 @@
                 CarrierSendCompleteCallback carrierSendCompleteCallback) {
             mCarrierSendCompleteCallback = carrierSendCompleteCallback;
             if (bindToCarrierMessagingService(context, carrierMessagingServicePackage)) {
-                LogUtil.v("bindService() for carrier messaging service succeeded");
+                LogUtil.v("bindService() for carrier messaging service succeeded. messageId: "
+                        + mMessageId);
             } else {
-                LogUtil.e("bindService() for carrier messaging service failed");
+                LogUtil.e("bindService() for carrier messaging service failed. messageId: "
+                        + mMessageId);
                 carrierSendCompleteCallback.onSendMmsComplete(
                         CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK,
                         null /* no sendConfPdu */);
@@ -409,7 +421,8 @@
                 }
                 sendMms(mPduUri, mSubId, locationUri, mCarrierSendCompleteCallback);
             } catch (RuntimeException e) {
-                LogUtil.e("Exception sending MMS using the carrier messaging service: " + e, e);
+                LogUtil.e("Exception sending MMS using the carrier messaging service. messageId: "
+                        + mMessageId + e, e);
                 mCarrierSendCompleteCallback.onSendMmsComplete(
                         CarrierMessagingService.SEND_STATUS_RETRY_ON_CARRIER_NETWORK,
                         null /* no sendConfPdu */);
@@ -433,7 +446,7 @@
 
         @Override
         public void onSendMmsComplete(int result, byte[] sendConfPdu) {
-            LogUtil.d("Carrier app result for send: " + result);
+            LogUtil.d("Carrier app result for sending messageId " + mMessageId + ": " + result);
             mCarrierSendManager.disposeConnection(mContext);
 
             if (!maybeFallbackToRegularDelivery(result)) {
@@ -444,7 +457,8 @@
 
         @Override
         public void onDownloadMmsComplete(int result) {
-            LogUtil.e("Unexpected onDownloadMmsComplete call with result: " + result);
+            LogUtil.e("Unexpected onDownloadMmsComplete call for messageId " + mMessageId
+                    + " with result: " + result);
         }
     }
 }
diff --git a/tests/robotests/src/com/android/mms/service/MmsServiceRoboTest.java b/tests/robotests/src/com/android/mms/service/MmsServiceRoboTest.java
index 5e4c309..c43fa74 100644
--- a/tests/robotests/src/com/android/mms/service/MmsServiceRoboTest.java
+++ b/tests/robotests/src/com/android/mms/service/MmsServiceRoboTest.java
@@ -56,13 +56,15 @@
     public void testSendMessage_DoesNotThrowIfSystemUid() throws RemoteException {
         ShadowBinder.setCallingUid(Process.SYSTEM_UID);
         binder.sendMessage(/* subId= */ 0, "callingPkg", Uri.parse("contentUri"),
-                "locationUrl", /* configOverrides= */ null, /* sentIntent= */ null);
+                "locationUrl", /* configOverrides= */ null, /* sentIntent= */ null,
+                /* messageId= */ 0L);
     }
 
     @Test
     public void testSendMessageThrows_IfNotSystemUid() {
         assertThrows(SecurityException.class,
                 () -> binder.sendMessage(/* subId= */ 0, "callingPkg", Uri.parse("contentUri"),
-                        "locationUrl", /* configOverrides= */ null, /* sentIntent= */ null));
+                        "locationUrl", /* configOverrides= */ null, /* sentIntent= */ null,
+                        /* messageId= */ 0L));
     }
 }