Bug 1242973 - Make services/mobileid eslintable. r?ferjm
--- a/services/mobileid/MobileIdentityManager.jsm
+++ b/services/mobileid/MobileIdentityManager.jsm
@@ -3,16 +3,17 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
this.EXPORTED_SYMBOLS = ["MobileIdentityManager"];
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/MobileIdentityCommon.jsm");
Cu.import("resource://gre/modules/MobileIdentityUIGlueCommon.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "MobileIdentityCredentialsStore",
"resource://gre/modules/MobileIdentityCredentialsStore.jsm");
@@ -46,29 +47,29 @@ XPCOMUtils.defineLazyServiceGetter(this,
XPCOMUtils.defineLazyServiceGetter(this, "securityManager",
"@mozilla.org/scriptsecuritymanager;1",
"nsIScriptSecurityManager");
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
"@mozilla.org/AppsService;1",
"nsIAppsService");
-#ifdef MOZ_B2G_RIL
-XPCOMUtils.defineLazyServiceGetter(this, "Ril",
- "@mozilla.org/ril;1",
- "nsIRadioInterfaceLayer");
+if (AppConstants.MOZ_B2G_RIL) {
+ XPCOMUtils.defineLazyServiceGetter(this, "Ril",
+ "@mozilla.org/ril;1",
+ "nsIRadioInterfaceLayer");
-XPCOMUtils.defineLazyServiceGetter(this, "IccService",
- "@mozilla.org/icc/iccservice;1",
- "nsIIccService");
+ XPCOMUtils.defineLazyServiceGetter(this, "IccService",
+ "@mozilla.org/icc/iccservice;1",
+ "nsIIccService");
-XPCOMUtils.defineLazyServiceGetter(this, "MobileConnectionService",
- "@mozilla.org/mobileconnection/mobileconnectionservice;1",
- "nsIMobileConnectionService");
-#endif
+ XPCOMUtils.defineLazyServiceGetter(this, "MobileConnectionService",
+ "@mozilla.org/mobileconnection/mobileconnectionservice;1",
+ "nsIMobileConnectionService");
+}
this.MobileIdentityManager = {
init: function() {
log.debug("MobileIdentityManager init");
Services.obs.addObserver(this, "xpcom-shutdown", false);
ppmm.addMessageListener(GET_ASSERTION_IPC_MSG, this);
@@ -102,166 +103,142 @@ this.MobileIdentityManager = {
ppmm.removeMessageListener(GET_ASSERTION_IPC_MSG, this);
Services.obs.removeObserver(this, "xpcom-shutdown");
this.messageManagers = null;
},
/*********************************************************
* Getters
********************************************************/
-#ifdef MOZ_B2G_RIL
- // We have these getters to allow mocking RIL stuff from the tests.
- get ril() {
- if (this._ril) {
- return this._ril;
- }
- return Ril;
- },
-
- get iccService() {
- if (this._iccService) {
- return this._iccService;
- }
- return IccService;
- },
-
- get mobileConnectionService() {
- if (this._mobileConnectionService) {
- return this._mobileConnectionService;
- }
- return MobileConnectionService;
- },
-#endif
-
get iccInfo() {
if (this._iccInfo) {
return this._iccInfo;
}
-#ifdef MOZ_B2G_RIL
- let self = this;
- let iccListener = {
- notifyStkCommand: function() {},
+ if (AppConstants.MOZ_B2G_RIL) {
+ let self = this;
+ let iccListener = {
+ notifyStkCommand: function() {},
+
+ notifyStkSessionEnd: function() {},
- notifyStkSessionEnd: function() {},
+ notifyCardStateChanged: function() {},
- notifyCardStateChanged: function() {},
+ notifyIccInfoChanged: function() {
+ // If we receive a notification about an ICC info change, we clear
+ // the ICC related caches so they can be rebuilt with the new changes.
+
+ log.debug("ICC info changed observed. Clearing caches");
- notifyIccInfoChanged: function() {
- // If we receive a notification about an ICC info change, we clear
- // the ICC related caches so they can be rebuilt with the new changes.
-
- log.debug("ICC info changed observed. Clearing caches");
+ // We don't need to keep listening for changes until we rebuild the
+ // cache again.
+ for (let i = 0; i < self._iccInfo.length; i++) {
+ let icc = self.iccService.getIccByServiceId(i);
+ if (icc) {
+ icc.unregisterListener(iccListener);
+ }
+ }
- // We don't need to keep listening for changes until we rebuild the
- // cache again.
- for (let i = 0; i < self._iccInfo.length; i++) {
- let icc = self.iccService.getIccByServiceId(i);
- if (icc) {
- icc.unregisterListener(iccListener);
- }
+ self._iccInfo = null;
+ self._iccIds = null;
+ }
+ };
+
+ // _iccInfo is a local cache containing the information about the SIM cards
+ // that is interesting for the Mobile ID flow.
+ // The index of this array does not necesarily need to match the real
+ // identifier of the SIM card ("clientId" or "serviceId" in RIL language).
+ this._iccInfo = [];
+
+ for (let i = 0; i < this.ril.numRadioInterfaces; i++) {
+ let icc = this.iccService.getIccByServiceId(i);
+ if (!icc) {
+ log.warn("Tried to get the Icc instance for an invalid service ID " + i);
+ continue;
}
- self._iccInfo = null;
- self._iccIds = null;
- }
- };
+ let info = icc.iccInfo;
+ if (!info || !info.iccid ||
+ !info.mcc || !info.mcc.length ||
+ !info.mnc || !info.mnc.length) {
+ log.warn("Absent or invalid ICC info");
+ continue;
+ }
- // _iccInfo is a local cache containing the information about the SIM cards
- // that is interesting for the Mobile ID flow.
- // The index of this array does not necesarily need to match the real
- // identifier of the SIM card ("clientId" or "serviceId" in RIL language).
- this._iccInfo = [];
+ // GSM SIMs may have MSISDN while CDMA SIMs may have MDN
+ let phoneNumber = null;
+ try {
+ if (info.iccType === "sim" || info.iccType === "usim") {
+ let gsmInfo = info.QueryInterface(Ci.nsIGsmIccInfo);
+ phoneNumber = gsmInfo.msisdn;
+ } else if (info.iccType === "ruim" || info.iccType === "csim") {
+ let cdmaInfo = info.QueryInterface(Ci.nsICdmaIccInfo);
+ phoneNumber = cdmaInfo.mdn;
+ }
+ } catch (e) {
+ log.error("Failed to retrieve phoneNumber: " + e);
+ }
- for (let i = 0; i < this.ril.numRadioInterfaces; i++) {
- let icc = this.iccService.getIccByServiceId(i);
- if (!icc) {
- log.warn("Tried to get the Icc instance for an invalid service ID " + i);
- continue;
- }
+ let connection = this.mobileConnectionService.getItemByServiceId(i);
+ let voice = connection && connection.voice;
+ let data = connection && connection.data;
+ let operator = null;
+ if (voice &&
+ voice.network &&
+ voice.network.shortName &&
+ voice.network.shortName.length) {
+ operator = voice.network.shortName;
+ } else if (data &&
+ data.network &&
+ data.network.shortName &&
+ data.network.shortName.length) {
+ operator = data.network.shortName;
+ }
- let info = icc.iccInfo;
- if (!info || !info.iccid ||
- !info.mcc || !info.mcc.length ||
- !info.mnc || !info.mnc.length) {
- log.warn("Absent or invalid ICC info");
- continue;
+ this._iccInfo.push({
+ // Because it is possible that the _iccInfo array index doesn't match
+ // the real client ID, we need to store this value for later usage.
+ clientId: i,
+ iccId: info.iccid,
+ mcc: info.mcc,
+ mnc: info.mnc,
+ msisdn: phoneNumber,
+ operator: operator,
+ roaming: voice && voice.roaming
+ });
+
+ // We need to subscribe to ICC change notifications so we can refresh
+ // the cache if any change is observed.
+ icc.registerListener(iccListener);
}
- // GSM SIMs may have MSISDN while CDMA SIMs may have MDN
- let phoneNumber = null;
- try {
- if (info.iccType === "sim" || info.iccType === "usim") {
- let gsmInfo = info.QueryInterface(Ci.nsIGsmIccInfo);
- phoneNumber = gsmInfo.msisdn;
- } else if (info.iccType === "ruim" || info.iccType === "csim") {
- let cdmaInfo = info.QueryInterface(Ci.nsICdmaIccInfo);
- phoneNumber = cdmaInfo.mdn;
- }
- } catch (e) {
- log.error("Failed to retrieve phoneNumber: " + e);
- }
-
- let connection = this.mobileConnectionService.getItemByServiceId(i);
- let voice = connection && connection.voice;
- let data = connection && connection.data;
- let operator = null;
- if (voice &&
- voice.network &&
- voice.network.shortName &&
- voice.network.shortName.length) {
- operator = voice.network.shortName;
- } else if (data &&
- data.network &&
- data.network.shortName &&
- data.network.shortName.length) {
- operator = data.network.shortName;
- }
-
- this._iccInfo.push({
- // Because it is possible that the _iccInfo array index doesn't match
- // the real client ID, we need to store this value for later usage.
- clientId: i,
- iccId: info.iccid,
- mcc: info.mcc,
- mnc: info.mnc,
- msisdn: phoneNumber,
- operator: operator,
- roaming: voice && voice.roaming
- });
-
- // We need to subscribe to ICC change notifications so we can refresh
- // the cache if any change is observed.
- icc.registerListener(iccListener);
+ return this._iccInfo;
+ } else {
+ return null;
}
-
- return this._iccInfo;
-#else
- return null;
-#endif
},
get iccIds() {
-#ifdef MOZ_B2G_RIL
- if (this._iccIds) {
+ if (AppConstants.MOZ_B2G_RIL) {
+ if (this._iccIds) {
+ return this._iccIds;
+ }
+
+ this._iccIds = [];
+ if (!this.iccInfo) {
+ return this._iccIds;
+ }
+
+ for (let i = 0; i < this.iccInfo.length; i++) {
+ this._iccIds.push(this.iccInfo[i].iccId);
+ }
+
return this._iccIds;
- }
-
- this._iccIds = [];
- if (!this.iccInfo) {
- return this._iccIds;
+ } else {
+ return null;
}
-
- for (let i = 0; i < this.iccInfo.length; i++) {
- this._iccIds.push(this.iccInfo[i].iccId);
- }
-
- return this._iccIds;
-#else
- return null;
-#endif
},
get credStore() {
if (!this._credStore) {
this._credStore = new MobileIdentityCredentialsStore();
this._credStore.init();
}
return this._credStore;
@@ -546,33 +523,32 @@ this.MobileIdentityManager = {
mnc: aToVerify.mnc,
iccId: aToVerify.iccId,
external: aToVerify.serviceId === undefined,
mtSender: aToVerify.verificationDetails.mtSender
},
this.ui,
this.client
);
-#ifdef MOZ_B2G_RIL
- } else if (aToVerify.verificationMethod.indexOf(SMS_MO_MT) != -1 &&
+ } else if (AppConstants.MOZ_B2G_RIL &&
+ aToVerify.verificationMethod.indexOf(SMS_MO_MT) != -1 &&
aToVerify.serviceId &&
aToVerify.verificationDetails &&
aToVerify.verificationDetails.moVerifier &&
aToVerify.verificationDetails.mtSender) {
this.activeVerificationFlow = new MobileIdentitySmsMoMtVerificationFlow({
origin: aOrigin,
serviceId: aToVerify.serviceId,
iccId: aToVerify.iccId,
mtSender: aToVerify.verificationDetails.mtSender,
moVerifier: aToVerify.verificationDetails.moVerifier
},
this.ui,
this.client
);
-#endif
} else {
return Promise.reject(ERROR_INTERNAL_CANNOT_VERIFY_SELECTION);
}
if (!this.activeVerificationFlow) {
return Promise.reject(ERROR_INTERNAL_CANNOT_CREATE_VERIFICATION_FLOW);
}
@@ -1063,9 +1039,45 @@ this.MobileIdentityManager = {
this.error(aPromiseId, error);
}
);
},
};
+if (AppConstants.MOZ_B2G_RIL) {
+ // We have these getters to allow mocking RIL stuff from the tests.
+ Object.defineProperties(MobileIdentityManager, {
+ "ril": {
+ configurable: true,
+ enumerable: true,
+ get() {
+ if (this._ril) {
+ return this._ril;
+ }
+ return Ril;
+ }
+ },
+ "iccService": {
+ configurable: true,
+ enumerable: true,
+ get() {
+ if (this._iccService) {
+ return this._iccService;
+ }
+ return IccService;
+ }
+ },
+ "mobileConnectionService": {
+ configurable: true,
+ enumerable: true,
+ get() {
+ if (this._mobileConnectionService) {
+ return this._mobileConnectionService;
+ }
+ return MobileConnectionService;
+ }
+ }
+ });
+}
+
MobileIdentityManager.init();
--- a/services/mobileid/MobileIdentitySmsVerificationFlow.jsm
+++ b/services/mobileid/MobileIdentitySmsVerificationFlow.jsm
@@ -3,26 +3,27 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
this.EXPORTED_SYMBOLS = ["MobileIdentitySmsVerificationFlow"];
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/MobileIdentityCommon.jsm");
Cu.import("resource://gre/modules/MobileIdentityVerificationFlow.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-#ifdef MOZ_B2G_RIL
-XPCOMUtils.defineLazyServiceGetter(this, "smsService",
- "@mozilla.org/sms/smsservice;1",
- "nsISmsService");
-#endif
+if (AppConstants.MOZ_B2G_RIL) {
+ XPCOMUtils.defineLazyServiceGetter(this, "smsService",
+ "@mozilla.org/sms/smsservice;1",
+ "nsISmsService");
+}
this.MobileIdentitySmsVerificationFlow = function(aVerificationOptions,
aUI,
aClient,
aVerifyStrategy) {
// SMS MT or SMS MO+MT specific verify strategy.
this.smsVerifyStrategy = aVerifyStrategy;
@@ -46,63 +47,63 @@ this.MobileIdentitySmsVerificationFlow.p
}
// Even if the user selection is given to us as a possible external phone
// number, it is also possible that the phone number introduced by the
// user belongs to one of the SIMs inserted in the device which MSISDN
// is unknown for us, so we always observe for incoming messages coming
// from the given mtSender.
-#ifdef MOZ_B2G_RIL
- this.observedSilentNumber = this.verificationOptions.mtSender;
- try {
- smsService.addSilentNumber(this.observedSilentNumber);
- } catch (e) {
- log.warn("We are already listening for that number");
- }
-
- this.onSilentSms = (function(aSubject, aTopic, aData) {
- log.debug("Got silent message " + aSubject.sender + " - " + aSubject.body);
- // We might have observed a notification of an incoming silent message
- // for other number. In that case, we just bail out.
- if (aSubject.sender != this.observedSilentNumber) {
- return;
+ if (AppConstants.MOZ_B2G_RIL) {
+ this.observedSilentNumber = this.verificationOptions.mtSender;
+ try {
+ smsService.addSilentNumber(this.observedSilentNumber);
+ } catch (e) {
+ log.warn("We are already listening for that number");
}
- // We got the SMS containing the verification code.
+ this.onSilentSms = (function(aSubject, aTopic, aData) {
+ log.debug("Got silent message " + aSubject.sender + " - " + aSubject.body);
+ // We might have observed a notification of an incoming silent message
+ // for other number. In that case, we just bail out.
+ if (aSubject.sender != this.observedSilentNumber) {
+ return;
+ }
+
+ // We got the SMS containing the verification code.
- // If the phone number we are trying to verify is or can be an external
- // phone number (meaning that it doesn't belong to any of the inserted
- // SIMs) we will be receiving an human readable SMS containing a short
- // verification code. In this case we need to parse the SMS body to
- // extract the verification code.
- // Otherwise, we just use the whole SMS body as it should contain a long
- // verification code.
- let verificationCode = aSubject.body;
- if (this.verificationOptions.external) {
- // We just take the numerical characters from the body.
- verificationCode = aSubject.body.replace(/[^0-9]/g,'');
- }
+ // If the phone number we are trying to verify is or can be an external
+ // phone number (meaning that it doesn't belong to any of the inserted
+ // SIMs) we will be receiving an human readable SMS containing a short
+ // verification code. In this case we need to parse the SMS body to
+ // extract the verification code.
+ // Otherwise, we just use the whole SMS body as it should contain a long
+ // verification code.
+ let verificationCode = aSubject.body;
+ if (this.verificationOptions.external) {
+ // We just take the numerical characters from the body.
+ verificationCode = aSubject.body.replace(/[^0-9]/g,'');
+ }
- log.debug("Verification code: " + verificationCode);
+ log.debug("Verification code: " + verificationCode);
- this.verificationCodeDeferred.resolve(verificationCode);
- }).bind(this);
+ this.verificationCodeDeferred.resolve(verificationCode);
+ }).bind(this);
- Services.obs.addObserver(this.onSilentSms,
- SILENT_SMS_RECEIVED_TOPIC,
- false);
- log.debug("Observing messages from " + this.observedSilentNumber);
-#endif
+ Services.obs.addObserver(this.onSilentSms,
+ SILENT_SMS_RECEIVED_TOPIC,
+ false);
+ log.debug("Observing messages from " + this.observedSilentNumber);
+ }
return this.smsVerifyStrategy();
},
_cleanupStrategy: function() {
-#ifdef MOZ_B2G_RIL
- smsService.removeSilentNumber(this.observedSilentNumber);
- Services.obs.removeObserver(this.onSilentSms,
- SILENT_SMS_RECEIVED_TOPIC);
- this.observedSilentNumber = null;
- this.onSilentSms = null;
-#endif
+ if (AppConstants.MOZ_B2G_RIL) {
+ smsService.removeSilentNumber(this.observedSilentNumber);
+ Services.obs.removeObserver(this.onSilentSms,
+ SILENT_SMS_RECEIVED_TOPIC);
+ this.observedSilentNumber = null;
+ this.onSilentSms = null;
+ }
}
};
--- a/services/mobileid/moz.build
+++ b/services/mobileid/moz.build
@@ -7,18 +7,15 @@
DIRS += ['interfaces']
XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
EXTRA_JS_MODULES += [
'MobileIdentityClient.jsm',
'MobileIdentityCommon.jsm',
'MobileIdentityCredentialsStore.jsm',
+ 'MobileIdentityManager.jsm',
'MobileIdentitySmsMoMtVerificationFlow.jsm',
'MobileIdentitySmsMtVerificationFlow.jsm',
+ 'MobileIdentitySmsVerificationFlow.jsm'
'MobileIdentityUIGlueCommon.jsm',
'MobileIdentityVerificationFlow.jsm'
]
-
-EXTRA_PP_JS_MODULES += [
- 'MobileIdentityManager.jsm',
- 'MobileIdentitySmsVerificationFlow.jsm'
-]