diff --git a/services/mobileid/MobileIdentityManager.jsm b/services/mobileid/MobileIdentityManager.jsm index 339341bbb5f..66828ad0e35 100644 --- a/services/mobileid/MobileIdentityManager.jsm +++ b/services/mobileid/MobileIdentityManager.jsm @@ -171,13 +171,13 @@ this.MobileIdentityManager = { this._iccInfo = []; for (let i = 0; i < this.ril.numRadioInterfaces; i++) { - let rilContext = this.ril.getRadioInterface(i).rilContext; - if (!rilContext) { - log.warn("Tried to get the RIL context for an invalid service ID " + 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 info = rilContext.iccInfo; + let info = icc.iccInfo; if (!info || !info.iccid || !info.mcc || !info.mcc.length || !info.mnc || !info.mnc.length) { @@ -185,6 +185,20 @@ this.MobileIdentityManager = { continue; } + // 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; @@ -208,18 +222,14 @@ this.MobileIdentityManager = { iccId: info.iccid, mcc: info.mcc, mnc: info.mnc, - // GSM SIMs may have MSISDN while CDMA SIMs may have MDN - msisdn: info.msisdn || info.mdn || null, + 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. - let icc = this.iccService.getIccByServiceId(i); - if (icc) { - icc.registerListener(iccListener); - } + icc.registerListener(iccListener); } return this._iccInfo; diff --git a/services/mobileid/tests/xpcshell/head.js b/services/mobileid/tests/xpcshell/head.js index 821a27c109b..5d2c388fb9d 100644 --- a/services/mobileid/tests/xpcshell/head.js +++ b/services/mobileid/tests/xpcshell/head.js @@ -46,16 +46,37 @@ const MCC = "aMcc"; const ANOTHER_MCC = "anotherMcc"; const OPERATOR = "aOperator"; const ANOTHER_OPERATOR = "anotherOperator"; +const ICC_INFO = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo, + Ci.nsIIccInfo]), + iccType: "usim", + iccid: ICC_ID, + mcc: MCC, + mnc: MNC, + msisdn: PHONE_NUMBER, + operator: OPERATOR +}; +const ANOTHER_ICC_INFO = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo, + Ci.nsIIccInfo]), + iccType: "usim", + iccid: ANOTHER_ICC_ID, + mcc: ANOTHER_MCC, + mnc: ANOTHER_MNC, + msisdn: ANOTHER_PHONE_NUMBER, + operator: ANOTHER_OPERATOR +}; +const INVALID_ICC_INFO = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIGsmIccInfo, + Ci.nsIIccInfo]), + iccType: "usim", + iccid: null, + mcc: "", + mnc: "", + msisdn: "", + operator: "" +}; const RADIO_INTERFACE = { - rilContext: { - iccInfo: { - iccid: ICC_ID, - mcc: MCC, - mnc: MNC, - msisdn: PHONE_NUMBER, - operator: OPERATOR - } - }, voice: { network: { shortName: OPERATOR @@ -69,15 +90,6 @@ const RADIO_INTERFACE = { } }; const ANOTHER_RADIO_INTERFACE = { - rilContext: { - iccInfo: { - iccid: ANOTHER_ICC_ID, - mcc: ANOTHER_MCC, - mnc: ANOTHER_MNC, - msisdn: ANOTHER_PHONE_NUMBER, - operator: ANOTHER_OPERATOR - } - }, voice: { network: { shortName: ANOTHER_OPERATOR @@ -92,15 +104,6 @@ const ANOTHER_RADIO_INTERFACE = { }; const INVALID_RADIO_INTERFACE = { - rilContext: { - iccInfo: { - iccid: null, - mcc: "", - mnc: "", - msisdn: "", - operator: "" - } - }, voice: { network: { shortName: "" diff --git a/services/mobileid/tests/xpcshell/test_mobileid_manager.js b/services/mobileid/tests/xpcshell/test_mobileid_manager.js index edd3e3d5fb0..4b67c7d8ddd 100644 --- a/services/mobileid/tests/xpcshell/test_mobileid_manager.js +++ b/services/mobileid/tests/xpcshell/test_mobileid_manager.js @@ -1003,33 +1003,35 @@ add_test(function() { }; MobileIdentityManager._iccService = { - _iccs: [], _listeners: [], + _iccInfos: [ICC_INFO, ANOTHER_ICC_INFO], getIccByServiceId: function(aClientId) { let self = this; - this_iccs.push({ + return { + get iccInfo() { + return self._iccInfos[aClientId]; + }, registerListener: function(aIccListener) { self._listeners.push(aIccListener); }, unregisterListener: function() { self._listeners.pop(); } - }); + }; } }; let ui = new MockUi(); ui.startFlow = function() { // At this point we've already built the ICC cache. - let interfaces = MobileIdentityManager._ril._interfaces; - for (let i = 0; i < interfaces.length; i++) { - let interfaceIccInfo = interfaces[i].rilContext.iccInfo; + let mockIccInfo = [ICC_INFO, ANOTHER_ICC_INFO]; + for (let i = 0; i < mockIccInfo.length; i++) { let mIdIccInfo = MobileIdentityManager._iccInfo[i]; - do_check_eq(interfaceIccInfo.iccid, mIdIccInfo.iccId); - do_check_eq(interfaceIccInfo.mcc, mIdIccInfo.mcc); - do_check_eq(interfaceIccInfo.mnc, mIdIccInfo.mnc); - do_check_eq(interfaceIccInfo.msisdn, mIdIccInfo.msisdn); - do_check_eq(interfaceIccInfo.operator, mIdIccInfo.operator); + do_check_eq(mockIccInfo[i].iccid, mIdIccInfo.iccId); + do_check_eq(mockIccInfo[i].mcc, mIdIccInfo.mcc); + do_check_eq(mockIccInfo[i].mnc, mIdIccInfo.mnc); + do_check_eq(mockIccInfo[i].msisdn, mIdIccInfo.msisdn); + do_check_eq(mockIccInfo[i].operator, mIdIccInfo.operator); } // We should have listeners for each valid icc. @@ -1111,18 +1113,21 @@ add_test(function() { }; MobileIdentityManager._iccService = { - _iccs: [], _listeners: [], + _iccInfos: [INVALID_ICC_INFO], getIccByServiceId: function(aClientId) { let self = this; - this_iccs.push({ + return { + get iccInfo() { + return self._iccInfos[aClientId]; + }, registerListener: function(aIccListener) { self._listeners.push(aIccListener); }, unregisterListener: function() { self._listeners.pop(); } - }); + }; } };