mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1155142 - Part 3: Refactor MobileIdentityManager. r=ferjm
This commit is contained in:
parent
6cf1fff5b0
commit
4f5cbdec91
@ -171,13 +171,13 @@ this.MobileIdentityManager = {
|
|||||||
this._iccInfo = [];
|
this._iccInfo = [];
|
||||||
|
|
||||||
for (let i = 0; i < this.ril.numRadioInterfaces; i++) {
|
for (let i = 0; i < this.ril.numRadioInterfaces; i++) {
|
||||||
let rilContext = this.ril.getRadioInterface(i).rilContext;
|
let icc = this.iccService.getIccByServiceId(i);
|
||||||
if (!rilContext) {
|
if (!icc) {
|
||||||
log.warn("Tried to get the RIL context for an invalid service ID " + i);
|
log.warn("Tried to get the Icc instance for an invalid service ID " + i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let info = rilContext.iccInfo;
|
let info = icc.iccInfo;
|
||||||
if (!info || !info.iccid ||
|
if (!info || !info.iccid ||
|
||||||
!info.mcc || !info.mcc.length ||
|
!info.mcc || !info.mcc.length ||
|
||||||
!info.mnc || !info.mnc.length) {
|
!info.mnc || !info.mnc.length) {
|
||||||
@ -185,6 +185,20 @@ this.MobileIdentityManager = {
|
|||||||
continue;
|
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 connection = this.mobileConnectionService.getItemByServiceId(i);
|
||||||
let voice = connection && connection.voice;
|
let voice = connection && connection.voice;
|
||||||
let data = connection && connection.data;
|
let data = connection && connection.data;
|
||||||
@ -208,18 +222,14 @@ this.MobileIdentityManager = {
|
|||||||
iccId: info.iccid,
|
iccId: info.iccid,
|
||||||
mcc: info.mcc,
|
mcc: info.mcc,
|
||||||
mnc: info.mnc,
|
mnc: info.mnc,
|
||||||
// GSM SIMs may have MSISDN while CDMA SIMs may have MDN
|
msisdn: phoneNumber,
|
||||||
msisdn: info.msisdn || info.mdn || null,
|
|
||||||
operator: operator,
|
operator: operator,
|
||||||
roaming: voice && voice.roaming
|
roaming: voice && voice.roaming
|
||||||
});
|
});
|
||||||
|
|
||||||
// We need to subscribe to ICC change notifications so we can refresh
|
// We need to subscribe to ICC change notifications so we can refresh
|
||||||
// the cache if any change is observed.
|
// the cache if any change is observed.
|
||||||
let icc = this.iccService.getIccByServiceId(i);
|
icc.registerListener(iccListener);
|
||||||
if (icc) {
|
|
||||||
icc.registerListener(iccListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._iccInfo;
|
return this._iccInfo;
|
||||||
|
@ -46,16 +46,37 @@ const MCC = "aMcc";
|
|||||||
const ANOTHER_MCC = "anotherMcc";
|
const ANOTHER_MCC = "anotherMcc";
|
||||||
const OPERATOR = "aOperator";
|
const OPERATOR = "aOperator";
|
||||||
const ANOTHER_OPERATOR = "anotherOperator";
|
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 = {
|
const RADIO_INTERFACE = {
|
||||||
rilContext: {
|
|
||||||
iccInfo: {
|
|
||||||
iccid: ICC_ID,
|
|
||||||
mcc: MCC,
|
|
||||||
mnc: MNC,
|
|
||||||
msisdn: PHONE_NUMBER,
|
|
||||||
operator: OPERATOR
|
|
||||||
}
|
|
||||||
},
|
|
||||||
voice: {
|
voice: {
|
||||||
network: {
|
network: {
|
||||||
shortName: OPERATOR
|
shortName: OPERATOR
|
||||||
@ -69,15 +90,6 @@ const RADIO_INTERFACE = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const ANOTHER_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: {
|
voice: {
|
||||||
network: {
|
network: {
|
||||||
shortName: ANOTHER_OPERATOR
|
shortName: ANOTHER_OPERATOR
|
||||||
@ -92,15 +104,6 @@ const ANOTHER_RADIO_INTERFACE = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const INVALID_RADIO_INTERFACE = {
|
const INVALID_RADIO_INTERFACE = {
|
||||||
rilContext: {
|
|
||||||
iccInfo: {
|
|
||||||
iccid: null,
|
|
||||||
mcc: "",
|
|
||||||
mnc: "",
|
|
||||||
msisdn: "",
|
|
||||||
operator: ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
voice: {
|
voice: {
|
||||||
network: {
|
network: {
|
||||||
shortName: ""
|
shortName: ""
|
||||||
|
@ -1003,33 +1003,35 @@ add_test(function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MobileIdentityManager._iccService = {
|
MobileIdentityManager._iccService = {
|
||||||
_iccs: [],
|
|
||||||
_listeners: [],
|
_listeners: [],
|
||||||
|
_iccInfos: [ICC_INFO, ANOTHER_ICC_INFO],
|
||||||
getIccByServiceId: function(aClientId) {
|
getIccByServiceId: function(aClientId) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this_iccs.push({
|
return {
|
||||||
|
get iccInfo() {
|
||||||
|
return self._iccInfos[aClientId];
|
||||||
|
},
|
||||||
registerListener: function(aIccListener) {
|
registerListener: function(aIccListener) {
|
||||||
self._listeners.push(aIccListener);
|
self._listeners.push(aIccListener);
|
||||||
},
|
},
|
||||||
unregisterListener: function() {
|
unregisterListener: function() {
|
||||||
self._listeners.pop();
|
self._listeners.pop();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ui = new MockUi();
|
let ui = new MockUi();
|
||||||
ui.startFlow = function() {
|
ui.startFlow = function() {
|
||||||
// At this point we've already built the ICC cache.
|
// At this point we've already built the ICC cache.
|
||||||
let interfaces = MobileIdentityManager._ril._interfaces;
|
let mockIccInfo = [ICC_INFO, ANOTHER_ICC_INFO];
|
||||||
for (let i = 0; i < interfaces.length; i++) {
|
for (let i = 0; i < mockIccInfo.length; i++) {
|
||||||
let interfaceIccInfo = interfaces[i].rilContext.iccInfo;
|
|
||||||
let mIdIccInfo = MobileIdentityManager._iccInfo[i];
|
let mIdIccInfo = MobileIdentityManager._iccInfo[i];
|
||||||
do_check_eq(interfaceIccInfo.iccid, mIdIccInfo.iccId);
|
do_check_eq(mockIccInfo[i].iccid, mIdIccInfo.iccId);
|
||||||
do_check_eq(interfaceIccInfo.mcc, mIdIccInfo.mcc);
|
do_check_eq(mockIccInfo[i].mcc, mIdIccInfo.mcc);
|
||||||
do_check_eq(interfaceIccInfo.mnc, mIdIccInfo.mnc);
|
do_check_eq(mockIccInfo[i].mnc, mIdIccInfo.mnc);
|
||||||
do_check_eq(interfaceIccInfo.msisdn, mIdIccInfo.msisdn);
|
do_check_eq(mockIccInfo[i].msisdn, mIdIccInfo.msisdn);
|
||||||
do_check_eq(interfaceIccInfo.operator, mIdIccInfo.operator);
|
do_check_eq(mockIccInfo[i].operator, mIdIccInfo.operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should have listeners for each valid icc.
|
// We should have listeners for each valid icc.
|
||||||
@ -1111,18 +1113,21 @@ add_test(function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MobileIdentityManager._iccService = {
|
MobileIdentityManager._iccService = {
|
||||||
_iccs: [],
|
|
||||||
_listeners: [],
|
_listeners: [],
|
||||||
|
_iccInfos: [INVALID_ICC_INFO],
|
||||||
getIccByServiceId: function(aClientId) {
|
getIccByServiceId: function(aClientId) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this_iccs.push({
|
return {
|
||||||
|
get iccInfo() {
|
||||||
|
return self._iccInfos[aClientId];
|
||||||
|
},
|
||||||
registerListener: function(aIccListener) {
|
registerListener: function(aIccListener) {
|
||||||
self._listeners.push(aIccListener);
|
self._listeners.push(aIccListener);
|
||||||
},
|
},
|
||||||
unregisterListener: function() {
|
unregisterListener: function() {
|
||||||
self._listeners.pop();
|
self._listeners.pop();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user