Bug 741862 - B2G 3G: Settings API hookup. r=philikon a=b2g-only

This commit is contained in:
Jose Antonio Olivera Ortega 2012-04-24 17:46:42 -03:00
Родитель c2770ba780
Коммит 07ee280452
4 изменённых файлов: 101 добавлений и 21 удалений

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

@ -475,15 +475,6 @@ pref("full-screen-api.enabled", true);
pref("media.volume.steps", 10);
// Data connection settings. These will eventually live in the
// navigator.settings API, or even in a database where we can look
// it up automatically (bug 729440), but for this will have to do.
pref("ril.data.enabled", false);
pref("ril.data.roaming.enabled", false);
pref("ril.data.apn", "");
pref("ril.data.user", "");
pref("ril.data.passwd", "");
//Enable/disable marionette server, set listening port
pref("marionette.defaultPrefs.enabled", true);
pref("marionette.defaultPrefs.port", 2828);

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

@ -365,6 +365,54 @@ var shell = {
};
})();
const DATA_CALL_SETTING_BOLKEYS = ["ril.data.enabled",
"ril.data.roaming.enabled"];
const DATA_CALL_SETTING_CHARKEYS = ["ril.data.apn",
"ril.data.user",
"ril.data.passwd"];
(function DataCallSettings() {
let sm = navigator.mozSettings;
let lock = sm.getLock();
DATA_CALL_SETTING_BOLKEYS.forEach(function(key) {
let request = lock.get(key);
request.onsuccess = function onSuccess() {
let value = request.result[key] || false;
Services.prefs.setBoolPref(key, value);
dump("DataCallSettings - " + key + ":" + value);
};
request.onerror = function onError() {
Services.prefs.setBoolPref(key, false);
};
});
DATA_CALL_SETTING_CHARKEYS.forEach(function(key) {
let request = lock.get(key);
request.onsuccess = function onSuccess() {
let value = request.result[key] || "";
Services.prefs.setCharPref(key, value);
dump("DataCallSettings - " + key + ":" + value);
};
request.onerror = function onError() {
Services.prefs.setCharPref(key, "");
};
});
navigator.mozSettings.onsettingchange = function onSettingChange(e) {
dump("DataCallSettings - onsettingchange: " + e.settingName +
": " + e.settingValue);
if (e.settingValue) {
if (DATA_CALL_SETTING_BOLKEYS.indexOf(e.settingName) > -1 ) {
Services.prefs.setBoolPref(e.settingName, e.settingValue);
return;
}
if (DATA_CALL_SETTING_CHARKEYS.indexOf(e.settingName) > -1) {
Services.prefs.setCharPref(e.settingName, e.settingValue);
}
}
};
})();
function nsBrowserAccess() {
}

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

@ -173,7 +173,7 @@ NetworkManager.prototype = {
break;
}
}
if (oldActive != this.active) {
if (this.active && (oldActive != this.active)) {
this.setDefaultRouteAndDNS();
}
},

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

@ -60,6 +60,7 @@ const nsIRadioInterfaceLayer = Ci.nsIRadioInterfaceLayer;
const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
const kSmsReceivedObserverTopic = "sms-received";
const kSmsDeliveredObserverTopic = "sms-delivered";
const kMozSettingsChangedObserverTopic = "mozsettings-changed";
const DOM_SMS_DELIVERY_RECEIVED = "received";
const DOM_SMS_DELIVERY_SENT = "sent";
@ -190,6 +191,7 @@ function RadioInterfaceLayer() {
ppmm.addMessageListener(msgname, this);
}
Services.obs.addObserver(this, "xpcom-shutdown", false);
Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
this._sentSmsEnvelopes = {};
this.portAddressedSmsApps = {};
@ -203,7 +205,8 @@ RadioInterfaceLayer.prototype = {
Ci.nsIRadioInterfaceLayer]}),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWorkerHolder,
Ci.nsIRadioInterfaceLayer]),
Ci.nsIRadioInterfaceLayer,
Ci.nsIObserver]),
/**
* Process a message from the content process.
@ -632,15 +635,44 @@ RadioInterfaceLayer.prototype = {
[datacalls, datacalls.length]);
},
/**
* Handle setting changes.
*/
handleMozSettingsChanged: function handleMozSettingsChanged(setting) {
// We only watch at "ril.data.enabled" flag changes for connecting or
// disconnecting the data call. If the value of "ril.data.enabled" is
// true and any of the remaining flags change the setting application
// should turn this flag to false and then to true in order to reload
// the new values and reconnect the data call.
if (setting.key != "ril.data.enabled") {
return;
}
if (!setting.value && RILNetworkInterface.connected) {
debug("Data call settings: disconnect data call.");
RILNetworkInterface.disconnect();
}
if (setting.value && !RILNetworkInterface.connected) {
debug("Data call settings connect data call.");
RILNetworkInterface.connect();
}
},
// nsIObserver
observe: function observe(subject, topic, data) {
if (topic == "xpcom-shutdown") {
for each (let msgname in RIL_IPC_MSG_NAMES) {
ppmm.removeMessageListener(msgname, this);
}
Services.obs.removeObserver(this, "xpcom-shutdown");
ppmm = null;
switch (topic) {
case kMozSettingsChangedObserverTopic:
let setting = JSON.parse(data);
this.handleMozSettingsChanged(setting);
break;
case "xpcom-shutdown":
for each (let msgname in RIL_IPC_MSG_NAMES) {
ppmm.removeMessageListener(msgname, this);
}
ppmm = null;
Services.obs.removeObserver(this, "xpcom-shutdown");
Services.obs.removeObserver(this, kMozSettingsChangedObserverTopic);
break;
}
},
@ -1211,13 +1243,13 @@ let RILNetworkInterface = {
// nsIRILDataCallback
dataCallStateChanged: function dataCallStateChanged(cid, interfaceName, callState) {
debug("Data call ID: " + cid + ", interface name: " + interfaceName);
if (this.connecting &&
(callState == RIL.GECKO_NETWORK_STATE_CONNECTING ||
callState == RIL.GECKO_NETWORK_STATE_CONNECTED)) {
this.connecting = false;
this.cid = cid;
this.name = interfaceName;
debug("Data call ID: " + cid + ", interface name: " + interfaceName);
if (!this.registeredAsNetworkInterface) {
let networkManager = Cc["@mozilla.org/network/manager;1"]
.getService(Ci.nsINetworkManager);
@ -1255,11 +1287,14 @@ let RILNetworkInterface = {
.getInterface(Ci.nsIRadioInterfaceLayer);
},
get connected() {
return this.state == RIL.GECKO_NETWORK_STATE_CONNECTED;
},
connect: function connect() {
if (this.connecting ||
this.state == RIL.GECKO_NETWORK_STATE_CONNECTED ||
this.state == RIL.GECKO_NETWORK_STATE_SUSPENDED ||
this.state == RIL.GECKO_NETWORK_STATE_DISCONNECTING) {
this.state == RIL.GECKO_NETWORK_STATE_SUSPENDED) {
return;
}
if (!this.registeredAsDataCallCallback) {
@ -1286,7 +1321,13 @@ let RILNetworkInterface = {
},
disconnect: function disconnect() {
this.mRIL.deactivateDataCall(this.cid);
if (this.state == RIL.GECKO_NETWORK_STATE_DISCONNECTING ||
this.state == RIL.GECKO_NETWORK_STATE_DISCONNECTED) {
return;
}
let reason = RIL.DATACALL_DEACTIVATE_NO_REASON;
debug("Going to disconnet data connection " + this.cid);
this.mRIL.deactivateDataCall(this.cid, reason);
},
};