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

Commit 7f8ece64 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Decouple WmTests and ActivityManagerService" into tm-qpr-dev

parents bcdaa9e7 6fe46eca
Loading
Loading
Loading
Loading
+13 −23
Original line number Diff line number Diff line
@@ -2281,13 +2281,9 @@ public class ActivityManagerService extends IActivityManager.Stub
        return mAppOpsManager;
    }
    /**
     * Provides the basic functionality for activity task related tests when a handler thread is
     * given to initialize the dependency members.
     */
    /** Provides the basic functionality for unit tests. */
    @VisibleForTesting
    public ActivityManagerService(Injector injector, ServiceThread handlerThread) {
        final boolean hasHandlerThread = handlerThread != null;
    ActivityManagerService(Injector injector, @NonNull ServiceThread handlerThread) {
        mInjector = injector;
        mContext = mInjector.getContext();
        mUiContext = null;
@@ -2295,33 +2291,27 @@ public class ActivityManagerService extends IActivityManager.Stub
        mPackageWatchdog = null;
        mAppOpsService = mInjector.getAppOpsService(null /* file */, null /* handler */);
        mBatteryStatsService = null;
        mHandler = hasHandlerThread ? new MainHandler(handlerThread.getLooper()) : null;
        mHandler = new MainHandler(handlerThread.getLooper());
        mHandlerThread = handlerThread;
        mConstants = hasHandlerThread
                ? new ActivityManagerConstants(mContext, this, mHandler) : null;
        mConstants = new ActivityManagerConstants(mContext, this, mHandler);
        final ActiveUids activeUids = new ActiveUids(this, false /* postChangesToAtm */);
        mPlatformCompat = null;
        mProcessList = injector.getProcessList(this);
        mProcessList.init(this, activeUids, mPlatformCompat);
        mAppProfiler = new AppProfiler(this, BackgroundThread.getHandler().getLooper(), null);
        mPhantomProcessList = new PhantomProcessList(this);
        mOomAdjuster = hasHandlerThread
                ? new OomAdjuster(this, mProcessList, activeUids, handlerThread) : null;
        mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids, handlerThread);
        mIntentFirewall = hasHandlerThread
                ? new IntentFirewall(new IntentFirewallInterface(), mHandler) : null;
        mIntentFirewall = null;
        mProcessStats = null;
        mCpHelper = new ContentProviderHelper(this, false);
        // For the usage of {@link ActiveServices#cleanUpServices} that may be invoked from
        // {@link ActivityTaskSupervisor#cleanUpRemovedTaskLocked}.
        mServices = hasHandlerThread ? new ActiveServices(this) : null;
        mServices = null;
        mSystemThread = null;
        mUiHandler = injector.getUiHandler(null /* service */);
        mUidObserverController = new UidObserverController(mUiHandler);
        mUserController = hasHandlerThread ? new UserController(this) : null;
        mPendingIntentController = hasHandlerThread
                ? new PendingIntentController(handlerThread.getLooper(), mUserController,
                        mConstants) : null;
        mUserController = new UserController(this);
        mPendingIntentController =
                new PendingIntentController(handlerThread.getLooper(), mUserController, mConstants);
        mAppRestrictionController = new AppRestrictionController(mContext, this);
        mProcStartHandlerThread = null;
        mProcStartHandler = null;
@@ -2329,7 +2319,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mFactoryTest = FACTORY_TEST_OFF;
        mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class);
        mInternal = new LocalService();
        mPendingStartActivityUids = new PendingStartActivityUids(mContext);
        mPendingStartActivityUids = new PendingStartActivityUids();
        mUseFifoUiScheduling = false;
        mEnableOffloadQueue = false;
        mFgBroadcastQueue = mBgBroadcastQueue = mBgOffloadBroadcastQueue =
@@ -2464,7 +2454,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        mInternal = new LocalService();
        mPendingStartActivityUids = new PendingStartActivityUids(mContext);
        mPendingStartActivityUids = new PendingStartActivityUids();
        mTraceErrorLogger = new TraceErrorLogger();
        mComponentAliasResolver = new ComponentAliasResolver(this);
    }
