Bug 1155142 - Part 2: Refactor RIL-related Modules. r=kchen

This commit is contained in:
Bevis Tseng 2015-04-17 19:06:24 +08:00
parent 411426aa0f
commit 3810a891ed
7 changed files with 86 additions and 40 deletions

View File

@ -56,6 +56,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gNetworkManager",
"@mozilla.org/network/manager;1",
"nsINetworkManager");
XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
"@mozilla.org/icc/iccservice;1",
"nsIIccService");
XPCOMUtils.defineLazyGetter(this, "gRadioInterfaceLayer", function() {
let ril = { numRadioInterfaces: 0 };
try {
@ -387,9 +391,8 @@ MobileConnectionProvider.prototype = {
* really the case. See bug 787967
*/
_checkRoamingBetweenOperators: function(aNetworkInfo) {
// TODO: Bug 864489 - B2G RIL: use ipdl as IPC in MozIccManager
// Should get iccInfo from GonkIccProvider.
let iccInfo = this._radioInterface.rilContext.iccInfo;
let icc = gIccService.getIccByServiceId(this._clientId);
let iccInfo = icc ? icc.iccInfo : null;
let operator = aNetworkInfo.network;
let state = aNetworkInfo.state;

View File

@ -134,6 +134,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gpps",
"@mozilla.org/network/protocol-proxy-service;1",
"nsIProtocolProxyService");
XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
"@mozilla.org/icc/iccservice;1",
"nsIIccService");
XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
"@mozilla.org/uuid-generator;1",
"nsIUUIDGenerator");
@ -347,7 +351,7 @@ MmsConnection.prototype = {
// Get the proper IccInfo based on the current card type.
try {
let iccInfo = null;
let baseIccInfo = this.radioInterface.rilContext.iccInfo;
let baseIccInfo = this.getIccInfo();
if (baseIccInfo.iccType === 'ruim' || baseIccInfo.iccType === 'csim') {
iccInfo = baseIccInfo.QueryInterface(Ci.nsICdmaIccInfo);
number = iccInfo.mdn;
@ -365,11 +369,27 @@ MmsConnection.prototype = {
return number;
},
/**
* A utility function to get IccInfo of the SIM card (if installed).
*/
getIccInfo: function() {
let icc = gIccService.getIccByServiceId(this.serviceId);
return icc ? icc.iccInfo : null;
},
/**
* A utility function to get CardState of the SIM card (if installed).
*/
getCardState: function() {
let icc = gIccService.getIccByServiceId(this.serviceId);
return icc ? icc.cardState : Ci.nsIIcc.CARD_STATE_UNKNOWN;
},
/**
* A utility function to get the ICC ID of the SIM card (if installed).
*/
getIccId: function() {
let iccInfo = this.radioInterface.rilContext.iccInfo;
let iccInfo = this.getIccInfo();
if (!iccInfo) {
return null;
@ -404,8 +424,7 @@ MmsConnection.prototype = {
if (getRadioDisabledState()) {
if (DEBUG) debug("Error! Radio is disabled when sending MMS.");
errorStatus = _HTTP_STATUS_RADIO_DISABLED;
} else if (this.radioInterface.rilContext.cardState !=
Ci.nsIIcc.CARD_STATE_READY) {
} else if (this.getCardState() != Ci.nsIIcc.CARD_STATE_READY) {
if (DEBUG) debug("Error! SIM card is not ready when sending MMS.");
errorStatus = _HTTP_STATUS_NO_SIM_CARD;
}

View File

@ -76,9 +76,13 @@ XPCOMUtils.defineLazyGetter(this, "gWAP", function() {
});
XPCOMUtils.defineLazyServiceGetter(this, "gCellBroadcastService",
"@mozilla.org/cellbroadcast/gonkservice;1",
"@mozilla.org/cellbroadcast/cellbroadcastservice;1",
"nsIGonkCellBroadcastService");
XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
"@mozilla.org/icc/iccservice;1",
"nsIIccService");
XPCOMUtils.defineLazyServiceGetter(this, "gMobileConnectionService",
"@mozilla.org/mobileconnection/mobileconnectionservice;1",
"nsIMobileConnectionService");
@ -158,7 +162,7 @@ SmsService.prototype = {
// Get the proper IccInfo based on the current card type.
try {
let iccInfo = null;
let baseIccInfo = gRadioInterfaces[aServiceId].rilContext.iccInfo;
let baseIccInfo = this._getIccInfo(aServiceId);
if (baseIccInfo.iccType === 'ruim' || baseIccInfo.iccType === 'csim') {
iccInfo = baseIccInfo.QueryInterface(Ci.nsICdmaIccInfo);
number = iccInfo.mdn;
@ -176,8 +180,18 @@ SmsService.prototype = {
return number;
},
_getIccInfo: function(aServiceId) {
let icc = gIccService.getIccByServiceId(aServiceId);
return icc ? icc.iccInfo : null;
},
_getCardState: function(aServiceId) {
let icc = gIccService.getIccByServiceId(aServiceId);
return icc ? icc.cardState : Ci.nsIIcc.CARD_STATE_UNKNOWN;
},
_getIccId: function(aServiceId) {
let iccInfo = gRadioInterfaces[aServiceId].rilContext.iccInfo;
let iccInfo = this._getIccInfo(aServiceId);
if (!iccInfo) {
return null;
@ -887,8 +901,7 @@ SmsService.prototype = {
radioState == Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED) {
if (DEBUG) debug("Error! Radio is disabled when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
} else if (gRadioInterfaces[aServiceId].rilContext.cardState !=
Ci.nsIIcc.CARD_STATE_READY) {
} else if (this._getCardState(aServiceId) != Ci.nsIIcc.CARD_STATE_READY) {
if (DEBUG) debug("Error! SIM card is not ready when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR;
}

View File

@ -69,6 +69,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "messenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
"@mozilla.org/icc/iccservice;1",
"nsIIccService");
this.NetworkStatsService = {
init: function() {
debug("Service started");
@ -253,11 +257,12 @@ this.NetworkStatsService = {
let networks = {};
let numRadioInterfaces = gRil.numRadioInterfaces;
for (let i = 0; i < numRadioInterfaces; i++) {
let icc = gIccService.getIccByServiceId(i);
let radioInterface = gRil.getRadioInterface(i);
if (radioInterface.rilContext.iccInfo) {
let netId = this.getNetworkId(radioInterface.rilContext.iccInfo.iccid,
if (icc && icc.iccInfo) {
let netId = this.getNetworkId(icc.iccInfo.iccid,
NET_TYPE_MOBILE);
networks[netId] = { id : radioInterface.rilContext.iccInfo.iccid,
networks[netId] = { id : icc.iccInfo.iccid,
type: NET_TYPE_MOBILE };
}
}

View File

@ -43,6 +43,7 @@
#include "nsIMobileCellInfo.h"
#include "nsIMobileNetworkInfo.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsIIccService.h"
#endif
#ifdef AGPS_TYPE_INVALID
@ -476,31 +477,35 @@ GonkGPSGeolocationProvider::RequestSetID(uint32_t flags)
AGpsSetIDType type = AGPS_SETID_TYPE_NONE;
nsCOMPtr<nsIRilContext> rilCtx;
mRadioInterface->GetRilContext(getter_AddRefs(rilCtx));
nsCOMPtr<nsIIccService> iccService =
do_GetService(ICC_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(iccService);
if (rilCtx) {
nsAutoString id;
if (flags & AGPS_RIL_REQUEST_SETID_IMSI) {
type = AGPS_SETID_TYPE_IMSI;
rilCtx->GetImsi(id);
}
nsCOMPtr<nsIIcc> icc;
iccService->GetIccByServiceId(mRilDataServiceId, getter_AddRefs(icc));
NS_ENSURE_TRUE_VOID(icc);
if (flags & AGPS_RIL_REQUEST_SETID_MSISDN) {
nsCOMPtr<nsIIccInfo> iccInfo;
rilCtx->GetIccInfo(getter_AddRefs(iccInfo));
if (iccInfo) {
nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
if (gsmIccInfo) {
type = AGPS_SETID_TYPE_MSISDN;
gsmIccInfo->GetMsisdn(id);
}
nsAutoString id;
if (flags & AGPS_RIL_REQUEST_SETID_IMSI) {
type = AGPS_SETID_TYPE_IMSI;
icc->GetImsi(id);
}
if (flags & AGPS_RIL_REQUEST_SETID_MSISDN) {
nsCOMPtr<nsIIccInfo> iccInfo;
icc->GetIccInfo(getter_AddRefs(iccInfo));
if (iccInfo) {
nsCOMPtr<nsIGsmIccInfo> gsmIccInfo = do_QueryInterface(iccInfo);
if (gsmIccInfo) {
type = AGPS_SETID_TYPE_MSISDN;
gsmIccInfo->GetMsisdn(id);
}
}
NS_ConvertUTF16toUTF8 idBytes(id);
mAGpsRilInterface->set_set_id(type, idBytes.get());
}
NS_ConvertUTF16toUTF8 idBytes(id);
mAGpsRilInterface->set_set_id(type, idBytes.get());
}
void

View File

@ -161,7 +161,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "gMobileConnectionService",
"nsIGonkMobileConnectionService");
XPCOMUtils.defineLazyServiceGetter(this, "gCellBroadcastService",
"@mozilla.org/cellbroadcast/gonkservice;1",
"@mozilla.org/cellbroadcast/cellbroadcastservice;1",
"nsIGonkCellBroadcastService");
XPCOMUtils.defineLazyServiceGetter(this, "gIccMessenger",

View File

@ -37,9 +37,9 @@ XPCOMUtils.defineLazyGetter(this, "CP", function () {
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
XPCOMUtils.defineLazyServiceGetter(this, "gRIL",
"@mozilla.org/ril;1",
"nsIRadioInterfaceLayer");
XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
"@mozilla.org/icc/iccservice;1",
"nsIIccService");
/**
* Helpers for WAP PDU processing.
@ -104,7 +104,8 @@ this.WapPushManager = {
let mac = params && params.mac;
authInfo = CP.Authenticator.check(data.array.subarray(data.offset),
sec, mac, function getNetworkPin() {
let imsi = gRIL.getRadioInterface(options.serviceId).rilContext.imsi;
let icc = gIccService.getIccByServiceId(options.serviceId);
let imsi = icc ? icc.imsi : null;
return CP.Authenticator.formatImsi(imsi);
});
}