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

Commit b6f59304 authored by Tony Wickham's avatar Tony Wickham
Browse files

Don't rely on QuickstepLauncher instance for tests

Instead, bind to TouchInteractionService and use that binder to call into taskbar.

Test: TaplTestsTaskbar
Bug: 235986838
Change-Id: I222522bc53c9d1698542fbae52c37889f14abf41
parent 7fb96a53
Loading
Loading
Loading
Loading
+27 −26
Original line number Diff line number Diff line
@@ -25,12 +25,14 @@ import androidx.annotation.Nullable;

import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.taskbar.LauncherTaskbarUIController;
import com.android.launcher3.testing.DebugTestInformationHandler;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.quickstep.TouchInteractionService.TISBinder;
import com.android.quickstep.util.TISBindHelper;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;

/**
 * Class to handle requests from tests, including debug ones, to Quickstep Launcher builds.
@@ -49,29 +51,26 @@ public abstract class DebugQuickstepTestInformationHandler extends QuickstepTest
        Bundle response = new Bundle();
        switch (method) {
            case TestProtocol.REQUEST_ENABLE_MANUAL_TASKBAR_STASHING:
                runOnUIThread(l -> {
                    enableManualTaskbarStashing(l, true);
                runOnTISBinder(tisBinder -> {
                    enableManualTaskbarStashing(tisBinder, true);
                });
                return response;

            case TestProtocol.REQUEST_DISABLE_MANUAL_TASKBAR_STASHING:
                runOnUIThread(l -> {
                    enableManualTaskbarStashing(l, false);
                runOnTISBinder(tisBinder -> {
                    enableManualTaskbarStashing(tisBinder, false);
                });
                return response;

            case TestProtocol.REQUEST_UNSTASH_TASKBAR_IF_STASHED:
                runOnUIThread(l -> {
                    enableManualTaskbarStashing(l, true);

                    QuickstepLauncher quickstepLauncher = (QuickstepLauncher) l;
                    LauncherTaskbarUIController taskbarUIController =
                            quickstepLauncher.getTaskbarUIController();
                runOnTISBinder(tisBinder -> {
                    enableManualTaskbarStashing(tisBinder, true);

                    // Allow null-pointer to catch illegal states.
                    taskbarUIController.unstashTaskbarIfStashed();
                    tisBinder.getTaskbarManager().getCurrentActivityContext()
                            .unstashTaskbarIfStashed();

                    enableManualTaskbarStashing(l, false);
                    enableManualTaskbarStashing(tisBinder, false);
                });
                return response;

@@ -89,24 +88,26 @@ public abstract class DebugQuickstepTestInformationHandler extends QuickstepTest
        }
    }

    private void enableManualTaskbarStashing(Launcher launcher, boolean enable) {
        QuickstepLauncher quickstepLauncher = (QuickstepLauncher) launcher;
        LauncherTaskbarUIController taskbarUIController =
                quickstepLauncher.getTaskbarUIController();

    private void enableManualTaskbarStashing(TISBinder tisBinder, boolean enable) {
        // Allow null-pointer to catch illegal states.
        taskbarUIController.enableManualStashingForTests(enable);
        tisBinder.getTaskbarManager().getCurrentActivityContext().enableManualStashingForTests(
                enable);
    }

    /**
     * Runs the given command on the UI thread.
     * Runs the given command on the UI thread, after ensuring we are connected to
     * TouchInteractionService.
     */
    private static void runOnUIThread(UIThreadCommand command) {
    private void runOnTISBinder(Consumer<TISBinder> connectionCallback) {
        try {
            MAIN_EXECUTOR.submit(() -> {
                command.execute(Launcher.ACTIVITY_TRACKER.getCreatedActivity());
                return null;
            }).get();
            CountDownLatch countDownLatch = new CountDownLatch(1);
            TISBindHelper helper = MAIN_EXECUTOR.submit(() ->
                    new TISBindHelper(mContext, tisBinder -> {
                        connectionCallback.accept(tisBinder);
                        countDownLatch.countDown();
                    })).get();
            countDownLatch.await();
            MAIN_EXECUTOR.submit(helper::onDestroy);
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
+0 −19
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.view.WindowManagerGlobal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherState;
@@ -123,24 +122,6 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
                shouldDelayLauncherStateAnim);
    }

    /**
     * Enables manual taskbar stashing. This method should only be used for tests that need to
     * stash/unstash the taskbar.
     */
    @VisibleForTesting
    public void enableManualStashingForTests(boolean enableManualStashing) {
        mControllers.taskbarStashController.enableManualStashingForTests(enableManualStashing);
    }

    /**
     * Unstashes the Taskbar if it is stashed. This method should only be used to unstash the
     * taskbar at the end of a test.
     */
    @VisibleForTesting
    public void unstashTaskbarIfStashed() {
        mControllers.taskbarStashController.onLongPressToUnstashTaskbar();
    }

    /**
     * Adds the Launcher resume animator to the given animator set.
     *
+18 −0
Original line number Diff line number Diff line
@@ -773,6 +773,24 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        mControllers.taskbarStashController.startUnstashHint(animateForward);
    }

    /**
     * Enables manual taskbar stashing. This method should only be used for tests that need to
     * stash/unstash the taskbar.
     */
    @VisibleForTesting
    public void enableManualStashingForTests(boolean enableManualStashing) {
        mControllers.taskbarStashController.enableManualStashingForTests(enableManualStashing);
    }

    /**
     * Unstashes the Taskbar if it is stashed. This method should only be used to unstash the
     * taskbar at the end of a test.
     */
    @VisibleForTesting
    public void unstashTaskbarIfStashed() {
        mControllers.taskbarStashController.onLongPressToUnstashTaskbar();
    }

    protected boolean isUserSetupComplete() {
        return mIsUserSetupComplete;
    }