Bug 761482 - Rename MobileOperatorInfo to MobileNetworkInfo for consistency and update MobileConnectionInfo.network to use the new MobileNetworkInfo type. r=philikon sr=sicking

This commit is contained in:
Marshall Culpepper 2012-06-12 17:05:50 -04:00
Родитель 7a3bfe572d
Коммит f574fbb6a6
5 изменённых файлов: 180 добавлений и 86 удалений

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

@ -7,6 +7,7 @@
interface nsIDOMEventListener;
interface nsIDOMDOMRequest;
interface nsIDOMMozMobileConnectionInfo;
interface nsIDOMMozMobileNetworkInfo;
[scriptable, builtinclass, uuid(e7309c47-9a2e-4e12-84ab-f8f39214eaba)]
interface nsIDOMMozMobileConnection : nsIDOMEventTarget
@ -33,7 +34,7 @@ interface nsIDOMMozMobileConnection : nsIDOMEventTarget
* Search for available networks.
*
* If successful, the request's onsuccess will be called, and the request's
* result will be an array of nsIDOMMozMobileOperatorInfo.
* result will be an array of nsIDOMMozMobileNetworkInfo.
*
* Otherwise, the request's onerror will be called, and the request's error
* will be either 'RadioNotAvailable', 'RequestNotSupported', or 'GenericFailure'.
@ -186,7 +187,7 @@ interface nsIDOMMozMobileConnection : nsIDOMEventTarget
attribute nsIDOMEventListener onussdreceived;
};
[scriptable, uuid(f3bb0611-5e4a-46f1-a8f5-cf592b37596e)]
[scriptable, uuid(46321d6e-bbce-4b7b-aa32-d17b6aa984fe)]
interface nsIDOMMozMobileConnectionInfo : nsISupports
{
/**
@ -209,9 +210,9 @@ interface nsIDOMMozMobileConnectionInfo : nsISupports
readonly attribute bool roaming;
/**
* Operator name.
* Network operator
*/
readonly attribute DOMString operator;
readonly attribute nsIDOMMozMobileNetworkInfo network;
/**
* Type of connection.
@ -234,8 +235,8 @@ interface nsIDOMMozMobileConnectionInfo : nsISupports
};
[scriptable, uuid(79217f7a-4401-4d75-9654-3b28bba698c9)]
interface nsIDOMMozMobileOperatorInfo : nsISupports
[scriptable, uuid(3bd866c7-98a5-4ef4-a464-c22d8cc6b992)]
interface nsIDOMMozMobileNetworkInfo: nsISupports
{
/**
* Short name of the network operator

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

@ -9,44 +9,70 @@ const WHITELIST_PREF = "dom.mobileconnection.whitelist";
let uriPrePath = window.location.protocol + "//" + window.location.host;
SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
ok(navigator.mozMobileConnection instanceof MozMobileConnection,
"mozMobileConnection is instanceof " + navigator.mozMobileConnection.constructor);
let connection = navigator.mozMobileConnection;
ok(connection instanceof MozMobileConnection,
"connection is instanceof " + connection.constructor);
let request = navigator.mozMobileConnection.getNetworks();
ok(request instanceof DOMRequest,
"request is instanceof " + request.constructor);
function isAndroidNetwork(network) {
is(network.longName, "Android");
is(network.shortName, "Android");
is(network.mcc, 310);
is(network.mnc, 260);
}
request.onerror = function() {
ok(false, request.error);
cleanUp();
};
function testConnectionInfo() {
let voice = connection.voice;
is(voice.connected, true);
is(voice.emergencyCallsOnly, false);
is(voice.roaming, false);
isAndroidNetwork(voice.network);
request.onsuccess = function() {
ok('result' in request, "Request did not contain a result");
let networks = request.result;
let data = connection.data;
// TODO Bug 762959: enable these checks when data state updates have been implemented
// is(data.connected, true);
// is(data.emergencyCallsOnly, false);
// is(data.roaming, false);
isAndroidNetwork(data.network);
// The emulator RIL server should always return 2 networks:
// {"longName":"Android","shortName":"Android","mcc":310,"mnc":260,"state":"available"}
// {"longName":"TelKila","shortName":"TelKila","mcc":310,"mnc":295,"state":"available"}
is(networks.length, 2);
testGetNetworks();
}
let network1 = networks[0];
is(network1.longName, "Android");
is(network1.shortName, "Android");
is(network1.mcc, 310);
is(network1.mnc, 260);
is(network1.state, "available");
function testGetNetworks() {
let request = connection.getNetworks();
ok(request instanceof DOMRequest,
"request is instanceof " + request.constructor);
let network2 = networks[1];
is(network2.longName, "TelKila");
is(network2.shortName, "TelKila");
is(network2.mcc, 310);
is(network2.mnc, 295);
is(network2.state, "available");
cleanUp();
};
request.onerror = function() {
ok(false, request.error);
cleanUp();
};
request.onsuccess = function() {
ok('result' in request, "Request did not contain a result");
let networks = request.result;
// The emulator RIL server should always return 2 networks:
// {"longName":"Android","shortName":"Android","mcc":310,"mnc":260,"state":"available"}
// {"longName":"TelKila","shortName":"TelKila","mcc":310,"mnc":295,"state":"available"}
is(networks.length, 2);
let network1 = networks[0];
isAndroidNetwork(network1);
is(network1.state, "available");
let network2 = networks[1];
is(network2.longName, "TelKila");
is(network2.shortName, "TelKila");
is(network2.mcc, 310);
is(network2.mnc, 295);
is(network2.state, "available");
cleanUp();
};
}
function cleanUp() {
SpecialPowers.clearUserPref(WHITELIST_PREF);
finish();
}
testConnectionInfo();

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

@ -19,7 +19,7 @@ const RILCONTENTHELPER_CID =
Components.ID("{472816e1-1fd6-4405-996c-806f9ea68174}");
const MOBILECONNECTIONINFO_CID =
Components.ID("{a35cfd39-2d93-4489-ac7d-396475dacb27}");
const MOBILEOPERATORINFO_CID =
const MOBILENETWORKINFO_CID =
Components.ID("{a6c8416c-09b4-46d1-bf29-6520d677d085}");
const RIL_IPC_MSG_NAMES = [
@ -68,24 +68,24 @@ MobileConnectionInfo.prototype = {
connected: false,
emergencyCallsOnly: false,
roaming: false,
operator: null,
network: null,
type: null,
signalStrength: null,
relSignalStrength: null
};
function MobileOperatorInfo() {}
MobileOperatorInfo.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileOperatorInfo]),
classID: MOBILEOPERATORINFO_CID,
function MobileNetworkInfo() {}
MobileNetworkInfo.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMMozMobileNetworkInfo]),
classID: MOBILENETWORKINFO_CID,
classInfo: XPCOMUtils.generateCI({
classID: MOBILEOPERATORINFO_CID,
classDescription: "MobileOperatorInfo",
classID: MOBILENETWORKINFO_CID,
classDescription: "MobileNetworkInfo",
flags: Ci.nsIClassInfo.DOM_OBJECT,
interfaces: [Ci.nsIDOMMozMobileOperatorInfo]
interfaces: [Ci.nsIDOMMozMobileNetworkInfo]
}),
// nsIDOMMozMobileOperatorInfo
// nsIDOMMozMobileNetworkInfo
shortName: null,
longName: null,
@ -105,18 +105,16 @@ function RILContentHelper() {
// Request initial state.
let radioState = cpmm.QueryInterface(Ci.nsISyncMessageSender)
.sendSyncMessage("RIL:GetRadioState")[0];
if (!radioState) {
debug("Received null radioState from chrome process.");
return;
}
this.cardState = radioState.cardState;
for (let key in radioState.voice) {
this.voiceConnectionInfo[key] = radioState.voice[key];
}
for (let key in radioState.data) {
this.dataConnectionInfo[key] = radioState.data[key];
}
this.updateConnectionInfo(radioState.voice, this.voiceConnectionInfo);
this.updateConnectionInfo(radioState.data, this.dataConnectionInfo);
}
RILContentHelper.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
@ -129,6 +127,30 @@ RILContentHelper.prototype = {
interfaces: [Ci.nsIMobileConnectionProvider,
Ci.nsIRILContentHelper]}),
updateConnectionInfo: function updateConnectionInfo(srcInfo, destInfo) {
for (let key in srcInfo) {
if (key != "network") {
destInfo[key] = srcInfo[key];
}
}
let srcNetwork = srcInfo.network;
if (!srcNetwork) {
destInfo.network= null;
return;
}
let network = destInfo.network;
if (!network) {
network = destInfo.network = new MobileNetworkInfo();
}
network.longName = srcNetwork.longName;
network.shortName = srcNetwork.shortName;
network.mnc = srcNetwork.mnc;
network.mcc = srcNetwork.mcc;
},
// nsIRILContentHelper
cardState: RIL.GECKO_CARDSTATE_UNAVAILABLE,
@ -304,6 +326,36 @@ RILContentHelper.prototype = {
// nsIFrameMessageListener
fireRequestSuccess: function fireRequestSuccess(requestId, result) {
let request = this.takeRequest(requestId);
if (!request) {
if (DEBUG) {
debug("not firing success for id: " + requestId + ", result: " + JSON.stringify(result));
}
return;
}
if (DEBUG) {
debug("fire request success, id: " + requestId + ", result: " + JSON.stringify(result));
}
Services.DOMRequest.fireSuccess(request, result);
},
fireRequestError: function fireRequestError(requestId, error) {
let request = this.takeRequest(requestId);
if (!request) {
if (DEBUG) {
debug("not firing error for id: " + requestId + ", error: " + JSON.stringify(error));
}
return;
}
if (DEBUG) {
debug("fire request error, id: " + requestId + ", result: " + JSON.stringify(error));
}
Services.DOMRequest.fireError(request, error);
},
receiveMessage: function receiveMessage(msg) {
let request;
debug("Received message '" + msg.name + "': " + JSON.stringify(msg.json));
@ -315,15 +367,11 @@ RILContentHelper.prototype = {
}
break;
case "RIL:VoiceInfoChanged":
for (let key in msg.json) {
this.voiceConnectionInfo[key] = msg.json[key];
}
this.updateConnectionInfo(msg.json, this.voiceConnectionInfo);
Services.obs.notifyObservers(null, kVoiceChangedTopic, null);
break;
case "RIL:DataInfoChanged":
for (let key in msg.json) {
this.dataConnectionInfo[key] = msg.json[key];
}
this.updateConnectionInfo(msg.json, this.dataConnectionInfo);
Services.obs.notifyObservers(null, kDataChangedTopic, null);
break;
case "RIL:EnumerateCalls":
@ -345,18 +393,12 @@ RILContentHelper.prototype = {
case "RIL:GetCardLock:Return:OK":
case "RIL:SetCardLock:Return:OK":
case "RIL:UnlockCardLock:Return:OK":
request = this.takeRequest(msg.json.requestId);
if (request) {
Services.DOMRequest.fireSuccess(request, msg.json);
}
this.fireRequestSuccess(msg.json.requestId, msg.json);
break;
case "RIL:GetCardLock:Return:KO":
case "RIL:SetCardLock:Return:KO":
case "RIL:UnlockCardLock:Return:KO":
request = this.takeRequest(msg.json.requestId);
if (request) {
Services.DOMRequest.fireError(request, msg.json.errorMsg);
}
this.fireRequestError(msg.json.requestId, msg.json.errorMsg);
break;
case "RIL:UssdReceived":
Services.obs.notifyObservers(null, kUssdReceivedTopic,
@ -419,7 +461,7 @@ RILContentHelper.prototype = {
let networks = message.networks;
for (let i = 0; i < networks.length; i++) {
let network = networks[i];
let info = new MobileOperatorInfo();
let info = new MobileNetworkInfo();
for (let key in network) {
info[key] = network[key];

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

@ -157,14 +157,14 @@ function RadioInterfaceLayer() {
voice: {connected: false,
emergencyCallsOnly: false,
roaming: false,
operator: null,
network: null,
type: null,
signalStrength: null,
relSignalStrength: null},
data: {connected: false,
emergencyCallsOnly: false,
roaming: false,
operator: null,
network: null,
type: null,
signalStrength: null,
relSignalStrength: null},
@ -405,7 +405,7 @@ RadioInterfaceLayer.prototype = {
voiceInfo.connected = false;
voiceInfo.emergencyCallsOnly = false;
voiceInfo.roaming = false;
voiceInfo.operator = null;
voiceInfo.network = null;
voiceInfo.type = null;
voiceInfo.signalStrength = null;
voiceInfo.relSignalStrength = null;
@ -475,15 +475,26 @@ RadioInterfaceLayer.prototype = {
ppmm.sendAsyncMessage("RIL:DataInfoChanged", this.radioState.data);
},
networkChanged: function networkChanged(srcNetwork, destNetwork) {
return !destNetwork ||
destNetwork.longName != srcNetwork.longName ||
destNetwork.shortName != srcNetwork.shortName ||
destNetwork.mnc != srcNetwork.mnc ||
destNetwork.mcc != srcNetwork.mcc;
},
handleOperatorChange: function handleOperatorChange(message) {
let operator = message.alphaLong;
if (operator != this.radioState.voice.operator) {
this.radioState.voice.operator = operator;
ppmm.sendAsyncMessage("RIL:VoiceInfoChanged", this.radioState.voice);
let voice = this.radioState.voice;
let data = this.radioState.data;
if (this.networkChanged(message, voice.network)) {
voice.network = message;
ppmm.sendAsyncMessage("RIL:VoiceInfoChanged", voice);
}
if (operator != this.radioState.data.operator) {
this.radioState.data.operator = operator;
ppmm.sendAsyncMessage("RIL:DataInfoChanged", this.radioState.data);
if (this.networkChanged(message, data.network)) {
data.network = message;
ppmm.sendAsyncMessage("RIL:DataInfoChanged", data);
}
},

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

@ -2849,15 +2849,29 @@ RIL[REQUEST_OPERATOR] = function REQUEST_OPERATOR(length, options) {
if (operator.length < 3) {
if (DEBUG) debug("Expected at least 3 strings for operator.");
}
if (!this.operator ||
this.operator.alphaLong != operator[0] ||
this.operator.alphaShort != operator[1] ||
this.operator.numeric != operator[2]) {
this.operator = {type: "operatorchange",
alphaLong: operator[0],
alphaShort: operator[1],
numeric: operator[2]};
this.sendDOMMessage(this.operator);
if (!this.operator) {
this.operator = {type: "operatorchange"};
}
let numeric = String(this.operator.mcc) + this.operator.mnc;
if (this.operator.longName != operator[0] ||
this.operator.shortName != operator[1] ||
numeric != operator[2]) {
this.operator.longName = operator[0];
this.operator.shortName = operator[1];
this.operator.mcc = 0;
this.operator.mnc = 0;
let networkTuple = operator[2];
try {
this._processNetworkTuple(networkTuple, this.operator);
} catch (e) {
debug("Error processing operator tuple: " + e);
}
this.sendDOMMessage(this.operator);
}
};
RIL[REQUEST_RADIO_POWER] = null;