Bug 814581 - Part 3/8: dispatch RIL messages. r=hsinyi,yoshi

This commit is contained in:
Vicamo Yang 2013-07-02 17:36:40 +08:00
parent b45e89537b
commit 836b77b5e8
2 changed files with 681 additions and 428 deletions

View File

@ -442,8 +442,6 @@ RILContentHelper.prototype = {
_windowsMap: null,
// nsIRILContentHelper
rilContext: null,
getRilContext: function getRilContext() {
@ -454,7 +452,8 @@ RILContentHelper.prototype = {
return this.rilContext;
};
let rilContext = cpmm.sendSyncMessage("RIL:GetRilContext")[0];
let rilContext =
cpmm.sendSyncMessage("RIL:GetRilContext", {clientId: 0})[0];
if (!rilContext) {
debug("Received null rilContext from chrome process.");
return;
@ -469,6 +468,10 @@ RILContentHelper.prototype = {
return this.rilContext;
},
/**
* nsIMobileConnectionProvider
*/
get iccInfo() {
let context = this.getRilContext();
return context && context.iccInfo;
@ -514,7 +517,12 @@ RILContentHelper.prototype = {
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:GetAvailableNetworks", {requestId: requestId});
cpmm.sendAsyncMessage("RIL:GetAvailableNetworks", {
clientId: 0,
data: {
requestId: requestId
}
});
return request;
},
@ -555,9 +563,12 @@ RILContentHelper.prototype = {
this._selectingNetwork = network;
cpmm.sendAsyncMessage("RIL:SelectNetwork", {
clientId: 0,
data: {
requestId: requestId,
mnc: network.mnc,
mcc: network.mcc
}
});
return request;
@ -585,7 +596,12 @@ RILContentHelper.prototype = {
}
this._selectingNetwork = "automatic";
cpmm.sendAsyncMessage("RIL:SelectNetworkAuto", {requestId: requestId});
cpmm.sendAsyncMessage("RIL:SelectNetworkAuto", {
clientId: 0,
data: {
requestId: requestId
}
});
return request;
},
@ -596,7 +612,13 @@ RILContentHelper.prototype = {
}
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:GetCardLockState", {lockType: lockType, requestId: requestId});
cpmm.sendAsyncMessage("RIL:GetCardLockState", {
clientId: 0,
data: {
lockType: lockType,
requestId: requestId
}
});
return request;
},
@ -607,7 +629,10 @@ RILContentHelper.prototype = {
}
let request = Services.DOMRequest.createRequest(window);
info.requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:UnlockCardLock", info);
cpmm.sendAsyncMessage("RIL:UnlockCardLock", {
clientId: 0,
data: info
});
return request;
},
@ -618,7 +643,10 @@ RILContentHelper.prototype = {
}
let request = Services.DOMRequest.createRequest(window);
info.requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:SetCardLock", info);
cpmm.sendAsyncMessage("RIL:SetCardLock", {
clientId: 0,
data: info
});
return request;
},
@ -634,7 +662,13 @@ RILContentHelper.prototype = {
}
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:SendMMI", {mmi: mmi, requestId: requestId});
cpmm.sendAsyncMessage("RIL:SendMMI", {
clientId: 0,
data: {
mmi: mmi,
requestId: requestId
}
});
return request;
},
@ -646,7 +680,12 @@ RILContentHelper.prototype = {
}
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:CancelMMI", {requestId: requestId});
cpmm.sendAsyncMessage("RIL:CancelMMI", {
clientId: 0,
data: {
requestId: requestId
}
});
return request;
},
@ -656,7 +695,10 @@ RILContentHelper.prototype = {
Cr.NS_ERROR_UNEXPECTED);
}
response.command = command;
cpmm.sendAsyncMessage("RIL:SendStkResponse", response);
cpmm.sendAsyncMessage("RIL:SendStkResponse", {
clientId: 0,
data: response
});
},
sendStkMenuSelection: function sendStkMenuSelection(window,
@ -666,8 +708,13 @@ RILContentHelper.prototype = {
throw Components.Exception("Can't get window object",
Cr.NS_ERROR_UNEXPECTED);
}
cpmm.sendAsyncMessage("RIL:SendStkMenuSelection", {itemIdentifier: itemIdentifier,
helpRequested: helpRequested});
cpmm.sendAsyncMessage("RIL:SendStkMenuSelection", {
clientId: 0,
data: {
itemIdentifier: itemIdentifier,
helpRequested: helpRequested
}
});
},
sendStkTimerExpiration: function sendStkTimerExpiration(window,
@ -676,7 +723,12 @@ RILContentHelper.prototype = {
throw Components.Exception("Can't get window object",
Cr.NS_ERROR_UNEXPECTED);
}
cpmm.sendAsyncMessage("RIL:SendStkTimerExpiration", {timer: timer});
cpmm.sendAsyncMessage("RIL:SendStkTimerExpiration", {
clientId: 0,
data: {
timer: timer
}
});
},
sendStkEventDownload: function sendStkEventDownload(window,
@ -685,7 +737,12 @@ RILContentHelper.prototype = {
throw Components.Exception("Can't get window object",
Cr.NS_ERROR_UNEXPECTED);
}
cpmm.sendAsyncMessage("RIL:SendStkEventDownload", {event: event});
cpmm.sendAsyncMessage("RIL:SendStkEventDownload", {
clientId: 0,
data: {
event: event
}
});
},
iccOpenChannel: function iccOpenChannel(window,
@ -698,8 +755,13 @@ RILContentHelper.prototype = {
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:IccOpenChannel", {requestId: requestId,
aid: aid});
cpmm.sendAsyncMessage("RIL:IccOpenChannel", {
clientId: 0,
data: {
requestId: requestId,
aid: aid
}
});
return request;
},
@ -715,9 +777,14 @@ RILContentHelper.prototype = {
let requestId = this.getRequestId(request);
//Potentially you need serialization here and can't pass the jsval through
cpmm.sendAsyncMessage("RIL:IccExchangeAPDU", {requestId: requestId,
cpmm.sendAsyncMessage("RIL:IccExchangeAPDU", {
clientId: 0,
data: {
requestId: requestId,
channel: channel,
apdu: apdu});
apdu: apdu
}
});
return request;
},
@ -731,8 +798,13 @@ RILContentHelper.prototype = {
let request = Services.DOMRequest.createRequest(window);
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:IccCloseChannel", {requestId: requestId,
channel: channel});
cpmm.sendAsyncMessage("RIL:IccCloseChannel", {
clientId: 0,
data: {
requestId: requestId,
channel: channel
}
});
return request;
},
@ -746,8 +818,13 @@ RILContentHelper.prototype = {
let requestId = this.getRequestId(request);
this._windowsMap[requestId] = window;
cpmm.sendAsyncMessage("RIL:ReadIccContacts", {requestId: requestId,
contactType: contactType});
cpmm.sendAsyncMessage("RIL:ReadIccContacts", {
clientId: 0,
data: {
requestId: requestId,
contactType: contactType
}
});
return request;
},
@ -779,10 +856,15 @@ RILContentHelper.prototype = {
iccContact.anr = contact.tel.slice(1);
}
cpmm.sendAsyncMessage("RIL:UpdateIccContact", {requestId: requestId,
cpmm.sendAsyncMessage("RIL:UpdateIccContact", {
clientId: 0,
data: {
requestId: requestId,
contactType: contactType,
contact: iccContact,
pin2: pin2});
pin2: pin2
}
});
return request;
},
@ -801,8 +883,11 @@ RILContentHelper.prototype = {
}
cpmm.sendAsyncMessage("RIL:GetCallForwardingOption", {
clientId: 0,
data: {
requestId: requestId,
reason: reason
}
});
return request;
@ -824,12 +909,15 @@ RILContentHelper.prototype = {
}
cpmm.sendAsyncMessage("RIL:SetCallForwardingOption", {
clientId: 0,
data: {
requestId: requestId,
active: cfInfo.active,
action: cfInfo.action,
reason: cfInfo.reason,
number: cfInfo.number,
timeSeconds: cfInfo.timeSeconds
}
});
return request;
@ -850,10 +938,13 @@ RILContentHelper.prototype = {
}
cpmm.sendAsyncMessage("RIL:GetCallBarringOption", {
clientId: 0,
data: {
requestId: requestId,
program: option.program,
password: option.password,
serviceClass: option.serviceClass
}
});
return request;
},
@ -873,11 +964,14 @@ RILContentHelper.prototype = {
}
cpmm.sendAsyncMessage("RIL:SetCallBarringOption", {
clientId: 0,
data: {
requestId: requestId,
program: option.program,
enabled: option.enabled,
password: option.password,
serviceClass: option.serviceClass
}
});
return request;
},
@ -891,7 +985,10 @@ RILContentHelper.prototype = {
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:GetCallWaitingOption", {
clientId: 0,
data: {
requestId: requestId
}
});
return request;
@ -906,8 +1003,11 @@ RILContentHelper.prototype = {
let requestId = this.getRequestId(request);
cpmm.sendAsyncMessage("RIL:SetCallWaitingOption", {
clientId: 0,
data: {
requestId: requestId,
enabled: enabled
}
});
return request;
@ -928,7 +1028,8 @@ RILContentHelper.prototype = {
return this.voicemailInfo;
};
let voicemailInfo = cpmm.sendSyncMessage("RIL:GetVoicemailInfo")[0];
let voicemailInfo =
cpmm.sendSyncMessage("RIL:GetVoicemailInfo", {clientId: 0})[0];
if (voicemailInfo) {
this.updateInfo(voicemailInfo, this.voicemailInfo);
}
@ -1032,7 +1133,12 @@ RILContentHelper.prototype = {
// We need 'requestId' to meet the 'RILContentHelper <--> RadioInterfaceLayer'
// protocol.
let requestId = this._getRandomId();
cpmm.sendAsyncMessage("RIL:EnumerateCalls", {requestId: requestId});
cpmm.sendAsyncMessage("RIL:EnumerateCalls", {
clientId: 0,
data: {
requestId: requestId
}
});
if (!this._enumerateTelephonyCallbacks) {
this._enumerateTelephonyCallbacks = [];
}
@ -1041,59 +1147,89 @@ RILContentHelper.prototype = {
startTone: function startTone(dtmfChar) {
debug("Sending Tone for " + dtmfChar);
cpmm.sendAsyncMessage("RIL:StartTone", dtmfChar);
cpmm.sendAsyncMessage("RIL:StartTone", {
clientId: 0,
data: dtmfChar
});
},
stopTone: function stopTone() {
debug("Stopping Tone");
cpmm.sendAsyncMessage("RIL:StopTone");
cpmm.sendAsyncMessage("RIL:StopTone", {clientId: 0});
},
dial: function dial(number) {
debug("Dialing " + number);
cpmm.sendAsyncMessage("RIL:Dial", number);
cpmm.sendAsyncMessage("RIL:Dial", {
clientId: 0,
data: number
});
},
dialEmergency: function dialEmergency(number) {
debug("Dialing emergency " + number);
cpmm.sendAsyncMessage("RIL:DialEmergency", number);
cpmm.sendAsyncMessage("RIL:DialEmergency", {
clientId: 0,
data: number
});
},
hangUp: function hangUp(callIndex) {
debug("Hanging up call no. " + callIndex);
cpmm.sendAsyncMessage("RIL:HangUp", callIndex);
cpmm.sendAsyncMessage("RIL:HangUp", {
clientId: 0,
data: callIndex
});
},
answerCall: function answerCall(callIndex) {
cpmm.sendAsyncMessage("RIL:AnswerCall", callIndex);
cpmm.sendAsyncMessage("RIL:AnswerCall", {
clientId: 0,
data: callIndex
});
},
rejectCall: function rejectCall(callIndex) {
cpmm.sendAsyncMessage("RIL:RejectCall", callIndex);
cpmm.sendAsyncMessage("RIL:RejectCall", {
clientId: 0,
data: callIndex
});
},
holdCall: function holdCall(callIndex) {
cpmm.sendAsyncMessage("RIL:HoldCall", callIndex);
cpmm.sendAsyncMessage("RIL:HoldCall", {
clientId: 0,
data: callIndex
});
},
resumeCall: function resumeCall(callIndex) {
cpmm.sendAsyncMessage("RIL:ResumeCall", callIndex);
cpmm.sendAsyncMessage("RIL:ResumeCall", {
clientId: 0,
data: callIndex
});
},
get microphoneMuted() {
return cpmm.sendSyncMessage("RIL:GetMicrophoneMuted")[0];
return cpmm.sendSyncMessage("RIL:GetMicrophoneMuted", {clientId: 0})[0];
},
set microphoneMuted(value) {
cpmm.sendAsyncMessage("RIL:SetMicrophoneMuted", value);
cpmm.sendAsyncMessage("RIL:SetMicrophoneMuted", {
clientId: 0,
data: value
});
},
get speakerEnabled() {
return cpmm.sendSyncMessage("RIL:GetSpeakerEnabled")[0];
return cpmm.sendSyncMessage("RIL:GetSpeakerEnabled", {clientId: 0})[0];
},
set speakerEnabled(value) {
cpmm.sendAsyncMessage("RIL:SetSpeakerEnabled", value);
cpmm.sendAsyncMessage("RIL:SetSpeakerEnabled", {
clientId: 0,
data: value
});
},
// nsIObserver
@ -1159,28 +1295,32 @@ RILContentHelper.prototype = {
let request;
debug("Received message '" + msg.name + "': " + JSON.stringify(msg.json));
switch (msg.name) {
case "RIL:CardStateChanged":
this.rilContext.retryCount = msg.json.retryCount;
if (this.rilContext.cardState != msg.json.cardState) {
this.rilContext.cardState = msg.json.cardState;
case "RIL:CardStateChanged": {
let data = msg.json.data;
this.rilContext.retryCount = data.retryCount;
if (this.rilContext.cardState != data.cardState) {
this.rilContext.cardState = data.cardState;
this._deliverEvent("_mobileConnectionListeners",
"notifyCardStateChanged",
null);
}
break;
}
case "RIL:IccInfoChanged":
this.updateInfo(msg.json, this.rilContext.iccInfo);
this.updateInfo(msg.json.data, this.rilContext.iccInfo);
this._deliverEvent("_mobileConnectionListeners",
"notifyIccInfoChanged", null);
break;
case "RIL:VoiceInfoChanged":
this.updateConnectionInfo(msg.json, this.rilContext.voiceConnectionInfo);
this.updateConnectionInfo(msg.json.data,
this.rilContext.voiceConnectionInfo);
this._deliverEvent("_mobileConnectionListeners",
"notifyVoiceChanged",
null);
break;
case "RIL:DataInfoChanged":
this.updateConnectionInfo(msg.json, this.rilContext.dataConnectionInfo);
this.updateConnectionInfo(msg.json.data,
this.rilContext.dataConnectionInfo);
this._deliverEvent("_mobileConnectionListeners",
"notifyDataChanged",
null);
@ -1192,7 +1332,7 @@ RILContentHelper.prototype = {
this.handleGetAvailableNetworks(msg.json);
break;
case "RIL:NetworkSelectionModeChanged":
this.rilContext.networkSelectionMode = msg.json.mode;
this.rilContext.networkSelectionMode = msg.json.data.mode;
break;
case "RIL:SelectNetwork":
this.handleSelectNetwork(msg.json,
@ -1202,23 +1342,27 @@ RILContentHelper.prototype = {
this.handleSelectNetwork(msg.json,
RIL.GECKO_NETWORK_SELECTION_AUTOMATIC);
break;
case "RIL:CallStateChanged":
case "RIL:CallStateChanged": {
let data = msg.json.data;
this._deliverEvent("_telephonyListeners",
"callStateChanged",
[msg.json.callIndex, msg.json.state,
msg.json.number, msg.json.isActive,
msg.json.isOutgoing, msg.json.isEmergency]);
[data.callIndex, data.state,
data.number, data.isActive,
data.isOutgoing, data.isEmergency]);
break;
case "RIL:CallError":
}
case "RIL:CallError": {
let data = msg.json.data;
this._deliverEvent("_telephonyListeners",
"notifyError",
[msg.json.callIndex, msg.json.errorMsg]);
[data.callIndex, data.errorMsg]);
break;
}
case "RIL:VoicemailNotification":
this.handleVoicemailNotification(msg.json);
this.handleVoicemailNotification(msg.json.data);
break;
case "RIL:VoicemailInfoChanged":
this.updateInfo(msg.json, this.voicemailInfo);
this.updateInfo(msg.json.data, this.voicemailInfo);
break;
case "RIL:CardLockResult":
if (msg.json.success) {
@ -1234,11 +1378,13 @@ RILContentHelper.prototype = {
this.fireRequestError(msg.json.requestId, msg.json.errorMsg);
}
break;
case "RIL:USSDReceived":
case "RIL:USSDReceived": {
let data = msg.json.data;
this._deliverEvent("_mobileConnectionListeners",
"notifyUssdReceived",
[msg.json.message, msg.json.sessionEnded]);
[data.message, data.sessionEnded]);
break;
}
case "RIL:SendMMI:Return:OK":
case "RIL:CancelMMI:Return:OK":
case "RIL:SendMMI:Return:KO":
@ -1247,7 +1393,7 @@ RILContentHelper.prototype = {
break;
case "RIL:StkCommand":
this._deliverEvent("_iccListeners", "notifyStkCommand",
[JSON.stringify(msg.json)]);
[JSON.stringify(msg.json.data)]);
break;
case "RIL:StkSessionEnd":
this._deliverEvent("_iccListeners", "notifyStkSessionEnd", null);
@ -1267,11 +1413,13 @@ RILContentHelper.prototype = {
case "RIL:UpdateIccContact":
this.handleUpdateIccContact(msg.json);
break;
case "RIL:DataError":
this.updateConnectionInfo(msg.json, this.rilContext.dataConnectionInfo);
case "RIL:DataError": {
let data = msg.json.data;
this.updateConnectionInfo(data, this.rilContext.dataConnectionInfo);
this._deliverEvent("_mobileConnectionListeners", "notifyDataError",
[msg.json.errorMsg]);
[data.errorMsg]);
break;
}
case "RIL:GetCallForwardingOption":
this.handleGetCallForwardingOption(msg.json);
break;
@ -1290,20 +1438,23 @@ RILContentHelper.prototype = {
case "RIL:SetCallWaitingOption":
this.handleSetCallWaitingOption(msg.json);
break;
case "RIL:CfStateChanged":
case "RIL:CfStateChanged": {
let data = msg.json.data;
this._deliverEvent("_mobileConnectionListeners",
"notifyCFStateChange",
[msg.json.success, msg.json.action,
msg.json.reason, msg.json.number,
msg.json.timeSeconds, msg.json.serviceClass]);
[data.success, data.action,
data.reason, data.number,
data.timeSeconds, data.serviceClass]);
break;
case "RIL:CellBroadcastReceived":
let message = new CellBroadcastMessage(msg.json);
}
case "RIL:CellBroadcastReceived": {
let message = new CellBroadcastMessage(msg.json.data);
this._deliverEvent("_cellBroadcastListeners",
"notifyMessageReceived",
[message]);
break;
}
}
},
handleEnumerateCalls: function handleEnumerateCalls(calls) {

File diff suppressed because it is too large Load Diff