Attempt to make data saver mode work for real.
The data saver refactoring change was incorrect in >= two ways:
1. It relied on the bw_costly_shared chain, which is currently
unused. NetworkManagementService just has a "TODO: support
quota shared across interfaces" comment about it. What
actually happens when setting quota is that each costly
interface chain (e.g., bw_costly_rmnet_data0) directly hooks
in the bw_penalty box chain.
2. Implementing app whitelisting using "RETURN" inside
bw_happy_box was pointless because if data saver was enabled,
there was a REJECT at the end of the bw_costly_shared chain
that it was returning to.
Instead, go back to the previous approach which hooked
bw_happy_box at the end of bw_penalty_box. Also, add an
additional bw_data_saver rule at the end of bw_happy_box.
bw_data_saver only contains one rule: RETURN if data saver is
enabled or REJECT if data saver is disabled.
That way:
1. If the app is blacklisted, bw_penalty_box REJECTs. If not:
2. If the app is whitelisted (system apps are always whitelisted)
bw_happy_box RETURNs to bw_costly_rmnet_data0, skipping
bw_data_saver.
3. If an app is neither blacklisted nor whitelisted, bw_happy_box
jumps to bw_data_saver. If data saver is enabled, it REJECTs
the packet, and if not, it RETURNs to bw_costly_rmnet_data0.
4. When we RETURN to bw_costly_rmnet_data0, either because the
app is whitelisted, or because data saver is off,
bw_costly_rmnet_data0 applies mobile data usage limits,
and then RETURNs to bw_OUTPUT, which calls xt_qtaguid, etc.
Bug: 26685616
Bug: 27506285
Change-Id: If15397afde6862d95827a1fdd30f60efd7fab66a
diff --git a/server/BandwidthControllerTest.cpp b/server/BandwidthControllerTest.cpp
index 4a59883..8251830 100644
--- a/server/BandwidthControllerTest.cpp
+++ b/server/BandwidthControllerTest.cpp
@@ -26,7 +26,7 @@
std::vector<std::string> gCmds = {};
-extern "C" int fake_android_fork_exec(int argc, char* argv[], int *status, bool, bool) {
+int fake_android_fork_exec(int argc, char* argv[], int *status, bool, bool) {
std::string cmd = argv[0];
for (int i = 1; i < argc; i++) {
cmd += " ";
@@ -72,6 +72,7 @@
"-F bw_FORWARD",
"-F bw_happy_box",
"-F bw_penalty_box",
+ "-F bw_data_saver",
"-F bw_costly_shared",
"-t raw -F bw_raw_PREROUTING",
"-t mangle -F bw_mangle_POSTROUTING",
@@ -80,9 +81,10 @@
"-t raw -A bw_raw_PREROUTING -m owner --socket-exists",
"-t mangle -A bw_mangle_POSTROUTING -m owner --socket-exists",
"-A bw_costly_shared --jump bw_penalty_box",
- "-A bw_costly_shared --jump bw_happy_box",
- "-A bw_costly_shared --jump RETURN",
- "-A bw_happy_box -m owner --uid-owner 0-9999 --jump RETURN",
+ "-A bw_penalty_box --jump bw_happy_box",
+ "-A bw_happy_box --jump bw_data_saver",
+ "-A bw_data_saver -j RETURN",
+ "-I bw_happy_box -m owner --uid-owner 0-9999 --jump RETURN",
};
expectIptablesCommands(expected);
}
@@ -90,13 +92,13 @@
TEST_F(BandwidthControllerTest, TestEnableDataSaver) {
mBw.enableDataSaver(true);
std::vector<std::string> expected = {
- "-R bw_costly_shared 3 --jump REJECT",
+ "-R bw_data_saver 1 --jump REJECT",
};
expectIptablesCommands(expected);
mBw.enableDataSaver(false);
expected = {
- "-R bw_costly_shared 3 --jump RETURN",
+ "-R bw_data_saver 1 --jump RETURN",
};
expectIptablesCommands(expected);
}