Bug 873380 - Part 3: RIL changes for icc card lock error. r=allstars.chh
authorEdgar Chen <echen@mozilla.com>
Wed, 25 Sep 2013 16:14:23 +0800
changeset 164250 365bc42758cd71e2c086cd44e27d58099acde782
parent 164249 1f391cd3728eb52bfec4f029b5539f773b8c6ff9
child 164251 7e6ef5e5ec5256f76bab5626286129e6945883c6
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars.chh
bugs873380
milestone27.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 873380 - Part 3: RIL changes for icc card lock error. r=allstars.chh
dom/icc/tests/marionette/test_icc_card_lock.js
dom/system/gonk/RILContentHelper.js
dom/system/gonk/RadioInterfaceLayer.manifest
--- a/dom/icc/tests/marionette/test_icc_card_lock.js
+++ b/dom/icc/tests/marionette/test_icc_card_lock.js
@@ -33,43 +33,24 @@ function testPinChangeFailed() {
      pin: "1111",
      newPin: "0000"});
 
   ok(request instanceof DOMRequest,
      "request instanceof " + request.constructor);
 
   request.onerror = function onerror() {
     is(request.error.name, "IncorrectPassword");
+    is(request.error.lockType, "pin");
+    // The default pin retries is 3, failed once becomes to 2
+    is(request.error.retryCount, 2);
 
     resetPinRetries("0000", runNextTest);
   };
 }
 
