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

Commit 2a3cc464 authored by Bryce Lee's avatar Bryce Lee
Browse files

Make ActivityStackSupervisor instrumentable for unit tests.

Currently, the ActivityStackSupervisor passes an instance of itself
during construction to a number of its member variables. Passing
a self reference at this time leads to an incomplete object being
passed. In the case of testing, it's possible for the instance to be
copied after construction for instrumentation, leading to the
original instance being retained.

This changelist addresses this by moving the creation of these
variables to a separate initialize methods. In addition, the affected
variables accessed outside the class are now behind accessors to
prevent their modification.

Bug: 64750076
Test: bit FrameworksServicesTests:com.android.server.am.ActivityStarterTests
Test: bit FrameworksServicesTests:com.android.server.am.ActivityStackSupervisorTests
Test: bit FrameworksServicesTests:com.android.server.am.ActivityStackTests
Test: bit FrameworksServicesTests:com.android.server.am.LaunchingBoundsControllerTests
Test: bit FrameworksServicesTests:com.android.server.am.LaunchingActivityPositionerTests
Test: bit FrameworksServicesTests:com.android.server.am.LaunchingTaskPositionerTests
Test: runtest --path frameworks/base/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
Change-Id: I19647b24925b82db0ab0955585d7588a28e00f94
parent 0fbd9d16
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -2779,7 +2779,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        mConfigurationSeq = mTempConfig.seq = 1;
        mStackSupervisor = createStackSupervisor();
        mStackSupervisor.onConfigurationChanged(mTempConfig);
        mKeyguardController = mStackSupervisor.mKeyguardController;
        mKeyguardController = mStackSupervisor.getKeyguardController();
        mCompatModePackages = new CompatModePackages(this, systemDir, mHandler);
        mIntentFirewall = new IntentFirewall(new IntentFirewallInterface(), mHandler);
        mTaskChangeNotificationController =
@@ -2828,7 +2828,9 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    protected ActivityStackSupervisor createStackSupervisor() {
        return new ActivityStackSupervisor(this, mHandler.getLooper());
        final ActivityStackSupervisor supervisor = new ActivityStackSupervisor(this, mHandler.getLooper());
        supervisor.initialize();
        return supervisor;
    }
    protected RecentTasks createRecentTasks() {
@@ -7117,7 +7119,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            }
            checkTime(startTime, "attachApplicationLocked: immediately before bindApplication");
            mStackSupervisor.mActivityMetricsLogger.notifyBindApplication(app);
            mStackSupervisor.getActivityMetricsLogger().notifyBindApplication(app);
            if (app.isolatedEntryPoint != null) {
                // This is an isolated process which should just call an entry point instead of
                // being bound to an application.
@@ -23886,7 +23888,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public void notifyAppTransitionStarting(SparseIntArray reasons, long timestamp) {
            synchronized (ActivityManagerService.this) {
                mStackSupervisor.mActivityMetricsLogger.notifyTransitionStarting(
                mStackSupervisor.getActivityMetricsLogger().notifyTransitionStarting(
                        reasons, timestamp);
            }
        }
+4 −4
Original line number Diff line number Diff line
@@ -1529,7 +1529,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

    void setVisibility(boolean visible) {
        mWindowContainerController.setVisibility(visible, mDeferHidingClient);
        mStackSupervisor.mActivityMetricsLogger.notifyVisibilityChanged(this);
        mStackSupervisor.getActivityMetricsLogger().notifyVisibilityChanged(this);
    }

    // TODO: Look into merging with #setVisibility()
@@ -1810,7 +1810,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
            }
            stack.mFullyDrawnStartTime = 0;
        }
        mStackSupervisor.mActivityMetricsLogger.logAppTransitionReportedDrawn(this,
        mStackSupervisor.getActivityMetricsLogger().logAppTransitionReportedDrawn(this,
                restoredFromBundle);
        fullyDrawnStartTime = 0;
    }
