Bug 900850 - Part 1: Support accessing contacts of CDMA RUIM. r=allstars.chh
authorEdgar Chen <echen@mozilla.com>
Fri, 02 Aug 2013 16:13:32 +0800
changeset 141781 bee83df3c47d8de06e67f36b4d8e55ca3d454cc7
parent 141780 6d1b36d14a76705ec9e2b361659c197be46500b9
child 141782 733697c789e804d5f77a42c2970a07e78cf7570e
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersallstars.chh
bugs900850
milestone26.0a1
Bug 900850 - Part 1: Support accessing contacts of CDMA RUIM. r=allstars.chh
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -1160,16 +1160,17 @@ this.GECKO_ICC_SERVICES = {
     SPN: 19,
     DATA_DOWNLOAD_SMS_PP: 28,
     DATA_DOWNLOAD_SMS_CB: 29,
     PNN: 45,
     OPL: 46,
     SPDI: 51
   },
   ruim: {
+    ENHANCED_PHONEBOOK: 6,
     SPN: 17
   }
 };
 
 /**
  * Cell Broadcast constants
  */
 
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -10517,16 +10517,18 @@ let ICCFileHelper = {
    * This function handles EFs for RUIM
    */
   getRuimEFPath: function getRuimEFPath(fileId) {
     switch(fileId) {
       case ICC_EF_CSIM_CDMAHOME:
       case ICC_EF_CSIM_CST:
       case ICC_EF_CSIM_SPN:
         return EF_PATH_MF_SIM + EF_PATH_DF_CDMA;
+      case ICC_EF_FDN:
+        return EF_PATH_MF_SIM + EF_PATH_DF_TELECOM;
       default:
         return null;
     }
   },
 
   /**
    * Helper function for getting the pathId for the specific ICC record
    * depeding on which type of ICC card we are using.
@@ -11073,19 +11075,18 @@ let ICCRecordHelper = {
 
     function callback(options) {
       if (onsuccess) {
         onsuccess();
       }
     }
 
     if (!contact || !contact.recordId) {
-      if (onerror) {
-        onerror("Invalid parameter.");
-      }
+      let error = onerror || debug;
+      error(GECKO_ERROR_INVALID_PARAMETER);
       return;
     }
 
     ICCIOHelper.updateLinearFixedEF({fileId: fileId,
                                      recordNumber: contact.recordId,
                                      dataWriter: dataWriter.bind(this),
                                      pin2: pin2,
                                      callback: callback.bind(this),
@@ -11751,19 +11752,18 @@ let ICCRecordHelper = {
       }
 
       Buf.readStringDelimiter(strLen);
 
       if (options.p1 < options.totalRecords) {
         ICCIOHelper.loadNextRecord(options);
       } else {
         // No free record found.
-        if (onerror) {
-          onerror("No free record found.");
-        }
+        let error = onerror || debug;
+        error("No free record found.");
       }
     }
 
     ICCIOHelper.loadLinearFixedEF({fileId: fileId,
                                    callback: callback.bind(this),
                                    onerror: onerror});
   },
 
@@ -12218,72 +12218,85 @@ let ICCUtilsHelper = {
   },
 };
 
 /**
  * Helper for ICC Contacts.
  */
 let ICCContactHelper = {
   /**
+   * Helper function to check DF_PHONEBOOK.
+   */
+  hasDfPhoneBook: function hasDfPhoneBook(appType) {
+    switch (appType) {
+      case CARD_APPTYPE_SIM:
+        return false;
+      case CARD_APPTYPE_USIM:
+        return true;
+      case CARD_APPTYPE_RUIM:
+        return ICCUtilsHelper.isICCServiceAvailable("ENHANCED_PHONEBOOK");
+      default:
+        return false;
+    }
+  },
+
+  /**
    * Helper function to read ICC contacts.
    *
-   * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
+   * @param appType       One of CARD_APPTYPE_*.
    * @param contactType   "adn" or "fdn".
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   readICCContacts: function readICCContacts(appType, contactType, onsuccess, onerror) {
     switch (contactType) {
       case "adn":
-        switch (appType) {
-          case CARD_APPTYPE_SIM:
-            ICCRecordHelper.readADNLike(ICC_EF_ADN, onsuccess, onerror);
-            break;
-          case CARD_APPTYPE_USIM:
-            this.readUSimContacts(onsuccess, onerror);
-            break;
+        if (!this.hasDfPhoneBook(appType)) {
+          ICCRecordHelper.readADNLike(ICC_EF_ADN, onsuccess, onerror);
+        } else {
+          this.readUSimContacts(onsuccess, onerror);
         }
         break;
       case "fdn":
         ICCRecordHelper.readADNLike(ICC_EF_FDN, onsuccess, onerror);
         break;
+      default:
+        let error = onerror || debug;
+        error(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
+        break;
     }
   },
 
   /**
    * Helper function to find free contact record.
    *
-   * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
+   * @param appType       One of CARD_APPTYPE_*.
    * @param contactType   "adn" or "fdn".
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   findFreeICCContact: function findFreeICCContact(appType, contactType, onsuccess, onerror) {
     switch (contactType) {
       case "adn":
-        switch (appType) {
-          case CARD_APPTYPE_SIM:
-            ICCRecordHelper.findFreeRecordId(ICC_EF_ADN, onsuccess, onerror);
-            break;
-          case CARD_APPTYPE_USIM:
-            let gotPbrCb = function gotPbrCb(pbrs) {
-              this.findUSimFreeADNRecordId(pbrs, onsuccess, onerror);
-            }.bind(this);
-
-            ICCRecordHelper.readPBR(gotPbrCb, onerror);
-            break;
+        if (!this.hasDfPhoneBook(appType)) {
+          ICCRecordHelper.findFreeRecordId(ICC_EF_ADN, onsuccess, onerror);
+        } else {
+          let gotPbrCb = function gotPbrCb(pbrs) {
+            this.findUSimFreeADNRecordId(pbrs, onsuccess, onerror);
+          }.bind(this);
+
+          ICCRecordHelper.readPBR(gotPbrCb, onerror);
         }
         break;
       case "fdn":
         ICCRecordHelper.findFreeRecordId(ICC_EF_FDN, onsuccess, onerror);
         break;
       default:
-        if (onerror) {
-          onerror(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
-        }
+        let error = onerror || debug;
+        error(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
         break;
     }
   },
 
    /**
     * Find free ADN record id in USIM.
     *
     * @param pbrs          All Phonebook Reference Files read.
@@ -12306,17 +12319,17 @@ let ICCContactHelper = {
           findFreeRecordId.bind(this, pbrIndex + 1);
         }.bind(this));
     })(0);
   },
 
   /**
    * Helper function to add a new ICC contact.
    *
-   * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
+   * @param appType       One of CARD_APPTYPE_*.
    * @param contactType   "adn" or "fdn".
    * @param contact       The contact will be added.
    * @param pin2          PIN2 is required for FDN.
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   addICCContact: function addICCContact(appType, contactType, contact, pin2, onsuccess, onerror) {
     let foundFreeCb = function foundFreeCb(recordId) {
@@ -12326,42 +12339,38 @@ let ICCContactHelper = {
 
     // Find free record first.
     ICCContactHelper.findFreeICCContact(appType, contactType, foundFreeCb, onerror);
   },
 
   /**
    * Helper function to update ICC contact.
    *
-   * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
+   * @param appType       One of CARD_APPTYPE_*.
    * @param contactType   "adn" or "fdn".
    * @param contact       The contact will be updated.
    * @param pin2          PIN2 is required for FDN.
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   updateICCContact: function updateICCContact(appType, contactType, contact, pin2, onsuccess, onerror) {
     switch (contactType) {
       case "adn":
-        switch (appType) {
-          case CARD_APPTYPE_SIM:
-            ICCRecordHelper.updateADNLike(ICC_EF_ADN, contact, null, onsuccess, onerror);
-            break;
-          case CARD_APPTYPE_USIM:
-            this.updateUSimContact(contact, onsuccess, onerror);
-            break;
+        if (!this.hasDfPhoneBook(appType)) {
+          ICCRecordHelper.updateADNLike(ICC_EF_ADN, contact, null, onsuccess, onerror);
+        } else {
+          this.updateUSimContact(contact, onsuccess, onerror);
         }
         break;
       case "fdn":
         ICCRecordHelper.updateADNLike(ICC_EF_FDN, contact, pin2, onsuccess, onerror);
         break;
       default:
-        if (onerror) {
-          onerror(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
-        }
+        let error = onerror || debug;
+        error(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
         break;
     }
   },
 
   /**
    * Read contacts from USIM.
    *
    * @param onsuccess     Callback to be called when success.
@@ -12522,17 +12531,18 @@ let ICCContactHelper = {
       switch (ef) {
         case USIM_PBR_EMAIL:
           ICCRecordHelper.readEmail(fileId, fileType, recordId, gotFieldCb, onerror);
           break;
         case USIM_PBR_ANR:
           ICCRecordHelper.readANR(fileId, fileType, recordId, gotFieldCb, onerror);
           break;
         default:
-          onerror("Unknown field " + field);
+          let error = onerror || debug;
+          error("Unknown field " + field);
           break;
       }
     }.bind(this);
 
     this.getContactFieldRecordId(pbr, contact, field, gotRecordIdCb, onerror);
   },
 
   /**