-/* Test PIN code changes fail notification */
-function testPinChangeFailedNotification() {
-  icc.addEventListener("icccardlockerror", function onicccardlockerror(result) {
-    icc.removeEventListener("icccardlockerror", onicccardlockerror);
-
-    is(result.lockType, "pin");
-    // The default pin retries is 3, failed once becomes to 2
-    is(result.retryCount, 2);
-
-    resetPinRetries("0000", runNextTest);
-  });
-
-  // The default pin is '0000' in emulator
-  let request = icc.setCardLock(
-    {lockType: "pin",
-     pin: "1111",
-     newPin: "0000"});
-
-  ok(request instanceof DOMRequest,
-     "request instanceof " + request.constructor);
-}
-
 /* Test PIN code changes success */
 function testPinChangeSuccess() {
   // The default pin is '0000' in emulator
   let request = icc.setCardLock(
     {lockType: "pin",
      pin: "0000",
      newPin: "0000"});
 
@@ -154,17 +135,16 @@ function testInvalidCardLockRetryCount()
     is(request.error.name, 'GenericFailure',
         'error name is ' + request.error.name);
     runNextTest();
   };
 }
 
 let tests = [
   testPinChangeFailed,
-  testPinChangeFailedNotification,
   testPinChangeSuccess,
   testPinCardLockRetryCount,
   testPukCardLockRetryCount,
   testInvalidCardLockRetryCount
 ];
 
 function runNextTest() {
   let test = tests.shift();
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -60,16 +60,18 @@ const VOICEMAILSTATUS_CID=
 const MOBILECFINFO_CID=
   Components.ID("{a4756f16-e728-4d9f-8baa-8464f894888a}");
 const CELLBROADCASTMESSAGE_CID =
   Components.ID("{29474c96-3099-486f-bb4a-3c9a1da834e4}");
 const CELLBROADCASTETWSINFO_CID =
   Components.ID("{59f176ee-9dcd-4005-9d47-f6be0cd08e17}");
 const DOMMMIERROR_CID =
   Components.ID("{6b204c42-7928-4e71-89ad-f90cd82aff96}");
+const ICCCARDLOCKERROR_CID =
+  Components.ID("{08a71987-408c-44ff-93fd-177c0a85c3dd}");
 
 const RIL_IPC_MSG_NAMES = [
   "RIL:CardStateChanged",
   "RIL:IccInfoChanged",
   "RIL:VoiceInfoChanged",
   "RIL:DataInfoChanged",
   "RIL:GetAvailableNetworks",
   "RIL:NetworkSelectionModeChanged",
@@ -427,16 +429,30 @@ DOMMMIError.prototype = {
                    message,
                    additionalInformation) {
     this.__DOM_IMPL__.init(name, message);
     this.serviceCode = serviceCode;
     this.additionalInformation = additionalInformation;
   },
 };
 
+function IccCardLockError() {
+}
+IccCardLockError.prototype = {
+  classDescription: "IccCardLockError",
+  classID:          ICCCARDLOCKERROR_CID,
+  contractID:       "@mozilla.org/dom/icccardlock-error;1",
+  QueryInterface:   XPCOMUtils.generateQI([Ci.nsISupports]),
+  __init: function(lockType, errorMsg, retryCount) {
+    this.__DOM_IMPL__.init(errorMsg);
+    this.lockType = lockType;
+    this.retryCount = retryCount;
+  },
+};
+
 function RILContentHelper() {
   this.rilContext = {
     cardState:            RIL.GECKO_CARDSTATE_UNKNOWN,
     networkSelectionMode: RIL.GECKO_NETWORK_SELECTION_UNKNOWN,
     iccInfo:              null,
     voiceConnectionInfo:  new MobileConnectionInfo(),
     dataConnectionInfo:   new MobileConnectionInfo()
   };
@@ -769,16 +785,18 @@ RILContentHelper.prototype = {
 
   getCardLockState: function getCardLockState(window, lockType) {
     if (window == null) {
       throw Components.Exception("Can't get window object",
                                   Cr.NS_ERROR_UNEXPECTED);
     }
     let request = Services.DOMRequest.createRequest(window);
     let requestId = this.getRequestId(request);
+    this._windowsMap[requestId] = window;
+
     cpmm.sendAsyncMessage("RIL:GetCardLockState", {
       clientId: 0,
       data: {
         lockType: lockType,
         requestId: requestId
       }
     });
     return request;
@@ -786,30 +804,34 @@ RILContentHelper.prototype = {
 
   unlockCardLock: function unlockCardLock(window, info) {
     if (window == null) {
       throw Components.Exception("Can't get window object",
                                   Cr.NS_ERROR_UNEXPECTED);
     }
     let request = Services.DOMRequest.createRequest(window);
     info.requestId = this.getRequestId(request);
+    this._windowsMap[info.requestId] = window;
+
     cpmm.sendAsyncMessage("RIL:UnlockCardLock", {
       clientId: 0,
       data: info
     });
     return request;
   },
 
   setCardLock: function setCardLock(window, info) {
     if (window == null) {
       throw Components.Exception("Can't get window object",
                                   Cr.NS_ERROR_UNEXPECTED);
     }
     let request = Services.DOMRequest.createRequest(window);
     info.requestId = this.getRequestId(request);
+    this._windowsMap[info.requestId] = window;
+
     cpmm.sendAsyncMessage("RIL:SetCardLock", {
       clientId: 0,
       data: info
     });
     return request;
   },
 
   getCardLockRetryCount: function getCardLockRetryCount(window, lockType) {
@@ -1433,16 +1455,29 @@ RILContentHelper.prototype = {
 
   dispatchFireRequestError: function dispatchFireRequestError(requestId, error) {
     let currentThread = Services.tm.currentThread;
 
     currentThread.dispatch(this.fireRequestError.bind(this, requestId, error),
                            Ci.nsIThread.DISPATCH_NORMAL);
   },
 
+  fireRequestDetailedError: function fireRequestDetailedError(requestId, detailedError) {
+    let request = this.takeRequest(requestId);
+    if (!request) {
+      if (DEBUG) {
+        debug("not firing detailed error for id: " + requestId +
+              ", detailedError: " + JSON.stringify(detailedError));
+      }
+      return;
+    }
+
+    Services.DOMRequest.fireDetailedError(request, detailedError);
+  },
+
   receiveMessage: function receiveMessage(msg) {
     let request;
     debug("Received message '" + msg.name + "': " + JSON.stringify(msg.json));
 
     let data = msg.json.data;
     switch (msg.name) {
       case "RIL:CardStateChanged":
         if (this.rilContext.cardState != data.cardState) {
@@ -1490,30 +1525,37 @@ RILContentHelper.prototype = {
                                  RIL.GECKO_NETWORK_SELECTION_AUTOMATIC);
         break;
       case "RIL:VoicemailNotification":
         this.handleVoicemailNotification(data);
         break;
       case "RIL:VoicemailInfoChanged":
         this.updateInfo(data, this.voicemailInfo);
         break;
-      case "RIL:CardLockResult":
+      case "RIL:CardLockResult": {
+        let requestId = data.requestId;
+        let requestWindow = this._windowsMap[requestId];
+        delete this._windowsMap[requestId];
+
         if (data.success) {
           let result = new MobileIccCardLockResult(data);
-          this.fireRequestSuccess(data.requestId, result);
+          this.fireRequestSuccess(requestId, result);
         } else {
           if (data.rilMessageType == "iccSetCardLock" ||
               data.rilMessageType == "iccUnlockCardLock") {
-            this._deliverEvent("_iccListeners",
-                               "notifyIccCardLockError",
-                               [data.lockType, data.retryCount]);
+            let cardLockError = new requestWindow.IccCardLockError(data.lockType,
+                                                                   data.errorMsg,
+                                                                   data.retryCount);
+            this.fireRequestDetailedError(requestId, cardLockError);
+          } else {
+            this.fireRequestError(requestId, data.errorMsg);
           }
-          this.fireRequestError(data.requestId, data.errorMsg);
         }
         break;
+      }
       case "RIL:CardLockRetryCount":
         if (data.success) {
           let result = new MobileIccCardLockRetryCount(data);
           this.fireRequestSuccess(data.requestId, result);
         } else {
           this.fireRequestError(data.requestId, data.errorMsg);
         }
         break;
@@ -1921,10 +1963,11 @@ RILContentHelper.prototype = {
       return false;
     }
 
     return true;
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RILContentHelper,
-                                                     DOMMMIError]);
+                                                     DOMMMIError,
+                                                     IccCardLockError]);
 
--- a/dom/system/gonk/RadioInterfaceLayer.manifest
+++ b/dom/system/gonk/RadioInterfaceLayer.manifest
@@ -15,11 +15,13 @@
 # RadioInterfaceLayer.js
 component {2d831c8d-6017-435b-a80c-e5d422810cea} RadioInterfaceLayer.js
 contract @mozilla.org/ril;1 {2d831c8d-6017-435b-a80c-e5d422810cea}
 category profile-after-change RadioInterfaceLayer @mozilla.org/ril;1
 
 # RILContentHelper.js
 component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js
 component {6b204c42-7928-4e71-89ad-f90cd82aff96} RILContentHelper.js
+component {08a71987-408c-44ff-93fd-177c0a85c3dd} RILContentHelper.js
 contract @mozilla.org/ril/content-helper;1 {472816e1-1fd6-4405-996c-806f9ea68174}
 contract @mozilla.org/dom/mmi-error;1 {6b204c42-7928-4e71-89ad-f90cd82aff96}
+contract @mozilla.org/dom/icccardlock-error;1 {08a71987-408c-44ff-93fd-177c0a85c3dd}
 category profile-after-change RILContentHelper @mozilla.org/ril/content-helper;1