mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Bug 1177236 - Usage alert doesn't work when tethering is enabled. r=ethan
This commit is contained in:
parent
340a2858c6
commit
f718e9cb41
@ -269,6 +269,58 @@ NetworkService.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
setNetworkTetheringAlarm(aEnable, aInterface) {
|
||||
// Method called when enabling disabling tethering, it checks if there is
|
||||
// some alarm active and move from interfaceAlarm to globalAlarm because
|
||||
// interfaceAlarm doens't work in tethering scenario due to forwarding.
|
||||
debug("setNetworkTetheringAlarm for tethering" + aEnable);
|
||||
|
||||
let filename = aEnable ? "/proc/net/xt_quota/" + aInterface + "Alert" :
|
||||
"/proc/net/xt_quota/globalAlert";
|
||||
|
||||
let file = new FileUtils.File(filename);
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
NetUtil.asyncFetch({
|
||||
uri: NetUtil.newURI(file),
|
||||
loadUsingSystemPrincipal: true
|
||||
}, (inputStream, status) => {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
let data = NetUtil.readInputStreamToString(inputStream, inputStream.available())
|
||||
.split("\n");
|
||||
if (data) {
|
||||
let threshold = parseInt(data[0], 10);
|
||||
|
||||
this._setNetworkTetheringAlarm(aEnable, aInterface, threshold);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_setNetworkTetheringAlarm(aEnable, aInterface, aThreshold, aCallback) {
|
||||
debug("_setNetworkTetheringAlarm for tethering" + aEnable);
|
||||
|
||||
let cmd = aEnable ? "setTetheringAlarm" : "removeTetheringAlarm";
|
||||
|
||||
let params = {
|
||||
cmd: cmd,
|
||||
ifname: aInterface,
|
||||
threshold: aThreshold,
|
||||
};
|
||||
|
||||
this.controlMessage(params, function(aData) {
|
||||
let code = aData.resultCode;
|
||||
let reason = aData.resultReason;
|
||||
let enableString = aEnable ? "Enable" : "Disable";
|
||||
debug(enableString + " tethering Alarm result: Code " + code + " reason " + reason);
|
||||
if (aCallback) {
|
||||
aCallback.networkUsageAlarmResult(null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setNetworkInterfaceAlarm: function(aInterfaceName, aThreshold, aCallback) {
|
||||
if (!aInterfaceName) {
|
||||
aCallback.networkUsageAlarmResult(-1);
|
||||
@ -286,7 +338,26 @@ NetworkService.prototype = {
|
||||
return
|
||||
}
|
||||
|
||||
self._setNetworkInterfaceAlarm(aInterfaceName, aThreshold, aCallback);
|
||||
// Check if tethering is enabled
|
||||
let params = {
|
||||
cmd: "getTetheringStatus"
|
||||
};
|
||||
|
||||
self.controlMessage(params, function(aResult) {
|
||||
if (isError(aResult.resultCode)) {
|
||||
aCallback.networkUsageAlarmResult(aResult.reason);
|
||||
return;
|
||||
}
|
||||
|
||||
if (aResult.resultReason.indexOf('started') == -1) {
|
||||
// Tethering disabled, set interfaceAlarm
|
||||
self._setNetworkInterfaceAlarm(aInterfaceName, aThreshold, aCallback);
|
||||
return;
|
||||
}
|
||||
|
||||
// Tethering enabled, set globalAlarm
|
||||
self._setNetworkTetheringAlarm(true, aInterfaceName, aThreshold, aCallback);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@ -545,7 +616,7 @@ NetworkService.prototype = {
|
||||
aConfig.cmd = "setWifiTethering";
|
||||
|
||||
// The callback function in controlMessage may not be fired immediately.
|
||||
this.controlMessage(aConfig, function(aData) {
|
||||
this.controlMessage(aConfig, (aData) => {
|
||||
let code = aData.resultCode;
|
||||
let reason = aData.resultReason;
|
||||
let enable = aData.enable;
|
||||
@ -553,6 +624,8 @@ NetworkService.prototype = {
|
||||
|
||||
debug(enableString + " Wifi tethering result: Code " + code + " reason " + reason);
|
||||
|
||||
this.setNetworkTetheringAlarm(aEnable, aConfig.externalIfname);
|
||||
|
||||
if (isError(code)) {
|
||||
aCallback.wifiTetheringEnabledChange("netd command error");
|
||||
} else {
|
||||
@ -565,7 +638,7 @@ NetworkService.prototype = {
|
||||
setUSBTethering: function(aEnable, aConfig, aCallback) {
|
||||
aConfig.cmd = "setUSBTethering";
|
||||
// The callback function in controlMessage may not be fired immediately.
|
||||
this.controlMessage(aConfig, function(aData) {
|
||||
this.controlMessage(aConfig, (aData) => {
|
||||
let code = aData.resultCode;
|
||||
let reason = aData.resultReason;
|
||||
let enable = aData.enable;
|
||||
@ -573,6 +646,8 @@ NetworkService.prototype = {
|
||||
|
||||
debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
|
||||
|
||||
this.setNetworkTetheringAlarm(aEnable, aConfig.externalIfname);
|
||||
|
||||
if (isError(code)) {
|
||||
aCallback.usbTetheringEnabledChange("netd command error");
|
||||
} else {
|
||||
|
@ -268,6 +268,23 @@ const CommandFunc NetworkUtils::sNetworkInterfaceSetAlarmChain[] = {
|
||||
NetworkUtils::networkInterfaceAlarmSuccess
|
||||
};
|
||||
|
||||
const CommandFunc NetworkUtils::sTetheringInterfaceSetAlarmChain[] = {
|
||||
NetworkUtils::setGlobalAlarm,
|
||||
NetworkUtils::removeAlarm,
|
||||
NetworkUtils::networkInterfaceAlarmSuccess
|
||||
};
|
||||
|
||||
const CommandFunc NetworkUtils::sTetheringInterfaceRemoveAlarmChain[] = {
|
||||
NetworkUtils::removeGlobalAlarm,
|
||||
NetworkUtils::setAlarm,
|
||||
NetworkUtils::networkInterfaceAlarmSuccess
|
||||
};
|
||||
|
||||
const CommandFunc NetworkUtils::sTetheringGetStatusChain[] = {
|
||||
NetworkUtils::tetheringStatus,
|
||||
NetworkUtils::defaultAsyncSuccessHandler
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to get the mask from given prefix length.
|
||||
*/
|
||||
@ -722,6 +739,36 @@ void NetworkUtils::setAlarm(CommandChain* aChain,
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::removeAlarm(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
PR_snprintf(command, MAX_COMMAND_SIZE - 1, "bandwidth removeinterfacealert %s", GET_CHAR(mIfname));
|
||||
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::setGlobalAlarm(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
|
||||
PR_snprintf(command, MAX_COMMAND_SIZE - 1, "bandwidth setglobalalert %ld", GET_FIELD(mThreshold));
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::removeGlobalAlarm(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
|
||||
PR_snprintf(command, MAX_COMMAND_SIZE - 1, "bandwidth removeglobalalert");
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::setInterfaceUp(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
@ -1611,6 +1658,9 @@ void NetworkUtils::ExecuteCommand(NetworkParams aOptions)
|
||||
BUILD_ENTRY(setNetworkInterfaceAlarm),
|
||||
BUILD_ENTRY(enableNetworkInterfaceAlarm),
|
||||
BUILD_ENTRY(disableNetworkInterfaceAlarm),
|
||||
BUILD_ENTRY(setTetheringAlarm),
|
||||
BUILD_ENTRY(removeTetheringAlarm),
|
||||
BUILD_ENTRY(getTetheringStatus),
|
||||
BUILD_ENTRY(setWifiOperationMode),
|
||||
BUILD_ENTRY(setDhcpServer),
|
||||
BUILD_ENTRY(setWifiTethering),
|
||||
@ -2357,6 +2407,27 @@ CommandResult NetworkUtils::disableNetworkInterfaceAlarm(NetworkParams& aOptions
|
||||
return CommandResult::Pending();
|
||||
}
|
||||
|
||||
CommandResult NetworkUtils::setTetheringAlarm(NetworkParams& aOptions)
|
||||
{
|
||||
NU_DBG("setTetheringAlarm");
|
||||
runChain(aOptions, sTetheringInterfaceSetAlarmChain, networkInterfaceAlarmFail);
|
||||
return CommandResult::Pending();
|
||||
}
|
||||
|
||||
CommandResult NetworkUtils::removeTetheringAlarm(NetworkParams& aOptions)
|
||||
{
|
||||
NU_DBG("removeTetheringAlarm");
|
||||
runChain(aOptions, sTetheringInterfaceRemoveAlarmChain, networkInterfaceAlarmFail);
|
||||
return CommandResult::Pending();
|
||||
}
|
||||
|
||||
CommandResult NetworkUtils::getTetheringStatus(NetworkParams& aOptions)
|
||||
{
|
||||
NU_DBG("getTetheringStatus");
|
||||
runChain(aOptions, sTetheringGetStatusChain, networkInterfaceAlarmFail);
|
||||
return CommandResult::Pending();
|
||||
}
|
||||
|
||||
/**
|
||||
* handling main thread's reload Wifi firmware request
|
||||
*/
|
||||
|
@ -302,6 +302,9 @@ private:
|
||||
CommandResult setNetworkInterfaceAlarm(NetworkParams& aOptions);
|
||||
CommandResult enableNetworkInterfaceAlarm(NetworkParams& aOptions);
|
||||
CommandResult disableNetworkInterfaceAlarm(NetworkParams& aOptions);
|
||||
CommandResult setTetheringAlarm(NetworkParams& aOptions);
|
||||
CommandResult removeTetheringAlarm(NetworkParams& aOptions);
|
||||
CommandResult getTetheringStatus(NetworkParams& aOptions);
|
||||
CommandResult setWifiOperationMode(NetworkParams& aOptions);
|
||||
CommandResult setDhcpServer(NetworkParams& aOptions);
|
||||
CommandResult setWifiTethering(NetworkParams& aOptions);
|
||||
@ -337,7 +340,9 @@ private:
|
||||
static const CommandFunc sNetworkInterfaceEnableAlarmChain[];
|
||||
static const CommandFunc sNetworkInterfaceDisableAlarmChain[];
|
||||
static const CommandFunc sNetworkInterfaceSetAlarmChain[];
|
||||
|
||||
static const CommandFunc sTetheringInterfaceSetAlarmChain[];
|
||||
static const CommandFunc sTetheringInterfaceRemoveAlarmChain[];
|
||||
static const CommandFunc sTetheringGetStatusChain[];
|
||||
/**
|
||||
* Individual netd command stored in command chain.
|
||||
*/
|
||||
@ -357,6 +362,9 @@ private:
|
||||
static void setQuota(PARAMS);
|
||||
static void removeQuota(PARAMS);
|
||||
static void setAlarm(PARAMS);
|
||||
static void removeAlarm(PARAMS);
|
||||
static void setGlobalAlarm(PARAMS);
|
||||
static void removeGlobalAlarm(PARAMS);
|
||||
static void setInterfaceUp(PARAMS);
|
||||
static void tetherInterface(PARAMS);
|
||||
static void addInterfaceToLocalNetwork(PARAMS);
|
||||
|
Loading…
x
Reference in New Issue
Block a user