Bug 960894 - 3.b/4: don't modify global. r=hsinyi
authorVicamo Yang <vyang@mozilla.com>
Mon, 17 Feb 2014 19:35:05 +0800
changeset 169522 c00a2b2adf68e5b142f373a41b033f9ce1fcc0f1
parent 169521 504dda11bdf9438f072ac41998e8ddb3006074f4
child 169523 5725bfc6d45e13da84a3b4a6a1ee123d39cf5259
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewershsinyi
bugs960894
milestone30.0a1
Bug 960894 - 3.b/4: don't modify global. r=hsinyi
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -48,16 +48,18 @@ let GLOBAL = this;
 
 if (!this.debug) {
   // Debugging stub that goes nowhere.
   this.debug = function debug(message) {
     dump("RIL Worker[" + CLIENT_ID + "]: " + message + "\n");
   };
 }
 
+let RIL_CELLBROADCAST_DISABLED;
+let RIL_CLIR_MODE;
 let RIL_EMERGENCY_NUMBERS;
 const DEFAULT_EMERGENCY_NUMBERS = ["112", "911"];
 
 // Timeout value for emergency callback mode.
 const EMERGENCY_CB_MODE_TIMEOUT_MS = 300000;  // 5 mins = 300000 ms.
 
 const ICC_MAX_LINEAR_FIXED_RECORDS = 0xfe;
 
