Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8040cae9 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

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

parents 2ec8cd25 6889563b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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
     */
+15 −0
Original line number Diff line number Diff line
@@ -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();
+14 −4
Original line number Diff line number Diff line
@@ -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,