Bug 1112471 - Part 3: RIL Changes for getting icc service state API. r=hsinyi
authorEdgar Chen <echen@mozilla.com>
Fri, 26 Dec 2014 10:57:44 +0800
changeset 235654 77324fcf60a058edfebee6fd294d5225678eec57
parent 235653 a07deec1d2721d1e4647da981d756875f0e88026
child 235655 f1997f0cf24b33e067272ec52a24e2993d629d54
push id366
push usercmanchester@mozilla.com
push dateThu, 08 Jan 2015 16:40:24 +0000
reviewershsinyi
bugs1112471
milestone37.0a1
Bug 1112471 - Part 3: RIL Changes for getting icc service state API. r=hsinyi
dom/system/gonk/RILContentHelper.js
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -50,17 +50,18 @@ const RIL_IPC_MSG_NAMES = [
   "RIL:CardLockRetryCount",
   "RIL:StkCommand",
   "RIL:StkSessionEnd",
   "RIL:IccOpenChannel",
   "RIL:IccCloseChannel",
   "RIL:IccExchangeAPDU",
   "RIL:ReadIccContacts",
   "RIL:UpdateIccContact",
-  "RIL:MatchMvno"
+  "RIL:MatchMvno",
+  "RIL:GetServiceState"
 ];
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsISyncMessageSender");
 
 XPCOMUtils.defineLazyServiceGetter(this, "UUIDGenerator",
                   "@mozilla.org/uuid-generator;1",
@@ -531,16 +532,37 @@ RILContentHelper.prototype = {
         contact: iccContact,
         pin2: pin2
       }
     });
 
     return request;
   },
 
