Bug 945647 - [DSDS][MMS] When change primary outgoing data SIM during MMS attachment downloading, it should stop downloading process. r=vicamo, r=bevis, a=1.3+
authorGene Lian <clian@mozilla.com>
Mon, 27 Jan 2014 11:22:18 +0800
changeset 176052 0596865af40ecd3455894949728b9a3d6368f110
parent 176051 07f77213ecf1ff028407968c39b136004b11dedf
child 176053 a20477cb1190c09a2a82d0a7038f2d56bc8fcdf2
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo, bevis, 1
bugs945647
milestone28.0a2
Bug 945647 - [DSDS][MMS] When change primary outgoing data SIM during MMS attachment downloading, it should stop downloading process. r=vicamo, r=bevis, a=1.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";
 
@@ -836,21 +837,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,
 
@@ -862,28 +867,30 @@ CancellableTransaction.prototype = {
 
   cancelledReason: _MMS_ERROR_USER_CANCELLED_NO_REASON,
 
   registerRunCallback: function registerRunCallback(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 removeObservers() {
     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 runCallbackIfValid(mmsStatus, msg) {
     this.removeObservers();
 
     if (this.runCallback) {
@@ -939,16 +946,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;
       }
     }
   }
 };
 
 /**
@@ -956,17 +966,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.
@@ -1058,17 +1068,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;
@@ -1640,17 +1650,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.
@@ -2198,16 +2209,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);
@@ -2312,16 +2325,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 () {