return res;
}
-int BandwidthController::enableHappyBox(void) {
- char cmd[MAX_CMD_LEN];
- int res = 0;
-
- /*
- * We tentatively delete before adding, which helps recovering
- * from bad states (e.g. netd died).
- */
-
- /* Should not exist, but ignore result if already there. */
- snprintf(cmd, sizeof(cmd), "-N bw_happy_box");
- runIpxtablesCmd(cmd, IptJumpNoAdd);
-
- /* Should be empty, but clear in case something was wrong. */
- snprintf(cmd, sizeof(cmd), "-F bw_happy_box");
- res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
-
- snprintf(cmd, sizeof(cmd), "-D bw_penalty_box -j bw_happy_box");
- runIpxtablesCmd(cmd, IptJumpNoAdd);
- snprintf(cmd, sizeof(cmd), "-A bw_penalty_box -j bw_happy_box");
- res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
-
- /* Whitelist all system apps. */
- snprintf(cmd, sizeof(cmd),
- "-A bw_happy_box -m owner --uid-owner %d-%d -j RETURN", 0, MAX_SYSTEM_UID);
- res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
-
- /* Reject. Defaulting to prot-unreachable */
- snprintf(cmd, sizeof(cmd), "-A bw_happy_box -j REJECT");
- res |= runIpxtablesCmd(cmd, IptJumpNoAdd);
-
- return res;
-}
-
-int BandwidthController::disableHappyBox(void) {
- char cmd[MAX_CMD_LEN];
-
- /* Best effort */
- snprintf(cmd, sizeof(cmd), "-D bw_penalty_box -j bw_happy_box");
- runIpxtablesCmd(cmd, IptJumpNoAdd);
- snprintf(cmd, sizeof(cmd), "-F bw_happy_box");
- runIpxtablesCmd(cmd, IptJumpNoAdd);
- snprintf(cmd, sizeof(cmd), "-X bw_happy_box");
- runIpxtablesCmd(cmd, IptJumpNoAdd);
-
- return 0;
-}
-
int BandwidthController::addNaughtyApps(int numUids, char *appUids[]) {
return manipulateNaughtyApps(numUids, appUids, SpecialAppOpAdd);
}
int getInterfaceQuota(const char *iface, int64_t *bytes);
int removeInterfaceQuota(const char *iface);
- int enableHappyBox(void);
- int disableHappyBox(void);
int addNaughtyApps(int numUids, char *appUids[]);
int removeNaughtyApps(int numUids, char *appUids[]);
int addNiceApps(int numUids, char *appUids[]);
sendGenericOkFail(cli, rc);
return 0;
}
- if (!strcmp(argv[1], "happybox")) {
- if (argc < 3) {
- sendGenericSyntaxError(cli, "happybox (enable | disable)");
- return 0;
- }
- if (!strcmp(argv[2], "enable")) {
- int rc = gCtls->bandwidthCtrl.enableHappyBox();
- sendGenericOkFail(cli, rc);
- return 0;
-
- }
- if (!strcmp(argv[2], "disable")) {
- int rc = gCtls->bandwidthCtrl.disableHappyBox();
- sendGenericOkFail(cli, rc);
- return 0;
- }
- sendGenericSyntaxError(cli, "happybox (enable | disable)");
- return 0;
- }
if (!strcmp(argv[1], "addniceapps") || !strcmp(argv[1], "aha")) {
if (argc < 3) {
sendGenericSyntaxError(cli, "addniceapps <appUid> ...");