mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Bug 803789 - RIL: refactor (un)registerMessageTargets() in RadioInterfaceLayer. r=philikon
This commit is contained in:
parent
f5110b7c82
commit
768a73bb89
@ -19,8 +19,8 @@ interface nsIMobileConnectionProvider : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called when a content process registers receiving unsolicited messages from
|
||||
* RadioInterfaceLayer in the chrome process. Only a content granted
|
||||
* mobileconnection permission is allowed to register. Note that a content
|
||||
* RadioInterfaceLayer in the chrome process. Only a content process that has
|
||||
* the 'mobileconnection' permission is allowed to register. Note that content
|
||||
* doesn't need to unregister because the chrome process will remove it from
|
||||
* the registration list once the chrome receives a 'child-process-shutdown'
|
||||
* message.
|
||||
|
@ -302,11 +302,9 @@ RadioInterfaceLayer.prototype = {
|
||||
debug("Received '" + msg.name + "' message from content process");
|
||||
if (msg.name == "child-process-shutdown") {
|
||||
// By the time we receive child-process-shutdown, the child process has
|
||||
// already forgotten its permissions so we need to unregister for both
|
||||
// telephony and mobile connection messages.
|
||||
this.unregisterTelephonyTarget(msg.target);
|
||||
this.unregisterMobileConnectionTarget(msg.target);
|
||||
this.unregisterVoicemailTarget(msg.target);
|
||||
// already forgotten its permissions so we need to unregister the target
|
||||
// for every permission.
|
||||
this.unregisterMessageTarget(null, msg.target);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -381,7 +379,7 @@ RadioInterfaceLayer.prototype = {
|
||||
this.resumeCall(msg.json);
|
||||
break;
|
||||
case "RIL:RegisterTelephonyMsg":
|
||||
this.registerTelephonyTarget(msg.target);
|
||||
this.registerMessageTarget("telephony", msg.target);
|
||||
break;
|
||||
case "RIL:GetAvailableNetworks":
|
||||
this.saveRequestTarget(msg);
|
||||
@ -425,10 +423,10 @@ RadioInterfaceLayer.prototype = {
|
||||
this.sendStkEventDownload(msg.json);
|
||||
break;
|
||||
case "RIL:RegisterMobileConnectionMsg":
|
||||
this.registerMobileConnectionTarget(msg.target);
|
||||
this.registerMessageTarget("mobileconnection", msg.target);
|
||||
break;
|
||||
case "RIL:RegisterVoicemailMsg":
|
||||
this.registerVoicemailTarget(msg.target);
|
||||
this.registerMessageTarget("voicemail", msg.target);
|
||||
break;
|
||||
}
|
||||
},
|
||||
@ -500,7 +498,7 @@ RadioInterfaceLayer.prototype = {
|
||||
break;
|
||||
case "cardstatechange":
|
||||
this.rilContext.cardState = message.cardState;
|
||||
this._sendMobileConnectionMessage("RIL:CardStateChanged", message);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:CardStateChanged", message);
|
||||
break;
|
||||
case "setCallWaiting":
|
||||
this.handleCallWaitingStatusChange(message);
|
||||
@ -547,7 +545,7 @@ RadioInterfaceLayer.prototype = {
|
||||
}
|
||||
break;
|
||||
case "iccmbdn":
|
||||
this._sendVoicemailMessage("RIL:VoicemailNumberChanged", message);
|
||||
this._sendTargetMessage("voicemail", "RIL:VoicemailNumberChanged", message);
|
||||
break;
|
||||
case "USSDReceived":
|
||||
debug("USSDReceived " + JSON.stringify(message));
|
||||
@ -565,7 +563,7 @@ RadioInterfaceLayer.prototype = {
|
||||
this.handleStkProactiveCommand(message);
|
||||
break;
|
||||
case "stksessionend":
|
||||
this._sendMobileConnectionMessage("RIL:StkSessionEnd", null);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:StkSessionEnd", null);
|
||||
break;
|
||||
case "setPreferredNetworkType":
|
||||
this.handleSetPreferredNetworkType(message);
|
||||
@ -607,10 +605,18 @@ RadioInterfaceLayer.prototype = {
|
||||
},
|
||||
|
||||
_messageManagerByPermission: null,
|
||||
_permissionList: null,
|
||||
registerMessageTarget: function registerMessageTarget(permission, target) {
|
||||
let targets = this._messageManagerByPermission[permission];
|
||||
if (!this._permissionList) {
|
||||
this._permissionList = [];
|
||||
}
|
||||
if (!targets) {
|
||||
targets = this._messageManagerByPermission[permission] = [];
|
||||
let list = this._permissionList;
|
||||
if (list.indexOf(permission) == -1) {
|
||||
list.push(permission);
|
||||
}
|
||||
}
|
||||
|
||||
if (targets.indexOf(target) != -1) {
|
||||
@ -623,6 +629,15 @@ RadioInterfaceLayer.prototype = {
|
||||
},
|
||||
|
||||
unregisterMessageTarget: function unregisterMessageTarget(permission, target) {
|
||||
if (permission == null) {
|
||||
// Unregister the target for every permission when no permission is specified.
|
||||
for (let type of this._permissionList) {
|
||||
this.unregisterMessageTarget(type, target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Unregister the target for a specified permission.
|
||||
let targets = this._messageManagerByPermission[permission];
|
||||
if (!targets) {
|
||||
return;
|
||||
@ -635,41 +650,13 @@ RadioInterfaceLayer.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
registerTelephonyTarget: function registerTelephonyTarget(target) {
|
||||
this.registerMessageTarget("telephony", target);
|
||||
},
|
||||
|
||||
registerMobileConnectionTarget: function registerMobileConnectionTarget(target) {
|
||||
this.registerMessageTarget("mobileconnection", target);
|
||||
},
|
||||
|
||||
registerVoicemailTarget: function registerVoicemailTarget(target) {
|
||||
this.registerMessageTarget("voicemail", target);
|
||||
},
|
||||
|
||||
unregisterTelephonyTarget: function unregisterTelephonyTarget(target) {
|
||||
this.unregisterMessageTarget("telephony", target);
|
||||
},
|
||||
|
||||
unregisterMobileConnectionTarget: function unregisterMobileConnectionTarget(target) {
|
||||
this.unregisterMessageTarget("mobileconnection", target);
|
||||
},
|
||||
|
||||
unregisterVoicemailTarget: function unregisterVoicemailTarget(target) {
|
||||
this.unregisterMessageTarget("voicemail", target);
|
||||
},
|
||||
|
||||
_sendTargetMessage: function _sendTargetMessage(permission, message, options) {
|
||||
let thisTargets = this._messageManagerByPermission[permission];
|
||||
if (!thisTargets) {
|
||||
let targets = this._messageManagerByPermission[permission];
|
||||
if (!targets) {
|
||||
return;
|
||||
}
|
||||
|
||||
let targets = thisTargets.slice();
|
||||
for each (let target in targets) {
|
||||
if (thisTargets.indexOf(target) == -1) {
|
||||
continue;
|
||||
}
|
||||
target.sendAsyncMessage(message, options);
|
||||
}
|
||||
},
|
||||
@ -719,10 +706,10 @@ RadioInterfaceLayer.prototype = {
|
||||
this.checkRoamingBetweenOperators(data);
|
||||
|
||||
if (voiceMessage || operatorMessage) {
|
||||
this._sendMobileConnectionMessage("RIL:VoiceInfoChanged", voice);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:VoiceInfoChanged", voice);
|
||||
}
|
||||
if (dataMessage || operatorMessage) {
|
||||
this._sendMobileConnectionMessage("RIL:DataInfoChanged", data);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:DataInfoChanged", data);
|
||||
}
|
||||
|
||||
if (selectionMessage) {
|
||||
@ -796,7 +783,7 @@ RadioInterfaceLayer.prototype = {
|
||||
}
|
||||
|
||||
if (!newInfo.batch) {
|
||||
this._sendMobileConnectionMessage("RIL:VoiceInfoChanged", voiceInfo);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:VoiceInfoChanged", voiceInfo);
|
||||
}
|
||||
},
|
||||
|
||||
@ -826,7 +813,7 @@ RadioInterfaceLayer.prototype = {
|
||||
}
|
||||
|
||||
if (!newInfo.batch) {
|
||||
this._sendMobileConnectionMessage("RIL:DataInfoChanged", dataInfo);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:DataInfoChanged", dataInfo);
|
||||
}
|
||||
this.updateRILNetworkInterface();
|
||||
},
|
||||
@ -837,7 +824,7 @@ RadioInterfaceLayer.prototype = {
|
||||
handleDataCallError: function handleDataCallError(message) {
|
||||
// Notify data call error only for data APN
|
||||
if (message.apn == this.dataCallSettings["apn"]) {
|
||||
this._sendMobileConnectionMessage("RIL:DataError", message);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:DataError", message);
|
||||
}
|
||||
|
||||
this._deliverDataCallCallback("dataCallError", [message]);
|
||||
@ -883,7 +870,7 @@ RadioInterfaceLayer.prototype = {
|
||||
voiceInfo.relSignalStrength != message.gsmRelative) {
|
||||
voiceInfo.signalStrength = message.gsmDBM;
|
||||
voiceInfo.relSignalStrength = message.gsmRelative;
|
||||
this._sendMobileConnectionMessage("RIL:VoiceInfoChanged", voiceInfo);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:VoiceInfoChanged", voiceInfo);
|
||||
}
|
||||
|
||||
let dataInfo = this.rilContext.data;
|
||||
@ -891,7 +878,7 @@ RadioInterfaceLayer.prototype = {
|
||||
dataInfo.relSignalStrength != message.gsmRelative) {
|
||||
dataInfo.signalStrength = message.gsmDBM;
|
||||
dataInfo.relSignalStrength = message.gsmRelative;
|
||||
this._sendMobileConnectionMessage("RIL:DataInfoChanged", dataInfo);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:DataInfoChanged", dataInfo);
|
||||
}
|
||||
},
|
||||
|
||||
@ -909,12 +896,12 @@ RadioInterfaceLayer.prototype = {
|
||||
|
||||
if (this.networkChanged(message, voice.network)) {
|
||||
voice.network = message;
|
||||
this._sendMobileConnectionMessage("RIL:VoiceInfoChanged", voice);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:VoiceInfoChanged", voice);
|
||||
}
|
||||
|
||||
if (this.networkChanged(message, data.network)) {
|
||||
data.network = message;
|
||||
this._sendMobileConnectionMessage("RIL:DataInfoChanged", data);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:DataInfoChanged", data);
|
||||
}
|
||||
},
|
||||
|
||||
@ -1111,7 +1098,7 @@ RadioInterfaceLayer.prototype = {
|
||||
this._activeCall = null;
|
||||
}
|
||||
this.updateCallAudioState();
|
||||
this._sendTelephonyMessage("RIL:CallStateChanged", call);
|
||||
this._sendTargetMessage("telephony", "RIL:CallStateChanged", call);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1124,7 +1111,7 @@ RadioInterfaceLayer.prototype = {
|
||||
}
|
||||
this.updateCallAudioState();
|
||||
call.state = nsIRadioInterfaceLayer.CALL_STATE_DISCONNECTED;
|
||||
this._sendTelephonyMessage("RIL:CallStateChanged", call);
|
||||
this._sendTargetMessage("telephony", "RIL:CallStateChanged", call);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1152,7 +1139,7 @@ RadioInterfaceLayer.prototype = {
|
||||
*/
|
||||
updateNetworkSelectionMode: function updateNetworkSelectionMode(message) {
|
||||
debug("updateNetworkSelectionMode: " + JSON.stringify(message));
|
||||
this._sendMobileConnectionMessage("RIL:NetworkSelectionModeChanged", message);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:NetworkSelectionModeChanged", message);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1175,7 +1162,7 @@ RadioInterfaceLayer.prototype = {
|
||||
* Handle call error.
|
||||
*/
|
||||
handleCallError: function handleCallError(message) {
|
||||
this._sendTelephonyMessage("RIL:CallError", message);
|
||||
this._sendTargetMessage("telephony", "RIL:CallError", message);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1236,7 +1223,7 @@ RadioInterfaceLayer.prototype = {
|
||||
if (mwi) {
|
||||
mwi.returnNumber = message.sender || null;
|
||||
mwi.returnMessage = message.fullBody || null;
|
||||
this._sendVoicemailMessage("RIL:VoicemailNotification", mwi);
|
||||
this._sendTargetMessage("voicemail", "RIL:VoicemailNotification", mwi);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1352,7 +1339,7 @@ RadioInterfaceLayer.prototype = {
|
||||
if (datacall.ifname &&
|
||||
datacall.apn == this.dataCallSettings["apn"]) {
|
||||
data.connected = (datacall.state == RIL.GECKO_NETWORK_STATE_CONNECTED);
|
||||
this._sendMobileConnectionMessage("RIL:DataInfoChanged", data);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:DataInfoChanged", data);
|
||||
}
|
||||
|
||||
this._deliverDataCallCallback("dataCallStateChanged",
|
||||
@ -1421,7 +1408,7 @@ RadioInterfaceLayer.prototype = {
|
||||
}
|
||||
// RIL:IccInfoChanged corresponds to a DOM event that gets fired only
|
||||
// when the MCC or MNC codes have changed.
|
||||
this._sendMobileConnectionMessage("RIL:IccInfoChanged", message);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:IccInfoChanged", message);
|
||||
},
|
||||
|
||||
handleICCCardLockResult: function handleICCCardLockResult(message) {
|
||||
@ -1430,7 +1417,7 @@ RadioInterfaceLayer.prototype = {
|
||||
|
||||
handleUSSDReceived: function handleUSSDReceived(ussd) {
|
||||
debug("handleUSSDReceived " + JSON.stringify(ussd));
|
||||
this._sendMobileConnectionMessage("RIL:USSDReceived", ussd);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:USSDReceived", ussd);
|
||||
},
|
||||
|
||||
handleSendMMI: function handleSendMMI(message) {
|
||||
@ -1450,7 +1437,7 @@ RadioInterfaceLayer.prototype = {
|
||||
handleStkProactiveCommand: function handleStkProactiveCommand(message) {
|
||||
debug("handleStkProactiveCommand " + JSON.stringify(message));
|
||||
gSystemMessenger.broadcastMessage("icc-stkcommand", message);
|
||||
this._sendMobileConnectionMessage("RIL:StkCommand", message);
|
||||
this._sendTargetMessage("mobileconnection", "RIL:StkCommand", message);
|
||||
},
|
||||
|
||||
// nsIObserver
|
||||
|
@ -150,21 +150,23 @@ interface nsIRILContentHelper : nsIMobileConnectionProvider
|
||||
|
||||
/**
|
||||
* Called when a content process registers receiving unsolicited messages from
|
||||
* RadioInterfaceLayer in the chrome process. Only content granted telephony
|
||||
* permission is allowed to register. Note that a content doesn't need to
|
||||
* unregister because the chrome process will remove it from the registration
|
||||
* list once the chrome receives a 'child-process-shutdown' message.
|
||||
* RadioInterfaceLayer in the chrome process. Only a content process that has
|
||||
* the 'telephony' permission is allowed to register. Note that content
|
||||
* doesn't need to unregister because the chrome process will remove it from
|
||||
* the registration list once the chrome receives a 'child-process-shutdown'
|
||||
* message.
|
||||
*/
|
||||
void registerTelephonyMsg();
|
||||
void registerTelephonyMsg();
|
||||
|
||||
/**
|
||||
* Called when a content process registers receiving unsolicited messages from
|
||||
* RadioInterfaceLayer in the chrome process. Only a content granted voice
|
||||
* mail permission is allowed to register. Note that a content doesn't need to
|
||||
* unregister because the chrome process will remove it from the registration
|
||||
* list once the chrome receives a 'child-process-shutdown' message.
|
||||
* RadioInterfaceLayer in the chrome process. Only a content process that has
|
||||
* the 'voicemail' permission is allowed to register. Note that content
|
||||
* doesn't need to unregister because the chrome process will remove it from
|
||||
* the registration list once the chrome receives a 'child-process-shutdown'
|
||||
* message.
|
||||
*/
|
||||
void registerVoicemailMsg();
|
||||
void registerVoicemailMsg();
|
||||
|
||||
/**
|
||||
* Will continue calling callback.enumerateCallState until the callback
|
||||
|
Loading…
Reference in New Issue
Block a user