Bug 900321 - Part 2: Update RIL and test case. r=vicamo
authorYoshi Huang <allstars.chh@mozilla.com>
Mon, 05 Aug 2013 15:23:10 +0800
changeset 141785 4bb87898165aae5aafeafa462c7a046688c2e73c
parent 141784 6f84ea80219db592c7a7a9a44bafde02524dfbc6
child 141786 daaaa9227b48525ab07d3d810c5c3ceb85d51cf1
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersvicamo
bugs900321
milestone26.0a1
Bug 900321 - Part 2: Update RIL and test case. r=vicamo
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
dom/system/gonk/tests/test_ril_worker_icc.js
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -2327,36 +2327,56 @@ this.CALL_FAIL_IMSI_UNKNOWN_IN_VLR = 242
 this.CALL_FAIL_IMEI_NOT_ACCEPTED = 243;
 this.CALL_FAIL_ERROR_UNSPECIFIED = 0xffff;
 
 // Other Gecko-specific constants
 this.GECKO_RADIOSTATE_UNAVAILABLE   = null;
 this.GECKO_RADIOSTATE_OFF           = "off";
 this.GECKO_RADIOSTATE_READY         = "ready";
 
-this.GECKO_CARDSTATE_NOT_READY               = null;
-this.GECKO_CARDSTATE_UNKNOWN                 = "unknown";
-this.GECKO_CARDSTATE_ABSENT                  = "absent";
-this.GECKO_CARDSTATE_PIN_REQUIRED            = "pinRequired";
-this.GECKO_CARDSTATE_PUK_REQUIRED            = "pukRequired";
-this.GECKO_CARDSTATE_NETWORK_LOCKED          = "networkLocked";
-this.GECKO_CARDSTATE_CORPORATE_LOCKED        = "corporateLocked";
-this.GECKO_CARDSTATE_SERVICE_PROVIDER_LOCKED = "serviceProviderLocked";
-this.GECKO_CARDSTATE_READY                   = "ready";
+this.GECKO_CARDSTATE_NOT_READY                     = null;
+this.GECKO_CARDSTATE_UNKNOWN                       = "unknown";
+this.GECKO_CARDSTATE_ABSENT                        = "absent";
+this.GECKO_CARDSTATE_PIN_REQUIRED                  = "pinRequired";
+this.GECKO_CARDSTATE_PUK_REQUIRED                  = "pukRequired";
+this.GECKO_CARDSTATE_PERSONALIZATION_IN_PROGRESS   = "personalizationInProgress";
+this.GECKO_CARDSTATE_NETWORK_LOCKED                = "networkLocked";
+this.GECKO_CARDSTATE_NETWORK_SUBSET_LOCKED         = "networkSubsetLocked";
+this.GECKO_CARDSTATE_CORPORATE_LOCKED              = "corporateLocked";
+this.GECKO_CARDSTATE_SERVICE_PROVIDER_LOCKED       = "serviceProviderLocked";
+this.GECKO_CARDSTATE_SIM_LOCKED                    = "simPersonalizationLock";
+this.GECKO_CARDSTATE_NETWORK_PUK_REQUIRED          = "networkPukRequired";
+this.GECKO_CARDSTATE_NETWORK_SUBSET_PUK_REQUIRED   = "networkSubsetPukRequired";
+this.GECKO_CARDSTATE_CORPORATE_PUK_REQUIRED        = "corporatePukRequired";
+this.GECKO_CARDSTATE_SERVICE_PROVIDER_PUK_REQUIRED = "serviceProviderPukRequired";
+this.GECKO_CARDSTATE_SIM_PUK_REQUIRED              = "simPersonalizationPukRequired";
+this.GECKO_CARDSTATE_READY                         = "ready";
 
 // See ril.h RIL_PersoSubstate
 this.PERSONSUBSTATE = {};
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_UNKNOWN] = GECKO_CARDSTATE_UNKNOWN;
-PERSONSUBSTATE[CARD_PERSOSUBSTATE_IN_PROGRESS] = "inProgress";
-PERSONSUBSTATE[CARD_PERSOSUBSTATE_READY] = GECKO_CARDSTATE_READY;
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_IN_PROGRESS] = GECKO_CARDSTATE_PERSONALIZATION_IN_PROGRESS;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK] = GECKO_CARDSTATE_NETWORK_LOCKED;
-PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET] = "networkSubsetLocked";
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET] = GECKO_CARDSTATE_NETWORK_SUBSET_LOCKED;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_CORPORATE] = GECKO_CARDSTATE_CORPORATE_LOCKED;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER] = GECKO_CARDSTATE_SERVICE_PROVIDER_LOCKED;
-PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_SIM] = "simPersonalizationLock";
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_SIM] = GECKO_CARDSTATE_SIM_LOCKED;
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK_PUK] = GECKO_CARDSTATE_NETWORK_PUK_REQUIRED;
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK] = GECKO_CARDSTATE_NETWORK_SUBSET_PUK_REQUIRED;
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_CORPORATE_PUK] = GECKO_CARDSTATE_CORPORATE_PUK_REQUIRED;
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK] = GECKO_CARDSTATE_SERVICE_PROVIDER_PUK_REQUIRED;
+PERSONSUBSTATE[CARD_PERSOSUBSTATE_READY] = GECKO_CARDSTATE_READY;
+
+this.GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK = {};
+GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK["nck"] = CARD_PERSOSUBSTATE_SIM_NETWORK;
+GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK["cck"] = CARD_PERSOSUBSTATE_SIM_CORPORATE;
+GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK["spck"] = CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER;
+GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK["nckPuk"] = CARD_PERSOSUBSTATE_SIM_NETWORK_PUK;
+GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK["cckPuk"] = CARD_PERSOSUBSTATE_SIM_CORPORATE_PUK;
+GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK["spckPuk"] = CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK;
 
 this.GECKO_NETWORK_SELECTION_UNKNOWN   = null;
 this.GECKO_NETWORK_SELECTION_AUTOMATIC = "automatic";
 this.GECKO_NETWORK_SELECTION_MANUAL    = "manual";
 
 this.GECKO_MOBILE_CONNECTION_STATE_UNKNOWN = null;
 this.GECKO_MOBILE_CONNECTION_STATE_NOTSEARCHING = "notSearching";
 this.GECKO_MOBILE_CONNECTION_STATE_SEARCHING = "searching";
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -975,27 +975,29 @@ let RIL = {
         break;
       case "puk":
         this.enterICCPUK(options);
         break;
       case "puk2":
         this.enterICCPUK2(options);
         break;
       case "nck":
-        options.type = CARD_PERSOSUBSTATE_SIM_NETWORK;
-        this.enterDepersonalization(options);
-        break;
-      case "cck":
-        options.type = CARD_PERSOSUBSTATE_SIM_CORPORATE;
-        this.enterDepersonalization(options);
-        break;
-      case "spck":
-        options.type = CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER;
-        this.enterDepersonalization(options);
-        break;
+      case "cck": // Fall through.
+      case "spck": {
+        let type = GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK[options.lockType];
+        this.enterDepersonalization(type, options.pin, options);
+        break;
+      }
+      case "nckPuk":
+      case "cckPuk": // Fall through.
+      case "spckPuk": {
+        let type = GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK[options.lockType];
+        this.enterDepersonalization(type, options.puk, options);
+        break;
+      }
       default:
         options.errorMsg = "Unsupported Card Lock.";
         options.success = false;
         this.sendChromeMessage(options);
     }
   },
 
   /**
@@ -1034,23 +1036,23 @@ let RIL = {
     Buf.sendParcel();
   },
 
   /**
    * Requests a network personalization be deactivated.
    *
    * @param type
    *        Integer indicating the network personalization be deactivated.
-   * @param pin
-   *        String containing the pin.
-   */
-  enterDepersonalization: function enterDepersonalization(options) {
+   * @param password
+   *        String containing the password.
+   */
+  enterDepersonalization: function enterDepersonalization(type, password, options) {
     Buf.newParcel(REQUEST_ENTER_NETWORK_DEPERSONALIZATION_CODE, options);
-    Buf.writeUint32(options.type);
-    Buf.writeString(options.pin);
+    Buf.writeUint32(type);
+    Buf.writeString(password);
     Buf.sendParcel();
   },
 
   /**
    * Helper function for changing ICC locks.
    */
   iccSetCardLock: function iccSetCardLock(options) {
     if (options.newPin !== undefined) { // Change PIN lock.
--- a/dom/system/gonk/tests/test_ril_worker_icc.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc.js
@@ -2671,92 +2671,91 @@ add_test(function test_find_free_icc_con
   let errorCb = function (errorMsg) {
     do_check_true(false);
     run_next_test();
   };
 
   contactHelper.findFreeICCContact(CARD_APPTYPE_USIM, "adn", successCb, errorCb);
 });
 
-/**
- * Verify cardState 'corporateLocked'.
- */
-add_test(function test_card_state_corporateLocked() {
+add_test(function test_personalization_state() {
   let worker = newUint8Worker();
   let ril = worker.RIL;
-  let iccStatus = {
-    gsmUmtsSubscriptionAppIndex: 0,
-    apps: [
-      {
-        app_state: CARD_APPSTATE_SUBSCRIPTION_PERSO,
-        perso_substate: CARD_PERSOSUBSTATE_SIM_CORPORATE
-      }],
-  };
-
-  ril._processICCStatus(iccStatus);
-  do_check_eq(ril.cardState, GECKO_CARDSTATE_CORPORATE_LOCKED);
+
+  function testPersonalization(cardPersoState, geckoCardState) {
+    let iccStatus = {
+      gsmUmtsSubscriptionAppIndex: 0,
+      apps: [
+        {
+          app_state: CARD_APPSTATE_SUBSCRIPTION_PERSO,
+          perso_substate: cardPersoState
+        }],
+    };
+
+    ril._processICCStatus(iccStatus);
+    do_check_eq(ril.cardState, geckoCardState);
+  }
+
+  testPersonalization(CARD_PERSOSUBSTATE_SIM_NETWORK,
+                      GECKO_CARDSTATE_NETWORK_LOCKED);
+  testPersonalization(CARD_PERSOSUBSTATE_SIM_CORPORATE,
+                      GECKO_CARDSTATE_CORPORATE_LOCKED);
+  testPersonalization(CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
+                      GECKO_CARDSTATE_SERVICE_PROVIDER_LOCKED);
+  testPersonalization(CARD_PERSOSUBSTATE_SIM_NETWORK_PUK,
+                      GECKO_CARDSTATE_NETWORK_PUK_REQUIRED);
+  testPersonalization(CARD_PERSOSUBSTATE_SIM_CORPORATE_PUK,
+                      GECKO_CARDSTATE_CORPORATE_PUK_REQUIRED);
+  testPersonalization(CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK,
+                      GECKO_CARDSTATE_SERVICE_PROVIDER_PUK_REQUIRED);
 
   run_next_test();
 });
 
 /**
- * Verify cardState 'serviceProviderLocked'.
- */
-add_test(function test_card_state_serviceProviderLocked() {
-  let worker = newUint8Worker();
-  let ril = worker.RIL;
-  let iccStatus = {
-    gsmUmtsSubscriptionAppIndex: 0,
-    apps: [
-      {
-        app_state: CARD_APPSTATE_SUBSCRIPTION_PERSO,
-        perso_substate: CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER
-      }],
-  };
-
-  ril._processICCStatus(iccStatus);
-  do_check_eq(ril.cardState, GECKO_CARDSTATE_SERVICE_PROVIDER_LOCKED);
-
-  run_next_test();
-});
-
-/**
- * Verify iccUnlockCardLock with lockType is "cck" and "spck".
+ * Verify iccUnlockCardLock.
  */
 add_test(function test_unlock_card_lock_corporateLocked() {
   let worker = newUint8Worker();
   let ril = worker.RIL;
   let buf = worker.Buf;
   const pin = "12345678";
-
-  function do_test(aLock, aPin) {
+  const puk = "12345678";
+
+  function do_test(aLock, aPassword) {
     buf.sendParcel = function fakeSendParcel () {
       // Request Type.
       do_check_eq(this.readUint32(), REQUEST_ENTER_NETWORK_DEPERSONALIZATION_CODE);
 
       // Token : we don't care
       this.readUint32();
 
-      let lockType = aLock === "cck" ?
-                     CARD_PERSOSUBSTATE_SIM_CORPORATE :
-                     CARD_PERSOSUBSTATE_SIM_SERVICE_PROVIDER;
-
+      let lockType = GECKO_PERSO_LOCK_TO_CARD_PERSO_LOCK[aLock];
       // Lock Type
       do_check_eq(this.readUint32(), lockType);
 
-      // Pin.
-      do_check_eq(this.readString(), aPin);
+      // Pin/Puk.
+      do_check_eq(this.readString(), aPassword);
     };
 
-    ril.iccUnlockCardLock({lockType: aLock,
-                           pin: aPin});
+    if (aLock.endsWith("Puk")) {
+      ril.iccUnlockCardLock({lockType: aLock,
+                             puk: aPassword});
+    } else {
+      ril.iccUnlockCardLock({lockType: aLock,
+                             pin: aPassword});
+    }
   }
 
+  do_test("nck", pin);
   do_test("cck", pin);
   do_test("spck", pin);
+  do_test("nckPuk", puk);
+  do_test("cckPuk", puk);
+  do_test("spckPuk", puk);
 
   run_next_test();
 });
 
 /**
  * Verify MCC and MNC parsing
  */
 add_test(function test_mcc_mnc_parsing() {