Bug 1122376 - Support write SIM contact dialling number exceed 20 digits. r=echen

This commit is contained in:
john1984 2015-09-20 19:57:00 +02:00
parent c288c4bd19
commit 1348a3cf3f
7 changed files with 765 additions and 51 deletions

View File

@ -5,6 +5,7 @@ qemu = true
[test_icc_contact_read.js]
[test_icc_contact_add.js]
[test_icc_contact_update.js]
[test_icc_card_lock_get_retry_count.js]
[test_icc_card_lock_change_pin.js]
[test_icc_card_lock_enable_pin.js]

View File

@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 90000;
MARIONETTE_TIMEOUT = 120000;
MARIONETTE_HEAD_JS = "head.js";
var TEST_ADD_DATA = [{
@ -13,17 +13,21 @@ var TEST_ADD_DATA = [{
name: ["add2"],
tel: [{value: "012345678901234567890123456789"}],
}, {
// a contact with email but without anr.
// a contact over 40 digits.
name: ["add3"],
tel: [{value: "01234567890123456789012345678901234567890123456789"}],
}, {
// a contact with email but without anr.
name: ["add4"],
tel: [{value: "01234567890123456789"}],
email:[{value: "test@mozilla.com"}],
}, {
// a contact with anr but without email.
name: ["add4"],
name: ["add5"],
tel: [{value: "01234567890123456789"}, {value: "123456"}, {value: "123"}],
}, {
// a contact with email and anr.
name: ["add5"],
name: ["add6"],
tel: [{value: "01234567890123456789"}, {value: "123456"}, {value: "123"}],
email:[{value: "test@mozilla.com"}],
}];
@ -35,8 +39,8 @@ function testAddContact(aIcc, aType, aMozContact, aPin2) {
return aIcc.updateContact(aType, contact, aPin2)
.then((aResult) => {
is(aResult.name[0], aMozContact.name[0]);
// Maximum digits of the Dialling Number is 20.
is(aResult.tel[0].value, aMozContact.tel[0].value.substring(0, 20));
// Maximum digits of the Dialling Number is 20, and maximum digits of Extension is 20.
is(aResult.tel[0].value, aMozContact.tel[0].value.substring(0, 40));
// We only support SIM in emulator, so we don't have anr and email field.
ok(aResult.tel.length == 1);
ok(!aResult.email);
@ -45,11 +49,10 @@ function testAddContact(aIcc, aType, aMozContact, aPin2) {
return aIcc.readContacts(aType)
.then((aResult) => {
let contact = aResult[aResult.length - 1];
is(contact.name[0], aMozContact.name[0]);
// Maximum digits of the Dialling Number is 20.
is(contact.tel[0].value, aMozContact.tel[0].value.substring(0, 20));
is(contact.id, aIcc.iccInfo.iccid + aResult.length);
// Maximum digits of the Dialling Number is 20, and maximum digits of Extension is 20.
is(contact.tel[0].value, aMozContact.tel[0].value.substring(0, 40));
is(contact.id.substring(0, aIcc.iccInfo.iccid.length), aIcc.iccInfo.iccid);
return contact.id;
})
@ -80,14 +83,15 @@ function removeContact(aIcc, aContactId, aType, aPin2) {
// Start tests
startTestCommon(function() {
let icc = getMozIcc();
let promise = Promise.resolve();
for (let i = 0; i < TEST_ADD_DATA.length; i++) {
let test_data = TEST_ADD_DATA[i];
// Test add adn contacts
return testAddContact(icc, "adn", test_data)
promise = promise.then(() => testAddContact(icc, "adn", test_data))
// Test add fdn contacts
.then(() => testAddContact(icc, "fdn", test_data, "0000"))
// Test add fdn contacts without passing pin2
.then(() => testAddContact(icc, "fdn", test_data));
}
return promise;
});

View File

@ -0,0 +1,122 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 120000;
MARIONETTE_HEAD_JS = "head.js";
const TEST_UPDATE_DATA = [{
id: 1,
data: {
name: ["Mozilla"],
tel: [{value: "9876543210987654321001234"}]},
expect: {
number: "9876543210987654321001234"}
}, {
id:2,
data: {
name: ["Saßê黃"],
tel: [{value: "98765432109876543210998877665544332211001234"}]},
expect: {
// We don't support extension chain now.
number: "9876543210987654321099887766554433221100"}
}, {
id: 3,
data: {
name: ["Fire 火"],
tel: [{value: ""}]},
expect: {
number: null}
}, {
id: 5,
data: {
name: ["Contact001"],
tel: [{value: "9988776655443322110098765432109876543210"}]},
expect: {
number: "9988776655443322110098765432109876543210"}
}, {
id: 6,
data: {
name: ["Contact002"],
tel: [{value: "+99887766554433221100"}]},
expect: {
number: "+99887766554433221100"}
}];
function testUpdateContact(aIcc, aType, aContactId, aMozContact, aExpect, aPin2) {
log("testUpdateContact: type=" + aType +
", mozContact=" + JSON.stringify(aMozContact) +
", expect=" + aExpect.number + ", pin2=" + aPin2);
let contact = new mozContact(aMozContact);
contact.id = aIcc.iccInfo.iccid + aContactId;
return aIcc.updateContact(aType, contact, aPin2)
.then((aResult) => {
// Get ICC contact for checking expect contact
return aIcc.readContacts(aType)
.then((aResult) => {
let contact = aResult[aContactId - 1];
is(contact.name[0], aMozContact.name[0]);
if (aExpect.number == null) {
is(contact.tel, null);
} else {
is(contact.tel[0].value, aExpect.number);
}
is(contact.id, aIcc.iccInfo.iccid + aContactId);
});
}, (aError) => {
if (aType === "fdn" && aPin2 === undefined) {
ok(aError.name === "SimPin2",
"expected error when pin2 is not provided");
} else {
ok(false, "Cannot update " + aType + " contact: " + aError.name);
}
});
}
function revertContact(aIcc, aContact, aType, aPin2) {
log("revertContact: contact:" + JSON.stringify(aContact) +
", type=" + aType + ", pin2=" + aPin2);
return aIcc.updateContact(aType, aContact, aPin2);
}
// Start tests
startTestCommon(function() {
let icc = getMozIcc();
let adnContacts;
let fdnContacts;
return icc.readContacts("adn")
.then((aResult) => {
adnContacts = aResult;
})
.then(() => icc.readContacts("fdn"))
.then((aResult) => {
fdnContacts = aResult;
})
.then(() => {
let promise = Promise.resolve();
for (let i = 0; i < TEST_UPDATE_DATA.length; i++) {
let test_data = TEST_UPDATE_DATA[i];
let adnContact = adnContacts[test_data.id - 1];
let fdnContact = fdnContacts[test_data.id - 1];
// Test update adn contacts
promise = promise.then(() => testUpdateContact(icc, "adn", test_data.id,
test_data.data, test_data.expect))
// Test update fdn contacts
.then(() => testUpdateContact(icc, "fdn", test_data.id, test_data.data,
test_data.expect))
// Test update fdn contacts without passing pin2
.then(() => testUpdateContact(icc, "fdn", test_data.id, test_data.data,
test_data.expect, "0000"))
.then(() => revertContact(icc, adnContact, "adn"))
.then(() => revertContact(icc, fdnContact, "fdn", "0000"));
}
return promise;
});
});

View File

@ -5564,6 +5564,16 @@ GsmPDUHelperObject.prototype = {
return this.extendedBcdChars.charAt(semiOctet);
},
/**
* Convert string to a GSM extended BCD string
*/
stringToExtendedBcd: function(string) {
return string.replace(/[^0-9*#,]/g, "")
.replace(/\*/g, "a")
.replace(/\#/g, "b")
.replace(/\,/g, "c");
},
/**
* Read a *swapped nibble* binary coded decimal (BCD)
*
@ -8977,29 +8987,34 @@ ICCPDUHelperObject.prototype = {
let number = this.readNumberWithLength();
// Skip 2 unused octets, CCP and EXT1.
Buf.seekIncoming(2 * Buf.PDU_HEX_OCTET_SIZE);
// Skip unused octet, CCP
Buf.seekIncoming(Buf.PDU_HEX_OCTET_SIZE);
let extRecordNumber = this.context.GsmPDUHelper.readHexOctet();
Buf.readStringDelimiter(length);
let contact = null;
if (alphaId || number) {
contact = {alphaId: alphaId,
number: number};
number: number,
extRecordNumber: extRecordNumber};
}
return contact;
},
/**
* Write Alpha Identifier and Dialling number from TS 151.011 clause 10.5.1
*
* @param recordSize The size of linear fixed record.
* @param alphaId Alpha Identifier to be written.
* @param number Dialling Number to be written.
* @param recordSize The size of linear fixed record.
* @param alphaId Alpha Identifier to be written.
* @param number Dialling Number to be written.
* @param extRecordNumber The record identifier of the EXT.
*
* @return An object contains the alphaId and number
* that have been written into Buf.
*/
writeAlphaIdDiallingNumber: function(recordSize, alphaId, number) {
writeAlphaIdDiallingNumber: function(recordSize, alphaId, number, extRecordNumber) {
let Buf = this.context.Buf;
let GsmPDUHelper = this.context.GsmPDUHelper;
@ -9011,9 +9026,10 @@ ICCPDUHelperObject.prototype = {
let writtenAlphaId = this.writeAlphaIdentifier(alphaLen, alphaId);
let writtenNumber = this.writeNumberWithLength(number);
// Write unused octets 0xff, CCP and EXT1.
GsmPDUHelper.writeHexOctet(0xff);
// Write unused CCP octet 0xff.
GsmPDUHelper.writeHexOctet(0xff);
GsmPDUHelper.writeHexOctet((extRecordNumber != null) ? extRecordNumber : 0xff);
Buf.writeStringDelimiter(strLen);
return {alphaId: writtenAlphaId,
@ -9177,8 +9193,8 @@ ICCPDUHelperObject.prototype = {
let writtenNumber = number.substring(0, numStart) +
number.substring(numStart)
.replace(/[^0-9*#,]/g, "");
let numDigits = writtenNumber.length - numStart;
if (numDigits > ADN_MAX_NUMBER_DIGITS) {
writtenNumber = writtenNumber.substring(0, ADN_MAX_NUMBER_DIGITS + numStart);
numDigits = writtenNumber.length - numStart;
@ -11645,18 +11661,20 @@ ICCRecordHelperObject.prototype = {
/**
* Update ICC ADN like EFs, like EF_ADN, EF_FDN.
*
* @param fileId EF id of the ADN or FDN.
* @param contact The contact will be updated. (Shall have recordId property)
* @param pin2 PIN2 is required when updating ICC_EF_FDN.
* @param onsuccess Callback to be called when success.
* @param onerror Callback to be called when error.
* @param fileId EF id of the ADN or FDN.
* @param extRecordNumber The record identifier of the EXT.
* @param contact The contact will be updated. (Shall have recordId property)
* @param pin2 PIN2 is required when updating ICC_EF_FDN.
* @param onsuccess Callback to be called when success.
* @param onerror Callback to be called when error.
*/
updateADNLike: function(fileId, contact, pin2, onsuccess, onerror) {
updateADNLike: function(fileId, extRecordNumber, contact, pin2, onsuccess, onerror) {
let updatedContact;
function dataWriter(recordSize) {
updatedContact = this.context.ICCPDUHelper.writeAlphaIdDiallingNumber(recordSize,
contact.alphaId,
contact.number);
contact.number,
extRecordNumber);
}
function callback(options) {
@ -12166,6 +12184,113 @@ ICCRecordHelperObject.prototype = {
onerror: onerror
});
},
/**
* Update Extension.
*
* @param fileId EF id of the EXT.
* @param recordNumber The number of the record shall be updated.
* @param number Dialling Number to be written.
* @param onsuccess Callback to be called when success.
* @param onerror Callback to be called when error.
*/
updateExtension: function(fileId, recordNumber, number, onsuccess, onerror) {
let dataWriter = (recordSize) => {
let GsmPDUHelper = this.context.GsmPDUHelper;
// Write String length
let strLen = recordSize * 2;
let Buf = this.context.Buf;
Buf.writeInt32(strLen);
// We don't support extension chain.
if (number.length > EXT_MAX_NUMBER_DIGITS) {
number = number.substring(0, EXT_MAX_NUMBER_DIGITS);
}
let numLen = Math.ceil(number.length / 2);
// Write Extension record
GsmPDUHelper.writeHexOctet(0x02);
GsmPDUHelper.writeHexOctet(numLen);
GsmPDUHelper.writeSwappedNibbleBCD(number);
// Write trailing 0xff of Extension data.
for (let i = 0; i < EXT_MAX_BCD_NUMBER_BYTES - numLen; i++) {
GsmPDUHelper.writeHexOctet(0xff);
}
// Write trailing 0xff for Identifier.
GsmPDUHelper.writeHexOctet(0xff);
Buf.writeStringDelimiter(strLen);
};
this.context.ICCIOHelper.updateLinearFixedEF({
fileId: fileId,
recordNumber: recordNumber,
dataWriter: dataWriter,
callback: onsuccess,
onerror: onerror
});
},
/**
* Clean an EF record.
*
* @param fileId EF id.
* @param recordNumber The number of the record shall be updated.
* @param onsuccess Callback to be called when success.
* @param onerror Callback to be called when error.
*/
cleanEFRecord: function(fileId, recordNumber, onsuccess, onerror) {
let dataWriter = (recordSize) => {
let GsmPDUHelper = this.context.GsmPDUHelper;
let Buf = this.context.Buf;
// Write String length
let strLen = recordSize * 2;
Buf.writeInt32(strLen);
// Write record to 0xff
for (let i = 0; i < recordSize; i++) {
GsmPDUHelper.writeHexOctet(0xff);
}
Buf.writeStringDelimiter(strLen);
}
this.context.ICCIOHelper.updateLinearFixedEF({
fileId: fileId,
recordNumber: recordNumber,
dataWriter: dataWriter,
callback: onsuccess,
onerror: onerror
});
},
/**
* Get ADNLike extension record number.
*
* @param fileId EF id of the ADN or FDN.
* @param recordNumber EF record id of the ADN or FDN.
* @param onsuccess Callback to be called when success.
* @param onerror Callback to be called when error.
*/
getADNLikeExtensionRecordNumber: function(fileId, recordNumber, onsuccess, onerror) {
let callback = (options) => {
let Buf = this.context.Buf;
let length = Buf.readInt32();
// Skip alphaLen, numLen, BCD Number, CCP octets.
Buf.seekIncoming((options.recordSize -1) * Buf.PDU_HEX_OCTET_SIZE);
let extRecordNumber = this.context.GsmPDUHelper.readHexOctet();
Buf.readStringDelimiter(length);
onsuccess(extRecordNumber);
}
this.context.ICCIOHelper.loadLinearFixedEF({
fileId: fileId,
recordNumber: recordNumber,
callback: callback,
onerror: onerror
});
},
};
/**
@ -14232,7 +14357,15 @@ ICCContactHelperObject.prototype = {
switch (contactType) {
case GECKO_CARDCONTACT_TYPE_ADN:
if (!this.hasDfPhoneBook(appType)) {
ICCRecordHelper.updateADNLike(ICC_EF_ADN, contact, null, updateContactCb, onerror);
if (ICCUtilsHelper.isICCServiceAvailable("EXT1")) {
this.updateADNLikeWithExtension(ICC_EF_ADN, ICC_EF_EXT1,
contact, null,
updateContactCb, onerror);
} else {
ICCRecordHelper.updateADNLike(ICC_EF_ADN, 0xff,
contact, null,
updateContactCb, onerror);
}
} else {
this.updateUSimContact(contact, updateContactCb, onerror);
}
@ -14246,7 +14379,16 @@ ICCContactHelperObject.prototype = {
onerror(CONTACT_ERR_CONTACT_TYPE_NOT_SUPPORTED);
break;
}
ICCRecordHelper.updateADNLike(ICC_EF_FDN, contact, pin2, updateContactCb, onerror);
if (ICCUtilsHelper.isICCServiceAvailable("EXT2")) {
this.updateADNLikeWithExtension(ICC_EF_FDN, ICC_EF_EXT2,
contact, pin2,
updateContactCb, onerror);
} else {
ICCRecordHelper.updateADNLike(ICC_EF_FDN,
0xff,
contact, pin2,
updateContactCb, onerror);
}
break;
default:
if (DEBUG) {
@ -14514,8 +14656,13 @@ ICCContactHelperObject.prototype = {
}, onerror);
}.bind(this);
this.context.ICCRecordHelper.updateADNLike(pbr.adn.fileId, contact, null,
updateAdnCb, onerror);
if (pbr.ext1) {
this.updateADNLikeWithExtension(pbr.adn.fileId, pbr.ext1.fileId,
contact, null, updateAdnCb, onerror);
} else {
this.context.ICCRecordHelper.updateADNLike(pbr.adn.fileId, 0xff, contact,
null, updateAdnCb, onerror);
}
},
/**
@ -14748,6 +14895,74 @@ ICCContactHelperObject.prototype = {
}.bind(this);
ICCRecordHelper.readIAP(pbr.iap.fileId, recordNumber, gotIAPCb, onerror);
},
/**
* Update ICC ADN like EFs with Extension, like EF_ADN, EF_FDN.
*
* @param fileId EF id of the ADN or FDN.
* @param extFileId EF id of the EXT.
* @param contact The contact will be updated. (Shall have recordId property)
* @param pin2 PIN2 is required when updating ICC_EF_FDN.
* @param onsuccess Callback to be called when success.
* @param onerror Callback to be called when error.
*/
updateADNLikeWithExtension: function(fileId, extFileId, contact, pin2, onsuccess, onerror) {
let ICCRecordHelper = this.context.ICCRecordHelper;
let extNumber;
if (contact.number) {
let numStart = contact.number[0] == "+" ? 1 : 0;
let number = contact.number.substring(0, numStart) +
this.context.GsmPDUHelper.stringToExtendedBcd(
contact.number.substring(numStart));
extNumber = number.substr(numStart + ADN_MAX_NUMBER_DIGITS,
EXT_MAX_NUMBER_DIGITS);
}
ICCRecordHelper.getADNLikeExtensionRecordNumber(fileId, contact.recordId,
(extRecordNumber) => {
let updateADNLike = (extRecordNumber) => {
ICCRecordHelper.updateADNLike(fileId, extRecordNumber, contact,
pin2, (updatedContact) => {
if (extNumber && extRecordNumber != 0xff) {
updatedContact.number = updatedContact.number.concat(extNumber);
}
onsuccess(updatedContact);
}, onerror);
};
let updateExtension = (extRecordNumber) => {
ICCRecordHelper.updateExtension(extFileId, extRecordNumber, extNumber,
() => updateADNLike(extRecordNumber),
() => updateADNLike(0xff));
};
if (extNumber) {
if (extRecordNumber != 0xff) {
updateExtension(extRecordNumber);
return;
}
ICCRecordHelper.findFreeRecordId(extFileId,
(extRecordNumber) => updateExtension(extRecordNumber),
(errorMsg) => {
if (DEBUG) {
this.context.debug("Couldn't find free extension record Id for " + extFileId + ": " + errorMsg);
}
updateADNLike(0xff);
});
return;
}
if (extRecordNumber != 0xff) {
ICCRecordHelper.cleanEFRecord(extFileId, extRecordNumber,
() => updateADNLike(0xff), onerror);
return;
}
updateADNLike(0xff);
}, onerror);
},
};
function IconLoaderObject(aContext) {

View File

@ -352,7 +352,7 @@ add_test(function test_read_icc_contacts() {
onsuccess(JSON.parse(JSON.stringify(aTestData.pbrs)));
};
record.readADNLike = function readADNLike(fileId, onsuccess, onerror) {
record.readADNLike = function readADNLike(fileId, extFileId, onsuccess, onerror) {
onsuccess(JSON.parse(JSON.stringify(aTestData.adnLike)));
};
@ -398,6 +398,7 @@ add_test(function test_update_icc_contact() {
const EMAIL_RECORD_ID = 20;
const ANR0_FILE_ID = 0x4f11;
const ANR0_RECORD_ID = 30;
const EXT_RECORD_ID = 0x01;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
@ -408,11 +409,11 @@ add_test(function test_update_icc_contact() {
function do_test(aSimType, aContactType, aContact, aPin2, aFileType, aHaveIapIndex, aEnhancedPhoneBook) {
ril.appType = aSimType;
ril._isCdma = (aSimType === CARD_APPTYPE_RUIM);
ril.iccInfoPrivate.cst = (aEnhancedPhoneBook) ? [0x20, 0x0C, 0x0, 0x0, 0x0]
: [0x20, 0x00, 0x0, 0x0, 0x0];
ril.iccInfoPrivate.cst = (aEnhancedPhoneBook) ? [0x20, 0x0C, 0x28, 0x0, 0x20]
: [0x20, 0x0, 0x28, 0x0, 0x20];
ril.iccInfoPrivate.sst = (aSimType === CARD_APPTYPE_SIM)?
[0x20, 0x0, 0x0, 0x0, 0x0]:
[0x2, 0x0, 0x0, 0x0, 0x0];
[0x20, 0x0, 0x28, 0x0, 0x20]:
[0x16, 0x0, 0x0, 0x0, 0x0];
recordHelper.readPBR = function(onsuccess, onerror) {
if (aFileType === ICC_USIM_TYPE1_TAG) {
@ -421,7 +422,9 @@ add_test(function test_update_icc_contact() {
email: {fileId: EMAIL_FILE_ID,
fileType: ICC_USIM_TYPE1_TAG},
anr0: {fileId: ANR0_FILE_ID,
fileType: ICC_USIM_TYPE1_TAG}
fileType: ICC_USIM_TYPE1_TAG},
ext1: {fileId: ICC_EF_EXT1}
}]);
} else if (aFileType === ICC_USIM_TYPE2_TAG) {
onsuccess([{
@ -433,24 +436,48 @@ add_test(function test_update_icc_contact() {
indexInIAP: 0},
anr0: {fileId: ANR0_FILE_ID,
fileType: ICC_USIM_TYPE2_TAG,
indexInIAP: 1}
indexInIAP: 1},
ext1: {fileId: ICC_EF_EXT1}
}]);
}
};
recordHelper.updateADNLike = function(fileId, contact, pin2, onsuccess, onerror) {
recordHelper.updateADNLike = function(fileId, extRecordNumber, contact, pin2, onsuccess, onerror) {
if (aContactType === GECKO_CARDCONTACT_TYPE_FDN) {
equal(fileId, ICC_EF_FDN);
} else if (aContactType === GECKO_CARDCONTACT_TYPE_ADN) {
equal(fileId, ICC_EF_ADN);
}
if (aContact.number.length > ADN_MAX_NUMBER_DIGITS) {
equal(extRecordNumber, EXT_RECORD_ID);
} else {
equal(extRecordNumber, 0xff);
}
equal(pin2, aPin2);
equal(contact.alphaId, aContact.alphaId);
equal(contact.number, aContact.number);
onsuccess({alphaId: contact.alphaId,
number: contact.number});
number: contact.number.substring(0, ADN_MAX_NUMBER_DIGITS)});
};
recordHelper.getADNLikeExtensionRecordNumber = function(fileId, recordNumber, onsuccess, onerror) {
onsuccess(EXT_RECORD_ID);
};
recordHelper.updateExtension = function(fileId, recordNumber, number, onsuccess, onerror) {
onsuccess();
};
recordHelper.findFreeRecordId = function(fileId, onsuccess, onerror) {
onsuccess(EXT_RECORD_ID);
};
recordHelper.cleanEFRecord = function(fileId, recordNumber, onsuccess, onerror) {
onsuccess();
}
recordHelper.readIAP = function(fileId, recordNumber, onsuccess, onerror) {
equal(fileId, IAP_FILE_ID);
equal(recordNumber, ADN_RECORD_ID);
@ -502,6 +529,8 @@ add_test(function test_update_icc_contact() {
let onsuccess = function onsuccess(updatedContact) {
equal(ADN_RECORD_ID, updatedContact.recordId);
equal(aContact.alphaId, updatedContact.alphaId);
equal(aContact.number.substring(0, ADN_MAX_NUMBER_DIGITS + EXT_MAX_NUMBER_DIGITS),
updatedContact.number);
if ((aSimType == CARD_APPTYPE_USIM || aSimType == CARD_APPTYPE_RUIM) &&
(aFileType == ICC_USIM_TYPE1_TAG || aFileType == ICC_USIM_TYPE2_TAG)) {
if (aContact.hasOwnProperty('email')) {
@ -559,6 +588,22 @@ add_test(function test_update_icc_contact() {
alphaId: "test4",
number: "123456",
anr: ["+654321"]
},
// a contact number over 20 digits.
{
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test4",
number: "0123456789012345678901234567890123456789",
anr: ["+654321"]
},
// a contact number over 40 digits.
{
pbrIndex: 0,
recordId: ADN_RECORD_ID,
alphaId: "test5",
number: "01234567890123456789012345678901234567890123456789",
anr: ["+654321"]
}];
for (let i = 0; i < contacts.length; i++) {
@ -643,7 +688,7 @@ add_test(function test_update_icc_contact_full_email_and_anr_field() {
}]);
};
recordHelper.updateADNLike = function(fileId, contact, pin2, onsuccess, onerror) {
recordHelper.updateADNLike = function(fileId, extRecordNumber, contact, pin2, onsuccess, onerror) {
if (aContactType === GECKO_CARDCONTACT_TYPE_ADN) {
equal(fileId, ICC_EF_ADN);
}
@ -727,7 +772,7 @@ add_test(function test_update_icc_contact_with_remove_type1_attr() {
let recordHelper = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
recordHelper.updateADNLike = function(fileId, contact, pin2, onsuccess, onerror) {
recordHelper.updateADNLike = function(fileId, extRecordNumber, contact, pin2, onsuccess, onerror) {
onsuccess({alphaId: contact.alphaId,
number: contact.number});
};
@ -907,3 +952,91 @@ add_test(function test_find_free_icc_contact_usim() {
run_next_test();
});
/**
* Verify ICCContactHelper.updateADNLikeWithExtension
*/
add_test(function test_update_adn_like_with_extension() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ril = context.RIL;
let record = context.ICCRecordHelper;
let contactHelper = context.ICCContactHelper;
ril.appType = CARD_APPTYPE_SIM;
// Correct record Id starts from 1, so put a null element at index 0.
// ext_records contains data at index 1, and it only has 1 free record at index 2.
let notFree = 0x01;
let ext_records = [null, notFree, null];
function do_test(contact, extRecordNumber, expectedExtRecordNumber, expectedNumber, expectedCleanEFRecord) {
// Override some functions to test.
record.getADNLikeExtensionRecordNumber = function(fileId, recordNumber, onsuccess, onerror) {
onsuccess(extRecordNumber);
}
record.updateADNLike = function(fileId, extRecordNumber, contact, pin2, onsuccess, onerror) {
equal(extRecordNumber, expectedExtRecordNumber);
onsuccess({alphaId: contact.alphaId,
number: contact.number.substring(0, ADN_MAX_NUMBER_DIGITS)});
}
record.updateExtension = function(fileId, recordNumber, number, onsuccess, onerror) {
if (recordNumber > ext_records.length) {
onerror("updateExtension failed.");
return;
}
ext_records[recordNumber] = number;
onsuccess();
}
record.findFreeRecordId = function(fileId, onsuccess, onerror) {
for (let i = 1; i < ext_records.length; i++) {
if (!ext_records[i]) {
onsuccess(i);
return;
}
}
onerror("No free record found.");
}
let isCleanEFRecord = false;
record.cleanEFRecord = function(fileId, recordNumber, onsuccess, onerror) {
if (recordNumber > ext_records.length) {
onerror("cleanEFRecord failed.");
return;
}
ext_records[recordNumber] = null;
isCleanEFRecord = true;
onsuccess();
}
let successCb = function successCb(updatedContact) {
equal(updatedContact.number, expectedNumber);
};
let errorCb = function errorCb(errorMsg) {
do_print("updateADNLikeWithExtension failed, msg = " + errorMsg);
ok(false);
};
contactHelper.updateADNLikeWithExtension(ICC_EF_ADN, ICC_EF_EXT1, contact, null, successCb, errorCb);
if (expectedCleanEFRecord) {
ok(isCleanEFRecord);
}
}
// Update extension record with previous extension record number.
do_test({recordId: 1, alphaId: "test", number: "001122334455667788991234"}, 0x01, 0x01, "001122334455667788991234");
// Update extension record and find a free record.
do_test({recordId: 1, alphaId: "test", number: "001122334455667788995678"}, 0xff, 0x02, "001122334455667788995678");
// Update extension record with no free extension record.
do_test({recordId: 1, alphaId: "test", number: "001122334455667788994321"}, 0xff, 0xff, "00112233445566778899");
// Update extension record with clean previous extension record.
do_test({recordId: 1, alphaId: "test", number: "00112233445566778899"}, 0x01, 0xff, "00112233445566778899", true);
// Update extension record with no extension record and previous extension record.
do_test({recordId: 1, alphaId: "test", number: "00112233445566778899"}, 0xff, 0xff, "00112233445566778899");
run_next_test();
});

View File

@ -462,25 +462,29 @@ add_test(function test_write_alpha_id_dialling_number() {
alphaId: "Mozilla",
number: "1234567890"
};
let writtenContact = helper.writeAlphaIdDiallingNumber(recordSize,
contactW.alphaId,
contactW.number);
contactW.number, 0xff);
let contactR = helper.readAlphaIdDiallingNumber(recordSize);
equal(writtenContact.alphaId, contactR.alphaId);
equal(writtenContact.number, contactR.number);
equal(0xff, contactR.extRecordNumber);
// Write a contact with alphaId encoded in UCS2 and number has '+'.
let contactUCS2 = {
alphaId: "火狐",
number: "+1234567890"
};
writtenContact = helper.writeAlphaIdDiallingNumber(recordSize,
contactUCS2.alphaId,
contactUCS2.number);
contactUCS2.number, 0xff);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
equal(writtenContact.alphaId, contactR.alphaId);
equal(writtenContact.number, contactR.number);
equal(0xff, contactR.extRecordNumber);
// Write a null contact (Removal).
writtenContact = helper.writeAlphaIdDiallingNumber(recordSize);
@ -498,21 +502,24 @@ add_test(function test_write_alpha_id_dialling_number() {
alphaId: "AAAAAAAAABBBBBBBBBCCCCCCCCC",
number: "123456789012345678901234567890",
};
writtenContact = helper.writeAlphaIdDiallingNumber(recordSize,
longContact.alphaId,
longContact.number);
longContact.number, 0xff);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
equal(writtenContact.alphaId, contactR.alphaId);
equal(writtenContact.number, contactR.number);
equal(0xff, contactR.extRecordNumber);
// Add '+' to number and test again.
longContact.number = "+123456789012345678901234567890";
writtenContact = helper.writeAlphaIdDiallingNumber(recordSize,
longContact.alphaId,
longContact.number);
longContact.number, 0xff);
contactR = helper.readAlphaIdDiallingNumber(recordSize);
equal(writtenContact.alphaId, contactR.alphaId);
equal(writtenContact.number, contactR.number);
equal(0xff, contactR.extRecordNumber);
run_next_test();
});

View File

@ -557,7 +557,7 @@ add_test(function test_read_adn_like() {
0xff, "99887766554433221100");
// Empty dialling number contact
do_test(null,"436f6e74616374303031ffffffffffffffffffffffffffffffffffffffffffff",
0xff, null);
0xff, "");
run_next_test();
});
@ -617,6 +617,7 @@ add_test(function test_update_adn_like() {
let contact = pdu.readAlphaIdDiallingNumber(0x20);
equal(contact.alphaId, "test");
equal(contact.number, "123456");
equal(contact.extRecordNumber, "0xff");
// pin2.
if (fileId == ICC_EF_ADN) {
@ -634,11 +635,11 @@ add_test(function test_update_adn_like() {
};
fileId = ICC_EF_ADN;
record.updateADNLike(fileId,
record.updateADNLike(fileId, 0xff,
{recordId: 1, alphaId: "test", number: "123456"});
fileId = ICC_EF_FDN;
record.updateADNLike(fileId,
record.updateADNLike(fileId, 0xff,
{recordId: 1, alphaId: "test", number: "123456"},
"1111");
});
@ -846,3 +847,234 @@ add_test(function test_read_extension() {
run_next_test();
});
/**
* Verify ICCRecordHelper.updateExtension
*/
add_test(function test_update_extension() {
const RECORD_SIZE = 13;
const RECORD_NUMBER = 1;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let ril = context.RIL;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = RECORD_SIZE;
ril.iccIO(options);
};
function do_test(fileId, number, expectedNumber) {
buf.sendParcel = function() {
// Request Type.
equal(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
equal(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
equal(this.readInt32(), fileId);
// pathId.
if (ril.appType == CARD_APPTYPE_SIM || ril.appType == CARD_APPTYPE_RUIM) {
equal(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM);
} else{
equal(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK);
}
// p1.
equal(this.readInt32(), RECORD_NUMBER);
// p2.
equal(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
equal(this.readInt32(), RECORD_SIZE);
// data.
let strLen = this.readInt32();
// Extension record
let recordType = pduHelper.readHexOctet();
equal(recordType, 0x02);
equal(pduHelper.readHexOctet(), 10);
equal(
pduHelper.readSwappedNibbleExtendedBcdString(EXT_MAX_NUMBER_DIGITS - 1),
expectedNumber);
this.readStringDelimiter(strLen);
// pin2.
equal(this.readString(), null);
// AID. Ignore because it's from modem.
this.readInt32();
};
recordHelper.updateExtension(fileId, RECORD_NUMBER, number);
}
ril.appType = CARD_APPTYPE_SIM;
do_test(ICC_EF_EXT1, "01234567890123456789", "01234567890123456789");
// We don't support extension chain.
do_test(ICC_EF_EXT1, "012345678901234567891234", "01234567890123456789");
ril.appType = CARD_APPTYPE_USIM;
do_test(ICC_EF_EXT1, "01234567890123456789", "01234567890123456789");
ril.appType = CARD_APPTYPE_RUIM;
do_test(ICC_EF_EXT1, "01234567890123456789", "01234567890123456789");
run_next_test();
});
/**
* Verify ICCRecordHelper.cleanEFRecord
*/
add_test(function test_clean_ef_record() {
const RECORD_SIZE = 13;
const RECORD_NUMBER = 1;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let pduHelper = context.GsmPDUHelper;
let ril = context.RIL;
let recordHelper = context.ICCRecordHelper;
let buf = context.Buf;
let ioHelper = context.ICCIOHelper;
// Override.
ioHelper.updateLinearFixedEF = function(options) {
options.pathId = context.ICCFileHelper.getEFPath(options.fileId);
options.command = ICC_COMMAND_UPDATE_RECORD;
options.p1 = options.recordNumber;
options.p2 = READ_RECORD_ABSOLUTE_MODE;
options.p3 = RECORD_SIZE;
ril.iccIO(options);
};
function do_test(fileId) {
buf.sendParcel = function() {
// Request Type.
equal(this.readInt32(), REQUEST_SIM_IO);
// Token : we don't care
this.readInt32();
// command.
equal(this.readInt32(), ICC_COMMAND_UPDATE_RECORD);
// fileId.
equal(this.readInt32(), fileId);
// pathId.
if (ril.appType == CARD_APPTYPE_SIM || ril.appType == CARD_APPTYPE_RUIM) {
equal(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM);
} else{
equal(this.readString(),
EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK);
}
// p1.
equal(this.readInt32(), RECORD_NUMBER);
// p2.
equal(this.readInt32(), READ_RECORD_ABSOLUTE_MODE);
// p3.
equal(this.readInt32(), RECORD_SIZE);
// data.
let strLen = this.readInt32();
// Extension record
for (let i = 0; i < RECORD_SIZE; i++) {
equal(pduHelper.readHexOctet(), 0xff);
}
this.readStringDelimiter(strLen);
// pin2.
equal(this.readString(), null);
// AID. Ignore because it's from modem.
this.readInt32();
};
recordHelper.cleanEFRecord(fileId, RECORD_NUMBER);
}
ril.appType = CARD_APPTYPE_SIM;
do_test(ICC_EF_EXT1);
run_next_test();
});
/**
* Verify ICCRecordHelper.getADNLikeExtensionRecordNumber
*/
add_test(function test_get_adn_like_extension_record_number() {
const RECORD_SIZE = 0x20;
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let helper = context.GsmPDUHelper;
let record = context.ICCRecordHelper;
let buf = context.Buf;
let io = context.ICCIOHelper;
function do_test(rawEF, expectedRecordNumber) {
io.loadLinearFixedEF = function fakeLoadLinearFixedEF(options) {
// Write data size
buf.writeInt32(rawEF.length * 2);
// Write ext
for (let i = 0; i < rawEF.length; i += 2) {
helper.writeHexOctet(parseInt(rawEF.substr(i, 2), 16));
}
// Write string delimiter
buf.writeStringDelimiter(rawEF.length);
options.recordSize = RECORD_SIZE;
if (options.callback) {
options.callback(options);
}
};
let isSuccess = false;
let successCb = function successCb(number) {
equal(number, expectedRecordNumber);
isSuccess = true;
};
let errorCb = function errorCb(errorMsg) {
do_print("Reading ADNLike failed, msg = " + errorMsg);
ok(false);
};
record.getADNLikeExtensionRecordNumber(ICC_EF_ADN, 1, successCb, errorCb);
ok(isSuccess);
}
// Valid Extension, Alpha Id(Encoded with GSM 8 bit): "Contact001",
// Dialling Number: 99887766554433221100, Ext1: 0x01
do_test("436f6e74616374303031ffffffffffffffff0b8199887766554433221100ff01", 0x01);
// Empty Extension, Alpha Id(Encoded with GSM 8 bit): "Contact001", Ext1: 0xff
do_test("436f6e74616374303031ffffffffffffffffffffffffffffffffffffffffffff", 0xff);
run_next_test();
});