Bug 847741 - Part 5: readContacts impl. r=vicamo
authorYoshi Huang <allstars.chh@mozilla.com>
Wed, 06 Mar 2013 10:51:40 +0800
changeset 141715 8f4cc68ae3c22b0194d5a320f6f896370e9ceaa5
parent 141714 e4ce63318b84db8f08083602ff4b9570d7b1d34e
child 141716 e465ed12846dd6cf257ddefc888abbb0dfb3273e
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs847741
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 847741 - Part 5: readContacts impl. r=vicamo
dom/icc/interfaces/nsIIccProvider.idl
dom/icc/tests/marionette/test_icc_contact.js
dom/system/gonk/RILContentHelper.js
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/nsIRadioInterfaceLayer.idl
dom/system/gonk/ril_worker.js
dom/system/gonk/tests/test_ril_worker_icc.js
--- a/dom/icc/interfaces/nsIIccProvider.idl
+++ b/dom/icc/interfaces/nsIIccProvider.idl
@@ -13,38 +13,47 @@ interface nsIIccListener : nsISupports
 {
   void notifyStkCommand(in DOMString aMessage);
   void notifyStkSessionEnd();
 };
 
 /**
  * XPCOM component (in the content process) that provides the ICC information.
  */
-[scriptable, uuid(c74b434a-fb2a-4e22-a6cd-1ac353e3f4ce)]
+[scriptable, uuid(041aee4f-fad0-4ed8-a11c-774b1aedd09e)]
 interface nsIIccProvider : nsISupports
 {
   /**
    * Called when a content process registers receiving unsolicited messages from
    * RadioInterfaceLayer in the chrome process. Only a content process that has
    * the 'mobileconnection' permission is allowed to register.
    */
   void registerIccMsg(in nsIIccListener listener);
   void unregisterIccMsg(in nsIIccListener listener);
 
+  /**
+   * STK interfaces.
+   */
   void sendStkResponse(in nsIDOMWindow window,
                        in jsval        command,
                        in jsval        response);
   void sendStkMenuSelection(in nsIDOMWindow   window,
                             in unsigned short itemIdentifier,
                             in boolean        helpRequested);
   void sendStkTimerExpiration(in nsIDOMWindow window,
                               in jsval        timer);
   void sendStkEventDownload(in nsIDOMWindow window,
                             in jsval        event);
 
+  /**
+   * Phonebook interfaces.
+   */
+  nsIDOMDOMRequest readContacts(in nsIDOMWindow window,
+                                in DOMString contactType);
+
   nsIDOMDOMRequest updateContact(in nsIDOMWindow window,
                                  in DOMString contactType,
                                  in nsIDOMContact contact,
                                  in DOMString pin2);
 
   /**
    * Secure Card Icc communication channel
    */
--- a/dom/icc/tests/marionette/test_icc_contact.js
+++ b/dom/icc/tests/marionette/test_icc_contact.js
@@ -1,44 +1,60 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 30000;
 
 SpecialPowers.addPermission("mobileconnection", true, document);
 
-// TODO: bug 847741 move getSimContacts to IccManager
-SpecialPowers.addPermission("contacts-read", true, document);
-SpecialPowers.addPermission("contacts-write", true, document);
-SpecialPowers.addPermission("contacts-create", true, document);
-
 let icc = navigator.mozMobileConnection.icc;
 ok(icc instanceof MozIccManager, "icc is instanceof " + icc.constructor);
 
-// TODO: bug 847741 move getSimContacts to IccManager
-let mozContacts = window.navigator.mozContacts;
-ok(mozContacts);
+function testImportSimContacts() {
+  let request = icc.readContacts("adn");
+  request.onsuccess = function onsuccess() {
+    let simContacts = request.result;
+
+    is(Array.isArray(simContacts), true);
+
+    is(simContacts[0].name, "Mozilla");
+    is(simContacts[0].tel[0].value, "15555218201");
+
+    is(simContacts[1].name, "Saßê黃");
+    is(simContacts[1].tel[0].value, "15555218202");
+
+    is(simContacts[2].name, "Fire 火");
+    is(simContacts[2].tel[0].value, "15555218203");
+
+    is(simContacts[3].name, "Huang 黃");
+    is(simContacts[3].tel[0].value, "15555218204");
+
+    runNextTest();
+  };
+
+  request.onerror = function onerror() {
+    ok(false, "Cannot get Sim Contacts");
+    runNextTest();
+  };
+};
 
 function testAddIccContact() {
   let contact = new mozContact();
 
   contact.init({
     name: "add",
     tel: [{value: "0912345678"}]
   });
 
-  // TODO: 'ADN' should change to use lower case
-  let updateRequest = icc.updateContact("ADN", contact);
+  let updateRequest = icc.updateContact("adn", contact);
 
   updateRequest.onsuccess = function onsuccess() {
     // Get ICC contact for checking new contact
 
-    // TODO: 1. bug 847741 move getSimContacts to IccManager
-    //       2. 'ADN' should change to use lower case
-    let getRequest = mozContacts.getSimContacts("ADN");
+    let getRequest = icc.readContacts("adn");
 
     getRequest.onsuccess = function onsuccess() {
       let simContacts = getRequest.result;
 
       // There are 4 SIM contacts which are harded in emulator
       is(simContacts.length, 5);
 
       is(simContacts[4].name, "add");
@@ -55,33 +71,28 @@ function testAddIccContact() {
 
   updateRequest.onerror = function onerror() {
     ok(false, "Cannot add ICC contact: " + updateRequest.error.name);
     runNextTest();
   };
 };
 
 let tests = [
+  testImportSimContacts,
   testAddIccContact,
 ];
 
 function runNextTest() {
   let test = tests.pop();
   if (!test) {
     cleanUp();
     return;
   }
 
   test();
 }
 
 function cleanUp() {
   SpecialPowers.removePermission("mobileconnection", document);
-
-  // TODO: bug 847741 move getSimContacts to IccManager
-  SpecialPowers.removePermission("contacts-read", document);
-  SpecialPowers.removePermission("contacts-write", document);
-  SpecialPowers.removePermission("contacts-create", document);
-
   finish();
 }
 
 runNextTest();
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -12,19 +12,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
+Cu.import("resource://gre/modules/ObjectWrapper.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 var RIL = {};
 Cu.import("resource://gre/modules/ril_consts.js", RIL);
 
 // set to true to in ril_consts.js to see debug messages
 var DEBUG = RIL.DEBUG_CONTENT_HELPER;
 
 // Read debug setting from pref
@@ -79,16 +80,17 @@ const RIL_IPC_MSG_NAMES = [
   "RIL:GetCallForwardingOption",
   "RIL:SetCallWaitingOption",
   "RIL:GetCallWaitingOption",
   "RIL:CellBroadcastReceived",
   "RIL:CfStateChanged",
   "RIL:IccOpenChannel",
   "RIL:IccCloseChannel",
   "RIL:IccExchangeAPDU",
+  "RIL:ReadIccContacts",
   "RIL:UpdateIccContact"
 ];
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsISyncMessageSender");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
@@ -316,16 +318,17 @@ function RILContentHelper() {
     iccInfo:              new MobileICCInfo(),
     voiceConnectionInfo:  new MobileConnectionInfo(),
     dataConnectionInfo:   new MobileConnectionInfo()
   };
   this.voicemailInfo = new VoicemailInfo();
 
   this.initRequests();
   this.initMessageListener(RIL_IPC_MSG_NAMES);
+  this._windowsMap = [],
   Services.obs.addObserver(this, "xpcom-shutdown", false);
 }
 
 RILContentHelper.prototype = {
   __proto__: DOMRequestIpcHelper.prototype,
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionProvider,
                                          Ci.nsICellBroadcastProvider,
@@ -378,16 +381,18 @@ RILContentHelper.prototype = {
     let network = destInfo.network;
     if (!network) {
       network = destInfo.network = new MobileNetworkInfo();
     }
 
     this.updateInfo(srcNetwork, network);
  },
 
+  _windowsMap: null,
+
   // nsIRILContentHelper
 
   rilContext: null,
 
   getRilContext: function getRilContext() {
     // Update ril context by sending IPC message to chrome only when the first
     // time we require it. The information will be updated by following info
     // changed messages.
@@ -657,16 +662,31 @@ RILContentHelper.prototype = {
     let request = Services.DOMRequest.createRequest(window);
     let requestId = this.getRequestId(request);
 
     cpmm.sendAsyncMessage("RIL:IccCloseChannel", {requestId: requestId,
                                                     channel: channel});
     return request;
   },
 
+  readContacts: function readContacts(window, contactType) {
+    if (window == null) {
+      throw Components.Exception("Can't get window object",
+                                  Cr.NS_ERROR_UNEXPECTED);
+    }
+
+    let request = Services.DOMRequest.createRequest(window);
+    let requestId = this.getRequestId(request);
+    this._windowsMap[requestId] = window;
+
+    cpmm.sendAsyncMessage("RIL:ReadIccContacts", {requestId: requestId,
+                                                  contactType: contactType});
+    return request;
+  },
+
   updateContact: function updateContact(window, contactType, contact, pin2) {
     if (window == null) {
       throw Components.Exception("Can't get window object",
                                   Cr.NS_ERROR_UNEXPECTED);
     }
 
     let request = Services.DOMRequest.createRequest(window);
     let requestId = this.getRequestId(request);
@@ -1118,16 +1138,19 @@ RILContentHelper.prototype = {
         this.handleIccOpenChannel(msg.json);
         break;
       case "RIL:IccCloseChannel":
         this.handleIccCloseChannel(msg.json);
         break;
       case "RIL:IccExchangeAPDU":
         this.handleIccExchangeAPDU(msg.json);
         break;
+      case "RIL:ReadIccContacts":
+        this.handleReadIccContacts(msg.json);
+        break;
       case "RIL:UpdateIccContact":
         this.handleUpdateIccContact(msg.json);
         break;
       case "RIL:DataError":
         this.updateConnectionInfo(msg.json, this.rilContext.dataConnectionInfo);
         this._deliverEvent("_mobileConnectionListeners", "notifyDataError",
                            [msg.json.errorMsg]);
         break;
@@ -1238,16 +1261,48 @@ RILContentHelper.prototype = {
     if (message.errorMsg) {
       this.fireRequestError(message.requestId, message.errorMsg);
     } else {
       var result = [message.sw1, message.sw2, message.simResponse];
       this.fireRequestSuccess(message.requestId, result);
     }
   },
 
+  handleReadIccContacts: function handleReadIccContacts(message) {
+    if (message.errorMsg) {
+      this.fireRequestError(message.requestId, message.errorMsg);
+      return;
+    }
+
+    let window = this._windowsMap[message.requestId];
+    delete this._windowsMap[message.requestId];
+    let contacts = message.contacts;
+    let result = contacts.map(function(c) {
+      let contact = Cc["@mozilla.org/contact;1"].createInstance(Ci.nsIDOMContact);
+      let prop = {name: [c.alphaId], tel: [{value: c.number}]};
+
+      if (c.email) {
+        prop.email = [{value: c.email}];
+      }
+
+      // ANR - Additional Number
+      let anrLen = c.anr ? c.anr.length : 0;
+      for (let i = 0; i < anrLen; i++) {
+        prop.tel.push({value: c.anr[i]});
+      }
+
+      contact.init(prop);
+      return contact;
+    });
+
+    let request = this.getRequest(message.requestId);
+    this.fireRequestSuccess(message.requestId,
+                            ObjectWrapper.wrap(result, window));
+  },
+
   handleUpdateIccContact: function handleUpdateIccContact(message) {
     if (message.errorMsg) {
       this.fireRequestError(message.requestId, message.errorMsg);
     } else {
       this.fireRequestSuccess(message.requestId, null);
     }
   },
 
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -94,16 +94,17 @@ const RIL_IPC_MOBILECONNECTION_MSG_NAMES
   "RIL:CancelMMI",
   "RIL:SendStkResponse",
   "RIL:SendStkMenuSelection",
   "RIL:SendStkTimerExpiration",
   "RIL:SendStkEventDownload",
   "RIL:IccOpenChannel",
   "RIL:IccExchangeAPDU",
   "RIL:IccCloseChannel",
+  "RIL:ReadIccContacts",
   "RIL:UpdateIccContact",
   "RIL:RegisterMobileConnectionMsg",
   "RIL:RegisterIccMsg",
   "RIL:SetCallForwardingOption",
   "RIL:GetCallForwardingOption",
   "RIL:SetCallWaitingOption",
   "RIL:GetCallWaitingOption"
 ];
@@ -507,16 +508,20 @@ RadioInterfaceLayer.prototype = {
       case "RIL:IccCloseChannel":
         this.saveRequestTarget(msg);
         this.iccCloseChannel(msg.json);
         break;
       case "RIL:IccExchangeAPDU":
         this.saveRequestTarget(msg);
         this.iccExchangeAPDU(msg.json);
         break;
+      case "RIL:ReadIccContacts":
+        this.saveRequestTarget(msg);
+        this.readIccContacts(msg.json);
+        break;
       case "RIL:UpdateIccContact":
         this.saveRequestTarget(msg);
         this.updateIccContact(msg.json);
         break;
       case "RIL:RegisterMobileConnectionMsg":
         this.registerMessageTarget("mobileconnection", msg.target);
         break;
       case "RIL:RegisterIccMsg":
@@ -669,26 +674,17 @@ RadioInterfaceLayer.prototype = {
         this.rilContext.imsi = message.imsi;
         break;
       case "iccGetCardLock":
       case "iccSetCardLock":
       case "iccUnlockCardLock":
         this.handleIccCardLockResult(message);
         break;
       case "icccontacts":
-        if (!this._contactsCallbacks) {
-          return;
-        }
-        let callback = this._contactsCallbacks[message.requestId];
-        if (callback) {
-          delete this._contactsCallbacks[message.requestId];
-          callback.receiveContactsList(message.errorMsg,
-                                       message.contactType,
-                                       message.contacts);
-        }
+        this.handleReadIccContacts(message);
         break;
       case "icccontactupdate":
         this.handleUpdateIccContact(message);
         break;
       case "iccmbdn":
         this.handleIccMbdn(message);
         break;
       case "USSDReceived":
@@ -1371,16 +1367,21 @@ RadioInterfaceLayer.prototype = {
     for (let i in options.calls) {
       options.calls[i].state = convertRILCallState(options.calls[i].state);
       options.calls[i].isActive = this._activeCall ?
         options.calls[i].callIndex == this._activeCall.callIndex : false;
     }
     this._sendRequestResults("RIL:EnumerateCalls", options);
   },
 
+  handleReadIccContacts: function handleReadIccContacts(message) {
+    debug("handleReadIccContacts: " + JSON.stringify(message));
+    this._sendRequestResults("RIL:ReadIccContacts", message);
+  },
+
   handleUpdateIccContact: function handleUpdateIccContact(message) {
     debug("handleUpdateIccContact: " + JSON.stringify(message));
     this._sendRequestResults("RIL:UpdateIccContact", message);
   },
 
   /**
    * Open Logical UICC channel (aid) for Secure Element access
    */
@@ -2876,26 +2877,19 @@ RadioInterfaceLayer.prototype = {
     this.worker.postMessage(message);
   },
 
   setCardLock: function setCardLock(message) {
     message.rilMessageType = "iccSetCardLock";
     this.worker.postMessage(message);
   },
 
-  _contactsCallbacks: null,
-  getICCContacts: function getICCContacts(contactType, callback) {
-    if (!this._contactsCallbacks) {
-      this._contactsCallbacks = {};
-    }
-    let requestId = Math.floor(Math.random() * 1000);
-    this._contactsCallbacks[requestId] = callback;
-    this.worker.postMessage({rilMessageType: "getICCContacts",
-                             contactType: contactType,
-                             requestId: requestId});
+  readIccContacts: function readIccContacts(message) {
+    message.rilMessageType = "readICCContacts";
+    this.worker.postMessage(message);
   },
 
   updateIccContact: function updateIccContact(message) {
     message.rilMessageType = "updateICCContact";
     this.worker.postMessage(message);
   },
 };
 
--- a/dom/system/gonk/nsIRadioInterfaceLayer.idl
+++ b/dom/system/gonk/nsIRadioInterfaceLayer.idl
@@ -46,34 +46,16 @@ interface nsIRILDataCallback : nsISuppor
    *        Array of nsIRILDataCallInfo objects.
    * @param length
    *        Lenght of the aforementioned array.
    */
   void receiveDataCallList([array,size_is(length)] in nsIRILDataCallInfo dataCalls,
                            in unsigned long length);
 };
 
-[scriptable, function, uuid(a94282b6-da60-4daf-95c1-82ee6889d0df)]
-interface nsIRILContactCallback : nsISupports
-{
-  /**
-   * Called when nsIRadioInterfaceLayer is asked to provide ICC contacts.
-   *
-   * @param errorMsg
-   *        error message from RIL.
-   * @param contactType
-   *        Type of the dialling number, i.e. ADN, FDN.
-   * @param contacts
-   *        Array of the ICC contacts of the specified type.
-   */
-  void receiveContactsList(in DOMString errorMsg,
-                           in DOMString contactType,
-                           in jsval contacts);
-};
-
 [scriptable, uuid(c0c5cb9f-6372-4b5a-b74c-baacc2da5e4f)]
 interface nsIVoicemailInfo : nsISupports
 {
   readonly attribute DOMString number;
 
   readonly attribute DOMString displayName;
 };
 
@@ -90,17 +72,17 @@ interface nsIRilContext : nsISupports
 
   readonly attribute nsIDOMMozMobileICCInfo iccInfo;
 
   readonly attribute nsIDOMMozMobileConnectionInfo voice;
 
   readonly attribute nsIDOMMozMobileConnectionInfo data;
 };
 
-[scriptable, uuid(9a914550-8f7a-11e2-9e96-0800200c9a66)]
+[scriptable, uuid(c1c9d1e6-fec6-4c99-880d-7a310d736e64)]
 interface nsIRadioInterfaceLayer : nsISupports
 {
   /**
    * Activates or deactivates radio power.
    */
   void setRadioEnabled(in bool value);
 
   readonly attribute nsIRilContext rilContext;
@@ -131,24 +113,9 @@ interface nsIRadioInterfaceLayer : nsISu
   /**
    * SMS-related functionality.
    */
   nsIDOMMozSmsSegmentInfo getSegmentInfoForText(in DOMString text);
 
   void sendSMS(in DOMString number,
                in DOMString message,
                in nsIMobileMessageCallback request);
-
-  /**
-   * ICC-related functionality.
-   */
-
-  /**
-   * Get ICC Contact List.
-   *
-   * @param contactType One of the values below.
-   *                    "ADN" (Abbreviated Dialling Numbers)
-   *                    "FDN" (Fixed Dialling Numbers)
-   * @param callback  A nsIRILContactCallback object.
-   */
-  void getICCContacts(in DOMString contactType,
-                      in nsIRILContactCallback callback);
 };
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -1296,24 +1296,24 @@ let RIL = {
     }
     let token = Buf.newParcel(REQUEST_GET_IMSI);
     Buf.writeUint32(1);
     Buf.writeString(aid || this.aid);
     Buf.sendParcel();
   },
 
   /**
-   * Get UICC Phonebook.
+   * Read UICC Phonebook contacts.
    *
    * @param contactType
-   *        "ADN" or "FDN".
+   *        "adn" or "fdn".
    * @param requestId
    *        Request id from RadioInterfaceLayer.
    */
-  getICCContacts: function getICCContacts(options) {
+  readICCContacts: function readICCContacts(options) {
     if (!this.appType) {
       options.rilMessageType = "icccontacts";
       options.errorMsg = GECKO_ERROR_REQUEST_NOT_SUPPORTED;
       this.sendDOMMessage(options);
     }
 
     ICCContactHelper.readICCContacts(
       this.appType,
@@ -1329,17 +1329,17 @@ let RIL = {
         options.errorMsg = errorMsg;
         RIL.sendDOMMessage(options);
       }.bind(this));
   },
 
   /**
    * Update UICC Phonebook.
    *
-   * @param contactType   "ADN" or "FDN".
+   * @param contactType   "adn" or "fdn".
    * @param contact       The contact will be updated.
    * @param pin2          PIN2 is required for updating FDN.
    * @param requestId     Request id from RadioInterfaceLayer.
    */
   updateICCContact: function updateICCContact(options) {
     let onsuccess = function onsuccess() {
       // Reuse 'options' to get 'requestId' and 'contactType'.
       options.rilMessageType = "icccontactupdate";
@@ -11297,80 +11297,80 @@ let ICCUtilsHelper = {
 /**
  * Helper for ICC Contacts.
  */
 let ICCContactHelper = {
   /**
    * Helper function to read ICC contacts.
    *
    * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
-   * @param contactType   "ADN" or "FDN"
+   * @param contactType   "adn" or "fdn".
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   readICCContacts: function readICCContacts(appType, contactType, onsuccess, onerror) {
     switch (contactType) {
-      case "ADN":
+      case "adn":
         switch (appType) {
           case CARD_APPTYPE_SIM:
             ICCRecordHelper.readADNLike(ICC_EF_ADN, onsuccess, onerror);
             break;
           case CARD_APPTYPE_USIM:
             this.readUSimContacts(onsuccess, onerror);
             break;
         }
         break;
-      case "FDN":
+      case "fdn":
         ICCRecordHelper.readADNLike(ICC_EF_FDN, onsuccess, onerror);
         break;
     }
   },
 
   /**
    * Helper function to find free contact record.
    *
    * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
-   * @param contactType   "ADN" or "FDN".
+   * @param contactType   "adn" or "fdn".
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   findFreeICCContact: function findFreeICCContact(appType, contactType, onsuccess, onerror) {
     switch (contactType) {
-      case "ADN":
+      case "adn":
         switch (appType) {
           case CARD_APPTYPE_SIM:
             ICCRecordHelper.getFreeRecordId(ICC_EF_ADN, onsuccess, onerror);
             break;
           case CARD_APPTYPE_USIM:
             let gotPbrCb = function gotPbrCb(pbr) {
               if (pbr.adn) {
                 ICCRecordHelper.getFreeRecordId(pbr.adn.fileId, onsuccess, onerror);
               }
             }.bind(this);
 
             ICCRecordHelper.readPBR(gotPbrCb, onerror);
             break;
         }
         break;
-      case "FDN":
+      case "fdn":
         ICCRecordHelper.getFreeRecordId(ICC_EF_FDN, onsuccess, onerror);
         break;
       default:
         if (onerror) {
           onerror(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
         }
         break;
     }
   },
 
   /**
    * Helper function to add a new ICC contact.
    *
    * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
-   * @param contactType   "ADN" or "FDN".
+   * @param contactType   "adn" or "fdn".
    * @param contact       The contact will be added.
    * @param pin2          PIN2 is required for FDN.
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   addICCContact: function addICCContact(appType, contactType, contact, pin2, onsuccess, onerror) {
     let foundFreeCb = function foundFreeCb(recordId) {
       contact.recordId = recordId;
@@ -11380,35 +11380,35 @@ let ICCContactHelper = {
     // Find free record first.
     ICCContactHelper.findFreeICCContact(appType, contactType, foundFreeCb, onerror);
   },
 
   /**
    * Helper function to update ICC contact.
    *
    * @param appType       CARD_APPTYPE_SIM or CARD_APPTYPE_USIM.
-   * @param contactType   "ADN" or "FDN".
+   * @param contactType   "adn" or "fdn".
    * @param contact       The contact will be updated.
    * @param pin2          PIN2 is required for FDN.
    * @param onsuccess     Callback to be called when success.
    * @param onerror       Callback to be called when error.
    */
   updateICCContact: function updateICCContact(appType, contactType, contact, pin2, onsuccess, onerror) {
     switch (contactType) {
-      case "ADN":
+      case "adn":
         switch (appType) {
           case CARD_APPTYPE_SIM:
             ICCRecordHelper.updateADNLike(ICC_EF_ADN, contact, null, onsuccess, onerror);
             break;
           case CARD_APPTYPE_USIM:
             this.updateUSimContact(contact, onsuccess, onerror);
             break;
         }
         break;
-      case "FDN":
+      case "fdn":
         ICCRecordHelper.updateADNLike(ICC_EF_FDN, contact, pin2, onsuccess, onerror);
         break;
       default:
         if (onerror) {
           onerror(GECKO_ERROR_REQUEST_NOT_SUPPORTED);
         }
         break;
     }
--- a/dom/system/gonk/tests/test_ril_worker_icc.js
+++ b/dom/system/gonk/tests/test_ril_worker_icc.js
@@ -2050,17 +2050,17 @@ add_test(function test_read_icc_contacts
   };
 
   let errorCb = function errorCb(errorMsg) {
     do_print(errorMsg);
     do_check_true(false);
     run_next_test();
   };
 
-  contactHelper.readICCContacts(CARD_APPTYPE_USIM, "ADN", successCb, errorCb);
+  contactHelper.readICCContacts(CARD_APPTYPE_USIM, "adn", successCb, errorCb);
 });
 
 /**
  * Verify ICCContactHelper.updateICCContact
  */
 add_test(function test_update_icc_contact() {
   let worker = newUint8Worker();
   let record = worker.ICCRecordHelper;
@@ -2073,18 +2073,18 @@ add_test(function test_update_icc_contac
       do_check_eq(contact.alphaId, aContact.alphaId);
       do_check_eq(contact.number, aContact.number);
       do_check_eq(pin2, aPin2);
     };
     contactHelper.updateICCContact(CARD_APPTYPE_SIM, aContactType, aContact, aPin2);
   };
 
   let contact = {recordId: 1, alphaId: "test", number: "123456"};
-  do_test(contact, "ADN", ICC_EF_ADN);
-  do_test(contact, "FDN", ICC_EF_FDN, "1111");
+  do_test(contact, "adn", ICC_EF_ADN);
+  do_test(contact, "fdn", ICC_EF_FDN, "1111");
 
   run_next_test();
 });
 
 /**
  * Verify cardState 'corporateLocked'.
  */
 add_test(function test_card_state_corporateLocked() {