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/tests/binder_test.cpp b/tests/binder_test.cpp
index ae743a9..defe875 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -155,24 +155,20 @@
}
static int bandwidthDataSaverEnabled(const char *binary) {
- std::vector<std::string> lines = listIptablesRule(binary, "bw_costly_shared");
+ std::vector<std::string> lines = listIptablesRule(binary, "bw_data_saver");
// Output looks like this:
//
- // Chain bw_costly_shared (0 references)
+ // Chain bw_data_saver (1 references)
// target prot opt source destination
- // bw_penalty_box all -- 0.0.0.0/0 0.0.0.0/0
- // bw_happy_box all -- 0.0.0.0/0 0.0.0.0/0
// RETURN all -- 0.0.0.0/0 0.0.0.0/0
- EXPECT_EQ(5U, lines.size());
- if (lines.size() != 5) return -1;
+ EXPECT_EQ(3U, lines.size());
+ if (lines.size() != 3) return -1;
- EXPECT_TRUE(android::base::StartsWith(lines[2], "bw_penalty_box "));
- EXPECT_TRUE(android::base::StartsWith(lines[3], "bw_happy_box "));
- EXPECT_TRUE(android::base::StartsWith(lines[4], "RETURN ") ||
- android::base::StartsWith(lines[4], "REJECT "));
+ EXPECT_TRUE(android::base::StartsWith(lines[2], "RETURN ") ||
+ android::base::StartsWith(lines[2], "REJECT "));
- return android::base::StartsWith(lines[4], "REJECT");
+ return android::base::StartsWith(lines[2], "REJECT");
}
bool enableDataSaver(sp<INetd>& netd, bool enable) {