Created a ACTION_RESTRICT_BACKGROUND_CHANGED intent.
This intent will be broadcasted when:
- Global restrict background setting is changed (sent to all packages)
- An individual uid is added to or removed from the whitelist (sent just
to the packages belonging to that uid).
This intent is only sent to registered receivers.
BUG: 26451391
Change-Id: Ic0a5771f88baa52076ad04764f29098a386463cc
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 492632c..9945b6e5 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -255,6 +255,7 @@
private static final int MSG_RESTRICT_BACKGROUND_CHANGED = 6;
private static final int MSG_ADVISE_PERSIST_THRESHOLD = 7;
private static final int MSG_SCREEN_ON_CHANGED = 8;
+ private static final int MSG_RESTRICT_BACKGROUND_WHITELIST_CHANGED = 9;
private final Context mContext;
private final IActivityManager mActivityManager;
@@ -1842,6 +1843,7 @@
writePolicyLocked();
// TODO: call other update methods like updateNetworkRulesLocked?
}
+ mHandler.obtainMessage(MSG_RESTRICT_BACKGROUND_WHITELIST_CHANGED, uid, 0).sendToTarget();
}
@Override
@@ -1851,6 +1853,7 @@
synchronized (mRulesLock) {
removeRestrictBackgroundWhitelistedUidLocked(uid);
}
+ mHandler.obtainMessage(MSG_RESTRICT_BACKGROUND_WHITELIST_CHANGED, uid, 0).sendToTarget();
}
private void removeRestrictBackgroundWhitelistedUidLocked(int uid) {
@@ -2548,6 +2551,25 @@
}
}
mListeners.finishBroadcast();
+ final Intent intent =
+ new Intent(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED);
+ intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+ mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+ return true;
+ }
+ case MSG_RESTRICT_BACKGROUND_WHITELIST_CHANGED: {
+ final int uid = msg.arg1;
+ final PackageManager pm = mContext.getPackageManager();
+ final String[] packages = pm.getPackagesForUid(uid);
+ final int userId = UserHandle.getUserId(uid);
+ for (String packageName : packages) {
+ final Intent intent =
+ new Intent(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED);
+ intent.setPackage(packageName);
+ intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+ mContext.sendBroadcastAsUser(intent, UserHandle.of(userId));
+ }
+
return true;
}
case MSG_ADVISE_PERSIST_THRESHOLD: {