canmove, Confirmed users
725
edits
Line 266: | Line 266: | ||
=== Example === | === Example === | ||
Let's start with an example that demonstrates the lower-level parts of the system. When the modem receives an incoming call, it notifies the <code>rild</code> using a proprietary mechanism. The rild then prepares a message for its client according to the "open" protocol [https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h here]. In this case, an incoming call generates the [https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h#L3290 RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED] message. This message is sent by rild to its client and received by rilproxy [https://github.com/mozilla-b2g/rilproxy/blob/master/src/rilproxy.c#L214 here] | Let's start with an example that demonstrates the lower-level parts of the system. When the modem receives an incoming call, it notifies the <code>rild</code> using a proprietary mechanism. The rild then prepares a message for its client according to the "open" protocol [https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h here]. In this case, an incoming call generates the [https://github.com/mozilla-b2g/android-hardware-ril/blob/master/include/telephony/ril.h#L3290 <code>RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED</code>] message. This message is sent by rild to its client and received by rilproxy [https://github.com/mozilla-b2g/rilproxy/blob/master/src/rilproxy.c#L214 here] | ||
<pre> | <pre> | ||
ret = read(rilproxy_rw, data, 1024); | ret = read(rilproxy_rw, data, 1024); | ||
Line 292: | Line 292: | ||
argv, argv); | argv, argv); | ||
</pre> | </pre> | ||
That function is [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#4482 defined in <code>ril_worker.js</code>]. The message bytes are processed a bit | That function is [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#4482 defined in <code>ril_worker.js</code>]. The message bytes are processed a bit and chopped into parcels. Each complete parcel is then [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#2525 dispatched to individual handler methods]: | ||
<pre> | <pre> | ||
handleParcel: function handleParcel(request_type, length) { | handleParcel: function handleParcel(request_type, length) { | ||
Line 303: | Line 303: | ||
}; | }; | ||
</pre> | </pre> | ||
For our example, <code>RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED</code>, this calls [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#3217 the following handler]: | |||
<pre> | <pre> | ||
RIL[UNSOLICITED_RESPONSE_CALL_STATE_CHANGED] = function UNSOLICITED_RESPONSE_CALL_STATE_CHANGED() { | RIL[UNSOLICITED_RESPONSE_CALL_STATE_CHANGED] = function UNSOLICITED_RESPONSE_CALL_STATE_CHANGED() { | ||
this.getCurrentCalls(); | |||
}; | }; | ||
</pre> | </pre> | ||
As you can see, upon being notified that the call state changed, the state machine simply fetches the current call state with a <code>REQUEST_GET_CURRENT_CALLS</code> request: | |||
<pre> | <pre> | ||
getCurrentCalls: function getCurrentCalls() { | getCurrentCalls: function getCurrentCalls() { | ||
Line 315: | Line 315: | ||
}, | }, | ||
</pre> | </pre> | ||
This sends a request ''back'' to the rild to request the state of all currently-active calls. The request follows a similar path back to rild (out from ril_worker.js, to SystemWorkerManager.cpp, off to Ril.cpp, then to rilproxy.c and finally written to the rild socket). The response from rild is processed similarly to above, | This sends a request ''back'' to the rild to request the state of all currently-active calls. The request follows a similar path back to rild (out from ril_worker.js, to SystemWorkerManager.cpp, off to Ril.cpp, then to rilproxy.c and finally written to the rild socket). The response from rild is processed similarly to above, in [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#2619 the <code>REQUEST_GET_CURRENT_CALLS</code> handler]. The call state is then [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#2057 processed and compared to the previous one]. If there's a change of state, we [https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/ril_worker.js#2117 notify the <code>nsIRadioInterfaceLayer</code> service] on the main thread: | ||
<pre> | <pre> | ||
_handleChangedCallState: function _handleChangedCallState(changedCall) { | |||
let message = {type: "callStateChange", | |||
call: changedCall}; | |||
this.sendDOMMessage(message); | |||
}, | |||
</pre> | |||
[https://mxr.mozilla.org/mozilla-central/source/dom/system/gonk/RadioInterfaceLayer.js#268 This message is processed] by the <code>nsIRadioInterfaceLayer</code> service: | |||
<pre> | |||
onmessage: function onmessage(event) { | |||
let message = event.data; | |||
debug("Received message from worker: " + JSON.stringify(message)); | |||
switch (message.type) { | |||
case "callStateChange": | |||
// This one will handle its own notifications. | |||
this.handleCallStateChange(message.call); | |||
break; | |||
</pre> | </pre> | ||
This sets off a chain of events that results in the currently-active dialer application being notified of an incoming call. In gaia, this notification is received [https://github.com/andreasgal/gaia/blob/master/apps/dialer/js/dialer.js#L297 here] | This sets off a chain of events that results in the currently-active dialer application being notified of an incoming call. In gaia, this notification is received [https://github.com/andreasgal/gaia/blob/master/apps/dialer/js/dialer.js#L297 here] | ||
<pre> | <pre> |