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