Remove network access for idle apps
Track apps going in and out of idle in the NetworkPolicyManagerService. Apply DROP rules in firewall controller if app is to be blacklisted for network access. Firewall can now be in whitelist (old) or blacklist mode. When in blacklist, it allows all by default and we can selectively DENY some uids. Track app idle in UsageStats and update periodically. Track charging/discharging states. TODO: Check for appidle temporary parole state Bug: 20066058 Change-Id: Ia65d7544204b3bcb78a517310ef4adcc05aac6fb
This commit is contained in:
@@ -24,6 +24,7 @@ import static android.net.ConnectivityManager.TYPE_VPN;
|
|||||||
import static android.net.ConnectivityManager.getNetworkTypeName;
|
import static android.net.ConnectivityManager.getNetworkTypeName;
|
||||||
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
||||||
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
|
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
|
||||||
|
import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
|
||||||
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -832,7 +833,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
|
uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (networkCostly && (uidRules & RULE_REJECT_METERED) != 0) {
|
if ((uidRules & RULE_REJECT_ALL) != 0
|
||||||
|
|| (networkCostly && (uidRules & RULE_REJECT_METERED) != 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3490,7 +3492,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
synchronized(mRulesLock) {
|
synchronized(mRulesLock) {
|
||||||
uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
|
uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
|
||||||
}
|
}
|
||||||
if ((uidRules & RULE_REJECT_METERED) != 0) {
|
if ((uidRules & (RULE_REJECT_METERED | RULE_REJECT_ALL)) != 0) {
|
||||||
// we could silently fail or we can filter the available nets to only give
|
// we could silently fail or we can filter the available nets to only give
|
||||||
// them those they have access to. Chose the more useful
|
// them those they have access to. Chose the more useful
|
||||||
networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
networkCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||||
|
|||||||
Reference in New Issue
Block a user