Bug 921318 - Part 1: Use contactId. r=vicamo

This commit is contained in:
"allstars.chh" 2013-11-08 18:49:38 +08:00
parent 4d822c8f24
commit 4703e83788
3 changed files with 34 additions and 23 deletions

View File

@ -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;
});

View File

@ -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);

View File

@ -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();
};