+  getServiceState: function(clientId, window, service) {
+    if (window == null) {
+      throw Components.Exception("Can't get window object",
+                                  Cr.NS_ERROR_UNEXPECTED);
+    }
+
+    return new window.Promise((resolve, reject) => {
+      let requestId =
+        this.getPromiseResolverId({resolve: resolve, reject: reject});
+      this._windowsMap[requestId] = window;
+
+      cpmm.sendAsyncMessage("RIL:GetServiceState", {
+        clientId: clientId,
+        data: {
+          requestId: requestId,
+          service: service
+        }
+      });
+    });
+  },
+
   _iccListeners: null,
 
   registerListener: function(listenerType, clientId, listener) {
     if (!this[listenerType]) {
       return;
     }
     let listeners = this[listenerType][clientId];
     if (!listeners) {
@@ -767,16 +789,19 @@ RILContentHelper.prototype = {
         this.handleReadIccContacts(data);
         break;
       case "RIL:UpdateIccContact":
         this.handleUpdateIccContact(data);
         break;
       case "RIL:MatchMvno":
         this.handleSimpleRequest(data.requestId, data.errorMsg, data.result);
         break;
+      case "RIL:GetServiceState":
+        this.handleGetServiceState(data);
+        break;
     }
   },
 
   handleSimpleRequest: function(requestId, errorMsg, result) {
     if (errorMsg) {
       this.fireRequestError(requestId, errorMsg);
     } else {
       this.fireRequestSuccess(requestId, result);
@@ -869,16 +894,30 @@ RILContentHelper.prototype = {
     }
 
     let contact = new window.mozContact(prop);
     contact.id = iccContact.contactId;
 
     this.fireRequestSuccess(message.requestId, contact);
   },
 
+  handleGetServiceState: function(message) {
+    let requestId = message.requestId;
+    let requestWindow = this._windowsMap[requestId];
+    delete this._windowsMap[requestId];
+
+    let resolver = this.takePromiseResolver(requestId);
+    if (message.errorMsg) {
+      resolver.reject(new requestWindow.DOMError(message.errorMsg));
+      return;
+    }
+
+    resolver.resolve(message.result);
+  },
+
   _deliverEvent: function(clientId, listenerType, name, args) {
     if (!this[listenerType]) {
       return;
     }
     let thisListeners = this[listenerType][clientId];
     if (!thisListeners) {
       return;
     }
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -96,17 +96,18 @@ const RIL_IPC_ICCMANAGER_MSG_NAMES = [
   "RIL:ChangeCardLockPassword",
   "RIL:GetCardLockRetryCount",
   "RIL:IccOpenChannel",
   "RIL:IccExchangeAPDU",
   "RIL:IccCloseChannel",
   "RIL:ReadIccContacts",
   "RIL:UpdateIccContact",
   "RIL:RegisterIccMsg",
-  "RIL:MatchMvno"
+  "RIL:MatchMvno",
+  "RIL:GetServiceState"
 ];
 
 // set to true in ril_consts.js to see debug messages
 var DEBUG = RIL.DEBUG_RIL;
 
 function updateDebugFlag() {
   // Read debug setting from pref
   let debugPref;
@@ -1831,16 +1832,19 @@ RadioInterface.prototype = {
         this.workerMessenger.sendWithIPCMessage(msg, "readICCContacts");
         break;
       case "RIL:UpdateIccContact":
         this.workerMessenger.sendWithIPCMessage(msg, "updateICCContact");
         break;
       case "RIL:MatchMvno":
         this.matchMvno(msg.target, msg.json.data);
         break;
+      case "RIL:GetServiceState":
+        this.workerMessenger.sendWithIPCMessage(msg, "getIccServiceState");
+        break;
     }
     return null;
   },
 
   handleUnsolicitedWorkerMessage: function(message) {
     let connHandler = gDataConnectionManager.getConnectionHandler(this.clientId);
     switch (message.rilMessageType) {
       case "audioStateChanged":
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -2646,16 +2646,19 @@ this.GECKO_CARDCONTACT_TYPE_ADN = 0;
 this.GECKO_CARDCONTACT_TYPE_FDN = 1;
 this.GECKO_CARDCONTACT_TYPE_SDN = 2;
 
 // See nsIIccProvider::CARD_MVNO_TYPE_*
 this.GECKO_CARDMVNO_TYPE_IMSI = 0;
 this.GECKO_CARDMVNO_TYPE_SPN = 1;
 this.GECKO_CARDMVNO_TYPE_GID = 2;
 
+// See nsIIccProvider::CARD_MVNO_TYPE_*
+this.GECKO_CARDSERVICE_FDN = 0;
+
 // See ril.h RIL_PersoSubstate
 this.PERSONSUBSTATE = {};
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_UNKNOWN] = GECKO_CARDSTATE_UNKNOWN;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_IN_PROGRESS] = GECKO_CARDSTATE_PERSONALIZATION_IN_PROGRESS;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_READY] = GECKO_CARDSTATE_PERSONALIZATION_READY;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK] = GECKO_CARDSTATE_NETWORK_LOCKED;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_NETWORK_SUBSET] = GECKO_CARDSTATE_NETWORK_SUBSET_LOCKED;
 PERSONSUBSTATE[CARD_PERSOSUBSTATE_SIM_CORPORATE] = GECKO_CARDSTATE_CORPORATE_LOCKED;
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -1499,16 +1499,32 @@ RilObject.prototype = {
     let Buf = this.context.Buf;
     Buf.newParcel(REQUEST_SIM_CLOSE_CHANNEL, options);
     Buf.writeInt32(1);
     Buf.writeInt32(options.channel);
     Buf.sendParcel();
   },
 
   /**
+   * Get UICC service state
+   */
+  getIccServiceState: function(options) {
+    switch (options.service) {
+      case GECKO_CARDSERVICE_FDN:
+        let ICCUtilsHelper = this.context.ICCUtilsHelper;
+        options.result = ICCUtilsHelper.isICCServiceAvailable("FDN");
+        break;
+      default:
+        options.errorMsg = GECKO_ERROR_REQUEST_NOT_SUPPORTED;
+        break;
+    }
+    this.sendChromeMessage(options);
+  },
+
+  /**
    * Enable/Disable UICC subscription
    */
   setUiccSubscription: function(options) {
     if (DEBUG) {
       this.context.debug("setUiccSubscription: " + JSON.stringify(options));
     }
 
     let Buf = this.context.Buf;