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

Commit a66d94b1 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Simplify initialization of transition controller

RootWindowContainer#mTransitionController was always null because
setWindowManager(create TransitionController) is called after the
creation of RootWindowContainer.

Now TransitionController is created with ActivityTaskMangerService,
and its fields of window manager dependencies are assigned from
setWindowManager. Then all WindowContainer#mTransitionController
will be non-null.

This also fixes that setNavigationBarLumaSamplingEnabled was
missing for transient launch because mStatusBar is always null
by the initialization order.

Bug: 163976519
Test: atest TransitionTests

Change-Id: Ic72c3f70b6de005d9b68a43e53510c2a5f4bdb44
parent f558dd2d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1027,7 +1027,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        synchronized (mGlobalLock) {
            mWindowManager = wm;
            mRootWindowContainer = wm.mRoot;
            mWindowOrganizerController.setWindowManager(wm);
            mWindowOrganizerController.mTransitionController.setWindowManager(wm);
            mTempConfig.setToDefaults();
            mTempConfig.setLocales(LocaleList.getDefault());
            mConfigurationSeq = mTempConfig.seq = 1;
+9 −6
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ import com.android.internal.protolog.ProtoLogGroup;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.statusbar.StatusBarManagerInternal;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -1205,6 +1206,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        }
    }

    // TODO(b/188595497): Remove after migrating to shell.
    /** @see RecentsAnimationController#attachNavigationBarToApp */
    private void handleLegacyRecentsStartBehavior(DisplayContent dc, TransitionInfo info) {
        if ((mFlags & TRANSIT_FLAG_IS_RECENTS) == 0) {
@@ -1285,8 +1287,9 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
            // Place the nav bar on top of anything else in the top activity.
            t.setLayer(navSurfaceControl, Integer.MAX_VALUE);
        }
        if (mController.mStatusBar != null) {
            mController.mStatusBar.setNavigationBarLumaSamplingEnabled(mRecentsDisplayId, false);
        final StatusBarManagerInternal bar = dc.getDisplayPolicy().getStatusBarManagerInternal();
        if (bar != null) {
            bar.setNavigationBarLumaSamplingEnabled(mRecentsDisplayId, false);
        }
    }

@@ -1300,12 +1303,12 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
            mRecentsDisplayId = DEFAULT_DISPLAY;
        }

        if (mController.mStatusBar != null) {
            mController.mStatusBar.setNavigationBarLumaSamplingEnabled(mRecentsDisplayId, true);
        }

        final DisplayContent dc =
                mController.mAtm.mRootWindowContainer.getDisplayContent(mRecentsDisplayId);
        final StatusBarManagerInternal bar = dc.getDisplayPolicy().getStatusBarManagerInternal();
        if (bar != null) {
            bar.setNavigationBarLumaSamplingEnabled(mRecentsDisplayId, true);
        }
        final WindowState navWindow = dc.getDisplayPolicy().getNavigationBar();
        if (navWindow == null) return;
        navWindow.setSurfaceTranslationY(0);
+10 −13
Original line number Diff line number Diff line
@@ -55,8 +55,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLogGroup;
import com.android.internal.protolog.common.ProtoLog;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.statusbar.StatusBarManagerInternal;

