Merge "Update usage of allowlist/denylist in some method names/comments." am: 771aa062b9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1402789 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I0d6e7220d742e38bd153916a95e43d5de0da830e
This commit is contained in:
@@ -282,8 +282,8 @@ interface INetworkManagementService
|
||||
/**
|
||||
* Control network activity of a UID over interfaces with a quota limit.
|
||||
*/
|
||||
void setUidMeteredNetworkDenylist(int uid, boolean enable);
|
||||
void setUidMeteredNetworkAllowlist(int uid, boolean enable);
|
||||
void setUidOnMeteredNetworkDenylist(int uid, boolean enable);
|
||||
void setUidOnMeteredNetworkAllowlist(int uid, boolean enable);
|
||||
boolean setDataSaverModeEnabled(boolean enable);
|
||||
|
||||
void setUidCleartextNetworkPolicy(int uid, int policy);
|
||||
|
||||
@@ -187,10 +187,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
/** Set of interfaces with active alerts. */
|
||||
@GuardedBy("mQuotaLock")
|
||||
private HashMap<String, Long> mActiveAlerts = Maps.newHashMap();
|
||||
/** Set of UIDs denylisted on metered networks. */
|
||||
/** Set of UIDs denied on metered networks. */
|
||||
@GuardedBy("mRulesLock")
|
||||
private SparseBooleanArray mUidRejectOnMetered = new SparseBooleanArray();
|
||||
/** Set of UIDs allowlisted on metered networks. */
|
||||
/** Set of UIDs allowed on metered networks. */
|
||||
@GuardedBy("mRulesLock")
|
||||
private SparseBooleanArray mUidAllowOnMetered = new SparseBooleanArray();
|
||||
/** Set of UIDs with cleartext penalties. */
|
||||
@@ -561,13 +561,13 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
}
|
||||
if (uidRejectOnQuota != null) {
|
||||
for (int i = 0; i < uidRejectOnQuota.size(); i++) {
|
||||
setUidMeteredNetworkDenylist(uidRejectOnQuota.keyAt(i),
|
||||
setUidOnMeteredNetworkDenylist(uidRejectOnQuota.keyAt(i),
|
||||
uidRejectOnQuota.valueAt(i));
|
||||
}
|
||||
}
|
||||
if (uidAcceptOnQuota != null) {
|
||||
for (int i = 0; i < uidAcceptOnQuota.size(); i++) {
|
||||
setUidMeteredNetworkAllowlist(uidAcceptOnQuota.keyAt(i),
|
||||
setUidOnMeteredNetworkAllowlist(uidAcceptOnQuota.keyAt(i),
|
||||
uidAcceptOnQuota.valueAt(i));
|
||||
}
|
||||
}
|
||||
@@ -1288,14 +1288,14 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private void setUidOnMeteredNetworkList(int uid, boolean denylist, boolean enable) {
|
||||
private void setUidOnMeteredNetworkList(int uid, boolean allowlist, boolean enable) {
|
||||
NetworkStack.checkNetworkStackPermission(mContext);
|
||||
|
||||
synchronized (mQuotaLock) {
|
||||
boolean oldEnable;
|
||||
SparseBooleanArray quotaList;
|
||||
synchronized (mRulesLock) {
|
||||
quotaList = denylist ? mUidRejectOnMetered : mUidAllowOnMetered;
|
||||
quotaList = allowlist ? mUidAllowOnMetered : mUidRejectOnMetered;
|
||||
oldEnable = quotaList.get(uid, false);
|
||||
}
|
||||
if (oldEnable == enable) {
|
||||
@@ -1305,18 +1305,18 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
|
||||
Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "inetd bandwidth");
|
||||
try {
|
||||
if (denylist) {
|
||||
if (enable) {
|
||||
mNetdService.bandwidthAddNaughtyApp(uid);
|
||||
} else {
|
||||
mNetdService.bandwidthRemoveNaughtyApp(uid);
|
||||
}
|
||||
} else {
|
||||
if (allowlist) {
|
||||
if (enable) {
|
||||
mNetdService.bandwidthAddNiceApp(uid);
|
||||
} else {
|
||||
mNetdService.bandwidthRemoveNiceApp(uid);
|
||||
}
|
||||
} else {
|
||||
if (enable) {
|
||||
mNetdService.bandwidthAddNaughtyApp(uid);
|
||||
} else {
|
||||
mNetdService.bandwidthRemoveNaughtyApp(uid);
|
||||
}
|
||||
}
|
||||
synchronized (mRulesLock) {
|
||||
if (enable) {
|
||||
@@ -1334,13 +1334,13 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUidMeteredNetworkDenylist(int uid, boolean enable) {
|
||||
setUidOnMeteredNetworkList(uid, true, enable);
|
||||
public void setUidOnMeteredNetworkDenylist(int uid, boolean enable) {
|
||||
setUidOnMeteredNetworkList(uid, false, enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUidMeteredNetworkAllowlist(int uid, boolean enable) {
|
||||
setUidOnMeteredNetworkList(uid, false, enable);
|
||||
public void setUidOnMeteredNetworkAllowlist(int uid, boolean enable) {
|
||||
setUidOnMeteredNetworkList(uid, true, enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1763,7 +1763,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
} else {
|
||||
ruleName = "deny";
|
||||
}
|
||||
} else { // Denylist mode
|
||||
} else { // Deny mode
|
||||
if (rule == FIREWALL_RULE_DENY) {
|
||||
ruleName = "deny";
|
||||
} else {
|
||||
@@ -1850,8 +1850,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
pw.print("Active alert ifaces: "); pw.println(mActiveAlerts.toString());
|
||||
pw.print("Data saver mode: "); pw.println(mDataSaverMode);
|
||||
synchronized (mRulesLock) {
|
||||
dumpUidRuleOnQuotaLocked(pw, "denylist", mUidRejectOnMetered);
|
||||
dumpUidRuleOnQuotaLocked(pw, "allowlist", mUidAllowOnMetered);
|
||||
dumpUidRuleOnQuotaLocked(pw, "denied UIDs", mUidRejectOnMetered);
|
||||
dumpUidRuleOnQuotaLocked(pw, "allowed UIDs", mUidAllowOnMetered);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1904,7 +1904,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
private void dumpUidRuleOnQuotaLocked(PrintWriter pw, String name, SparseBooleanArray list) {
|
||||
pw.print("UID bandwith control ");
|
||||
pw.print(name);
|
||||
pw.print(" rule: [");
|
||||
pw.print(": [");
|
||||
final int size = list.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
pw.print(list.keyAt(i));
|
||||
|
||||
@@ -686,7 +686,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
* Allows pre-defined apps for restrict background, but only if the user didn't already
|
||||
* revoked them.
|
||||
*
|
||||
* @return whether any uid has been allowlisted.
|
||||
* @return whether any uid has been added to allowlist.
|
||||
*/
|
||||
@GuardedBy("mUidRulesFirstLock")
|
||||
boolean addDefaultRestrictBackgroundAllowlistUidsUL() {
|
||||
@@ -710,7 +710,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
for (int i = 0; i < allowDataUsage.size(); i++) {
|
||||
final String pkg = allowDataUsage.valueAt(i);
|
||||
if (LOGD)
|
||||
Slog.d(TAG, "checking restricted background allowlisting for package " + pkg
|
||||
Slog.d(TAG, "checking restricted background exemption for package " + pkg
|
||||
+ " and user " + userId);
|
||||
final ApplicationInfo app;
|
||||
try {
|
||||
@@ -1027,7 +1027,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
// user resets app preferences.
|
||||
mMeteredRestrictedUids.remove(userId);
|
||||
if (action == ACTION_USER_ADDED) {
|
||||
// Add apps that are allowlisted by default.
|
||||
// Add apps that are allowed by default.
|
||||
addDefaultRestrictBackgroundAllowlistUidsUL(userId);
|
||||
}
|
||||
// Update global restrict for that user
|
||||
@@ -2233,8 +2233,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
in.setInput(fis, StandardCharsets.UTF_8.name());
|
||||
|
||||
// Must save the <restrict-background> tags and convert them to <uid-policy> later,
|
||||
// to skip UIDs that were explicitly denylisted.
|
||||
final SparseBooleanArray allowlistedRestrictBackground = new SparseBooleanArray();
|
||||
// to skip UIDs that were explicitly denied.
|
||||
final SparseBooleanArray restrictBackgroundAllowedUids = new SparseBooleanArray();
|
||||
|
||||
int type;
|
||||
int version = VERSION_INIT;
|
||||
@@ -2392,7 +2392,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
insideAllowlist = true;
|
||||
} else if (TAG_RESTRICT_BACKGROUND.equals(tag) && insideAllowlist) {
|
||||
final int uid = readIntAttribute(in, ATTR_UID);
|
||||
allowlistedRestrictBackground.append(uid, true);
|
||||
restrictBackgroundAllowedUids.append(uid, true);
|
||||
} else if (TAG_REVOKED_RESTRICT_BACKGROUND.equals(tag) && insideAllowlist) {
|
||||
final int uid = readIntAttribute(in, ATTR_UID);
|
||||
mRestrictBackgroundAllowlistRevokedUids.put(uid, true);
|
||||
@@ -2405,9 +2405,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
final int size = allowlistedRestrictBackground.size();
|
||||
final int size = restrictBackgroundAllowedUids.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final int uid = allowlistedRestrictBackground.keyAt(i);
|
||||
final int uid = restrictBackgroundAllowedUids.keyAt(i);
|
||||
final int policy = mUidPolicy.get(uid, POLICY_NONE);
|
||||
if ((policy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
|
||||
Slog.w(TAG, "ignoring restrict-background-allowlist for " + uid
|
||||
@@ -2674,13 +2674,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
if (!isUidValidForAllowlistRulesUL(uid)) {
|
||||
notifyApp = false;
|
||||
} else {
|
||||
final boolean wasDenylisted = oldPolicy == POLICY_REJECT_METERED_BACKGROUND;
|
||||
final boolean isDenylisted = policy == POLICY_REJECT_METERED_BACKGROUND;
|
||||
final boolean wasAllowlisted = oldPolicy == POLICY_ALLOW_METERED_BACKGROUND;
|
||||
final boolean isAllowlisted = policy == POLICY_ALLOW_METERED_BACKGROUND;
|
||||
final boolean wasBlocked = wasDenylisted || (mRestrictBackground && !wasAllowlisted);
|
||||
final boolean isBlocked = isDenylisted || (mRestrictBackground && !isAllowlisted);
|
||||
if ((wasAllowlisted && (!isAllowlisted || isDenylisted))
|
||||
final boolean wasDenied = oldPolicy == POLICY_REJECT_METERED_BACKGROUND;
|
||||
final boolean isDenied = policy == POLICY_REJECT_METERED_BACKGROUND;
|
||||
final boolean wasAllowed = oldPolicy == POLICY_ALLOW_METERED_BACKGROUND;
|
||||
final boolean isAllowed = policy == POLICY_ALLOW_METERED_BACKGROUND;
|
||||
final boolean wasBlocked = wasDenied || (mRestrictBackground && !wasAllowed);
|
||||
final boolean isBlocked = isDenied || (mRestrictBackground && !isAllowed);
|
||||
if ((wasAllowed && (!isAllowed || isDenied))
|
||||
&& mDefaultRestrictBackgroundAllowlistUids.get(uid)
|
||||
&& !mRestrictBackgroundAllowlistRevokedUids.get(uid)) {
|
||||
if (LOGD)
|
||||
@@ -2965,7 +2965,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
Slog.d(TAG, "setRestrictBackgroundUL(): " + restrictBackground + "; reason: " + reason);
|
||||
final boolean oldRestrictBackground = mRestrictBackground;
|
||||
mRestrictBackground = restrictBackground;
|
||||
// Must allowlist foreground apps before turning data saver mode on.
|
||||
// Must allow foreground apps before turning data saver mode on.
|
||||
// TODO: there is no need to iterate through all apps here, just those in the foreground,
|
||||
// so it could call AM to get the UIDs of such apps, and iterate through them instead.
|
||||
updateRulesForRestrictBackgroundUL();
|
||||
@@ -3018,7 +3018,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
Binder.restoreCallingIdentity(token);
|
||||
}
|
||||
if (policy == POLICY_REJECT_METERED_BACKGROUND) {
|
||||
// App is denylisted.
|
||||
// App is restricted.
|
||||
return RESTRICT_BACKGROUND_STATUS_ENABLED;
|
||||
}
|
||||
if (!mRestrictBackground) {
|
||||
@@ -4310,9 +4310,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
* <ul>
|
||||
* <li>@{code bw_penalty_box}: UIDs added to this chain do not have access (denylist).
|
||||
* <li>@{code bw_happy_box}: UIDs added to this chain have access (allowlist), unless they're
|
||||
* also denylisted.
|
||||
* also in denylist.
|
||||
* <li>@{code bw_data_saver}: when enabled (through {@link #setRestrictBackground(boolean)}),
|
||||
* no UIDs other than those allowlisted will have access.
|
||||
* no UIDs other than those in allowlist will have access.
|
||||
* <ul>
|
||||
*
|
||||
* <p>The @{code bw_penalty_box} and @{code bw_happy_box} are primarily managed through the
|
||||
@@ -4327,7 +4327,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
* <ul>
|
||||
* <li>When Data Saver mode is on, the foreground app should be temporarily added to
|
||||
* {@code bw_happy_box} before the @{code bw_data_saver} chain is enabled.
|
||||
* <li>If the foreground app is denylisted by the user, it should be temporarily removed from
|
||||
* <li>If the foreground app was restricted by the user (i.e. has the policy
|
||||
* {@code POLICY_REJECT_METERED_BACKGROUND}), it should be temporarily removed from
|
||||
* {@code bw_penalty_box}.
|
||||
* <li>When the app leaves foreground state, the temporary changes above should be reverted.
|
||||
* </ul>
|
||||
@@ -4362,8 +4363,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
final boolean isForeground = isUidForegroundOnRestrictBackgroundUL(uid);
|
||||
final boolean isRestrictedByAdmin = isRestrictedByAdminUL(uid);
|
||||
|
||||
final boolean isDenylisted = (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0;
|
||||
final boolean isAllowlisted = (uidPolicy & POLICY_ALLOW_METERED_BACKGROUND) != 0;
|
||||
final boolean isDenied = (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0;
|
||||
final boolean isAllowed = (uidPolicy & POLICY_ALLOW_METERED_BACKGROUND) != 0;
|
||||
final int oldRule = oldUidRules & MASK_METERED_NETWORKS;
|
||||
int newRule = RULE_NONE;
|
||||
|
||||
@@ -4371,15 +4372,15 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
if (isRestrictedByAdmin) {
|
||||
newRule = RULE_REJECT_METERED;
|
||||
} else if (isForeground) {
|
||||
if (isDenylisted || (mRestrictBackground && !isAllowlisted)) {
|
||||
if (isDenied || (mRestrictBackground && !isAllowed)) {
|
||||
newRule = RULE_TEMPORARY_ALLOW_METERED;
|
||||
} else if (isAllowlisted) {
|
||||
} else if (isAllowed) {
|
||||
newRule = RULE_ALLOW_METERED;
|
||||
}
|
||||
} else {
|
||||
if (isDenylisted) {
|
||||
if (isDenied) {
|
||||
newRule = RULE_REJECT_METERED;
|
||||
} else if (mRestrictBackground && isAllowlisted) {
|
||||
} else if (mRestrictBackground && isAllowed) {
|
||||
newRule = RULE_ALLOW_METERED;
|
||||
}
|
||||
}
|
||||
@@ -4388,8 +4389,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
if (LOGV) {
|
||||
Log.v(TAG, "updateRuleForRestrictBackgroundUL(" + uid + ")"
|
||||
+ ": isForeground=" +isForeground
|
||||
+ ", isDenylisted=" + isDenylisted
|
||||
+ ", isAllowlisted=" + isAllowlisted
|
||||
+ ", isDenied=" + isDenied
|
||||
+ ", isAllowed=" + isAllowed
|
||||
+ ", isRestrictedByAdmin=" + isRestrictedByAdmin
|
||||
+ ", oldRule=" + uidRulesToString(oldRule)
|
||||
+ ", newRule=" + uidRulesToString(newRule)
|
||||
@@ -4406,49 +4407,49 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
// Second step: apply bw changes based on change of state.
|
||||
if (newRule != oldRule) {
|
||||
if (hasRule(newRule, RULE_TEMPORARY_ALLOW_METERED)) {
|
||||
// Temporarily allowlist foreground app, removing from denylist if necessary
|
||||
// Temporarily allow foreground app, removing from denylist if necessary
|
||||
// (since bw_penalty_box prevails over bw_happy_box).
|
||||
|
||||
setMeteredNetworkAllowlist(uid, true);
|
||||
// TODO: if statement below is used to avoid an unnecessary call to netd / iptables,
|
||||
// but ideally it should be just:
|
||||
// setMeteredNetworkDenylist(uid, isDenylisted);
|
||||
if (isDenylisted) {
|
||||
// setMeteredNetworkDenylist(uid, isDenied);
|
||||
if (isDenied) {
|
||||
setMeteredNetworkDenylist(uid, false);
|
||||
}
|
||||
} else if (hasRule(oldRule, RULE_TEMPORARY_ALLOW_METERED)) {
|
||||
// Remove temporary allowlist from app that is not on foreground anymore.
|
||||
// Remove temporary exemption from app that is not on foreground anymore.
|
||||
|
||||
// TODO: if statements below are used to avoid unnecessary calls to netd / iptables,
|
||||
// but ideally they should be just:
|
||||
// setMeteredNetworkAllowlist(uid, isAllowlisted);
|
||||
// setMeteredNetworkDenylist(uid, isDenylisted);
|
||||
if (!isAllowlisted) {
|
||||
// setMeteredNetworkAllowlist(uid, isAllowed);
|
||||
// setMeteredNetworkDenylist(uid, isDenied);
|
||||
if (!isAllowed) {
|
||||
setMeteredNetworkAllowlist(uid, false);
|
||||
}
|
||||
if (isDenylisted || isRestrictedByAdmin) {
|
||||
if (isDenied || isRestrictedByAdmin) {
|
||||
setMeteredNetworkDenylist(uid, true);
|
||||
}
|
||||
} else if (hasRule(newRule, RULE_REJECT_METERED)
|
||||
|| hasRule(oldRule, RULE_REJECT_METERED)) {
|
||||
// Flip state because app was explicitly added or removed to denylist.
|
||||
setMeteredNetworkDenylist(uid, (isDenylisted || isRestrictedByAdmin));
|
||||
if (hasRule(oldRule, RULE_REJECT_METERED) && isAllowlisted) {
|
||||
// Since denylist prevails over allowlist, we need to handle the special case
|
||||
// where app is allowlisted and denylisted at the same time (although such
|
||||
// scenario should be blocked by the UI), then denylist is removed.
|
||||
setMeteredNetworkAllowlist(uid, isAllowlisted);
|
||||
setMeteredNetworkDenylist(uid, (isDenied || isRestrictedByAdmin));
|
||||
if (hasRule(oldRule, RULE_REJECT_METERED) && isAllowed) {
|
||||
// Since denial prevails over allowance, we need to handle the special case
|
||||
// where app is allowed and denied at the same time (although such
|
||||
// scenario should be blocked by the UI), then it is removed from the denylist.
|
||||
setMeteredNetworkAllowlist(uid, isAllowed);
|
||||
}
|
||||
} else if (hasRule(newRule, RULE_ALLOW_METERED)
|
||||
|| hasRule(oldRule, RULE_ALLOW_METERED)) {
|
||||
// Flip state because app was explicitly added or removed to allowlist.
|
||||
setMeteredNetworkAllowlist(uid, isAllowlisted);
|
||||
setMeteredNetworkAllowlist(uid, isAllowed);
|
||||
} else {
|
||||
// All scenarios should have been covered above.
|
||||
Log.wtf(TAG, "Unexpected change of metered UID state for " + uid
|
||||
+ ": foreground=" + isForeground
|
||||
+ ", allowlisted=" + isAllowlisted
|
||||
+ ", denylisted=" + isDenylisted
|
||||
+ ", allowlisted=" + isAllowed
|
||||
+ ", denylisted=" + isDenied
|
||||
+ ", isRestrictedByAdmin=" + isRestrictedByAdmin
|
||||
+ ", newRule=" + uidRulesToString(newUidRules)
|
||||
+ ", oldRule=" + uidRulesToString(oldUidRules));
|
||||
@@ -4464,7 +4465,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
* listeners in case of change.
|
||||
* <p>
|
||||
* There are 3 power-related rules that affects whether an app has background access on
|
||||
* non-metered networks, and when the condition applies and the UID is not allowlisted for power
|
||||
* non-metered networks, and when the condition applies and the UID is not allowed for power
|
||||
* restriction, it's added to the equivalent firewall chain:
|
||||
* <ul>
|
||||
* <li>App is idle: {@code fw_standby} firewall chain.
|
||||
@@ -4929,7 +4930,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
private void setMeteredNetworkDenylist(int uid, boolean enable) {
|
||||
if (LOGV) Slog.v(TAG, "setMeteredNetworkDenylist " + uid + ": " + enable);
|
||||
try {
|
||||
mNetworkManager.setUidMeteredNetworkDenylist(uid, enable);
|
||||
mNetworkManager.setUidOnMeteredNetworkDenylist(uid, enable);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.wtf(TAG, "problem setting denylist (" + enable + ") rules for " + uid, e);
|
||||
} catch (RemoteException e) {
|
||||
@@ -4940,7 +4941,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
private void setMeteredNetworkAllowlist(int uid, boolean enable) {
|
||||
if (LOGV) Slog.v(TAG, "setMeteredNetworkAllowlist " + uid + ": " + enable);
|
||||
try {
|
||||
mNetworkManager.setUidMeteredNetworkAllowlist(uid, enable);
|
||||
mNetworkManager.setUidOnMeteredNetworkAllowlist(uid, enable);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.wtf(TAG, "problem setting allowlist (" + enable + ") rules for " + uid, e);
|
||||
} catch (RemoteException e) {
|
||||
@@ -5062,8 +5063,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
mNetworkManager.setFirewallUidRule(FIREWALL_CHAIN_STANDBY, uid, FIREWALL_RULE_DEFAULT);
|
||||
mNetworkManager
|
||||
.setFirewallUidRule(FIREWALL_CHAIN_POWERSAVE, uid, FIREWALL_RULE_DEFAULT);
|
||||
mNetworkManager.setUidMeteredNetworkAllowlist(uid, false);
|
||||
mNetworkManager.setUidMeteredNetworkDenylist(uid, false);
|
||||
mNetworkManager.setUidOnMeteredNetworkAllowlist(uid, false);
|
||||
mNetworkManager.setUidOnMeteredNetworkDenylist(uid, false);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.wtf(TAG, "problem resetting firewall uid rules for " + uid, e);
|
||||
} catch (RemoteException e) {
|
||||
|
||||
@@ -479,7 +479,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds allowlist when restrict background is on - app should receive an intent.
|
||||
* Adds an app to allowlist when restrict background is on - app should receive an intent.
|
||||
*/
|
||||
@Test
|
||||
@NetPolicyXml("restrict-background-on.xml")
|
||||
@@ -490,7 +490,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds allowlist when restrict background is off - app should not receive an intent.
|
||||
* Adds an app to allowlist when restrict background is off - app should not receive an intent.
|
||||
*/
|
||||
@Test
|
||||
public void testAddRestrictBackgroundAllowlist_restrictBackgroundOff() throws Exception {
|
||||
@@ -499,7 +499,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
private void addRestrictBackgroundAllowlist(boolean expectIntent) throws Exception {
|
||||
assertAllowlistUids();
|
||||
assertRestrictBackgroundAllowedUids();
|
||||
assertUidPolicy(UID_A, POLICY_NONE);
|
||||
|
||||
final FutureIntent futureIntent = newRestrictBackgroundChangedFuture();
|
||||
@@ -507,7 +507,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
|
||||
mService.setUidPolicy(UID_A, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
|
||||
assertAllowlistUids(UID_A);
|
||||
assertRestrictBackgroundAllowedUids(UID_A);
|
||||
assertUidPolicy(UID_A, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
mPolicyListener.waitAndVerify()
|
||||
.onUidPoliciesChanged(APP_ID_A, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
@@ -519,10 +519,10 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes allowlist when restrict background is on - app should receive an intent.
|
||||
* Removes an app from allowlist when restrict background is on - app should receive an intent.
|
||||
*/
|
||||
@Test
|
||||
@NetPolicyXml("uidA-allowlisted-restrict-background-on.xml")
|
||||
@NetPolicyXml("uidA-allowed-restrict-background-on.xml")
|
||||
public void testRemoveRestrictBackgroundAllowlist_restrictBackgroundOn() throws Exception {
|
||||
assertRestrictBackgroundOn();
|
||||
assertRestrictBackgroundChangedReceived(mFutureIntent, null);
|
||||
@@ -530,10 +530,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes allowlist when restrict background is off - app should not receive an intent.
|
||||
* Removes an app from allowlist when restrict background is off - app should not
|
||||
* receive an intent.
|
||||
*/
|
||||
@Test
|
||||
@NetPolicyXml("uidA-allowlisted-restrict-background-off.xml")
|
||||
@NetPolicyXml("uidA-allowed-restrict-background-off.xml")
|
||||
public void testRemoveRestrictBackgroundAllowlist_restrictBackgroundOff() throws Exception {
|
||||
assertRestrictBackgroundOff();
|
||||
removeRestrictBackgroundAllowlist(false);
|
||||
@@ -688,7 +689,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
private void removeRestrictBackgroundAllowlist(boolean expectIntent) throws Exception {
|
||||
assertAllowlistUids(UID_A);
|
||||
assertRestrictBackgroundAllowedUids(UID_A);
|
||||
assertUidPolicy(UID_A, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
|
||||
final FutureIntent futureIntent = newRestrictBackgroundChangedFuture();
|
||||
@@ -696,7 +697,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
|
||||
mService.setUidPolicy(UID_A, POLICY_NONE);
|
||||
|
||||
assertAllowlistUids();
|
||||
assertRestrictBackgroundAllowedUids();
|
||||
assertUidPolicy(UID_A, POLICY_NONE);
|
||||
mPolicyListener.waitAndVerify().onUidPoliciesChanged(APP_ID_A, POLICY_NONE);
|
||||
if (expectIntent) {
|
||||
@@ -707,7 +708,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds denylist when restrict background is on - app should not receive an intent.
|
||||
* Adds an app to denylist when restrict background is on - app should not receive an intent.
|
||||
*/
|
||||
@Test
|
||||
@NetPolicyXml("restrict-background-on.xml")
|
||||
@@ -718,7 +719,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds denylist when restrict background is off - app should receive an intent.
|
||||
* Adds an app to denylist when restrict background is off - app should receive an intent.
|
||||
*/
|
||||
@Test
|
||||
public void testAddRestrictBackgroundDenylist_restrictBackgroundOff() throws Exception {
|
||||
@@ -744,10 +745,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes denylist when restrict background is on - app should not receive an intent.
|
||||
* Removes an app from denylist when restrict background is on - app should not
|
||||
* receive an intent.
|
||||
*/
|
||||
@Test
|
||||
@NetPolicyXml("uidA-denylisted-restrict-background-on.xml")
|
||||
@NetPolicyXml("uidA-denied-restrict-background-on.xml")
|
||||
public void testRemoveRestrictBackgroundDenylist_restrictBackgroundOn() throws Exception {
|
||||
assertRestrictBackgroundOn();
|
||||
assertRestrictBackgroundChangedReceived(mFutureIntent, null);
|
||||
@@ -755,10 +757,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes denylist when restrict background is off - app should receive an intent.
|
||||
* Removes an app from denylist when restrict background is off - app should
|
||||
* receive an intent.
|
||||
*/
|
||||
@Test
|
||||
@NetPolicyXml("uidA-denylisted-restrict-background-off.xml")
|
||||
@NetPolicyXml("uidA-denied-restrict-background-off.xml")
|
||||
public void testRemoveRestrictBackgroundDenylist_restrictBackgroundOff() throws Exception {
|
||||
assertRestrictBackgroundOff();
|
||||
removeRestrictBackgroundDenylist(true);
|
||||
@@ -782,8 +785,8 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@NetPolicyXml("uidA-denylisted-restrict-background-on.xml")
|
||||
public void testDenylistedAppIsNotNotifiedWhenRestrictBackgroundIsOn() throws Exception {
|
||||
@NetPolicyXml("uidA-denied-restrict-background-on.xml")
|
||||
public void testDeniedAppIsNotNotifiedWhenRestrictBackgroundIsOn() throws Exception {
|
||||
assertRestrictBackgroundOn();
|
||||
assertRestrictBackgroundChangedReceived(mFutureIntent, null);
|
||||
assertUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
|
||||
@@ -794,11 +797,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@NetPolicyXml("uidA-allowlisted-restrict-background-on.xml")
|
||||
public void testAllowlistedAppIsNotNotifiedWhenRestrictBackgroundIsOn() throws Exception {
|
||||
@NetPolicyXml("uidA-allowed-restrict-background-on.xml")
|
||||
public void testAllowedAppIsNotNotifiedWhenRestrictBackgroundIsOn() throws Exception {
|
||||
assertRestrictBackgroundOn();
|
||||
assertRestrictBackgroundChangedReceived(mFutureIntent, null);
|
||||
assertAllowlistUids(UID_A);
|
||||
assertRestrictBackgroundAllowedUids(UID_A);
|
||||
|
||||
final FutureIntent futureIntent = newRestrictBackgroundChangedFuture();
|
||||
setRestrictBackground(true);
|
||||
@@ -806,11 +809,11 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@NetPolicyXml("uidA-allowlisted-restrict-background-on.xml")
|
||||
public void testAllowlistedAppIsNotifiedWhenDenylisted() throws Exception {
|
||||
@NetPolicyXml("uidA-allowed-restrict-background-on.xml")
|
||||
public void testAllowedAppIsNotifiedWhenDenylisted() throws Exception {
|
||||
assertRestrictBackgroundOn();
|
||||
assertRestrictBackgroundChangedReceived(mFutureIntent, null);
|
||||
assertAllowlistUids(UID_A);
|
||||
assertRestrictBackgroundAllowedUids(UID_A);
|
||||
|
||||
final FutureIntent futureIntent = newRestrictBackgroundChangedFuture();
|
||||
mService.setUidPolicy(UID_A, POLICY_REJECT_METERED_BACKGROUND);
|
||||
@@ -830,33 +833,33 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
|
||||
private void restrictBackgroundListsTest() throws Exception {
|
||||
// UIds that are allowlisted.
|
||||
assertAllowlistUids(UID_A, UID_B, UID_C);
|
||||
// UIds that are in allowlist.
|
||||
assertRestrictBackgroundAllowedUids(UID_A, UID_B, UID_C);
|
||||
assertUidPolicy(UID_A, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
assertUidPolicy(UID_B, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
assertUidPolicy(UID_C, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
|
||||
// UIDs that are denylisted.
|
||||
// UIDs that are in denylist.
|
||||
assertUidPolicy(UID_D, POLICY_NONE);
|
||||
assertUidPolicy(UID_E, POLICY_REJECT_METERED_BACKGROUND);
|
||||
|
||||
// UIDS that have legacy policies.
|
||||
assertUidPolicy(UID_F, 2); // POLICY_ALLOW_BACKGROUND_BATTERY_SAVE
|
||||
|
||||
// Remove allowlist.
|
||||
// Remove an uid from allowlist.
|
||||
mService.setUidPolicy(UID_A, POLICY_NONE);
|
||||
assertUidPolicy(UID_A, POLICY_NONE);
|
||||
assertAllowlistUids(UID_B, UID_C);
|
||||
assertRestrictBackgroundAllowedUids(UID_B, UID_C);
|
||||
|
||||
// Add allowlist when denylisted.
|
||||
// Add an app to allowlist which is currently in denylist.
|
||||
mService.setUidPolicy(UID_E, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
assertUidPolicy(UID_E, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
assertAllowlistUids(UID_B, UID_C, UID_E);
|
||||
assertRestrictBackgroundAllowedUids(UID_B, UID_C, UID_E);
|
||||
|
||||
// Add denylist when allowlisted.
|
||||
// Add an app to denylist when is currently in allowlist.
|
||||
mService.setUidPolicy(UID_B, POLICY_REJECT_METERED_BACKGROUND);
|
||||
assertUidPolicy(UID_B, POLICY_REJECT_METERED_BACKGROUND);
|
||||
assertAllowlistUids(UID_C, UID_E);
|
||||
assertRestrictBackgroundAllowedUids(UID_C, UID_E);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -865,7 +868,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
@Test
|
||||
@NetPolicyXml("restrict-background-lists-mixed-format.xml")
|
||||
public void testRestrictBackgroundLists_mixedFormat() throws Exception {
|
||||
assertAllowlistUids(UID_A, UID_C, UID_D);
|
||||
assertRestrictBackgroundAllowedUids(UID_A, UID_C, UID_D);
|
||||
assertUidPolicy(UID_A, POLICY_ALLOW_METERED_BACKGROUND);
|
||||
assertUidPolicy(UID_B, POLICY_REJECT_METERED_BACKGROUND); // Denylist prevails.
|
||||
assertUidPolicy(UID_C, (POLICY_ALLOW_METERED_BACKGROUND | 2));
|
||||
@@ -2040,7 +2043,7 @@ public class NetworkPolicyManagerServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertAllowlistUids(int... uids) {
|
||||
private void assertRestrictBackgroundAllowedUids(int... uids) {
|
||||
assertContainsInAnyOrder(mService.getUidsWithPolicy(POLICY_ALLOW_METERED_BACKGROUND), uids);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,23 +234,23 @@ public class NetworkManagementServiceTest {
|
||||
doReturn(true).when(mNetdService).bandwidthEnableDataSaver(anyBoolean());
|
||||
|
||||
// Restrict usage of mobile data in background
|
||||
mNMService.setUidMeteredNetworkDenylist(TEST_UID, true);
|
||||
mNMService.setUidOnMeteredNetworkDenylist(TEST_UID, true);
|
||||
assertTrue("Should be true since mobile data usage is restricted",
|
||||
mNMService.isNetworkRestricted(TEST_UID));
|
||||
|
||||
mNMService.setDataSaverModeEnabled(true);
|
||||
verify(mNetdService).bandwidthEnableDataSaver(true);
|
||||
|
||||
mNMService.setUidMeteredNetworkDenylist(TEST_UID, false);
|
||||
mNMService.setUidOnMeteredNetworkDenylist(TEST_UID, false);
|
||||
assertTrue("Should be true since data saver is on and the uid is not allowlisted",
|
||||
mNMService.isNetworkRestricted(TEST_UID));
|
||||
|
||||
mNMService.setUidMeteredNetworkAllowlist(TEST_UID, true);
|
||||
mNMService.setUidOnMeteredNetworkAllowlist(TEST_UID, true);
|
||||
assertFalse("Should be false since data saver is on and the uid is allowlisted",
|
||||
mNMService.isNetworkRestricted(TEST_UID));
|
||||
|
||||
// remove uid from allowlist and turn datasaver off again
|
||||
mNMService.setUidMeteredNetworkAllowlist(TEST_UID, false);
|
||||
mNMService.setUidOnMeteredNetworkAllowlist(TEST_UID, false);
|
||||
mNMService.setDataSaverModeEnabled(false);
|
||||
verify(mNetdService).bandwidthEnableDataSaver(false);
|
||||
assertFalse("Network should not be restricted when data saver is off",
|
||||
|
||||
Reference in New Issue
Block a user