@@ -189,16 +191,18 @@ let Buf = {
 /**
  * The RIL state machine.
  *
  * This object communicates with rild via parcels and with the main thread
  * via post messages. It maintains state about the radio, ICC, calls, etc.
  * and acts upon state changes accordingly.
  */
 let RIL = {
+  v5Legacy: null,
+
   /**
    * Valid calls.
    */
   currentCalls: {},
 
   /**
    * Existing conference call and its participants.
    */
@@ -478,37 +482,37 @@ let RIL = {
    *
    * @param pin
    *        String containing the PIN.
    * @param [optional] aid
    *        AID value.
    */
   enterICCPIN: function(options) {
     Buf.newParcel(REQUEST_ENTER_SIM_PIN, options);
-    Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 1 : 2);
+    Buf.writeInt32(this.v5Legacy ? 1 : 2);
     Buf.writeString(options.pin);
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
 
   /**
    * Enter a PIN2 to unlock the ICC.
    *
    * @param pin
    *        String containing the PIN2.
    * @param [optional] aid
    *        AID value.
    */
   enterICCPIN2: function(options) {
     Buf.newParcel(REQUEST_ENTER_SIM_PIN2, options);
-    Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 1 : 2);
+    Buf.writeInt32(this.v5Legacy ? 1 : 2);
     Buf.writeString(options.pin);
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
 
   /**
    * Requests a network personalization be deactivated.
    *
@@ -572,20 +576,20 @@ let RIL = {
    *        String containing the old PIN value
    * @param newPin
    *        String containing the new PIN value
    * @param [optional] aid
    *        AID value.
    */
   changeICCPIN: function(options) {
     Buf.newParcel(REQUEST_CHANGE_SIM_PIN, options);
-    Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 2 : 3);
+    Buf.writeInt32(this.v5Legacy ? 2 : 3);
     Buf.writeString(options.pin);
     Buf.writeString(options.newPin);
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
 
   /**
    * Change the current ICC PIN2 number.
    *
@@ -593,40 +597,40 @@ let RIL = {
    *        String containing the old PIN2 value
    * @param newPin
    *        String containing the new PIN2 value
    * @param [optional] aid
    *        AID value.
    */
   changeICCPIN2: function(options) {
     Buf.newParcel(REQUEST_CHANGE_SIM_PIN2, options);
-    Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 2 : 3);
+    Buf.writeInt32(this.v5Legacy ? 2 : 3);
     Buf.writeString(options.pin);
     Buf.writeString(options.newPin);
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
   /**
    * Supplies ICC PUK and a new PIN to unlock the ICC.
    *
    * @param puk
    *        String containing the PUK value.
    * @param newPin
    *        String containing the new PIN value.
    * @param [optional] aid
    *        AID value.
    */
    enterICCPUK: function(options) {
      Buf.newParcel(REQUEST_ENTER_SIM_PUK, options);
-     Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 2 : 3);
+     Buf.writeInt32(this.v5Legacy ? 2 : 3);
      Buf.writeString(options.puk);
      Buf.writeString(options.newPin);
-     if (!RILQUIRKS_V5_LEGACY) {
+     if (!this.v5Legacy) {
        Buf.writeString(options.aid || this.aid);
      }
      Buf.sendParcel();
    },
 
   /**
    * Supplies ICC PUK2 and a new PIN2 to unlock the ICC.
    *
@@ -634,20 +638,20 @@ let RIL = {
    *        String containing the PUK2 value.
    * @param newPin
    *        String containing the new PIN2 value.
    * @param [optional] aid
    *        AID value.
    */
    enterICCPUK2: function(options) {
      Buf.newParcel(REQUEST_ENTER_SIM_PUK2, options);
-     Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 2 : 3);
+     Buf.writeInt32(this.v5Legacy ? 2 : 3);
      Buf.writeString(options.puk);
      Buf.writeString(options.newPin);
-     if (!RILQUIRKS_V5_LEGACY) {
+     if (!this.v5Legacy) {
        Buf.writeString(options.aid || this.aid);
      }
      Buf.sendParcel();
    },
 
   /**
    * Helper function for fetching the state of ICC locks.
    */
@@ -734,21 +738,21 @@ let RIL = {
    *        Password for the facility, or "" if not required.
    * @param serviceClass
    *        One of ICC_SERVICE_CLASS_*.
    * @param [optional] aid
    *        AID value.
    */
   queryICCFacilityLock: function(options) {
     Buf.newParcel(REQUEST_QUERY_FACILITY_LOCK, options);
-    Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 3 : 4);
+    Buf.writeInt32(this.v5Legacy ? 3 : 4);
     Buf.writeString(options.facility);
     Buf.writeString(options.password);
     Buf.writeString(options.serviceClass.toString());
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
 
   /**
    * Set ICC facility lock.
    *
@@ -760,22 +764,22 @@ let RIL = {
    *        Password for the facility, or "" if not required.
    * @param serviceClass
    *        One of ICC_SERVICE_CLASS_*.
    * @param [optional] aid
    *        AID value.
    */
   setICCFacilityLock: function(options) {
     Buf.newParcel(REQUEST_SET_FACILITY_LOCK, options);
-    Buf.writeInt32(RILQUIRKS_V5_LEGACY ? 4 : 5);
+    Buf.writeInt32(this.v5Legacy ? 4 : 5);
     Buf.writeString(options.facility);
     Buf.writeString(options.enabled ? "1" : "0");
     Buf.writeString(options.password);
     Buf.writeString(options.serviceClass.toString());
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
 
   /**
    *  Request an ICC I/O operation.
    *
@@ -818,30 +822,30 @@ let RIL = {
     // Write pin2.
     if (options.command == ICC_COMMAND_UPDATE_RECORD &&
         options.pin2) {
       Buf.writeString(options.pin2);
     } else {
       Buf.writeString(null);
     }
 
-    if (!RILQUIRKS_V5_LEGACY) {
+    if (!this.v5Legacy) {
       Buf.writeString(options.aid || this.aid);
     }
     Buf.sendParcel();
   },
 
   /**
    * Get IMSI.
    *
    * @param [optional] aid
    *        AID value.
    */
   getIMSI: function(aid) {
-    if (RILQUIRKS_V5_LEGACY) {
+    if (this.v5Legacy) {
       Buf.simpleRequest(REQUEST_GET_IMSI);
       return;
     }
     Buf.newParcel(REQUEST_GET_IMSI);
     Buf.writeInt32(1);
     Buf.writeString(aid || this.aid);
     Buf.sendParcel();
   },
@@ -1858,17 +1862,17 @@ let RIL = {
     // for values above 2 this is RIL_RadioTechnology + 2.
     //
     // From frameworks/base/telephony/java/com/android/internal/telephony/DataConnection.java:
     // if the mRilVersion < 6, radio technology must be GSM/UMTS or CDMA.
     // Otherwise, it must be + 2
     //
     // See also bug 901232 and 867873
     let radioTech;
-    if (RILQUIRKS_V5_LEGACY) {
+    if (this.v5Legacy) {
       radioTech = this._isCdma ? DATACALL_RADIOTECHNOLOGY_CDMA
                                : DATACALL_RADIOTECHNOLOGY_GSM;
     } else {
       radioTech = options.radioTech + 2;
     }
     let token = Buf.newParcel(REQUEST_SETUP_DATA_CALL, options);
     Buf.writeInt32(7);
     Buf.writeString(radioTech.toString());
@@ -4962,48 +4966,54 @@ let RIL = {
     if (typeof method == "function") {
       if (DEBUG) debug("Handling parcel as " + method.name);
       method.call(this, length, options);
     }
   },
 
   setInitialOptions: function(options) {
     DEBUG = DEBUG_WORKER || options.debug;
-    this.cellBroadcastDisabled = options.cellBroadcastDisabled;
-    this.clirMode = options.clirMode;
     RIL_EMERGENCY_NUMBERS = options.rilEmergencyNumbers;
+    RIL_CELLBROADCAST_DISABLED = options.cellBroadcastDisabled;
+    RIL_CLIR_MODE = options.clirMode;
+
     let quirks = options.quirks;
     RILQUIRKS_CALLSTATE_EXTRA_UINT32 = quirks.callstateExtraUint32;
     RILQUIRKS_V5_LEGACY = quirks.v5Legacy;
     RILQUIRKS_REQUEST_USE_DIAL_EMERGENCY_CALL = quirks.requestUseDialEmergencyCall;
     RILQUIRKS_SIM_APP_STATE_EXTRA_FIELDS = quirks.simAppStateExtraFields;
     RILQUIRKS_EXTRA_UINT32_2ND_CALL = quirks.extraUint2ndCall;
     RILQUIRKS_HAVE_QUERY_ICC_LOCK_RETRY_COUNT = quirks.haveQueryIccLockRetryCount;
     RILQUIRKS_SEND_STK_PROFILE_DOWNLOAD = quirks.sendStkProfileDownload;
     RILQUIRKS_DATA_REGISTRATION_ON_DEMAND = quirks.dataRegistrationOnDemand;
   },
 
   registerClient: function(aOptions) {
     CLIENT_ID = aOptions.clientId;
-  }
-};
-
-RIL.initRILState();
+
+    // Init properties that are only initialized once.
+    this.v5Legacy = RILQUIRKS_V5_LEGACY;
+    this.cellBroadcastDisabled = RIL_CELLBROADCAST_DISABLED;
+    this.clirMode = RIL_CLIR_MODE;
+
+    this.initRILState();
+  }
+};
 
 RIL[REQUEST_GET_SIM_STATUS] = function REQUEST_GET_SIM_STATUS(length, options) {
   if (options.rilRequestError) {
     return;
   }
 
   let iccStatus = {};
   iccStatus.cardState = Buf.readInt32(); // CARD_STATE_*
   iccStatus.universalPINState = Buf.readInt32(); // CARD_PINSTATE_*
   iccStatus.gsmUmtsSubscriptionAppIndex = Buf.readInt32();
   iccStatus.cdmaSubscriptionAppIndex = Buf.readInt32();
-  if (!RILQUIRKS_V5_LEGACY) {
+  if (!this.v5Legacy) {
     iccStatus.imsSubscriptionAppIndex = Buf.readInt32();
   }
 
   let apps_length = Buf.readInt32();
   if (apps_length > CARD_MAX_APPS) {
     apps_length = CARD_MAX_APPS;
   }
 
@@ -5201,17 +5211,17 @@ RIL[REQUEST_SIGNAL_STRENGTH] = function 
     gsmBitErrorRate:   Buf.readInt32(),
     cdmaDBM:           Buf.readInt32(),
     cdmaECIO:          Buf.readInt32(),
     evdoDBM:           Buf.readInt32(),
     evdoECIO:          Buf.readInt32(),
     evdoSNR:           Buf.readInt32()
   };
 
-  if (!RILQUIRKS_V5_LEGACY) {
+  if (!this.v5Legacy) {
     signal.lteSignalStrength = Buf.readInt32();
     signal.lteRSRP =           Buf.readInt32();
     signal.lteRSRQ =           Buf.readInt32();
     signal.lteRSSNR =          Buf.readInt32();
     signal.lteCQI =            Buf.readInt32();
   }
 
   if (DEBUG) debug("signal strength: " + JSON.stringify(signal));
@@ -5299,17 +5309,17 @@ RIL.readSetupDataCall_v5 = function read
 
 RIL[REQUEST_SETUP_DATA_CALL] = function REQUEST_SETUP_DATA_CALL(length, options) {
   if (options.rilRequestError) {
     // On Data Call generic errors, we shall notify caller
     this._sendDataCallError(options, options.rilRequestError);
     return;
   }
 
-  if (RILQUIRKS_V5_LEGACY) {
+  if (this.v5Legacy) {
     // Populate the `options` object with the data call information. That way
     // we retain the APN and other info about how the data call was set up.
     this.readSetupDataCall_v5(options);
     this.currentDataCalls[options.cid] = options;
     options.rilMessageType = "datacallstatechange";
     this.sendChromeMessage(options);
     // Let's get the list of data calls to ensure we know whether it's active
     // or not.
@@ -5848,17 +5858,17 @@ RIL[REQUEST_DATA_CALL_LIST] = function R
   }
 
   if (!length) {
     this._processDataCallList(null);
     return;
   }
 
   let version = 0;
-  if (!RILQUIRKS_V5_LEGACY) {
+  if (!this.v5Legacy) {
     version = Buf.readInt32();
   }
   let num = Buf.readInt32();
   let datacalls = {};
   for (let i = 0; i < num; i++) {
     let datacall;
     if (version < 6) {
       datacall = this.readDataCall_v5();
@@ -6261,17 +6271,17 @@ RIL[UNSOLICITED_NITZ_TIME_RECEIVED] = fu
                           networkDSTInMinutes: -(dst * 60),
                           receiveTimeInMS: now});
 };
 
 RIL[UNSOLICITED_SIGNAL_STRENGTH] = function UNSOLICITED_SIGNAL_STRENGTH(length) {
   this[REQUEST_SIGNAL_STRENGTH](length, {rilRequestError: ERROR_SUCCESS});
 };
 RIL[UNSOLICITED_DATA_CALL_LIST_CHANGED] = function UNSOLICITED_DATA_CALL_LIST_CHANGED(length) {
-  if (RILQUIRKS_V5_LEGACY) {
+  if (this.v5Legacy) {
     this.getDataCallList();
     return;
   }
   this[REQUEST_DATA_CALL_LIST](length, {rilRequestError: ERROR_SUCCESS});
 };
 RIL[UNSOLICITED_SUPP_SVC_NOTIFICATION] = function UNSOLICITED_SUPP_SVC_NOTIFICATION(length) {
   let info = {};
   info.notificationType = Buf.readInt32();
@@ -6389,20 +6399,20 @@ RIL[UNSOLICITED_EXIT_EMERGENCY_CALLBACK_
 RIL[UNSOLICITED_RIL_CONNECTED] = function UNSOLICITED_RIL_CONNECTED(length) {
   // Prevent response id collision between UNSOLICITED_RIL_CONNECTED and
   // UNSOLICITED_VOICE_RADIO_TECH_CHANGED for Akami on gingerbread branch.
   if (!length) {
     return;
   }
 
   let version = Buf.readInt32List()[0];
-  RILQUIRKS_V5_LEGACY = (version < 5);
+  this.v5Legacy = (version < 5);
   if (DEBUG) {
     debug("Detected RIL version " + version);
-    debug("RILQUIRKS_V5_LEGACY is " + RILQUIRKS_V5_LEGACY);
+    debug("this.v5Legacy is " + this.v5Legacy);
   }
 
   this.initRILState();
   // Always ensure that we are not in emergency callback mode when init.
   this.exitEmergencyCbMode();
   // Reset radio in the case that b2g restart (or crash).
   this.setRadioEnabled({enabled: false});
 };