Bug 1061380 - Part 2: Refactor ICC I/O error. r=vicamo, a=bajaj
authorEdgar Chen <echen@mozilla.com>
Wed, 10 Sep 2014 18:25:13 +0800
changeset 225439 d5fcddc6091b74d2fb7449b46abdbb6041bcfa36
parent 225438 f774ac47264124ed6ed7aff7e0f0f7c6472b57a6
child 225440 c89cf06d1f3feb0e94c43d97715761c0956927a2
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo, bajaj
bugs1061380
milestone34.0a2
Bug 1061380 - Part 2: Refactor ICC I/O error. r=vicamo, a=bajaj
dom/system/gonk/ril_worker.js
dom/system/gonk/tests/test_ril_worker_icc_ICCIOHelper.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -5839,36 +5839,48 @@ RilObject.prototype[REQUEST_SETUP_DATA_C
     this.getDataCallList();
     return;
   }
   // Pass `options` along. That way we retain the APN and other info about
   // how the data call was set up.
   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);
-    return;
-  }
-
-  // Don't need to read rilRequestError since we can know error status from
-  // sw1 and sw2.
+  if (options.rilRequestError) {
+    if (options.onerror) {
+      options.onerror(RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError] ||
+                      GECKO_ERROR_GENERIC_FAILURE);
+    }
+    return;
+  }
+
   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);
-    return;
-  }
-  ICCIOHelper.processICCIO(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;
+  }
+  this.context.ICCIOHelper.processICCIO(options);
 };
 RilObject.prototype[REQUEST_SEND_USSD] = function REQUEST_SEND_USSD(length, options) {
   if (DEBUG) {
     this.context.debug("REQUEST_SEND_USSD " + JSON.stringify(options));
   }
   options.success = (this._ussdSession = options.rilRequestError === 0);
   options.errorMsg = RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError];
   this.sendChromeMessage(options);
@@ -12838,38 +12850,16 @@ ICCIOHelperObject.prototype = {
   /**
    * Process a ICC_COMMAND_UPDATE_RECORD type command for REQUEST_SIM_IO.
    */
   processICCIOUpdateRecord: function(options) {
     if (options.callback) {
       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) {
   this.processICCIOReadBinary(options);
 };
 ICCIOHelperObject.prototype[ICC_COMMAND_READ_RECORD] = function ICC_COMMAND_READ_RECORD(options) {
   this.processICCIOReadRecord(options);
 };
--- a/dom/system/gonk/tests/test_ril_worker_icc_ICCIOHelper.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc_ICCIOHelper.js
@@ -49,41 +49,51 @@ add_test(function test_load_linear_fixed
     do_check_true(false);
     run_next_test();
   };
 
   io.loadLinearFixedEF({});
 });
 
 /**
- * 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();
 });
 
 /**
  * Verify ICCIOHelper.processICCIOGetResponse for EF_TYPE_TRANSPARENT.
  */