Bug 944225 - Part 3: Add set/getPreferredNetworkType() API (ril). r=hsinyi

This commit is contained in:
Jessica Jong 2013-12-11 11:15:03 +08:00
parent 1c462d3129
commit 95f0015641
3 changed files with 113 additions and 9 deletions

View File

@ -71,6 +71,8 @@ const RIL_IPC_MSG_NAMES = [
"RIL:NetworkSelectionModeChanged",
"RIL:SelectNetwork",
"RIL:SelectNetworkAuto",
"RIL:SetPreferredNetworkType",
"RIL:GetPreferredNetworkType",
"RIL:EmergencyCbModeChanged",
"RIL:VoicemailNotification",
"RIL:VoicemailInfoChanged",
@ -769,6 +771,43 @@ RILContentHelper.prototype = {
return request;
},
setPreferredNetworkType: function setPreferredNetworkType(clientId, window, type) {
if (window == null) {
throw Components.Exception("Can't get window object",
Cr.NS_ERROR_UNEXPECTED);
}
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:SetPreferredNetworkType", {
clientId: clientId,
data: {
requestId: requestId,
type: type
}
});
return request;
},
getPreferredNetworkType: function getPreferredNetworkType(clientId, window) {
if (window == null) {
throw Components.Exception("Can't get window object",
Cr.NS_ERROR_UNEXPECTED);
}
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:GetPreferredNetworkType", {
clientId: clientId,
data: {
requestId: requestId
}
});
return request;
},
setRoamingPreference: function setRoamingPreference(clientId, window, mode) {
if (window == null) {
throw Components.Exception("Can't get window object",
@ -1663,6 +1702,12 @@ RILContentHelper.prototype = {
this.handleSelectNetwork(clientId, data,
RIL.GECKO_NETWORK_SELECTION_AUTOMATIC);
break;
case "RIL:SetPreferredNetworkType":
this.handleSimpleRequest(data.requestId, data.errorMsg, null);
break;
case "RIL:GetPreferredNetworkType":
this.handleSimpleRequest(data.requestId, data.errorMsg, data.type);
break;
case "RIL:VoicemailNotification":
this.handleVoicemailNotification(clientId, data);
break;

View File

@ -92,6 +92,8 @@ const RIL_IPC_MOBILECONNECTION_MSG_NAMES = [
"RIL:GetAvailableNetworks",
"RIL:SelectNetwork",
"RIL:SelectNetworkAuto",
"RIL:SetPreferredNetworkType",
"RIL:GetPreferredNetworkType",
"RIL:SendMMI",
"RIL:CancelMMI",
"RIL:RegisterMobileConnectionMsg",
@ -1053,6 +1055,12 @@ RadioInterface.prototype = {
case "RIL:SelectNetworkAuto":
this.workerMessenger.sendWithIPCMessage(msg, "selectNetworkAuto");
break;
case "RIL:SetPreferredNetworkType":
this.setPreferredNetworkType(msg.target, msg.json.data);
break;
case "RIL:GetPreferredNetworkType":
this.getPreferredNetworkType(msg.target, msg.json.data);
break;
case "RIL:GetCardLockState":
this.workerMessenger.sendWithIPCMessage(msg, "iccGetCardLockState",
"RIL:CardLockResult");
@ -1487,7 +1495,58 @@ RadioInterface.prototype = {
},
_preferredNetworkType: null,
setPreferredNetworkType: function setPreferredNetworkType(value) {
getPreferredNetworkType: function getPreferredNetworkType(target, message) {
this.workerMessenger.send("getPreferredNetworkType", message, (function(response) {
if (response.success) {
this._preferredNetworkType = response.networkType;
response.type = RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO[this._preferredNetworkType];
if (DEBUG) {
this.debug("_preferredNetworkType is now " +
RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO[this._preferredNetworkType]);
}
}
target.sendAsyncMessage("RIL:GetPreferredNetworkType", {
clientId: this.clientId,
data: response
});
return false;
}).bind(this));
},
setPreferredNetworkType: function setPreferredNetworkType(target, message) {
if (DEBUG) this.debug("setPreferredNetworkType: " + JSON.stringify(message));
let networkType = RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO.indexOf(message.type);
if (networkType < 0) {
message.errorMsg = RIL.GECKO_ERROR_INVALID_PARAMETER;
target.sendAsyncMessage("RIL:SetPreferredNetworkType", {
clientId: this.clientId,
data: message
});
return false;
}
message.networkType = networkType;
this.workerMessenger.send("setPreferredNetworkType", message, (function(response) {
if (response.success) {
this._preferredNetworkType = response.networkType;
if (DEBUG) {
this.debug("_preferredNetworkType is now " +
RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO[this._preferredNetworkType]);
}
}
target.sendAsyncMessage("RIL:SetPreferredNetworkType", {
clientId: this.clientId,
data: response
});
return false;
}).bind(this));
},
// TODO: Bug 946589 - B2G RIL: follow-up to bug 944225 - remove
// 'ril.radio.preferredNetworkType' setting handler
setPreferredNetworkTypeBySetting: function setPreferredNetworkTypeBySetting(value) {
let networkType = RIL.RIL_PREFERRED_NETWORK_TYPE_TO_GECKO.indexOf(value);
if (networkType < 0) {
networkType = (this._preferredNetworkType != null)
@ -2498,9 +2557,11 @@ RadioInterface.prototype = {
// nsISettingsServiceCallback
handle: function handle(aName, aResult) {
switch(aName) {
// TODO: Bug 946589 - B2G RIL: follow-up to bug 944225 - remove
// 'ril.radio.preferredNetworkType' setting handler
case "ril.radio.preferredNetworkType":
if (DEBUG) this.debug("'ril.radio.preferredNetworkType' is now " + aResult);
this.setPreferredNetworkType(aResult);
this.setPreferredNetworkTypeBySetting(aResult);
break;
case "ril.data.enabled":
if (DEBUG) this.debug("'ril.data.enabled' is now " + aResult);

View File

@ -1112,8 +1112,8 @@ let RIL = {
/**
* Get the preferred network type.
*/
getPreferredNetworkType: function getPreferredNetworkType() {
Buf.simpleRequest(REQUEST_GET_PREFERRED_NETWORK_TYPE);
getPreferredNetworkType: function getPreferredNetworkType(options) {
Buf.simpleRequest(REQUEST_GET_PREFERRED_NETWORK_TYPE, options);
},
/**
@ -5886,13 +5886,11 @@ RIL[REQUEST_GET_PREFERRED_NETWORK_TYPE] = function REQUEST_GET_PREFERRED_NETWORK
if (responseLen) {
this.preferredNetworkType = networkType = Buf.readInt32();
}
options.networkType = networkType;
}
this.sendChromeMessage({
rilMessageType: "getPreferredNetworkType",
networkType: networkType,
success: options.rilRequestError == ERROR_SUCCESS
});
options.success = (options.rilRequestError == ERROR_SUCCESS);
this.sendChromeMessage(options);
};
RIL[REQUEST_GET_NEIGHBORING_CELL_IDS] = null;
RIL[REQUEST_SET_LOCATION_UPDATES] = null;