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

Commit 8f1a1c4b authored by Brian Isganitis's avatar Brian Isganitis
Browse files

Suspend Launcher taskbar while removed for tests.

This approach is less destructive than completely destroying Taskbar
while still ensuring it will not try to recreate itself.

Test: Taskbar Unit Tests
Bug: 230027385
Flag: TEST_ONLY
Change-Id: Ida0f7cc0b9c5b1d53bbadc2bb9fd81689c7f3940
parent 025c8a0c
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ public class TaskbarManager {
    private WindowManager mWindowManager;
    private FrameLayout mTaskbarRootLayout;
    private boolean mAddedWindow;
    private boolean mIsSuspended;
    private final TaskbarNavButtonController mNavButtonController;
    private final ComponentCallbacks mComponentCallbacks;

@@ -443,6 +444,8 @@ public class TaskbarManager {
     */
    @VisibleForTesting
    public synchronized void recreateTaskbar() {
        if (mIsSuspended) return;

        Trace.beginSection("recreateTaskbar");
        try {
            DeviceProfile dp = mUserUnlocked ?
@@ -648,8 +651,22 @@ public class TaskbarManager {
        }
    }

    /**
     * Removes Taskbar from the window manager and prevents recreation if {@code true}.
     * <p>
     * Suspending is for testing purposes only; avoid calling this method in production.
     */
    @VisibleForTesting
    public void addTaskbarRootViewToWindow() {
    public void setSuspended(boolean isSuspended) {
        mIsSuspended = isSuspended;
        if (mIsSuspended) {
            removeTaskbarRootViewFromWindow();
        } else {
            addTaskbarRootViewToWindow();
        }
    }

    private void addTaskbarRootViewToWindow() {
        if (enableTaskbarNoRecreate() && !mAddedWindow && mTaskbarActivityContext != null) {
            mWindowManager.addView(mTaskbarRootLayout,
                    mTaskbarActivityContext.getWindowLayoutParams());
@@ -657,8 +674,7 @@ public class TaskbarManager {
        }
    }

    @VisibleForTesting
    public void removeTaskbarRootViewFromWindow() {
    private void removeTaskbarRootViewFromWindow() {
        if (enableTaskbarNoRecreate() && mAddedWindow) {
            mWindowManager.removeViewImmediate(mTaskbarRootLayout);
            mAddedWindow = false;
+2 −2
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ class TaskbarUnitTestRule(
                try {
                    // Replace Launcher Taskbar window with test instance.
                    instrumentation.runOnMainSync {
                        launcherTaskbarManager?.removeTaskbarRootViewFromWindow()
                        launcherTaskbarManager?.setSuspended(true)
                        taskbarManager.onUserUnlocked() // Required to complete initialization.
                    }

@@ -129,7 +129,7 @@ class TaskbarUnitTestRule(
                    // Revert Taskbar window.
                    instrumentation.runOnMainSync {
                        taskbarManager.destroy()
                        launcherTaskbarManager?.addTaskbarRootViewToWindow()
                        launcherTaskbarManager?.setSuspended(false)
                    }
                }
            }