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

Commit 8df4942e authored by Winson Chung's avatar Winson Chung
Browse files

4/ Separate construction and initializing in a few more controllers

- To be inline with other controllers, we should be doing setup work
  on initialization and not on construction

Test: atest WMShellUnitTests
Test: atest SystemUITests
Bug: 238217847

Change-Id: Ifb9924a7704e6089286bb7aa1077bf01a0316de2
parent 0dfdd607
Loading
Loading
Loading
Loading
+17 −5
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.wm.shell.common.RemoteCallable;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.sysui.ShellInit;


import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;


@@ -90,7 +91,6 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
     * Raw delta between {@link #mInitTouchLocation} and the last touch location.
     * Raw delta between {@link #mInitTouchLocation} and the last touch location.
     */
     */
    private final Point mTouchEventDelta = new Point();
    private final Point mTouchEventDelta = new Point();
    private final ShellExecutor mShellExecutor;


    /** True when a back gesture is ongoing */
    /** True when a back gesture is ongoing */
    private boolean mBackGestureStarted = false;
    private boolean mBackGestureStarted = false;
@@ -105,6 +105,9 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    private final SurfaceControl.Transaction mTransaction;
    private final SurfaceControl.Transaction mTransaction;
    private final IActivityTaskManager mActivityTaskManager;
    private final IActivityTaskManager mActivityTaskManager;
    private final Context mContext;
    private final Context mContext;
    private final ContentResolver mContentResolver;
    private final ShellExecutor mShellExecutor;
    private final Handler mBgHandler;
    @Nullable
    @Nullable
    private IOnBackInvokedCallback mBackToLauncherCallback;
    private IOnBackInvokedCallback mBackToLauncherCallback;
    private float mTriggerThreshold;
    private float mTriggerThreshold;
@@ -133,16 +136,19 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
    };
    };


    public BackAnimationController(
    public BackAnimationController(
            @NonNull ShellInit shellInit,
            @NonNull @ShellMainThread ShellExecutor shellExecutor,
            @NonNull @ShellMainThread ShellExecutor shellExecutor,
            @NonNull @ShellBackgroundThread Handler backgroundHandler,
            @NonNull @ShellBackgroundThread Handler backgroundHandler,
            Context context) {
            Context context) {
        this(shellExecutor, backgroundHandler, new SurfaceControl.Transaction(),
        this(shellInit, shellExecutor, backgroundHandler, new SurfaceControl.Transaction(),
                ActivityTaskManager.getService(), context, context.getContentResolver());
                ActivityTaskManager.getService(), context, context.getContentResolver());
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    BackAnimationController(@NonNull @ShellMainThread ShellExecutor shellExecutor,
    BackAnimationController(
            @NonNull @ShellBackgroundThread Handler handler,
            @NonNull ShellInit shellInit,
            @NonNull @ShellMainThread ShellExecutor shellExecutor,
            @NonNull @ShellBackgroundThread Handler bgHandler,
            @NonNull SurfaceControl.Transaction transaction,
            @NonNull SurfaceControl.Transaction transaction,
            @NonNull IActivityTaskManager activityTaskManager,
            @NonNull IActivityTaskManager activityTaskManager,
            Context context, ContentResolver contentResolver) {
            Context context, ContentResolver contentResolver) {
@@ -150,7 +156,13 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
        mTransaction = transaction;
        mTransaction = transaction;
        mActivityTaskManager = activityTaskManager;
        mActivityTaskManager = activityTaskManager;
        mContext = context;
        mContext = context;
        setupAnimationDeveloperSettingsObserver(contentResolver, handler);
        mContentResolver = contentResolver;
        mBgHandler = bgHandler;
        shellInit.addInitCallback(this::onInit, this);
    }

    private void onInit() {
        setupAnimationDeveloperSettingsObserver(mContentResolver, mBgHandler);
    }
    }


    private void setupAnimationDeveloperSettingsObserver(
    private void setupAnimationDeveloperSettingsObserver(
+8 −2
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.wm.shell.compatui.CompatUIWindowManager.CompatUIHintsState;
import com.android.wm.shell.compatui.letterboxedu.LetterboxEduWindowManager;
import com.android.wm.shell.compatui.letterboxedu.LetterboxEduWindowManager;
import com.android.wm.shell.sysui.KeyguardChangeListener;
import com.android.wm.shell.sysui.KeyguardChangeListener;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.transition.Transitions;


import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;
@@ -119,6 +120,7 @@ public class CompatUIController implements OnDisplaysChangedListener,
    private boolean mKeyguardShowing;
    private boolean mKeyguardShowing;


    public CompatUIController(Context context,
    public CompatUIController(Context context,
            ShellInit shellInit,
            ShellController shellController,
            ShellController shellController,
            DisplayController displayController,
            DisplayController displayController,
            DisplayInsetsController displayInsetsController,
            DisplayInsetsController displayInsetsController,
@@ -134,10 +136,14 @@ public class CompatUIController implements OnDisplaysChangedListener,
        mSyncQueue = syncQueue;
        mSyncQueue = syncQueue;
        mMainExecutor = mainExecutor;
        mMainExecutor = mainExecutor;
        mTransitionsLazy = transitionsLazy;
        mTransitionsLazy = transitionsLazy;
        mCompatUIHintsState = new CompatUIHintsState();
        shellInit.addInitCallback(this::onInit, this);
    }

    private void onInit() {
        mShellController.addKeyguardChangeListener(this);
        mDisplayController.addDisplayWindowListener(this);
        mDisplayController.addDisplayWindowListener(this);
        mImeController.addPositionProcessor(this);
        mImeController.addPositionProcessor(this);
        mCompatUIHintsState = new CompatUIHintsState();
        shellController.addKeyguardChangeListener(this);
    }
    }


    /** Sets the callback for UI interactions. */
    /** Sets the callback for UI interactions. */
+10 −5
Original line number Original line Diff line number Diff line
@@ -204,11 +204,12 @@ public abstract class WMShellBaseModule {
    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static CompatUIController provideCompatUIController(Context context,
    static CompatUIController provideCompatUIController(Context context,
            ShellInit shellInit,
            ShellController shellController,
            ShellController shellController,
            DisplayController displayController, DisplayInsetsController displayInsetsController,
            DisplayController displayController, DisplayInsetsController displayInsetsController,
            DisplayImeController imeController, SyncTransactionQueue syncQueue,
            DisplayImeController imeController, SyncTransactionQueue syncQueue,
            @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) {
            @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) {
        return new CompatUIController(context, shellController, displayController,
        return new CompatUIController(context, shellInit, shellController, displayController,
                displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy);
                displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy);
    }
    }


@@ -268,12 +269,14 @@ public abstract class WMShellBaseModule {
    @Provides
    @Provides
    static Optional<BackAnimationController> provideBackAnimationController(
    static Optional<BackAnimationController> provideBackAnimationController(
            Context context,
            Context context,
            ShellInit shellInit,
            @ShellMainThread ShellExecutor shellExecutor,
            @ShellMainThread ShellExecutor shellExecutor,
            @ShellBackgroundThread Handler backgroundHandler
            @ShellBackgroundThread Handler backgroundHandler
    ) {
    ) {
        if (BackAnimationController.IS_ENABLED) {
        if (BackAnimationController.IS_ENABLED) {
            return Optional.of(
            return Optional.of(
                    new BackAnimationController(shellExecutor, backgroundHandler, context));
                    new BackAnimationController(shellInit, shellExecutor, backgroundHandler,
                            context));
        }
        }
        return Optional.empty();
        return Optional.empty();
    }
    }
@@ -384,11 +387,13 @@ public abstract class WMShellBaseModule {
    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static Optional<HideDisplayCutoutController> provideHideDisplayCutoutController(Context context,
    static Optional<HideDisplayCutoutController> provideHideDisplayCutoutController(Context context,
            ShellController shellController, DisplayController displayController,
            ShellInit shellInit,
            ShellController shellController,
            DisplayController displayController,
            @ShellMainThread ShellExecutor mainExecutor) {
            @ShellMainThread ShellExecutor mainExecutor) {
        return Optional.ofNullable(
        return Optional.ofNullable(
                HideDisplayCutoutController.create(context, shellController, displayController,
                HideDisplayCutoutController.create(context, shellInit, shellController,
                        mainExecutor));
                        displayController, mainExecutor));
    }
    }


    //
    //
+17 −12
Original line number Original line Diff line number Diff line
@@ -248,12 +248,17 @@ public abstract class WMShellModule {
    @Provides
    @Provides
    @DynamicOverride
    @DynamicOverride
    static OneHandedController provideOneHandedController(Context context,
    static OneHandedController provideOneHandedController(Context context,
            ShellInit shellInit,
            ShellController shellController,
            ShellController shellController,
            WindowManager windowManager, DisplayController displayController,
            WindowManager windowManager,
            DisplayLayout displayLayout, TaskStackListenerImpl taskStackListener,
            DisplayController displayController,
            UiEventLogger uiEventLogger, InteractionJankMonitor jankMonitor,
            DisplayLayout displayLayout,
            @ShellMainThread ShellExecutor mainExecutor, @ShellMainThread Handler mainHandler) {
            TaskStackListenerImpl taskStackListener,
        return OneHandedController.create(context, shellController, windowManager,
            UiEventLogger uiEventLogger,
            InteractionJankMonitor jankMonitor,
            @ShellMainThread ShellExecutor mainExecutor,
            @ShellMainThread Handler mainHandler) {
        return OneHandedController.create(context, shellInit, shellController, windowManager,
                displayController, displayLayout, taskStackListener, jankMonitor, uiEventLogger,
                displayController, displayLayout, taskStackListener, jankMonitor, uiEventLogger,
                mainExecutor, mainHandler);
                mainExecutor, mainHandler);
    }
    }
@@ -293,7 +298,7 @@ public abstract class WMShellModule {


    @WMSingleton
    @WMSingleton
    @Provides
    @Provides
    static Optional<Pip> providePip(Context context,
    static Optional<Pip> providePip(Context context, ShellInit shellInit,
            ShellController shellController, DisplayController displayController,
            ShellController shellController, DisplayController displayController,
            PipAppOpsListener pipAppOpsListener, PipBoundsAlgorithm pipBoundsAlgorithm,
            PipAppOpsListener pipAppOpsListener, PipBoundsAlgorithm pipBoundsAlgorithm,
            PipKeepClearAlgorithm pipKeepClearAlgorithm, PipBoundsState pipBoundsState,
            PipKeepClearAlgorithm pipKeepClearAlgorithm, PipBoundsState pipBoundsState,
@@ -306,12 +311,12 @@ public abstract class WMShellModule {
            PipParamsChangedForwarder pipParamsChangedForwarder,
            PipParamsChangedForwarder pipParamsChangedForwarder,
            Optional<OneHandedController> oneHandedController,
            Optional<OneHandedController> oneHandedController,
            @ShellMainThread ShellExecutor mainExecutor) {
            @ShellMainThread ShellExecutor mainExecutor) {
        return Optional.ofNullable(PipController.create(context, shellController, displayController,
        return Optional.ofNullable(PipController.create(context, shellInit, shellController,
                pipAppOpsListener, pipBoundsAlgorithm, pipKeepClearAlgorithm, pipBoundsState,
                displayController, pipAppOpsListener, pipBoundsAlgorithm, pipKeepClearAlgorithm,
                pipMotionHelper,
                pipBoundsState, pipMotionHelper, pipMediaController, phonePipMenuController,
                pipMediaController, phonePipMenuController, pipTaskOrganizer, pipTransitionState,
                pipTaskOrganizer, pipTransitionState, pipTouchHandler, pipTransitionController,
                pipTouchHandler, pipTransitionController, windowManagerShellWrapper,
                windowManagerShellWrapper, taskStackListener, pipParamsChangedForwarder,
                taskStackListener, pipParamsChangedForwarder, oneHandedController, mainExecutor));
                oneHandedController, mainExecutor));
    }
    }


    @WMSingleton
    @WMSingleton
+12 −3
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.sysui.ConfigurationChangeListener;
import com.android.wm.shell.sysui.ConfigurationChangeListener;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;


import java.io.PrintWriter;
import java.io.PrintWriter;


@@ -49,7 +50,9 @@ public class HideDisplayCutoutController implements ConfigurationChangeListener
     */
     */
    @Nullable
    @Nullable
    public static HideDisplayCutoutController create(Context context,
    public static HideDisplayCutoutController create(Context context,
            ShellController shellController, DisplayController displayController,
            ShellInit shellInit,
            ShellController shellController,
            DisplayController displayController,
            ShellExecutor mainExecutor) {
            ShellExecutor mainExecutor) {
        // The SystemProperty is set for devices that support this feature and is used to control
        // The SystemProperty is set for devices that support this feature and is used to control
        // whether to create the HideDisplayCutout instance.
        // whether to create the HideDisplayCutout instance.
@@ -60,14 +63,20 @@ public class HideDisplayCutoutController implements ConfigurationChangeListener


        HideDisplayCutoutOrganizer organizer =
        HideDisplayCutoutOrganizer organizer =
                new HideDisplayCutoutOrganizer(context, displayController, mainExecutor);
                new HideDisplayCutoutOrganizer(context, displayController, mainExecutor);
        return new HideDisplayCutoutController(context, shellController, organizer);
        return new HideDisplayCutoutController(context, shellInit, shellController, organizer);
    }
    }


    HideDisplayCutoutController(Context context, ShellController shellController,
    HideDisplayCutoutController(Context context,
            ShellInit shellInit,
            ShellController shellController,
            HideDisplayCutoutOrganizer organizer) {
            HideDisplayCutoutOrganizer organizer) {
        mContext = context;
        mContext = context;
        mShellController = shellController;
        mShellController = shellController;
        mOrganizer = organizer;
        mOrganizer = organizer;
        shellInit.addInitCallback(this::onInit, this);
    }

    private void onInit() {
        updateStatus();
        updateStatus();
        mShellController.addConfigurationChangeListener(this);
        mShellController.addConfigurationChangeListener(this);
    }
    }
Loading