diff options
author | Sudheer Shanka <sudheersai@google.com> | 2020-07-17 01:50:22 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-17 01:50:22 +0000 |
commit | 4f0be2c657b51e5b4d7f679f07269fad3ae6fa2f (patch) | |
tree | 1b9eaf74e91de8357ec3589d2dcd7c4a04132d76 | |
parent | e56069ae786ca8008894309197f5a16826491348 (diff) | |
parent | e103d5f04cd63e0f2eca881dcfa67776d0ebf783 (diff) |
Merge "Evaluate and sync firewall rules when parole state changes." into rvc-dev am: 311f3508f7 am: e103d5f04c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12162118
Change-Id: Ia05344b618d7e55247d14d74d79e119cd246ec4a
-rw-r--r-- | services/core/java/com/android/server/net/NetworkPolicyManagerService.java | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java index 87f0fb14ee33..ea047888caff 100644 --- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java @@ -3910,11 +3910,14 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private void updateRulesForAppIdleParoleUL() { final boolean paroled = mAppStandby.isInParole(); final boolean enableChain = !paroled; - enableFirewallChainUL(FIREWALL_CHAIN_STANDBY, enableChain); int ruleCount = mUidFirewallStandbyRules.size(); + final SparseIntArray blockedUids = new SparseIntArray(); for (int i = 0; i < ruleCount; i++) { final int uid = mUidFirewallStandbyRules.keyAt(i); + if (!isUidValidForBlacklistRulesUL(uid)) { + continue; + } int oldRules = mUidRules.get(uid); if (enableChain) { // Chain wasn't enabled before and the other power-related @@ -3926,13 +3929,24 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { // Skip if it had no restrictions to begin with if ((oldRules & MASK_ALL_NETWORKS) == 0) continue; } - final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldRules, paroled); + final boolean isUidIdle = !paroled && isUidIdle(uid); + if (isUidIdle && !mPowerSaveTempWhitelistAppIds.get(UserHandle.getAppId(uid)) + && !isUidForegroundOnRestrictPowerUL(uid)) { + mUidFirewallStandbyRules.put(uid, FIREWALL_RULE_DENY); + blockedUids.put(uid, FIREWALL_RULE_DENY); + } else { + mUidFirewallStandbyRules.put(uid, FIREWALL_RULE_DEFAULT); + } + final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldRules, + isUidIdle); if (newUidRules == RULE_NONE) { mUidRules.delete(uid); } else { mUidRules.put(uid, newUidRules); } } + setUidFirewallRulesUL(FIREWALL_CHAIN_STANDBY, blockedUids, + enableChain ? CHAIN_TOGGLE_ENABLE : CHAIN_TOGGLE_DISABLE); } /** @@ -4400,7 +4414,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { private void updateRulesForPowerRestrictionsUL(int uid) { final int oldUidRules = mUidRules.get(uid, RULE_NONE); - final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldUidRules, false); + final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldUidRules, + isUidIdle(uid)); if (newUidRules == RULE_NONE) { mUidRules.delete(uid); @@ -4414,33 +4429,33 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { * * @param uid the uid of the app to update rules for * @param oldUidRules the current rules for the uid, in order to determine if there's a change - * @param paroled whether to ignore idle state of apps and only look at other restrictions + * @param isUidIdle whether uid is idle or not * * @return the new computed rules for the uid */ @GuardedBy("mUidRulesFirstLock") - private int updateRulesForPowerRestrictionsUL(int uid, int oldUidRules, boolean paroled) { + private int updateRulesForPowerRestrictionsUL(int uid, int oldUidRules, boolean isUidIdle) { if (Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK)) { Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "updateRulesForPowerRestrictionsUL: " + uid + "/" + oldUidRules + "/" - + (paroled ? "P" : "-")); + + (isUidIdle ? "I" : "-")); } try { - return updateRulesForPowerRestrictionsULInner(uid, oldUidRules, paroled); + return updateRulesForPowerRestrictionsULInner(uid, oldUidRules, isUidIdle); } finally { Trace.traceEnd(Trace.TRACE_TAG_NETWORK); } } @GuardedBy("mUidRulesFirstLock") - private int updateRulesForPowerRestrictionsULInner(int uid, int oldUidRules, boolean paroled) { + private int updateRulesForPowerRestrictionsULInner(int uid, int oldUidRules, + boolean isUidIdle) { if (!isUidValidForBlacklistRulesUL(uid)) { if (LOGD) Slog.d(TAG, "no need to update restrict power rules for uid " + uid); return RULE_NONE; } - final boolean isIdle = !paroled && isUidIdle(uid); - final boolean restrictMode = isIdle || mRestrictPower || mDeviceIdleMode; + final boolean restrictMode = isUidIdle || mRestrictPower || mDeviceIdleMode; final boolean isForeground = isUidForegroundOnRestrictPowerUL(uid); final boolean isWhitelisted = isWhitelistedFromPowerSaveUL(uid, mDeviceIdleMode); @@ -4463,7 +4478,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { if (LOGV) { Log.v(TAG, "updateRulesForPowerRestrictionsUL(" + uid + ")" - + ", isIdle: " + isIdle + + ", isIdle: " + isUidIdle + ", mRestrictPower: " + mRestrictPower + ", mDeviceIdleMode: " + mDeviceIdleMode + ", isForeground=" + isForeground |