Bug 734300 - B2G RIL: Network registration state improvements. r=qDot

This commit is contained in:
Philipp von Weitershausen 2012-03-12 16:45:57 -07:00
parent 3f6f075a5d
commit 22ca36f404
4 changed files with 96 additions and 20 deletions

View File

@ -47,7 +47,7 @@ Cu.import("resource://gre/modules/Services.jsm");
var RIL = {};
Cu.import("resource://gre/modules/ril_consts.js", RIL);
const DEBUG = false; // set to true to see debug messages
const DEBUG = true; // set to true to see debug messages
const RADIOINTERFACELAYER_CID =
Components.ID("{2d831c8d-6017-435b-a80c-e5d422810cea}");
@ -141,11 +141,15 @@ function RadioInterfaceLayer() {
this.worker.onerror = this.onerror.bind(this);
this.worker.onmessage = this.onmessage.bind(this);
debug("Starting Worker\n");
this.currentState = {
signalStrength: null,
operator: null,
this.radioState = {
radioState: null,
cardState: null
cardState: null,
connected: null,
roaming: null,
signalStrength: null,
bars: null,
operator: null,
type: null,
};
}
RadioInterfaceLayer.prototype = {
@ -169,7 +173,7 @@ RadioInterfaceLayer.prototype = {
* Process the incoming message from the RIL worker:
* (1) Update the current state. This way any component that hasn't
* been listening for callbacks can easily catch up by looking at
* this.currentState.
* this.radioState.
* (2) Update state in related systems such as the audio.
* (3) Multiplex the message to telephone callbacks.
*/
@ -190,22 +194,58 @@ RadioInterfaceLayer.prototype = {
this.handleEnumerateCalls(message.calls);
break;
case "registrationstatechange":
this.currentState.registrationState = message.registrationState;
//TODO for simplicity's sake, for now we only look at
// gprsregistrationstatechange.
break;
case "gprsregistrationstatechange":
this.currentState.gprsRegistrationState = message.gprsRegistrationState;
let state = message.gprsRegistrationState;
if (!state || state.regState == RIL.NETWORK_CREG_STATE_UNKNOWN) {
this.resetRadioState();
this.notifyRadioStateChanged();
return;
}
this.radioState.connected =
(state.regState == RIL.NETWORK_CREG_STATE_REGISTERED_HOME) ||
(state.regState == RIL.NETWORK_CREG_STATE_REGISTERED_ROAMING);
this.radioState.roaming =
this.radioState.connected &&
(state.regState == RIL.NETWORK_CREG_STATE_REGISTERED_ROAMING);
this.radioState.type = RIL.GECKO_RADIO_TECH[state.radioTech] || null;
this.notifyRadioStateChanged();
break;
case "signalstrengthchange":
this.currentState.signalStrength = message.signalStrength;
//TODO GSM only?
let signalStrength = message.signalStrength.gsmSignalStrength;
if (signalStrength == 99) {
signalStrength = null;
}
this.radioState.signalStrength = signalStrength;
if (message.signalStrength.bars) {
this.radioState.bars = message.signalStrength.bars;
} else if (signalStrength != null) {
//TODO pretty sure that the bars aren't linear, but meh...
// Convert signal strength (0...31) to bars (0...4).
this.radioState.bars = Math.round(signalStrength / 7.75);
} else {
this.radioState.bars = null;
}
this.notifyRadioStateChanged();
break;
case "operatorchange":
this.currentState.operator = message.operator;
this.radioState.operator = message.operator.alphaLong;
this.notifyRadioStateChanged();
break;
case "radiostatechange":
this.currentState.radioState = message.radioState;
this.radioState.radioState = message.radioState;
this.notifyRadioStateChanged();
break;
case "cardstatechange":
this.currentState.cardState = message.cardState;
this.radioState.cardState = message.cardState;
if (!message.cardState || message.cardState == "absent") {
this.resetRadioState();
}
this.notifyRadioStateChanged();
break;
case "sms-received":
this.handleSmsReceived(message);
@ -376,13 +416,27 @@ RadioInterfaceLayer.prototype = {
[datacalls, datacalls.length]);
},
resetRadioState: function resetRadioState() {
this.radioState.connected = null;
this.radioState.roaming = null;
this.radioState.signalStrength = null;
this.radioState.bars = null;
this.radioState.operator = null;
this.radioState.type = null;
},
notifyRadioStateChanged: function notifyRadioStateChanged() {
debug("Radio state changed: " + JSON.stringify(this.radioState));
Services.obs.notifyObservers(null, "ril-radiostate-changed", null);
},
// nsIRadioWorker
worker: null,
// nsIRadioInterfaceLayer
currentState: null,
radioState: null,
dial: function dial(number) {
debug("Dialing " + number);

View File

@ -116,7 +116,7 @@ interface nsIRILDataCallback : nsISupports
in unsigned long length);
};
[scriptable, uuid(aeb7ffe7-7d3a-4b7d-9b59-b6d3ae1c72ed)]
[scriptable, uuid(78fc7ef6-0941-4fc8-89ff-de9398ef478a)]
interface nsIRadioInterfaceLayer : nsISupports
{
const unsigned short CALL_STATE_UNKNOWN = 0;
@ -139,7 +139,7 @@ interface nsIRadioInterfaceLayer : nsISupports
const unsigned short DATACALL_STATE_DISCONNECTING = 3;
const unsigned short DATACALL_STATE_DISCONNECTED = 4;
readonly attribute jsval currentState;
readonly attribute jsval radioState;
void registerCallback(in nsIRILTelephonyCallback callback);
void unregisterCallback(in nsIRILTelephonyCallback callback);

View File

@ -1122,14 +1122,29 @@ const GECKO_RADIOSTATE_UNAVAILABLE = "unavailable";
const GECKO_RADIOSTATE_OFF = "off";
const GECKO_RADIOSTATE_READY = "ready";
const GECKO_CARDSTATE_UNAVAILABLE = "unavailable";
const GECKO_CARDSTATE_UNAVAILABLE = null;
const GECKO_CARDSTATE_ABSENT = "absent";
const GECKO_CARDSTATE_PIN_REQUIRED = "pin_required";
const GECKO_CARDSTATE_PUK_REQUIRED = "puk_required";
const GECKO_CARDSTATE_NETWORK_LOCKED = "network_locked";
const GECKO_CARDSTATE_NOT_READY = "not_ready";
const GECKO_CARDSTATE_NOT_READY = null;
const GECKO_CARDSTATE_READY = "ready";
const GECKO_RADIO_TECH = [
null,
"gprs",
"edge",
"umts",
"is95a",
"is95b",
"1xrtt",
"evdo0",
"evdoa",
"hsdpa",
"hsupa",
"hspa",
"evdob",
];
// Allow this file to be imported via Components.utils.import().
const EXPORTED_SYMBOLS = Object.keys(this);

View File

@ -1113,11 +1113,16 @@ RIL[REQUEST_UDUB] = function REQUEST_UDUB(length) {
};
RIL[REQUEST_LAST_CALL_FAIL_CAUSE] = null;
RIL[REQUEST_SIGNAL_STRENGTH] = function REQUEST_SIGNAL_STRENGTH() {
let signalStrength = Buf.readUint32();
// The SGS2 seems to compute the number of bars for us and expose those
// instead of the actual signal strength.
let bars = signalStrength >> 8;
signalStrength = signalStrength & 0xff;
let strength = {
// Valid values are (0-31, 99) as defined in TS 27.007 8.5.
// For some reason we're getting int32s like [99, 4, 0, 0] and [99, 3, 0, 0]
// here, so let's strip of anything beyond the first byte.
gsmSignalStrength: Buf.readUint32() & 0xff,
gsmSignalStrength: signalStrength,
// Non-standard extension by the SGS2.
bars: bars,
// GSM bit error rate (0-7, 99) as defined in TS 27.007 8.5.
gsmBitErrorRate: Buf.readUint32(),
// The CDMA RSSI value.
@ -1650,6 +1655,7 @@ let Phone = {
if ((!iccStatus) || (iccStatus.cardState == CARD_STATE_ABSENT)) {
if (DEBUG) debug("ICC absent");
if (this.cardState == GECKO_CARDSTATE_ABSENT) {
this.operator = null;
return;
}
this.cardState = GECKO_CARDSTATE_ABSENT;
@ -1687,6 +1693,7 @@ let Phone = {
return;
}
this.cardState = GECKO_CARDSTATE_ABSENT;
this.operator = null;
this.sendDOMMessage({type: "cardstatechange",
cardState: this.cardState});
return;