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

Commit 11ca5138 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Inform Application thread to block for network rules to be updated. am: 3bad67bf

parents 710fdef5 3bad67bf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -587,7 +587,7 @@ public abstract class ActivityManagerInternal {
     * @param uid uid
     * @param pid pid of the ProcessRecord that is pending top.
     */
    public abstract void addPendingTopUid(int uid, int pid);
    public abstract void addPendingTopUid(int uid, int pid, @Nullable IApplicationThread thread);

    /**
     * Delete uid from the ActivityManagerService PendingStartActivityUids list.
+21 −5
Original line number Diff line number Diff line
@@ -16338,20 +16338,36 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public void addPendingTopUid(int uid, int pid) {
            mPendingStartActivityUids.add(uid, pid);
        public void addPendingTopUid(int uid, int pid, @Nullable IApplicationThread thread) {
            final boolean isNewPending = mPendingStartActivityUids.add(uid, pid);
            // We need to update the network rules for the app coming to the top state so that
            // it can access network when the device or the app is in a restricted state
            // (e.g. battery/data saver) but since waiting for updateOomAdj to complete and then
            // informing NetworkPolicyManager might get delayed, informing the state change as soon
            // as we know app is going to come to the top state.
            if (mNetworkPolicyUidObserver != null) {
            if (isNewPending && mNetworkPolicyUidObserver != null) {
                try {
                    final long procStateSeq = mProcessList.getNextProcStateSeq();
                    mNetworkPolicyUidObserver.onUidStateChanged(uid, PROCESS_STATE_TOP,
                            mProcessList.getNextProcStateSeq(), PROCESS_CAPABILITY_ALL);
                            procStateSeq, PROCESS_CAPABILITY_ALL);
                    if (thread != null && isNetworkingBlockedForUid(uid)) {
                        thread.setNetworkBlockSeq(procStateSeq);
                    }
                } catch (RemoteException e) {
                    // Should not happen; call is within the same process
                    Slog.d(TAG, "Error calling setNetworkBlockSeq", e);
                }
            }
        }
        private boolean isNetworkingBlockedForUid(int uid) {
            synchronized (mUidNetworkBlockedReasons) {
                // TODO: We can consider only those blocked reasons that will be overridden
                // by the TOP state. For other ones, there is no point in waiting.
                // TODO: We can reuse this data in
                // ProcessList#incrementProcStateSeqAndNotifyAppsLOSP instead of calling into
                // NetworkManagementService.
                return mUidNetworkBlockedReasons.get(uid, BLOCKED_REASON_NONE)
                        != BLOCKED_REASON_NONE;
            }
        }
+3 −1
Original line number Diff line number Diff line
@@ -44,10 +44,12 @@ final class PendingStartActivityUids {
        mContext = context;
    }

    synchronized void add(int uid, int pid) {
    synchronized boolean add(int uid, int pid) {
        if (mPendingUids.get(uid) == null) {
            mPendingUids.put(uid, new Pair<>(pid, SystemClock.elapsedRealtime()));
            return true;
        }
        return false;
    }

    synchronized void delete(int uid, long nowElapsed) {
+2 −2
Original line number Diff line number Diff line
@@ -1123,7 +1123,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio

    /** Makes the process have top state before oom-adj is computed from a posted message. */
    void addToPendingTop() {
        mAtm.mAmInternal.addPendingTopUid(mUid, mPid);
        mAtm.mAmInternal.addPendingTopUid(mUid, mPid, mThread);
    }

    void updateServiceConnectionActivities() {
@@ -1176,7 +1176,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        }
        // update ActivityManagerService.PendingStartActivityUids list.
        if (topProcessState == ActivityManager.PROCESS_STATE_TOP) {
            mAtm.mAmInternal.addPendingTopUid(mUid, mPid);
            mAtm.mAmInternal.addPendingTopUid(mUid, mPid, mThread);
        }
        prepareOomAdjustment();
        // Posting the message at the front of queue so WM lock isn't held when we call into AM,