Bug 943350 - [B2G][DSDS] Gecko needs to properly download MMS for non-active SIM (follow-up fix). r=vicamo
authorGene Lian <clian@mozilla.com>
Wed, 27 Nov 2013 11:50:49 +0800
changeset 157738 bf4079fa03e56d8cf88dc0ac0751dc817de83460
parent 157737 4646c42ccb99b23ee5ccbbbf39130dd4951c784e
child 157739 ba1fc388f146c3a84839fea24e8c6e32c0422a1b
push id25722
push useremorley@mozilla.com
push dateWed, 27 Nov 2013 16:45:44 +0000
treeherdermozilla-central@5eb1c89fc2bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs943350
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 943350 - [B2G][DSDS] Gecko needs to properly download MMS for non-active SIM (follow-up fix). r=vicamo
dom/mobilemessage/src/gonk/MmsService.js
--- a/dom/mobilemessage/src/gonk/MmsService.js
+++ b/dom/mobilemessage/src/gonk/MmsService.js
@@ -1426,19 +1426,20 @@ MmsService.prototype = {
    *
    * @param mmsConnection
    *        The MMS connection.
    * @param retrievalMode
    *        Retrieval mode for MMS receiving setting.
    * @param intermediate
    *        Intermediate MMS message parsed from PDU.
    */
-  convertIntermediateToSavable: function convertIntermediateToSavable(mmsConnection,
-                                                                      intermediate,
-                                                                      retrievalMode) {
+  convertIntermediateToSavable:
+    function convertIntermediateToSavable(mmsConnection,
+                                          intermediate,
+                                          retrievalMode) {
     intermediate.type = "mms";
     intermediate.delivery = DELIVERY_NOT_DOWNLOADED;
 
     let deliveryStatus;
     switch (retrievalMode) {
       case RETRIEVAL_MODE_MANUAL:
         deliveryStatus = DELIVERY_STATUS_MANUAL;
         break;
@@ -1677,21 +1678,22 @@ MmsService.prototype = {
 
       this.broadcastReceivedMessageEvent(domMessage);
     }).bind(this));
   },
 
   /**
    * Callback for saveReceivedMessage.
    */
-  saveReceivedMessageCallback: function saveReceivedMessageCallback(mmsConnection,
-                                                                    retrievalMode,
-                                                                    savableMessage,
-                                                                    rv,
-                                                                    domMessage) {
+  saveReceivedMessageCallback:
+    function saveReceivedMessageCallback(mmsConnection,
+                                         retrievalMode,
+                                         savableMessage,
+                                         rv,
+                                         domMessage) {
     let success = Components.isSuccessCode(rv);
     if (!success) {
       // At this point we could send a message to content to notify the
       // user that storing an incoming MMS notification indication failed,
       // ost likely due to a full disk.
       if (DEBUG) debug("Could not store MMS " + JSON.stringify(savableMessage) +
             ", error code " + rv);
       // Because MMSC will resend the notification indication once we don't
@@ -1701,31 +1703,23 @@ MmsService.prototype = {
     }
 
     // For X-Mms-Report-Allowed and X-Mms-Transaction-Id
     let wish = savableMessage.headers["x-mms-delivery-report"];
     let transactionId = savableMessage.headers["x-mms-transaction-id"];
 
     this.broadcastReceivedMessageEvent(domMessage);
 
-    // In the roaming environment, we send notify response only for the
-    // automatic retrieval mode.
-    if ((retrievalMode !== RETRIEVAL_MODE_AUTOMATIC) &&
+    // To avoid costing money, we only send notify response when it's under
+    // the "automatic" retrieval mode or it's not in the roaming environment.
+    if (retrievalMode !== RETRIEVAL_MODE_AUTOMATIC &&
         mmsConnection.isVoiceRoaming()) {
       return;
     }
 
-    // Under the "automatic" retrieval mode, for the non-active SIM, we have to
-    // download the MMS as if it is downloaded by the "manual" retrieval mode.
-    if ((retrievalMode == RETRIEVAL_MODE_AUTOMATIC ||
-         retrievalMode == RETRIEVAL_MODE_AUTOMATIC_HOME) &&
-        mmsConnection.serviceId != this.mmsDefaultServiceId) {
-      retrievalMode = RETRIEVAL_MODE_MANUAL;
-    }
-
     if (RETRIEVAL_MODE_MANUAL === retrievalMode ||
         RETRIEVAL_MODE_NEVER === retrievalMode) {
       let mmsStatus = RETRIEVAL_MODE_NEVER === retrievalMode
                     ? MMS.MMS_PDU_STATUS_REJECTED
                     : MMS.MMS_PDU_STATUS_DEFERRED;
 
       // For X-Mms-Report-Allowed
       let reportAllowed = this.getReportAllowed(this.confSendDeliveryReport,
@@ -1772,27 +1766,43 @@ MmsService.prototype = {
         return;
       }
 
       let retrievalMode = RETRIEVAL_MODE_MANUAL;
       try {
         retrievalMode = Services.prefs.getCharPref(kPrefRetrievalMode);
       } catch (e) {}
 
+      // Under the "automatic"/"automatic-home" retrieval mode, we switch to
+      // the "manual" retrieval mode to download MMS for non-active SIM.
+      if ((retrievalMode == RETRIEVAL_MODE_AUTOMATIC ||
+           retrievalMode == RETRIEVAL_MODE_AUTOMATIC_HOME) &&
+          serviceId != this.mmsDefaultServiceId) {
+        if (DEBUG) {
+          debug("Switch to 'manual' mode to download MMS for non-active SIM: " +
+                "serviceId = " + serviceId + " doesn't equal to " +
+                "mmsDefaultServiceId = " + this.mmsDefaultServiceId);
+        }
+
+        retrievalMode = RETRIEVAL_MODE_MANUAL;
+      }
+
       let mmsConnection = gMmsConnections.getConnByServiceId(serviceId);
+
       let savableMessage = this.convertIntermediateToSavable(mmsConnection,
                                                              notification,
                                                              retrievalMode);
 
       gMobileMessageDatabaseService
         .saveReceivedMessage(savableMessage,
-                             this.saveReceivedMessageCallback.bind(this,
-                                                                   mmsConnection,
-                                                                   retrievalMode,
-                                                                   savableMessage));
+                             this.saveReceivedMessageCallback
+                                 .bind(this,
+                                       mmsConnection,
+                                       retrievalMode,
+                                       savableMessage));
     }).bind(this));
   },
 
   /**
    * Handle incoming M-Delivery.ind PDU.
    *
    * @param aMsg
    *        The MMS message object.