@@ -17283,7 +17273,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            // next top activity on time. This race will fail the following binder transactions WM
            // sends to the activity. After this race issue between WM/ATMS and AMS is solved, this
            // workaround can be removed. (b/213288355)
            if (isNewPending && mOomAdjuster != null) { // It can be null in unit test.
            if (isNewPending) {
                mOomAdjuster.mCachedAppOptimizer.unfreezeProcess(pid);
            }
            // We need to update the network rules for the app coming to the top state so that
+0 −6
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server.am;

import android.content.Context;
import android.os.SystemClock;
import android.util.Pair;
import android.util.Slog;
@@ -40,11 +39,6 @@ final class PendingStartActivityUids {
    // Key is uid, value is Pair of pid and SystemClock.elapsedRealtime() when the
    // uid is added.
    private final SparseArray<Pair<Integer, Long>> mPendingUids = new SparseArray();
    private Context mContext;

    PendingStartActivityUids(Context context) {
        mContext = context;
    }

    /** Returns {@code true} if the uid is put to the pending array. Otherwise it existed. */
    synchronized boolean add(int uid, int pid) {
+2 −6
Original line number Diff line number Diff line
@@ -1062,7 +1062,6 @@ public class WindowManagerService extends IWindowManager.Stub

    Function<SurfaceSession, SurfaceControl.Builder> mSurfaceControlFactory;
    Supplier<SurfaceControl.Transaction> mTransactionFactory;
    final Supplier<Surface> mSurfaceFactory;

    private final SurfaceControl.Transaction mTransaction;

@@ -1145,7 +1144,7 @@ public class WindowManagerService extends IWindowManager.Stub
            final boolean showBootMsgs, final boolean onlyCore, WindowManagerPolicy policy,
            ActivityTaskManagerService atm) {
        return main(context, im, showBootMsgs, onlyCore, policy, atm,
                new DisplayWindowSettingsProvider(), SurfaceControl.Transaction::new, Surface::new,
                new DisplayWindowSettingsProvider(), SurfaceControl.Transaction::new,
                SurfaceControl.Builder::new);
    }

@@ -1158,12 +1157,11 @@ public class WindowManagerService extends IWindowManager.Stub
            final boolean showBootMsgs, final boolean onlyCore, WindowManagerPolicy policy,
            ActivityTaskManagerService atm, DisplayWindowSettingsProvider
            displayWindowSettingsProvider, Supplier<SurfaceControl.Transaction> transactionFactory,
            Supplier<Surface> surfaceFactory,
            Function<SurfaceSession, SurfaceControl.Builder> surfaceControlFactory) {
        final WindowManagerService[] wms = new WindowManagerService[1];
        DisplayThread.getHandler().runWithScissors(() ->
                wms[0] = new WindowManagerService(context, im, showBootMsgs, onlyCore, policy,
                        atm, displayWindowSettingsProvider, transactionFactory, surfaceFactory,
                        atm, displayWindowSettingsProvider, transactionFactory,
                        surfaceControlFactory), 0);
        return wms[0];
    }
@@ -1188,7 +1186,6 @@ public class WindowManagerService extends IWindowManager.Stub
            boolean showBootMsgs, boolean onlyCore, WindowManagerPolicy policy,
            ActivityTaskManagerService atm, DisplayWindowSettingsProvider
            displayWindowSettingsProvider, Supplier<SurfaceControl.Transaction> transactionFactory,
            Supplier<Surface> surfaceFactory,
            Function<SurfaceSession, SurfaceControl.Builder> surfaceControlFactory) {
        installLock(this, INDEX_WINDOW);
        mGlobalLock = atm.getGlobalLock();
@@ -1228,7 +1225,6 @@ public class WindowManagerService extends IWindowManager.Stub

        mSurfaceControlFactory = surfaceControlFactory;
        mTransactionFactory = transactionFactory;
        mSurfaceFactory = surfaceFactory;
        mTransaction = mTransactionFactory.get();

        mPolicy = policy;
+8 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.ActivityManager.START_TASK_TO_FRONT;
import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
@@ -34,6 +35,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -284,10 +286,14 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
                .setCreateActivity(true).build().getTopMostActivity();
        activity2.getTask().setResumedActivity(activity2, "test");

        mAtm.mAmInternal.deletePendingTopUid(activity1.getUid(), Long.MAX_VALUE);
        final int[] pendingTopUid = new int[1];
        doAnswer(invocation -> {
            pendingTopUid[0] = invocation.getArgument(0);
            return null;
        }).when(mAtm.mAmInternal).addPendingTopUid(anyInt(), anyInt(), any());
        clearInvocations(mAtm);
        activity1.moveFocusableActivityToTop("test");
        assertTrue(mAtm.mAmInternal.isPendingTopUid(activity1.getUid()));
        assertEquals(activity1.getUid(), pendingTopUid[0]);
        verify(mAtm).updateOomAdj();
    }

+6 −13
Original line number Diff line number Diff line
@@ -657,7 +657,7 @@ public class RootWindowContainerTests extends WindowTestsBase {

        doReturn(true).when(mRootWindowContainer).resumeHomeActivity(any(), any(), any());

        mAtm.setBooted(true);
        setBooted(mAtm);

        // Trigger resume on all displays
        mRootWindowContainer.resumeFocusedTasksTopActivities();
@@ -685,7 +685,7 @@ public class RootWindowContainerTests extends WindowTestsBase {

        doReturn(true).when(mRootWindowContainer).resumeHomeActivity(any(), any(), any());

        mAtm.setBooted(true);
        setBooted(mAtm);

        // Trigger resume on all displays
        mRootWindowContainer.resumeFocusedTasksTopActivities();
@@ -771,17 +771,10 @@ public class RootWindowContainerTests extends WindowTestsBase {
    @Test
    public void testNotStartHomeBeforeBoot() {
        final int displayId = 1;
        final boolean isBooting = mAtm.mAmInternal.isBooting();
        final boolean isBooted = mAtm.mAmInternal.isBooted();
        try {
            mAtm.mAmInternal.setBooting(false);
            mAtm.mAmInternal.setBooted(false);
        doReturn(false).when(mAtm).isBooting();
        doReturn(false).when(mAtm).isBooted();
        mRootWindowContainer.onDisplayAdded(displayId);
        verify(mRootWindowContainer, never()).startHomeOnDisplay(anyInt(), any(), anyInt());
        } finally {
            mAtm.mAmInternal.setBooting(isBooting);
            mAtm.mAmInternal.setBooted(isBooted);
        }
    }

    /**
Loading