Inform AMS about the uid blocked reasons. am: eb5e04aeca am: 7ee9ee6a32
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2065619 Change-Id: I832831890114d2ecf674ffcdb24af84305ecc7a4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -208,6 +208,12 @@ public abstract class ActivityManagerInternal {
|
||||
*/
|
||||
public abstract void notifyNetworkPolicyRulesUpdated(int uid, long procStateSeq);
|
||||
|
||||
/**
|
||||
* Inform ActivityManagerService about the latest {@code blockedReasons} for an uid, which
|
||||
* can be used to understand whether the {@code uid} is allowed to access network or not.
|
||||
*/
|
||||
public abstract void onUidBlockedReasonsChanged(int uid, int blockedReasons);
|
||||
|
||||
/**
|
||||
* @return true if runtime was restarted, false if it's normal boot
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,7 @@ import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
|
||||
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
|
||||
import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static android.net.ConnectivityManager.BLOCKED_REASON_NONE;
|
||||
import static android.os.FactoryTest.FACTORY_TEST_OFF;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL;
|
||||
import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_HIGH;
|
||||
@@ -1419,6 +1420,9 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
final UidObserverController mUidObserverController;
|
||||
private volatile IUidObserver mNetworkPolicyUidObserver;
|
||||
|
||||
@GuardedBy("mUidNetworkBlockedReasons")
|
||||
private final SparseIntArray mUidNetworkBlockedReasons = new SparseIntArray();
|
||||
|
||||
private final class AppDeathRecipient implements IBinder.DeathRecipient {
|
||||
final ProcessRecord mApp;
|
||||
final int mPid;
|
||||
@@ -15622,6 +15626,17 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUidBlockedReasonsChanged(int uid, int blockedReasons) {
|
||||
synchronized (mUidNetworkBlockedReasons) {
|
||||
if (blockedReasons == BLOCKED_REASON_NONE) {
|
||||
mUidNetworkBlockedReasons.delete(uid);
|
||||
} else {
|
||||
mUidNetworkBlockedReasons.put(uid, blockedReasons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntimeRestarted() {
|
||||
return mSystemServiceManager.isRuntimeRestarted();
|
||||
|
||||
@@ -926,6 +926,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
|
||||
mUsageStats = LocalServices.getService(UsageStatsManagerInternal.class);
|
||||
mAppStandby = LocalServices.getService(AppStandbyInternal.class);
|
||||
mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
|
||||
|
||||
synchronized (mUidRulesFirstLock) {
|
||||
synchronized (mNetworkPoliciesSecondLock) {
|
||||
@@ -1003,7 +1004,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
|
||||
try {
|
||||
final int changes = ActivityManager.UID_OBSERVER_PROCSTATE
|
||||
| ActivityManager.UID_OBSERVER_GONE
|
||||
@@ -4239,7 +4239,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
: uidBlockedState.deriveUidRules();
|
||||
}
|
||||
if (oldEffectiveBlockedReasons != newEffectiveBlockedReasons) {
|
||||
postBlockedReasonsChangedMsg(uid,
|
||||
handleBlockedReasonsChanged(uid,
|
||||
newEffectiveBlockedReasons, oldEffectiveBlockedReasons);
|
||||
|
||||
postUidRulesChangedMsg(uid, uidRules);
|
||||
@@ -4601,6 +4601,9 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
someArgs.argi2 = uidBlockedState.effectiveBlockedReasons;
|
||||
someArgs.argi3 = uidBlockedState.deriveUidRules();
|
||||
uidStateUpdates.append(uid, someArgs);
|
||||
// TODO: Update the state for all changed uids together.
|
||||
mActivityManagerInternal.onUidBlockedReasonsChanged(uid,
|
||||
uidBlockedState.effectiveBlockedReasons);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4824,6 +4827,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
mUidBlockedState.delete(uid);
|
||||
}
|
||||
mUidState.delete(uid);
|
||||
mActivityManagerInternal.onUidBlockedReasonsChanged(uid, BLOCKED_REASON_NONE);
|
||||
mUidPolicy.delete(uid);
|
||||
mUidFirewallStandbyRules.delete(uid);
|
||||
mUidFirewallDozableRules.delete(uid);
|
||||
@@ -4986,7 +4990,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
if (oldEffectiveBlockedReasons != newEffectiveBlockedReasons) {
|
||||
postBlockedReasonsChangedMsg(uid,
|
||||
handleBlockedReasonsChanged(uid,
|
||||
newEffectiveBlockedReasons, oldEffectiveBlockedReasons);
|
||||
|
||||
postUidRulesChangedMsg(uid, uidRules);
|
||||
@@ -5129,7 +5133,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
: uidBlockedState.deriveUidRules();
|
||||
}
|
||||
if (oldEffectiveBlockedReasons != newEffectiveBlockedReasons) {
|
||||
postBlockedReasonsChangedMsg(uid,
|
||||
handleBlockedReasonsChanged(uid,
|
||||
newEffectiveBlockedReasons,
|
||||
oldEffectiveBlockedReasons);
|
||||
|
||||
@@ -5162,6 +5166,12 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBlockedReasonsChanged(int uid, int newEffectiveBlockedReasons,
|
||||
int oldEffectiveBlockedReasons) {
|
||||
mActivityManagerInternal.onUidBlockedReasonsChanged(uid, newEffectiveBlockedReasons);
|
||||
postBlockedReasonsChangedMsg(uid, newEffectiveBlockedReasons, oldEffectiveBlockedReasons);
|
||||
}
|
||||
|
||||
private void postBlockedReasonsChangedMsg(int uid, int newEffectiveBlockedReasons,
|
||||
int oldEffectiveBlockedReasons) {
|
||||
mHandler.obtainMessage(MSG_UID_BLOCKED_REASON_CHANGED, uid,
|
||||
|
||||
Reference in New Issue
Block a user