Bug 945647 - [DSDS][MMS] When change primary outgoing data SIM during MMS attachment downloading, it should stop downloading process. r=vicamo,bevis a=v1.3+
authorGene Lian <clian@mozilla.com>
Mon, 27 Jan 2014 11:22:18 +0800
changeset 165529 a0489a2299c5bd31551cc4985bd2627789cdb083
parent 165528 b4a7eb17ce69b199722c4dfdad16643e69446930
child 165530 7422401971491c425769b3a9818f549e46e43d2b
push id26096
push userryanvm@gmail.com
push dateTue, 28 Jan 2014 21:12:38 +0000
treeherdermozilla-central@245b92f1de4f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo, bevis, v1.3
bugs945647
milestone29.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 945647 - [DSDS][MMS] When change primary outgoing data SIM during MMS attachment downloading, it should stop downloading process. r=vicamo,bevis a=v1.3+
dom/mobilemessage/src/gonk/MmsService.js
--- a/dom/mobilemessage/src/gonk/MmsService.js
+++ b/dom/mobilemessage/src/gonk/MmsService.js
@@ -54,18 +54,19 @@ const _HTTP_STATUS_USER_CANCELLED       
 const _HTTP_STATUS_RADIO_DISABLED              = -2;
 const _HTTP_STATUS_NO_SIM_CARD                 = -3;
 const _HTTP_STATUS_ACQUIRE_TIMEOUT             = -4;
 
 // Non-standard MMS status for internal use.
 const _MMS_ERROR_MESSAGE_DELETED               = -1;
 const _MMS_ERROR_RADIO_DISABLED                = -2;
 const _MMS_ERROR_NO_SIM_CARD                   = -3;
-const _MMS_ERROR_SHUTDOWN                      = -4;
-const _MMS_ERROR_USER_CANCELLED_NO_REASON      = -5;
+const _MMS_ERROR_SIM_CARD_CHANGED              = -4;
+const _MMS_ERROR_SHUTDOWN                      = -5;
+const _MMS_ERROR_USER_CANCELLED_NO_REASON      = -6;
 
 const CONFIG_SEND_REPORT_NEVER       = 0;
 const CONFIG_SEND_REPORT_DEFAULT_NO  = 1;
 const CONFIG_SEND_REPORT_DEFAULT_YES = 2;
 const CONFIG_SEND_REPORT_ALWAYS      = 3;
 
 const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
 
@@ -833,21 +834,25 @@ NotifyResponseTransaction.prototype = {
                                       null,
                                       this.istream,
                                       requestCallback);
   }
 };
 
 /**
  * CancellableTransaction - base class inherited by [Send|Retrieve]Transaction.
+ * We can call |cancelRunning(reason)| to cancel the on-going transaction.
  * @param cancellableId
  *        An ID used to keep track of if an message is deleted from DB.
+ * @param serviceId
+ *        An ID used to keep track of if the primary SIM service is changed.
  */
