From 4703e8378879e477b680643e1551f4aaef8c275c Mon Sep 17 00:00:00 2001 From: "\"allstars.chh\"" Date: Fri, 8 Nov 2013 18:49:38 +0800 Subject: [PATCH] Bug 921318 - Part 1: Use contactId. r=vicamo --- dom/system/gonk/RILContentHelper.js | 4 +- dom/system/gonk/ril_worker.js | 42 +++++++++++--------- dom/system/gonk/tests/test_ril_worker_icc.js | 11 +++-- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/dom/system/gonk/RILContentHelper.js b/dom/system/gonk/RILContentHelper.js index a66c9fd4802..13b206f0244 100644 --- a/dom/system/gonk/RILContentHelper.js +++ b/dom/system/gonk/RILContentHelper.js @@ -1116,7 +1116,7 @@ RILContentHelper.prototype = { iccContact.email = contact.email[0].value; } - iccContact.id = contact.id; + iccContact.contactId = contact.id; cpmm.sendAsyncMessage("RIL:UpdateIccContact", { clientId: clientId, @@ -1848,7 +1848,7 @@ RILContentHelper.prototype = { } let contact = new window.mozContact(prop); - contact.id = message.iccid + c.recordId; + contact.id = c.contactId; return contact; }); diff --git a/dom/system/gonk/ril_worker.js b/dom/system/gonk/ril_worker.js index 1b2b1155d7b..ecb2b972ca4 100644 --- a/dom/system/gonk/ril_worker.js +++ b/dom/system/gonk/ril_worker.js @@ -877,9 +877,14 @@ let RIL = { this.appType, options.contactType, function onsuccess(contacts) { + for (let i = 0; i < contacts.length; i++) { + let contact = contacts[i]; + let pbrIndex = contact.pbrIndex || 0; + let recordIndex = pbrIndex * ICC_MAX_LINEAR_FIXED_RECORDS + contact.recordId; + contact.contactId = this.iccInfo.iccid + recordIndex; + } // Reuse 'options' to get 'requestId' and 'contactType'. options.contacts = contacts; - options.iccid = RIL.iccInfo.iccid; RIL.sendChromeMessage(options); }.bind(this), function onerror(errorMsg) { @@ -914,22 +919,26 @@ let RIL = { let contact = options.contact; let iccid = RIL.iccInfo.iccid; - if (contact.id.startsWith(iccid)) { - contact.recordId = contact.id.substring(iccid.length); + if (contact.contactId.startsWith(iccid)) { + let recordIndex = contact.contactId.substring(iccid.length); + contact.pbrIndex = Math.floor(recordIndex / ICC_MAX_LINEAR_FIXED_RECORDS); + contact.recordId = recordIndex % ICC_MAX_LINEAR_FIXED_RECORDS; } + let isValidRecordId = contact.recordId > 0 && contact.recordId < 0xff; + if (DEBUG) { debug("Update ICC Contact " + JSON.stringify(contact)); } // If contact has 'recordId' property, updates corresponding record. // If not, inserts the contact into a free record. - if (options.contact.recordId) { + if (isValidRecordId) { ICCContactHelper.updateICCContact( - this.appType, options.contactType, options.contact, options.pin2, onsuccess, onerror); + this.appType, options.contactType, contact, options.pin2, onsuccess, onerror); } else { ICCContactHelper.addICCContact( - this.appType, options.contactType, options.contact, options.pin2, onsuccess, onerror); + this.appType, options.contactType, contact, options.pin2, onsuccess, onerror); } }, @@ -12673,7 +12682,7 @@ let ICCContactHelper = { switch (contactType) { case "adn": if (!this.hasDfPhoneBook(appType)) { - ICCRecordHelper.findFreeRecordId(ICC_EF_ADN, onsuccess, onerror); + ICCRecordHelper.findFreeRecordId(ICC_EF_ADN, onsuccess.bind(null, 0), onerror); } else { let gotPbrCb = function gotPbrCb(pbrs) { this.findUSimFreeADNRecordId(pbrs, onsuccess, onerror); @@ -12683,7 +12692,7 @@ let ICCContactHelper = { } break; case "fdn": - ICCRecordHelper.findFreeRecordId(ICC_EF_FDN, onsuccess, onerror); + ICCRecordHelper.findFreeRecordId(ICC_EF_FDN, onsuccess.bind(null, 0), onerror); break; default: let error = onerror || debug; @@ -12710,10 +12719,8 @@ let ICCContactHelper = { let pbr = pbrs[pbrIndex]; ICCRecordHelper.findFreeRecordId( pbr.adn.fileId, - onsuccess, - function (errorMsg) { - findFreeRecordId.bind(this, pbrIndex + 1); - }.bind(this)); + onsuccess.bind(this, pbrIndex), + findFreeRecordId.bind(null, pbrIndex + 1)); })(0); }, @@ -12728,10 +12735,11 @@ let ICCContactHelper = { * @param onerror Callback to be called when error. */ addICCContact: function addICCContact(appType, contactType, contact, pin2, onsuccess, onerror) { - let foundFreeCb = function foundFreeCb(recordId) { + let foundFreeCb = function foundFreeCb(pbrIndex, recordId) { + contact.pbrIndex = pbrIndex; contact.recordId = recordId; ICCContactHelper.updateICCContact(appType, contactType, contact, pin2, onsuccess, onerror); - }.bind(this); + }; // Find free record first. ICCContactHelper.findFreeICCContact(appType, contactType, foundFreeCb, onerror); @@ -12800,7 +12808,7 @@ let ICCContactHelper = { let cLen = contacts ? contacts.length : 0; for (let i = 0; i < cLen; i++) { - contacts[i].recordId += pbrIndex * ICC_MAX_LINEAR_FIXED_RECORDS; + contacts[i].pbrIndex = pbrIndex; } pbrIndex++; @@ -12991,14 +12999,12 @@ let ICCContactHelper = { */ updateUSimContact: function updateUSimContact(contact, onsuccess, onerror) { let gotPbrCb = function gotPbrCb(pbrs) { - let pbrIndex = Math.floor(contact.recordId / ICC_MAX_LINEAR_FIXED_RECORDS); - let pbr = pbrs[pbrIndex]; + let pbr = pbrs[contact.pbrIndex]; if (!pbr) { let error = onerror || debug; error("Cannot access Phonebook."); return; } - contact.recordId %= ICC_MAX_LINEAR_FIXED_RECORDS; this.updatePhonebookSet(pbr, contact, onsuccess, onerror); }.bind(this); diff --git a/dom/system/gonk/tests/test_ril_worker_icc.js b/dom/system/gonk/tests/test_ril_worker_icc.js index 755ce6b8bdf..0de948c9471 100644 --- a/dom/system/gonk/tests/test_ril_worker_icc.js +++ b/dom/system/gonk/tests/test_ril_worker_icc.js @@ -1379,7 +1379,7 @@ add_test(function test_read_icc_contacts() { }; record.readPBR = function readPBR(onsuccess, onerror) { - onsuccess([{adn:{}, email: {}, anr0: {}}]); + onsuccess([{adn:{fileId: 0x6f3a}, email: {}, anr0: {}}]); }; record.readADNLike = function readADNLike(fileId, onsuccess, onerror) { @@ -1396,7 +1396,7 @@ add_test(function test_read_icc_contacts() { let onsuccess = function onsuccess(contacts) { let contact = contacts[0]; - for (key in contact) { + for (let key in contact) { do_print("check " + key); if (Array.isArray(contact[key])) { do_check_eq(contact[key][0], aExpectedContact[key]); @@ -1415,12 +1415,14 @@ add_test(function test_read_icc_contacts() { } let expectedContact1 = { + pbrIndex: 0, recordId: 1, alphaId: "name", number: "111111" }; let expectedContact2 = { + pbrIndex: 0, recordId: 1, alphaId: "name", number: "111111", @@ -1559,6 +1561,7 @@ add_test(function test_update_icc_contact() { } let contact = { + pbrIndex: 0, recordId: ADN_RECORD_ID, alphaId: "test", number: "123456", @@ -1607,6 +1610,7 @@ add_test(function test_find_free_icc_contact() { let recordHelper = worker.ICCRecordHelper; let contactHelper = worker.ICCContactHelper; const RECORD_ID = 1; + const PBR_INDEX = 0; recordHelper.readPBR = function (onsuccess, onerror) { onsuccess([{adn:{}, email: {}, anr0: {}}]); @@ -1616,7 +1620,8 @@ add_test(function test_find_free_icc_contact() { onsuccess(RECORD_ID); }; - let successCb = function (recordId) { + let successCb = function (pbrIndex, recordId) { + do_check_eq(pbrIndex, PBR_INDEX); do_check_eq(recordId, RECORD_ID); run_next_test(); };