@@ -1852,7 +1852,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
    @Override
    public void onStartingWindowDrawn(long timestamp) {
        synchronized (service) {
            mStackSupervisor.mActivityMetricsLogger.notifyStartingWindowDrawn(
            mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(
                    getStackId(), timestamp);
        }
    }
@@ -1860,7 +1860,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
    @Override
    public void onWindowsDrawn(long timestamp) {
        synchronized (service) {
            mStackSupervisor.mActivityMetricsLogger.notifyWindowsDrawn(getStackId(), timestamp);
            mStackSupervisor.getActivityMetricsLogger().notifyWindowsDrawn(getStackId(), timestamp);
            if (displayStartTime != 0) {
                reportLaunchTimeLocked(timestamp);
            }
+9 −9
Original line number Diff line number Diff line
@@ -1669,7 +1669,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
            boolean preserveWindows) {
        mTopActivityOccludesKeyguard = false;
        mTopDismissingKeyguardActivity = null;
        mStackSupervisor.mKeyguardController.beginActivityVisibilityUpdate();
        mStackSupervisor.getKeyguardController().beginActivityVisibilityUpdate();
        try {
            ActivityRecord top = topRunningActivityLocked();
            if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top
@@ -1777,7 +1777,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                notifyActivityDrawnLocked(null);
            }
        } finally {
            mStackSupervisor.mKeyguardController.endActivityVisibilityUpdate();
            mStackSupervisor.getKeyguardController().endActivityVisibilityUpdate();
        }
    }

@@ -1828,9 +1828,9 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible,
            boolean isTop) {
        final boolean isInPinnedStack = r.inPinnedWindowingMode();
        final boolean keyguardShowing = mStackSupervisor.mKeyguardController.isKeyguardShowing(
        final boolean keyguardShowing = mStackSupervisor.getKeyguardController().isKeyguardShowing(
                mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY);
        final boolean keyguardLocked = mStackSupervisor.mKeyguardController.isKeyguardLocked();
        final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked();
        final boolean showWhenLocked = r.canShowWhenLocked() && !isInPinnedStack;
        final boolean dismissKeyguard = r.hasDismissKeyguardWindows();
        if (shouldBeVisible) {
@@ -1845,7 +1845,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
            }

            final boolean canShowWithKeyguard = canShowWithInsecureKeyguard()
                    && mStackSupervisor.mKeyguardController.canDismissKeyguard();
                    && mStackSupervisor.getKeyguardController().canDismissKeyguard();
            if (canShowWithKeyguard) {
                return true;
            }
@@ -1854,10 +1854,10 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

            // If keyguard is showing, nothing is visible, except if we are able to dismiss Keyguard
            // right away.
            return shouldBeVisible && mStackSupervisor.mKeyguardController
            return shouldBeVisible && mStackSupervisor.getKeyguardController()
                    .canShowActivityWhileKeyguardShowing(r, dismissKeyguard);
        } else if (keyguardLocked) {
            return shouldBeVisible && mStackSupervisor.mKeyguardController.canShowWhileOccluded(
            return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded(
                    dismissKeyguard, showWhenLocked);
        } else {
            return shouldBeVisible;
@@ -2421,7 +2421,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                    // if needed to get the correct rotation behavior.
                    // TODO: Remove this once visibilities are set correctly immediately when
                    // starting an activity.
                    if (mStackSupervisor.mKeyguardController.isKeyguardLocked()) {
                    if (mStackSupervisor.getKeyguardController().isKeyguardLocked()) {
                        mStackSupervisor.ensureActivitiesVisibleLocked(null /* starting */,
                                0 /* configChanges */, false /* preserveWindows */);
                    }
@@ -4889,7 +4889,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
                voiceInteractor);
        // add the task to stack first, mTaskPositioner might need the stack association
        addTask(task, toTop, "createTaskRecord");
        final boolean isLockscreenShown = mService.mStackSupervisor.mKeyguardController
        final boolean isLockscreenShown = mService.mStackSupervisor.getKeyguardController()
                .isKeyguardShowing(mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY);
        if (!mStackSupervisor.getLaunchingBoundsController().layoutTask(task, info.windowLayout)
                && mBounds != null && task.isResizeable() && !isLockscreenShown) {
+25 −8
Original line number Diff line number Diff line
@@ -295,7 +295,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    WindowManagerService mWindowManager;
    DisplayManager mDisplayManager;

    private final LaunchingBoundsController mLaunchingBoundsController;
    private LaunchingBoundsController mLaunchingBoundsController;

    /** Counter for next free stack ID to use for dynamic activity stacks. */
    private int mNextFreeStackId = 0;
@@ -395,7 +395,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>();

    private DisplayManagerInternal mDisplayManagerInternal;
    private InputManagerInternal mInputManagerInternal;

    /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */
    boolean inResumeTopActivity;
@@ -414,7 +413,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    // Whether tasks have moved and we need to rank the tasks before next OOM scoring
    private boolean mTaskLayersChanged = true;

    final ActivityMetricsLogger mActivityMetricsLogger;
    private ActivityMetricsLogger mActivityMetricsLogger;

    private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>();

@@ -534,11 +533,13 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
     */
    boolean mIsDockMinimized;

    final KeyguardController mKeyguardController;
    private KeyguardController mKeyguardController;

    private PowerManager mPowerManager;
    private int mDeferResumeCount;

    private boolean mInitialized;

    /**
     * Description of a request to start a new activity, which has been held
     * due to app switches being disabled.
@@ -574,14 +575,32 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    public ActivityStackSupervisor(ActivityManagerService service, Looper looper) {
        mService = service;
        mHandler = new ActivityStackSupervisorHandler(looper);
    }

    public void initialize() {
        if (mInitialized) {
            return;
        }

        mInitialized = true;
        mRunningTasks = createRunningTasks();
        mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext, looper);
        mKeyguardController = new KeyguardController(service, this);
        mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext,
                mHandler.getLooper());
        mKeyguardController = new KeyguardController(mService, this);

        mLaunchingBoundsController = new LaunchingBoundsController();
        mLaunchingBoundsController.registerDefaultPositioners(this);
    }


    public ActivityMetricsLogger getActivityMetricsLogger() {
        return mActivityMetricsLogger;
    }

    public KeyguardController getKeyguardController() {
        return mKeyguardController;
    }

    void setRecentTasks(RecentTasks recentTasks) {
        mRecentTasks = recentTasks;
        mRecentTasks.registerCallback(this);
@@ -624,8 +643,6 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D

            mHomeStack = mFocusedStack = mLastFocusedStack = getDefaultDisplay().getOrCreateStack(
                    WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP);

            mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -665,7 +665,7 @@ class ActivityStarter {
        if (intent != null && intent.hasFileDescriptors()) {
            throw new IllegalArgumentException("File descriptors passed in Intent");
        }
        mSupervisor.mActivityMetricsLogger.notifyActivityLaunching();
        mSupervisor.getActivityMetricsLogger().notifyActivityLaunching();
        boolean componentSpecified = intent.getComponent() != null;

        // Save a copy in case ephemeral needs it
@@ -859,7 +859,7 @@ class ActivityStarter {
                }
            }

            mSupervisor.mActivityMetricsLogger.notifyActivityLaunched(res, outRecord[0]);
            mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(res, outRecord[0]);
            return res;
        }
    }
Loading