Refactored NetworkPolicyManagerService mUidRules.
NetworkPolicyManagerService (NMPS) keeps an internal list of uid rules (mUidRules) for network restrictions, and when these rules changes it needs to notify external listeners (such as ConnectivityService / CS). Prior to Android N, both Data Saver mode (the feature previously known as "Restrict Baground Data") and Battery Save mode used the same set of firewall rules to implement their restrictions: when Battery Saver mode NPMS would mark all networks as metered and set the proper firewall rules externally. Recently, these 2 modes were split in 2 distinct firewall rules and NMPS.updateRuleForRestrictBackgroundLocked() was changed to update the mUidRules logic based on the Data Saver firewall (since the Battery Saver firewall changes are handled externally, on updateRuleForRestrictPowerLocked()). As such, CS was not notified when the power-related changes were made, which would cause apps to get a state of CONNECTED / CONNECTED when querying its active connection. This change refactores the mUidRules to use bitmasks, in preparation for another change that will fix the issue. It also fixes a minor bug that was preventing removed packages to be removed from the whitelist. BUG: 28521946 Change-Id: I9f0e1509a6192cad403f740c1cd76a6b7dab7d26
This commit is contained in:
@@ -30,10 +30,11 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED;
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
||||
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
|
||||
import static android.net.NetworkPolicyManager.RULE_ALLOW_METERED;
|
||||
import static android.net.NetworkPolicyManager.RULE_NONE;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
||||
import static android.net.NetworkPolicyManager.RULE_TEMPORARY_ALLOW_METERED;
|
||||
import static android.net.NetworkPolicyManager.RULE_UNKNOWN;
|
||||
import static android.net.NetworkPolicyManager.uidRulesToString;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.BroadcastOptions;
|
||||
@@ -915,7 +916,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
final String iface = (lp == null ? "" : lp.getInterfaceName());
|
||||
synchronized (mRulesLock) {
|
||||
networkMetered = mMeteredIfaces.contains(iface);
|
||||
uidRules = mUidRules.get(uid, RULE_UNKNOWN);
|
||||
uidRules = mUidRules.get(uid, RULE_NONE);
|
||||
}
|
||||
|
||||
switch (uidRules) {
|
||||
@@ -927,7 +928,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return networkMetered;
|
||||
case RULE_REJECT_ALL:
|
||||
return true;
|
||||
case RULE_UNKNOWN:
|
||||
case RULE_NONE:
|
||||
default:
|
||||
// When background data is restricted device-wide, the default
|
||||
// behavior for apps should be like RULE_REJECT_METERED
|
||||
@@ -1861,6 +1862,21 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
pw.println(mRestrictBackground);
|
||||
pw.println();
|
||||
|
||||
pw.println("Status for known UIDs:");
|
||||
pw.increaseIndent();
|
||||
final int size = mUidRules.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final int uid = mUidRules.keyAt(i);
|
||||
pw.print("UID=");
|
||||
pw.print(uid);
|
||||
final int uidRules = mUidRules.get(uid, RULE_NONE);
|
||||
pw.print(" rules=");
|
||||
pw.print(uidRulesToString(uidRules));
|
||||
pw.println();
|
||||
}
|
||||
pw.println();
|
||||
pw.decreaseIndent();
|
||||
|
||||
pw.println("Network Requests:");
|
||||
pw.increaseIndent();
|
||||
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||
|
||||
Reference in New Issue
Block a user