Bug 1063304 - 3.c/3: accommodate other components. r=echen

This commit is contained in:
Vicamo Yang 2014-09-21 15:24:43 +08:00
Родитель 75268db7f4
Коммит ede03dd674
13 изменённых файлов: 160 добавлений и 85 удалений

Просмотреть файл

@ -7,9 +7,11 @@
#include "BluetoothRilListener.h"
#include "BluetoothHfpManager.h"
#include "nsIIccProvider.h"
#include "nsIMobileConnectionInfo.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsRadioInterfaceLayer.h"
#include "nsIMobileConnectionService.h"
#include "nsITelephonyService.h"
#include "nsRadioInterfaceLayer.h" // For NS_RILCONTENTHELPER_CONTRACTID.
#include "nsServiceManagerUtils.h"
#include "nsString.h"
@ -179,11 +181,15 @@ MobileConnectionListener::Listen(bool aStart)
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, false);
nsCOMPtr<nsIMobileConnection> connection;
service->GetItemByServiceId(mClientId, getter_AddRefs(connection));
NS_ENSURE_TRUE(connection, false);
nsresult rv;
if (aStart) {
rv = service->RegisterListener(mClientId, this);
rv = connection->RegisterListener(this);
} else {
rv = service->UnregisterListener(mClientId, this);
rv = connection->UnregisterListener(this);
}
return NS_SUCCEEDED(rv);
@ -329,17 +335,17 @@ TelephonyListener::Listen(bool aStart)
*/
BluetoothRilListener::BluetoothRilListener()
{
nsCOMPtr<nsIMobileConnectionService> service =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(service);
// Query number of total clients (sim slots)
uint32_t numOfClients;
nsCOMPtr<nsIRadioInterfaceLayer> radioInterfaceLayer =
do_GetService(NS_RADIOINTERFACELAYER_CONTRACTID);
NS_ENSURE_TRUE_VOID(radioInterfaceLayer);
radioInterfaceLayer->GetNumRadioInterfaces(&numOfClients);
// Init MobileConnectionListener array and IccInfoListener
for (uint32_t i = 0; i < numOfClients; i++) {
mMobileConnListeners.AppendElement(new MobileConnectionListener(i));
uint32_t numItems = 0;
if (NS_SUCCEEDED(service->GetNumItems(&numItems))) {
// Init MobileConnectionListener array and IccInfoListener
for (uint32_t i = 0; i < numItems; i++) {
mMobileConnListeners.AppendElement(new MobileConnectionListener(i));
}
}
mTelephonyListener = new TelephonyListener();
@ -375,8 +381,15 @@ BluetoothRilListener::SelectClient()
NS_ENSURE_TRUE_VOID(service);
for (uint32_t i = 0; i < mMobileConnListeners.Length(); i++) {
nsCOMPtr<nsIMobileConnection> connection;
service->GetItemByServiceId(i, getter_AddRefs(connection));
if (!connection) {
BT_WARNING("%s: Failed to get mobile connection", __FUNCTION__);
continue;
}
nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
service->GetVoiceConnectionInfo(i, getter_AddRefs(voiceInfo));
connection->GetVoice(getter_AddRefs(voiceInfo));
if (!voiceInfo) {
BT_WARNING("%s: Failed to get voice connection info", __FUNCTION__);
continue;

Просмотреть файл

@ -612,12 +612,16 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
void
BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
{
nsCOMPtr<nsIMobileConnectionService> connection =
nsCOMPtr<nsIMobileConnectionService> mcService =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(mcService);
nsCOMPtr<nsIMobileConnection> connection;
mcService->GetItemByServiceId(aClientId, getter_AddRefs(connection));
NS_ENSURE_TRUE_VOID(connection);
nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
connection->GetVoiceConnectionInfo(aClientId, getter_AddRefs(voiceInfo));
connection->GetVoice(getter_AddRefs(voiceInfo));
NS_ENSURE_TRUE_VOID(voiceInfo);
nsString type;

Просмотреть файл

@ -606,12 +606,16 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
void
BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
{
nsCOMPtr<nsIMobileConnectionService> connection =
nsCOMPtr<nsIMobileConnectionService> mcService =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(mcService);
nsCOMPtr<nsIMobileConnection> connection;
mcService->GetItemByServiceId(aClientId, getter_AddRefs(connection));
NS_ENSURE_TRUE_VOID(connection);
nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
connection->GetVoiceConnectionInfo(aClientId, getter_AddRefs(voiceInfo));
connection->GetVoice(getter_AddRefs(voiceInfo));
NS_ENSURE_TRUE_VOID(voiceInfo);
nsString type;
@ -646,7 +650,7 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
* - manual: set mNetworkSelectionMode to 1 (manual)
*/
nsString mode;
connection->GetNetworkSelectionMode(aClientId, mode);
connection->GetNetworkSelectionMode(mode);
if (mode.EqualsLiteral("manual")) {
mNetworkSelectionMode = 1;
} else {

Просмотреть файл

@ -7,9 +7,11 @@
#include "BluetoothRilListener.h"
#include "BluetoothHfpManager.h"
#include "nsIIccProvider.h"
#include "nsIMobileConnectionInfo.h"
#include "nsIRadioInterfaceLayer.h"
#include "nsRadioInterfaceLayer.h"
#include "nsIMobileConnectionService.h"
#include "nsITelephonyService.h"
#include "nsRadioInterfaceLayer.h" // For NS_RILCONTENTHELPER_CONTRACTID.
#include "nsServiceManagerUtils.h"
#include "nsString.h"
@ -179,11 +181,15 @@ MobileConnectionListener::Listen(bool aStart)
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, false);
nsCOMPtr<nsIMobileConnection> connection;
mcService->GetItemByServiceId(mClientId, getter_AddRefs(connection));
NS_ENSURE_TRUE(connection, false);
nsresult rv;
if (aStart) {
rv = service->RegisterListener(mClientId, this);
rv = connection->RegisterListener(this);
} else {
rv = service->UnregisterListener(mClientId, this);
rv = connection->UnregisterListener(this);
}
return NS_SUCCEEDED(rv);
@ -329,17 +335,17 @@ TelephonyListener::Listen(bool aStart)
*/
BluetoothRilListener::BluetoothRilListener()
{
nsCOMPtr<nsIMobileConnectionService> service =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(service);
// Query number of total clients (sim slots)
uint32_t numOfClients;
nsCOMPtr<nsIRadioInterfaceLayer> radioInterfaceLayer =
do_GetService(NS_RADIOINTERFACELAYER_CONTRACTID);
NS_ENSURE_TRUE_VOID(radioInterfaceLayer);
radioInterfaceLayer->GetNumRadioInterfaces(&numOfClients);
// Init MobileConnectionListener array and IccInfoListener
for (uint32_t i = 0; i < numOfClients; i++) {
mMobileConnListeners.AppendElement(new MobileConnectionListener(i));
uint32_t numItems = 0;
if (NS_SUCCEEDED(service->GetNumItems(&numItems))) {
// Init MobileConnectionListener array and IccInfoListener
for (uint32_t i = 0; i < numItems; i++) {
mMobileConnListeners.AppendElement(new MobileConnectionListener(i));
}
}
mTelephonyListener = new TelephonyListener();
@ -375,8 +381,15 @@ BluetoothRilListener::SelectClient()
NS_ENSURE_TRUE_VOID(service);
for (uint32_t i = 0; i < mMobileConnListeners.Length(); i++) {
nsCOMPtr<nsIMobileConnection> connection;
service->GetItemByServiceId(i, getter_AddRefs(connection));
if (!connection) {
BT_WARNING("%s: Failed to get mobile connection", __FUNCTION__);
continue;
}
nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
service->GetVoiceConnectionInfo(i, getter_AddRefs(voiceInfo));
connection->GetVoice(getter_AddRefs(voiceInfo));
if (!voiceInfo) {
BT_WARNING("%s: Failed to get voice connection info", __FUNCTION__);
continue;

Просмотреть файл

@ -615,12 +615,16 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
void
BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
{
nsCOMPtr<nsIMobileConnectionService> connection =
nsCOMPtr<nsIMobileConnectionService> mcService =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(mcService);
nsCOMPtr<nsIMobileConnection> connection;
mcService->GetItemByServiceId(aClientId, getter_AddRefs(connection));
NS_ENSURE_TRUE_VOID(connection);
nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
connection->GetVoiceConnectionInfo(aClientId, getter_AddRefs(voiceInfo));
connection->GetVoice(getter_AddRefs(voiceInfo));
NS_ENSURE_TRUE_VOID(voiceInfo);
nsString type;

Просмотреть файл

@ -606,12 +606,16 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
void
BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
{
nsCOMPtr<nsIMobileConnectionService> connection =
nsCOMPtr<nsIMobileConnectionService> mcService =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
NS_ENSURE_TRUE_VOID(mcService);
nsCOMPtr<nsIMobileConnection> connection;
mcService->GetItemByServiceId(aClientId, getter_AddRefs(connection));
NS_ENSURE_TRUE_VOID(connection);
nsCOMPtr<nsIMobileConnectionInfo> voiceInfo;
connection->GetVoiceConnectionInfo(aClientId, getter_AddRefs(voiceInfo));
connection->GetVoice(getter_AddRefs(voiceInfo));
NS_ENSURE_TRUE_VOID(voiceInfo);
nsString type;
@ -646,7 +650,7 @@ BluetoothHfpManager::HandleVoiceConnectionChanged(uint32_t aClientId)
* - manual: set mNetworkSelectionMode to 1 (manual)
*/
nsString mode;
connection->GetNetworkSelectionMode(aClientId, mode);
connection->GetNetworkSelectionMode(mode);
if (mode.EqualsLiteral("manual")) {
mNetworkSelectionMode = 1;
} else {

Просмотреть файл

@ -328,8 +328,9 @@ MmsConnection.prototype = {
* @return true if voice call is roaming.
*/
isVoiceRoaming: function() {
let voice = gMobileConnectionService.getVoiceConnectionInfo(this.serviceId);
let isRoaming = voice.roaming;
let connection =
gMobileConnectionService.getItemByServiceId(this.serviceId);
let isRoaming = connection && connection.voice && connection.voice.roaming;
if (DEBUG) debug("isVoiceRoaming = " + isRoaming);
return isRoaming;
},

Просмотреть файл

@ -54,7 +54,8 @@ this.PhoneNumberUtils = {
let clientId = 0;
// Get network mcc
let voice = mobileConnection.getVoiceConnectionInfo(clientId);
let connection = mobileConnection.getItemByServiceId(clientId);
let voice = connection && connection.voice;
if (voice && voice.network && voice.network.mcc) {
mcc = voice.network.mcc;
}

Просмотреть файл

@ -412,14 +412,14 @@ WifiGeoPositionProvider.prototype = {
let service = Cc["@mozilla.org/mobileconnection/mobileconnectionservice;1"]
.getService(Ci.nsIMobileConnectionService);
let numInterfaces = radioService.numRadioInterfaces;
let result = [];
for (let i = 0; i < numInterfaces; i++) {
LOG("Looking for SIM in slot:" + i + " of " + numInterfaces);
let voice = service.getVoiceConnectionInfo(i);
let cell = voice.cell;
let type = voice.type;
let network = voice.network;
for (let i = 0; i < service.length; i++) {
LOG("Looking for SIM in slot:" + i + " of " + service.length);
let connection = service.getItemByServiceId(i);
let voice = connection && connection.voice;
let cell = voice && voice.cell;
let type = voice && voice.type;
let network = voice && voice.network;
if (network && cell && type) {
if (type === "gsm" || type === "gprs" || type === "edge") {

Просмотреть файл

@ -523,10 +523,14 @@ GonkGPSGeolocationProvider::SetReferenceLocation()
return;
}
nsCOMPtr<nsIMobileConnectionInfo> voice;
nsCOMPtr<nsIMobileConnection> connection;
// TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
// MultiSIM configuration
service->GetVoiceConnectionInfo(0 /* Client Id */, getter_AddRefs(voice));
service->GetItemByServiceId(0 /* Client Id */, getter_AddRefs(connection));
NS_ENSURE_TRUE_VOID(connection);
nsCOMPtr<nsIMobileConnectionInfo> voice;
connection->GetVoice(getter_AddRefs(voice));
if (voice) {
nsCOMPtr<nsIMobileCellInfo> cell;
voice->GetCell(getter_AddRefs(cell));
@ -947,16 +951,28 @@ GonkGPSGeolocationProvider::Observe(nsISupports* aSubject,
bool roaming = false;
int gpsNetworkType = ConvertToGpsNetworkType(type);
if (gpsNetworkType >= 0) {
nsCOMPtr<nsIMobileConnectionService> service =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
if (rilface && service) {
nsCOMPtr<nsIMobileConnectionInfo> voice;
// TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
// MultiSIM configuration
service->GetVoiceConnectionInfo(0 /* Client Id */, getter_AddRefs(voice));
if (voice) {
voice->GetRoaming(&roaming);
}
if (rilface) {
do {
nsCOMPtr<nsIMobileConnectionService> service =
do_GetService(NS_MOBILE_CONNECTION_SERVICE_CONTRACTID);
if (!service) {
break;
}
nsCOMPtr<nsIMobileConnection> connection;
// TODO: Bug 878748 - B2G GPS: acquire correct RadioInterface instance in
// MultiSIM configuration
service->GetItemByServiceId(0 /* Client Id */, getter_AddRefs(connection));
if (!connection) {
break;
}
nsCOMPtr<nsIMobileConnectionInfo> voice;
connection->GetVoice(getter_AddRefs(voice));
if (voice) {
voice->GetRoaming(&roaming);
}
} while (0);
}
mAGpsRilInterface->update_network_state(
connected,

Просмотреть файл

@ -859,7 +859,9 @@ NetworkManager.prototype = {
dunRetryTimer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer),
setupDunConnection: function() {
this.dunRetryTimer.cancel();
let data = gMobileConnectionService.getDataConnectionInfo(this._dataDefaultServiceId);
let connection =
gMobileConnectionService.getItemByServiceId(this._dataDefaultServiceId);
let data = connection && connection.data;
if (data && data.state === "registered") {
this.dunRetryTimes = 0;
ril.setupDataCallByType("dun");

Просмотреть файл

@ -584,14 +584,12 @@ XPCOMUtils.defineLazyGetter(this, "gRadioEnabledController", function() {
return false;
},
_isValidStateForSetRadioEnabled: function(clientId) {
let radioState = gMobileConnectionService.getRadioState(clientId);
_isValidStateForSetRadioEnabled: function(radioState) {
return radioState == RIL.GECKO_RADIOSTATE_ENABLED ||
radioState == RIL.GECKO_RADIOSTATE_DISABLED;
},
_isDummyForSetRadioEnabled: function(clientId, data) {
let radioState = gMobileConnectionService.getRadioState(clientId);
_isDummyForSetRadioEnabled: function(radioState, data) {
return (radioState == RIL.GECKO_RADIOSTATE_ENABLED && data.enabled) ||
(radioState == RIL.GECKO_RADIOSTATE_DISABLED && !data.enabled);
},
@ -599,16 +597,18 @@ XPCOMUtils.defineLazyGetter(this, "gRadioEnabledController", function() {
_handleMessage: function(message) {
if (DEBUG) debug("RadioControl: handleMessage: " + JSON.stringify(message));
let clientId = message.clientId || 0;
let radioInterface = _ril.getRadioInterface(clientId);
let connection =
gMobileConnectionService.getItemByServiceId(clientId);
let radioState = connection && connection.radioState;
if (!this._isValidStateForSetRadioEnabled(clientId)) {
if (!this._isValidStateForSetRadioEnabled(radioState)) {
message.data.errorMsg = "InvalidStateError";
message.callback(message.data);
this._processNextMessage();
return;
}
if (this._isDummyForSetRadioEnabled(clientId, message.data)) {
if (this._isDummyForSetRadioEnabled(radioState, message.data)) {
message.callback(message.data);
this._processNextMessage();
return;
@ -1402,9 +1402,12 @@ DataConnectionHandler.prototype = {
return;
}
let connection =
gMobileConnectionService.getItemByServiceId(this.clientId);
// This check avoids data call connection if the radio is not ready
// yet after toggling off airplane mode.
let radioState = gMobileConnectionService.getRadioState(this.clientId);
let radioState = connection && connection.radioState;
if (radioState != RIL.GECKO_RADIOSTATE_ENABLED) {
if (DEBUG) {
this.debug("RIL is not ready for data connection: radio's not ready");
@ -1424,10 +1427,12 @@ DataConnectionHandler.prototype = {
return;
}
let dataInfo = gMobileConnectionService.getDataConnectionInfo(this.clientId);
let dataInfo = connection && connection.data;
let isRegistered =
dataInfo &&
dataInfo.state == RIL.GECKO_MOBILE_CONNECTION_STATE_REGISTERED;
let haveDataConnection =
dataInfo &&
dataInfo.type != RIL.GECKO_MOBILE_CONNECTION_STATE_UNKNOWN;
if (!isRegistered || !haveDataConnection) {
if (DEBUG) {
@ -1487,9 +1492,7 @@ DataConnectionHandler.prototype = {
return;
}
if (gRadioEnabledController.isDeactivatingDataCalls() ||
radioState == RIL.GECKO_RADIOSTATE_ENABLING ||
radioState == RIL.GECKO_RADIOSTATE_DISABLING) {
if (gRadioEnabledController.isDeactivatingDataCalls()) {
// We're changing the radio power currently, ignore any changes.
return;
}
@ -3702,15 +3705,18 @@ RadioInterface.prototype = {
Services.obs.notifyObservers(domMessage, kSmsSendingObserverTopic, null);
}
let connection =
gMobileConnectionService.getItemByServiceId(this.clientId);
// If the radio is disabled or the SIM card is not ready, just directly
// return with the corresponding error code.
let errorCode;
let radioState = gMobileConnectionService.getRadioState(this.clientId);
let radioState = connection && connection.radioState;
if (!PhoneNumberUtils.isPlainPhoneNumber(options.number)) {
if (DEBUG) this.debug("Error! Address is invalid when sending SMS: " +
options.number);
errorCode = Ci.nsIMobileMessageCallback.INVALID_ADDRESS_ERROR;
} else if (radioState == RIL.GECKO_RADIOSTATE_DISABLED) {
} else if (radioState == null ||
radioState == RIL.GECKO_RADIOSTATE_DISABLED) {
if (DEBUG) this.debug("Error! Radio is disabled when sending SMS.");
errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR;
} else if (this.rilContext.cardState != "ready") {
@ -4214,9 +4220,11 @@ DataCall.prototype = {
this.apnProfile.apn);
}
let radioInterface = this.gRIL.getRadioInterface(this.clientId);
let dataInfo = gMobileConnectionService.getDataConnectionInfo(this.clientId);
if (dataInfo.state != RIL.GECKO_MOBILE_CONNECTION_STATE_REGISTERED ||
let connection =
gMobileConnectionService.getItemByServiceId(this.clientId);
let dataInfo = connection && connection.data;
if (dataInfo == null ||
dataInfo.state != RIL.GECKO_MOBILE_CONNECTION_STATE_REGISTERED ||
dataInfo.type == RIL.GECKO_MOBILE_CONNECTION_STATE_UNKNOWN) {
return;
}
@ -4245,6 +4253,8 @@ DataCall.prototype = {
pdpType = RIL.GECKO_DATACALL_PDP_TYPE_DEFAULT;
}
}
let radioInterface = this.gRIL.getRadioInterface(this.clientId);
radioInterface.sendWorkerMessage("setupDataCall", {
radioTech: radioTechnology,
apn: this.apnProfile.apn,

Просмотреть файл

@ -127,14 +127,17 @@ this.MobileIdentityManager = {
continue;
}
let voice = mobileConnectionService.getVoiceConnectionInfo(i);
let data = mobileConnectionService.getDataConnectionInfo(i);
let connection = mobileConnectionService.getItemByServiceId(i);
let voice = connection && connection.voice;
let data = connection && connection.data;
let operator = null;
if (voice.network &&
if (voice &&
voice.network &&
voice.network.shortName &&
voice.network.shortName.length) {
operator = voice.network.shortName;
} else if (data.network &&
} else if (data &&
data.network &&
data.network.shortName &&
data.network.shortName.length) {
operator = data.network.shortName;
@ -148,7 +151,7 @@ this.MobileIdentityManager = {
msisdn: info.msisdn || info.mdn || null,
operator: operator,
serviceId: i,
roaming: voice.roaming
roaming: voice && voice.roaming
});
}