-function CancellableTransaction(cancellableId) {
+function CancellableTransaction(cancellableId, serviceId) {
   this.cancellableId = cancellableId;
+  this.serviceId = serviceId;
   this.isCancelled = false;
 }
 CancellableTransaction.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   // The timer for retrying sending or retrieving process.
   timer: null,
 
@@ -859,28 +864,30 @@ CancellableTransaction.prototype = {
 
   cancelledReason: _MMS_ERROR_USER_CANCELLED_NO_REASON,
 
   registerRunCallback: function(callback) {
     if (!this.isObserversAdded) {
       Services.obs.addObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
       Services.obs.addObserver(this, kMobileMessageDeletedObserverTopic, false);
       Services.prefs.addObserver(kPrefRilRadioDisabled, this, false);
+      Services.prefs.addObserver(kPrefDefaultServiceId, this, false);
       this.isObserversAdded = true;
     }
 
     this.runCallback = callback;
     this.isCancelled = false;
   },
 
   removeObservers: function() {
     if (this.isObserversAdded) {
       Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
       Services.obs.removeObserver(this, kMobileMessageDeletedObserverTopic);
       Services.prefs.removeObserver(kPrefRilRadioDisabled, this);
+      Services.prefs.removeObserver(kPrefDefaultServiceId, this);
       this.isObserversAdded = false;
     }
   },
 
   runCallbackIfValid: function(mmsStatus, msg) {
     this.removeObservers();
 
     if (this.runCallback) {
@@ -936,16 +943,19 @@ CancellableTransaction.prototype = {
           try {
             let radioDisabled = Services.prefs.getBoolPref(kPrefRilRadioDisabled);
             if (radioDisabled) {
               this.cancelRunning(_MMS_ERROR_RADIO_DISABLED);
             }
           } catch (e) {
             if (DEBUG) debug("Failed to get preference of 'ril.radio.disabled'.");
           }
+        } else if (data === kPrefDefaultServiceId &&
+                   this.serviceId != getDefaultServiceId()) {
+          this.cancelRunning(_MMS_ERROR_SIM_CARD_CHANGED);
         }
         break;
       }
     }
   }
 };
 
 /**
@@ -953,17 +963,17 @@ CancellableTransaction.prototype = {
  *
  * @param contentLocation
  *        X-Mms-Content-Location of the message.
  */
 function RetrieveTransaction(mmsConnection, cancellableId, contentLocation) {
   this.mmsConnection = mmsConnection;
 
   // Call |CancellableTransaction| constructor.
-  CancellableTransaction.call(this, cancellableId);
+  CancellableTransaction.call(this, cancellableId, mmsConnection.serviceId);
 
   this.contentLocation = contentLocation;
 }
 RetrieveTransaction.prototype = Object.create(CancellableTransaction.prototype, {
   /**
    * @param callback [optional]
    *        A callback function that takes two arguments: one for X-Mms-Status,
    *        the other for the parsed M-Retrieve.conf message.
@@ -1055,17 +1065,17 @@ RetrieveTransaction.prototype = Object.c
  * SendTransaction.
  *   Class for sending M-Send.req to MMSC, which inherits CancellableTransaction.
  *   @throws Error("Check max values parameters fail.")
  */
 function SendTransaction(mmsConnection, cancellableId, msg, requestDeliveryReport) {
   this.mmsConnection = mmsConnection;
 
   // Call |CancellableTransaction| constructor.
-  CancellableTransaction.call(this, cancellableId);
+  CancellableTransaction.call(this, cancellableId, mmsConnection.serviceId);
 
   msg.headers["x-mms-message-type"] = MMS.MMS_PDU_TYPE_SEND_REQ;
   if (!msg.headers["x-mms-transaction-id"]) {
     // Create an unique transaction id
     let tid = gUUIDGenerator.generateUUID().toString();
     msg.headers["x-mms-transaction-id"] = tid;
   }
   msg.headers["x-mms-mms-version"] = MMS.MMS_VERSION;
@@ -1634,17 +1644,18 @@ MmsService.prototype = {
     let reportAllowed = this.getReportAllowed(this.confSendDeliveryReport,
                                               wish);
     // If the mmsStatus isn't MMS_PDU_STATUS_RETRIEVED after retrieving,
     // something must be wrong with MMSC, so stop updating the DB record.
     // We could send a message to content to notify the user the MMS
     // retrieving failed. The end user has to retrieve the MMS again.
     if (MMS.MMS_PDU_STATUS_RETRIEVED !== mmsStatus) {
       if (mmsStatus != _MMS_ERROR_RADIO_DISABLED &&
-          mmsStatus != _MMS_ERROR_NO_SIM_CARD) {
+          mmsStatus != _MMS_ERROR_NO_SIM_CARD &&
+          mmsStatus != _MMS_ERROR_SIM_CARD_CHANGED) {
         let transaction = new NotifyResponseTransaction(mmsConnection,
                                                         transactionId,
                                                         mmsStatus,
                                                         reportAllowed);
         transaction.run();
       }
       // Retrieved fail after retry, so we update the delivery status in DB and
       // notify this domMessage that error happen.
@@ -2185,16 +2196,18 @@ MmsService.prototype = {
         if (DEBUG) debug("The sending status of sendTransaction.run(): " + aMmsStatus);
         let errorCode;
         if (aMmsStatus == _MMS_ERROR_MESSAGE_DELETED) {
           errorCode = Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR;
         } else if (aMmsStatus == _MMS_ERROR_RADIO_DISABLED) {
           errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
         } else if (aMmsStatus == _MMS_ERROR_NO_SIM_CARD) {
           errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
+        } else if (aMmsStatus == _MMS_ERROR_SIM_CARD_CHANGED) {
+          errorCode = Ci.nsIMobileMessageCallback.NON_ACTIVE_SIM_CARD_ERROR;
         } else if (aMmsStatus != MMS.MMS_PDU_ERROR_OK) {
           errorCode = Ci.nsIMobileMessageCallback.INTERNAL_ERROR;
         } else {
           errorCode = Ci.nsIMobileMessageCallback.SUCCESS_NO_ERROR;
         }
         let envelopeId =
           aMsg && aMsg.headers && aMsg.headers["message-id"] || null;
         sendTransactionCb(aDomMessage, errorCode, envelopeId);
@@ -2299,16 +2312,18 @@ MmsService.prototype = {
         // status to 'error'.
         if (MMS.MMS_PDU_STATUS_RETRIEVED !== mmsStatus) {
           if (DEBUG) debug("RetrieveMessage fail after retry.");
           let errorCode = Ci.nsIMobileMessageCallback.INTERNAL_ERROR;
           if (mmsStatus == _MMS_ERROR_RADIO_DISABLED) {
             errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
           } else if (mmsStatus == _MMS_ERROR_NO_SIM_CARD) {
             errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
+          } else if (mmsStatus == _MMS_ERROR_SIM_CARD_CHANGED) {
+            errorCode = Ci.nsIMobileMessageCallback.NON_ACTIVE_SIM_CARD_ERROR;
           }
           gMobileMessageDatabaseService
             .setMessageDeliveryByMessageId(aMessageId,
                                            null,
                                            null,
                                            DELIVERY_STATUS_ERROR,
                                            null,
                                            function() {