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 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.annotations.ShellBackgroundThread;
import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.sysui.ShellInit;

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.
     */
    private final Point mTouchEventDelta = new Point();
    private final ShellExecutor mShellExecutor;

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

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

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

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

    private void setupAnimationDeveloperSettingsObserver(
+8 −2
Original line number 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.sysui.KeyguardChangeListener;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

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

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

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

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

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

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

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

    @WMSingleton
+12 −3
Original line number 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.sysui.ConfigurationChangeListener;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;

import java.io.PrintWriter;

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

        HideDisplayCutoutOrganizer organizer =
                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) {
        mContext = context;
        mShellController = shellController;
        mOrganizer = organizer;
        shellInit.addInitCallback(this::onInit, this);
    }

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