import java.util.ArrayList;
import java.util.function.LongConsumer;
@@ -88,12 +86,12 @@ class TransitionController {

    private ITransitionPlayer mTransitionPlayer;
    final TransitionMetricsReporter mTransitionMetricsReporter = new TransitionMetricsReporter();
    final TransitionTracer mTransitionTracer;

    private WindowProcessController mTransitionPlayerProc;
    final ActivityTaskManagerService mAtm;
    final TaskSnapshotController mTaskSnapshotController;
    final RemotePlayer mRemotePlayer;
    TaskSnapshotController mTaskSnapshotController;
    TransitionTracer mTransitionTracer;

    private final ArrayList<WindowManagerInternal.AppTransitionListener> mLegacyListeners =
            new ArrayList<>();
@@ -111,9 +109,6 @@ class TransitionController {
    /** The transition currently being constructed (collecting participants). */
    private Transition mCollectingTransition = null;

    // TODO(b/188595497): remove when not needed.
    final StatusBarManagerInternal mStatusBar;

    /**
     * `true` when building surface layer order for the finish transaction. We want to prevent
     * wm from touching z-order of surfaces during transitions, but we still need to be able to
@@ -133,14 +128,9 @@ class TransitionController {
     */
    boolean mIsWaitingForDisplayEnabled = false;

    TransitionController(ActivityTaskManagerService atm,
            TaskSnapshotController taskSnapshotController,
            TransitionTracer transitionTracer) {
    TransitionController(ActivityTaskManagerService atm) {
        mAtm = atm;
        mRemotePlayer = new RemotePlayer(atm);
        mStatusBar = LocalServices.getService(StatusBarManagerInternal.class);
        mTaskSnapshotController = taskSnapshotController;
        mTransitionTracer = transitionTracer;
        mTransitionPlayerDeath = () -> {
            synchronized (mAtm.mGlobalLock) {
                detachPlayer();
@@ -148,6 +138,13 @@ class TransitionController {
        };
    }

    void setWindowManager(WindowManagerService wms) {
        mTaskSnapshotController = wms.mTaskSnapshotController;
        mTransitionTracer = wms.mTransitionTracer;
        mIsWaitingForDisplayEnabled = !wms.mDisplayEnabled;
        registerLegacyListener(wms.mActivityManagerAppTransitionNotifier);
    }

    private void detachPlayer() {
        if (mTransitionPlayer == null) return;
        // Clean-up/finish any playing transitions.
+3 −8
Original line number Diff line number Diff line
@@ -146,7 +146,8 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
    final DisplayAreaOrganizerController mDisplayAreaOrganizerController;
    final TaskFragmentOrganizerController mTaskFragmentOrganizerController;

    TransitionController mTransitionController;
    final TransitionController mTransitionController;

    /**
     * A Map which manages the relationship between
     * {@link TaskFragmentCreationParams#getFragmentToken()} and {@link TaskFragment}
@@ -163,13 +164,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
        mTaskOrganizerController = new TaskOrganizerController(mService);
        mDisplayAreaOrganizerController = new DisplayAreaOrganizerController(mService);
        mTaskFragmentOrganizerController = new TaskFragmentOrganizerController(atm, this);
    }

    void setWindowManager(WindowManagerService wms) {
        mTransitionController = new TransitionController(mService, wms.mTaskSnapshotController,
                wms.mTransitionTracer);
        mTransitionController.mIsWaitingForDisplayEnabled = !wms.mDisplayEnabled;
        mTransitionController.registerLegacyListener(wms.mActivityManagerAppTransitionNotifier);
        mTransitionController = new TransitionController(atm);
    }

    TransitionController getTransitionController() {
+7 −15
Original line number Diff line number Diff line
@@ -106,10 +106,8 @@ public class TransitionTests extends WindowTestsBase {
    private BLASTSyncEngine mSyncEngine;

    private Transition createTestTransition(int transitType) {
        TransitionTracer tracer = mock(TransitionTracer.class);
        final TransitionController controller = new TransitionController(
                mock(ActivityTaskManagerService.class), mock(TaskSnapshotController.class),
                mock(TransitionTracer.class));
        final TransitionController controller = new TestTransitionController(
                mock(ActivityTaskManagerService.class));

        mSyncEngine = createTestBLASTSyncEngine();
        final Transition t = new Transition(transitType, 0 /* flags */, controller, mSyncEngine);
@@ -780,8 +778,7 @@ public class TransitionTests extends WindowTestsBase {

    @Test
    public void testTimeout() {
        final TransitionController controller = new TransitionController(mAtm,
                mock(TaskSnapshotController.class), mock(TransitionTracer.class));
        final TransitionController controller = new TestTransitionController(mAtm);
        final BLASTSyncEngine sync = new BLASTSyncEngine(mWm);
        final CountDownLatch latch = new CountDownLatch(1);
        // When the timeout is reached, it will finish the sync-group and notify transaction ready.
@@ -1062,9 +1059,7 @@ public class TransitionTests extends WindowTestsBase {

    @Test
    public void testIntermediateVisibility() {
        final TaskSnapshotController snapshotController = mock(TaskSnapshotController.class);
        final TransitionController controller = new TransitionController(mAtm, snapshotController,
                mock(TransitionTracer.class));
        final TransitionController controller = new TestTransitionController(mAtm);
        final ITransitionPlayer player = new ITransitionPlayer.Default();
        controller.registerTransitionPlayer(player, null /* playerProc */);
        final Transition openTransition = controller.createTransition(TRANSIT_OPEN);
@@ -1135,10 +1130,8 @@ public class TransitionTests extends WindowTestsBase {

    @Test
    public void testTransientLaunch() {
        final TaskSnapshotController snapshotController = mock(TaskSnapshotController.class);
        final ArrayList<ActivityRecord> enteringAnimReports = new ArrayList<>();
        final TransitionController controller = new TransitionController(mAtm, snapshotController,
                mock(TransitionTracer.class)) {
        final TransitionController controller = new TestTransitionController(mAtm) {
            @Override
            protected void dispatchLegacyAppTransitionFinished(ActivityRecord ar) {
                if (ar.mEnteringAnimation) {
@@ -1147,6 +1140,7 @@ public class TransitionTests extends WindowTestsBase {
                super.dispatchLegacyAppTransitionFinished(ar);
            }
        };
        final TaskSnapshotController snapshotController = controller.mTaskSnapshotController;
        final ITransitionPlayer player = new ITransitionPlayer.Default();
        controller.registerTransitionPlayer(player, null /* playerProc */);
        final Transition openTransition = controller.createTransition(TRANSIT_OPEN);
@@ -1211,9 +1205,7 @@ public class TransitionTests extends WindowTestsBase {

    @Test
    public void testNotReadyPushPop() {
        final TaskSnapshotController snapshotController = mock(TaskSnapshotController.class);
        final TransitionController controller = new TransitionController(mAtm, snapshotController,
                mock(TransitionTracer.class));
        final TransitionController controller = new TestTransitionController(mAtm);
        final ITransitionPlayer player = new ITransitionPlayer.Default();
        controller.registerTransitionPlayer(player, null /* playerProc */);
        final Transition openTransition = controller.createTransition(TRANSIT_OPEN);
Loading