Bug 783966 - Process netd's InterfaceChange(600) and BandwidthControl(601) message. r=vchang

This commit is contained in:
Albert Crespell 2013-04-23 09:27:05 +02:00
parent 06809c83ef
commit dc3cd58064
3 changed files with 39 additions and 2 deletions

View File

@ -401,6 +401,10 @@ NetworkManager.prototype = {
debug("NetworkManager received message from worker: " + JSON.stringify(e.data));
let response = e.data;
let id = response.id;
if (id == 'broadcast') {
Services.obs.notifyObservers(null, response.topic, response.reason);
return;
}
let callback = this.controlCallbacks[id];
if (callback) {
callback.call(this, response);

View File

@ -24,6 +24,9 @@ const SYS_USB_STATE_PROPERTY = "sys.usb.state";
const USB_FUNCTION_RNDIS = "rndis";
const USB_FUNCTION_ADB = "adb";
const kNetdInterfaceChangedTopic = "netd-interface-change";
const kNetdBandwidthControlTopic = "netd-bandwidth-control";
// Retry 20 times (2 seconds) for usb state transition.
const USB_FUNCTION_RETRY_TIMES = 20;
// Check "sys.usb.state" every 100ms.
@ -41,12 +44,21 @@ const NETD_COMMAND_ERROR = 500;
// 6xx - Unsolicited broadcasts
const NETD_COMMAND_UNSOLICITED = 600;
// Broadcast messages
const NETD_COMMAND_INTERFACE_CHANGE = 600;
const NETD_COMMAND_BANDWIDTH_CONTROLLER = 601;
importScripts("systemlibs.js");
function netdResponseType(code) {
return Math.floor(code/100)*100;
}
function isBroadcastMessage(code) {
let type = netdResponseType(code);
return (type == NETD_COMMAND_UNSOLICITED);
}
function isError(code) {
let type = netdResponseType(code);
return (type != NETD_COMMAND_PROCEEDING && type != NETD_COMMAND_OKAY);
@ -57,6 +69,22 @@ function isComplete(code) {
return (type != NETD_COMMAND_PROCEEDING);
}
function sendBroadcastMessage(code, reason) {
let topic = null;
switch (code) {
case NETD_COMMAND_INTERFACE_CHANGE:
topic = "netd-interface-change";
break;
case NETD_COMMAND_BANDWIDTH_CONTROLLER:
topic = "netd-bandwidth-control";
break;
}
if (topic) {
postMessage({id: 'broadcast', topic: topic, reason: reason});
}
}
let gWifiFailChain = [stopSoftAP,
setIpForwardingEnabled,
stopTethering];
@ -253,6 +281,12 @@ function onNetdMessage(data) {
// 1xx response code regards as command is proceeding, we need to wait for
// final response code such as 2xx, 4xx and 5xx before sending next command.
if (isBroadcastMessage(code)) {
sendBroadcastMessage(code, reason);
nextNetdCommand();
return;
}
if (isComplete(code)) {
gPending = false;
}

View File

@ -156,8 +156,7 @@ void NetdClient::OnLineRead(int aFd, nsDependentCSubstring& aMessage)
// integer response code followed by the rest of the line.
// Fish out the response code.
int responseCode = strtol(aMessage.Data(), nullptr, 10);
// TODO, Bug 783966, handle InterfaceChange(600) and BandwidthControl(601).
if (!errno && responseCode < 600) {
if (!errno) {
NetdCommand* response = new NetdCommand();
// Passing all the response message, including the line terminator.
response->mSize = aMessage.Length();