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

Commit 51ab3acf authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add lastProcStateSeqDispatchedToObservers to UidRecord.

This will help in identifying the last procStateSeq for which AMS
notified NPMS about the process state change.

Bug: 27803922
Test: runtest -c com.android.server.am.ActivityManagerServiceTest frameworks-services

Change-Id: I741a8ffe31de92070f3ebbc9c4f95fc1c0a340cd
parent 67bdd0f2
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -1721,7 +1721,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    final ServiceThread mHandlerThread;
    final MainHandler mHandler;
    final UiHandler mUiHandler;
    final Handler mUiHandler;
    final ActivityManagerConstants mConstants;
@@ -2706,11 +2706,11 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @VisibleForTesting
    public ActivityManagerService(AppOpsService appOpsService) {
    public ActivityManagerService(Injector injector) {
        GL_ES_VERSION = 0;
        mActivityStarter = null;
        mAppErrors = null;
        mAppOpsService = appOpsService;
        mAppOpsService = injector.getAppOpsService();
        mBatteryStatsService = null;
        mCompatModePackages = null;
        mConstants = null;
@@ -2728,7 +2728,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mStackSupervisor = null;
        mSystemThread = null;
        mTaskChangeNotificationController = null;
        mUiHandler = null;
        mUiHandler = injector.getHandler();
        mUserController = null;
    }
@@ -21633,7 +21633,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                packages[0]);
    }
    private final void enqueueUidChangeLocked(UidRecord uidRec, int uid, int change) {
    @VisibleForTesting
    final void enqueueUidChangeLocked(UidRecord uidRec, int uid, int change) {
        final UidRecord.ChangeItem pendingChange;
        if (uidRec == null || uidRec.pendingChange == null) {
            if (mPendingUidChanges.size() == 0) {
@@ -21675,6 +21676,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                ? uidRec.setProcState : ActivityManager.PROCESS_STATE_NONEXISTENT;
        pendingChange.ephemeral = uidRec != null ? uidRec.ephemeral : isEphemeralLocked(uid);
        pendingChange.procStateSeq = uidRec != null ? uidRec.curProcStateSeq : 0;
        if (uidRec != null) {
            uidRec.updateLastDispatchedProcStateSeq(change);
        }
        // Directly update the power manager, since we sit on top of it and it is critical
        // it be kept in sync (so wake locks will be held as soon as appropriate).
@@ -23590,4 +23594,9 @@ public class ActivityManagerService extends IActivityManager.Stub
            throw new IllegalStateException("Process disappeared");
        }
    }
    static interface Injector {
        public AppOpsService getAppOpsService();
        public Handler getHandler();
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -34,18 +34,26 @@ public final class UidRecord {
    boolean setWhitelist;
    boolean idle;
    int numProcs;

    /**
     * Sequence number associated with the {@link #curProcState}. This is incremented using
     * {@link ActivityManagerService#mProcStateSeqCounter}
     * when {@link #curProcState} changes from background to foreground or vice versa.
     */
    long curProcStateSeq;

    /**
     * Last seq number for which NetworkPolicyManagerService notified ActivityManagerService that
     * network policies rules were updated.
     */
    long lastNetworkUpdatedProcStateSeq;

    /**
     * Last seq number for which AcitivityManagerService dispatched uid state change to
     * NetworkPolicyManagerService.
     */
    long lastDispatchedProcStateSeq;

    static final int CHANGE_PROCSTATE = 0;
    static final int CHANGE_GONE = 1;
    static final int CHANGE_GONE_IDLE = 2;
@@ -72,6 +80,17 @@ public final class UidRecord {
        curProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
    }

    /**
     * If the change being dispatched is neither CHANGE_GONE nor CHANGE_GONE_IDLE (not interested in
     * these changes), then update the {@link #lastDispatchedProcStateSeq} with
     * {@link #curProcStateSeq}.
     */
    public void updateLastDispatchedProcStateSeq(int changeToDispatch) {
        if (changeToDispatch != CHANGE_GONE && changeToDispatch != CHANGE_GONE_IDLE) {
            lastDispatchedProcStateSeq = curProcStateSeq;
        }
    }

    public String toString() {
        StringBuilder sb = new StringBuilder(128);
        sb.append("UidRecord{");
@@ -99,6 +118,8 @@ public final class UidRecord {
        sb.append(curProcStateSeq);
        sb.append(" lastNetworkUpdatedProcStateSeq:");
        sb.append(lastNetworkUpdatedProcStateSeq);
        sb.append(" lastDispatchedProcStateSeq:");
        sb.append(lastDispatchedProcStateSeq);
        sb.append("}");
        return sb.toString();
    }
+7 −3
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ import android.app.ActivityManagerInternal;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import com.android.server.AppOpsService;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

/**
 * Test class for {@link ActivityManagerInternal}.
@@ -46,11 +46,15 @@ import org.junit.runner.RunWith;
@SmallTest
@RunWith(AndroidJUnit4.class)
public class ActivityManagerInternalTest {
    @Mock private ActivityManagerService.Injector mMockInjector;

    private ActivityManagerService mAms;
    private ActivityManagerInternal mAmi;
    @Before
    public void setUp() {
        mAms = new ActivityManagerService((AppOpsService) null);
        MockitoAnnotations.initMocks(this);

        mAms = new ActivityManagerService(mMockInjector);
        mAmi = mAms.new LocalService();
    }

+201 −62

File changed.

Preview size limit exceeded, changes collapsed.