Bug 835802 - Part 1: Support more phonebook sets when reading ICC contact. r=vicamo
authorYoshi Huang <allstars.chh@mozilla.com>
Tue, 26 Feb 2013 18:29:58 +0800
changeset 141716 e465ed12846dd6cf257ddefc888abbb0dfb3273e
parent 141715 8f4cc68ae3c22b0194d5a320f6f896370e9ceaa5
child 141717 502bedabba41084554518cf1b787d1deccb40e88
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs835802
milestone23.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 835802 - Part 1: Support more phonebook sets when reading ICC contact. r=vicamo
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -48,16 +48,18 @@ const UINT8_SIZE  = 1;
 const UINT16_SIZE = 2;
 const UINT32_SIZE = 4;
 const PARCEL_SIZE_SIZE = UINT32_SIZE;
 
 const PDU_HEX_OCTET_SIZE = 4;
 
 const DEFAULT_EMERGENCY_NUMBERS = ["112", "911"];
 
+const ICC_MAX_LINEAR_FIXED_RECORDS = 0xfe;
+
 // MMI match groups
 const MMI_MATCH_GROUP_FULL_MMI = 1;
 const MMI_MATCH_GROUP_MMI_PROCEDURE = 2;
 const MMI_MATCH_GROUP_SERVICE_CODE = 3;
 const MMI_MATCH_GROUP_SIA = 5;
 const MMI_MATCH_GROUP_SIB = 7;
 const MMI_MATCH_GROUP_SIC = 9;
 const MMI_MATCH_GROUP_PWD_CONFIRM = 11;
@@ -10354,21 +10356,34 @@ let ICCRecordHelper = {
 
       if (pbrTlvs.length == 0) {
         let error = onerror || debug;
         error("Cannot access Phonebook.");
         return;
       }
 
       let pbr = ICCUtilsHelper.parsePbrTlvs(pbrTlvs);
-      if (onsuccess) {
-        onsuccess(pbr);
-      }
-    }
-
+      // EF_ADN is mandatory if and only if DF_PHONEBOOK is present.
+      if (!pbr.adn) {
+        let error = onerror || debug;
+        error("Cannot access ADN.");
+        return;
+      }
+      pbrs.push(pbr);
+
+      if (options.p1 < options.totalRecords) {
+        ICCIOHelper.loadNextRecord(options);
+      } else {
+        if (onsuccess) {
+          onsuccess(pbrs);
+        }
+      }
+    }
+
+    let pbrs = [];
     ICCIOHelper.loadLinearFixedEF({fileId : ICC_EF_PBR,
                                    callback: callback.bind(this),
                                    onerror: onerror});
   },
 
   /**
    * Cache EF_IAP record size.
    */
@@ -11416,45 +11431,83 @@ let ICCContactHelper = {
 
   /**
    * Read contacts from USIM.
    *
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   readUSimContacts: function readUSimContacts(onsuccess, onerror) {
-    let gotPbrCb = function gotPbrCb(pbr) {
-      if (pbr.adn) {
-        let gotAdnCb = function gotAdnCb(contacts) {
-          this.readSupportedPBRFields(pbr, contacts, onsuccess, onerror);
-        }.bind(this);
-
-        let fileId = pbr.adn.fileId;
-        ICCRecordHelper.readADNLike(fileId, gotAdnCb, onerror);
-      } else {
-        let error = onerror || debug;
-        error("Cannot access ADN.");
-      }
+    let gotPbrCb = function gotPbrCb(pbrs) {
+      this.readAllPhonebookSets(pbrs, onsuccess, onerror);
     }.bind(this);
 
     ICCRecordHelper.readPBR(gotPbrCb, onerror);
   },
 
   /**
+   * Read all Phonebook sets.
+   *
+   * @param pbrs          All Phonebook Reference Files read.
+   * @param onsuccess     Callback to be called when success.
+   * @param onerror       Callback to be called when error.
+   */
+  readAllPhonebookSets: function readAllPhonebookSets(pbrs, onsuccess, onerror) {
+    let allContacts = [], pbrIndex = 0;
+    let readPhonebook = function readPhonebook(contacts) {
+      if (contacts) {
+        allContacts = allContacts.concat(contacts);
+      }
+
+      let cLen = contacts ? contacts.length : 0;
+      for (let i = 0; i < cLen; i++) {
+        contacts[i].recordId += pbrIndex * ICC_MAX_LINEAR_FIXED_RECORDS;
+      }
+
+      pbrIndex++;
+      if (pbrIndex >= pbrs.length) {
+        if (onsuccess) {
+          onsuccess(allContacts);
+        }
+        return;
+      }
+
+      this.readPhonebookSet(pbrs[pbrIndex], readPhonebook, onerror);
+    }.bind(this);
+
+    this.readPhonebookSet(pbrs[pbrIndex], readPhonebook, onerror);
+  },
+
+  /**
+   * Read from Phonebook Reference File.
+   *
+   * @param pbr           Phonebook Reference File to be read.
+   * @param onsuccess     Callback to be called when success.
+   * @param onerror       Callback to be called when error.
+   */
+  readPhonebookSet: function readPhonebookSet(pbr, onsuccess, onerror) {
+    let gotAdnCb = function gotAdnCb(contacts) {
+      this.readSupportedPBRFields(pbr, contacts, onsuccess, onerror);
+    }.bind(this);
+
+    ICCRecordHelper.readADNLike(pbr.adn.fileId, gotAdnCb, onerror);
+  },
+
+  /**
    * Read supported Phonebook fields.
    *
    * @param pbr         Phone Book Reference file.
    * @param contacts    Contacts stored on ICC.
    * @param onsuccess   Callback to be called when success.
    * @param onerror     Callback to be called when error.
    */
   readSupportedPBRFields: function readSupportedPBRFields(pbr, contacts, onsuccess, onerror) {
     // Current supported fields. Adding more fields to read will increasing I/O
     // time dramatically, do check the performance is acceptable when you add
-    // more fileds.
+    // more fields.
     const fields = ["email", "anr0"];
 
     (function readField(field) {
       let field = fields.pop();
       if (!field) {
         if (onsuccess) {
           onsuccess(contacts);
         }