Bug 1061380 - Part 2: Refactor ICC I/O error. r=vicamo

This commit is contained in:
Edgar Chen 2014-09-10 18:25:13 +08:00
parent a250ed304c
commit a9ab13838e
2 changed files with 41 additions and 41 deletions

View File

@ -5629,26 +5629,38 @@ RilObject.prototype[REQUEST_SETUP_DATA_CALL] = function REQUEST_SETUP_DATA_CALL(
this[REQUEST_DATA_CALL_LIST](length, options);
};
RilObject.prototype[REQUEST_SIM_IO] = function REQUEST_SIM_IO(length, options) {
let ICCIOHelper = this.context.ICCIOHelper;
if (!length) {
ICCIOHelper.processICCIOError(options);
if (options.rilRequestError) {
if (options.onerror) {
options.onerror(RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError] ||
GECKO_ERROR_GENERIC_FAILURE);
}
return;
}
// Don't need to read rilRequestError since we can know error status from
// sw1 and sw2.
let Buf = this.context.Buf;
options.sw1 = Buf.readInt32();
options.sw2 = Buf.readInt32();
// See 3GPP TS 11.11, clause 9.4.1 for opetation success results.
// See 3GPP TS 11.11, clause 9.4.1 for operation success results.
if (options.sw1 !== ICC_STATUS_NORMAL_ENDING &&
options.sw1 !== ICC_STATUS_NORMAL_ENDING_WITH_EXTRA &&
options.sw1 !== ICC_STATUS_WITH_SIM_DATA &&
options.sw1 !== ICC_STATUS_WITH_RESPONSE_DATA) {
ICCIOHelper.processICCIOError(options);
if (DEBUG) {
this.context.debug("ICC I/O Error EF id = 0x" + options.fileId.toString(16) +
", command = 0x" + options.command.toString(16) +
", sw1 = 0x" + options.sw1.toString(16) +
", sw2 = 0x" + options.sw2.toString(16));
}
if (options.onerror) {
// We can get fail cause from sw1/sw2 (See TS 11.11 clause 9.4.1 and
// ISO 7816-4 clause 6). But currently no one needs this information,
// so simply reports "GenericFailure" for now.
options.onerror(GECKO_ERROR_GENERIC_FAILURE);
}
return;
}
ICCIOHelper.processICCIO(options);
this.context.ICCIOHelper.processICCIO(options);
};
RilObject.prototype[REQUEST_SEND_USSD] = function REQUEST_SEND_USSD(length, options) {
if (DEBUG) {
@ -12491,28 +12503,6 @@ ICCIOHelperObject.prototype = {
options.callback(options);
}
},
/**
* Process ICC IO error.
*/
processICCIOError: function(options) {
let requestError = RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError];
if (DEBUG) {
// See GSM11.11, TS 51.011 clause 9.4, and ISO 7816-4 for the error
// description.
let errorMsg = "ICC I/O Error code " + requestError +
" EF id = " + options.fileId.toString(16) +
" command = " + options.command.toString(16);
if (options.sw1 && options.sw2) {
errorMsg += "(" + options.sw1.toString(16) +
"/" + options.sw2.toString(16) + ")";
}
this.context.debug(errorMsg);
}
if (options.onerror) {
options.onerror(requestError);
}
},
};
ICCIOHelperObject.prototype[ICC_COMMAND_SEEK] = null;
ICCIOHelperObject.prototype[ICC_COMMAND_READ_BINARY] = function ICC_COMMAND_READ_BINARY(options) {

View File

@ -54,31 +54,41 @@ add_test(function test_load_linear_fixed_ef() {
});
/**
* Verify ICCIOHelper.processICCIOError.
* Verify ICC IO Error.
*/
add_test(function test_process_icc_io_error() {
let worker = newUint8Worker();
let context = worker.ContextPool._contexts[0];
let ioHelper = context.ICCIOHelper;
let buf = context.Buf;
function do_test(errorCode, expectedErrorMsg) {
function do_test(sw1, sw2, expectedErrorMsg) {
let called = false;
function errorCb(errorMsg) {
called = true;
do_check_eq(errorMsg, expectedErrorMsg);
}
ioHelper.processICCIOError({rilRequestError: errorCode,
fileId: 0xffff,
command: 0xff,
sw1: 0xff,
sw2: 0xff,
onerror: errorCb});
// Write sw1 and sw2 to buffer.
buf.writeInt32(sw1);
buf.writeInt32(sw2);
context.RIL[REQUEST_SIM_IO](0, {rilRequestError: ERROR_SUCCESS,
fileId: 0xffff,
command: 0xff,
onerror: errorCb});
// onerror callback should be triggered.
do_check_true(called);
}
for (let i = 0; i < ERROR_REJECTED_BY_REMOTE + 1; i++) {
do_test(i, RIL_ERROR_TO_GECKO_ERROR[i]);
let TEST_DATA = [
// [sw1, sw2, expectError]
[ICC_STATUS_ERROR_COMMAND_NOT_ALLOWED, 0xff, GECKO_ERROR_GENERIC_FAILURE],
[ICC_STATUS_ERROR_WRONG_PARAMETERS, 0xff, GECKO_ERROR_GENERIC_FAILURE],
];
for (let i = 0; i < TEST_DATA.length; i++) {
do_test.apply(null, TEST_DATA[i]);
}
run_next_test();