Merge "Inform AMS about the uid blocked reasons." into tm-dev am: 6889563b7e am: 881205ff60

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17587699

Change-Id: I93de4884e960195671b777891a46a1b035865b60
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sudheer Shanka
2022-04-09 06:04:40 +00:00
committed by Automerger Merge Worker
3 changed files with 35 additions and 4 deletions

View File

@@ -238,6 +238,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
*/

View File

@@ -49,6 +49,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;
@@ -1477,6 +1478,9 @@ public class ActivityManagerService extends IActivityManager.Stub
final UidObserverController mUidObserverController;
private volatile IUidObserver mNetworkPolicyUidObserver;
@GuardedBy("mUidNetworkBlockedReasons")
private final SparseIntArray mUidNetworkBlockedReasons = new SparseIntArray();
final AppRestrictionController mAppRestrictionController;
private final class AppDeathRecipient implements IBinder.DeathRecipient {
@@ -16535,6 +16539,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();

View File

@@ -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
@@ -4225,7 +4225,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
: uidBlockedState.deriveUidRules();
}
if (oldEffectiveBlockedReasons != newEffectiveBlockedReasons) {
postBlockedReasonsChangedMsg(uid,
handleBlockedReasonsChanged(uid,
newEffectiveBlockedReasons, oldEffectiveBlockedReasons);
postUidRulesChangedMsg(uid, uidRules);
@@ -4587,6 +4587,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);
}
}
}
@@ -4810,6 +4813,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);
@@ -4972,7 +4976,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
}
if (oldEffectiveBlockedReasons != newEffectiveBlockedReasons) {
postBlockedReasonsChangedMsg(uid,
handleBlockedReasonsChanged(uid,
newEffectiveBlockedReasons, oldEffectiveBlockedReasons);
postUidRulesChangedMsg(uid, uidRules);
@@ -5115,7 +5119,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
: uidBlockedState.deriveUidRules();
}
if (oldEffectiveBlockedReasons != newEffectiveBlockedReasons) {
postBlockedReasonsChangedMsg(uid,
handleBlockedReasonsChanged(uid,
newEffectiveBlockedReasons,
oldEffectiveBlockedReasons);
@@ -5148,6 +5152,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,