diff --git a/quickstep/ext_tests/src/com/android/quickstep/DebugQuickstepTestInformationHandler.java b/quickstep/ext_tests/src/com/android/quickstep/DebugQuickstepTestInformationHandler.java index 2ffb28e8fb..7fa62c1ca5 100644 --- a/quickstep/ext_tests/src/com/android/quickstep/DebugQuickstepTestInformationHandler.java +++ b/quickstep/ext_tests/src/com/android/quickstep/DebugQuickstepTestInformationHandler.java @@ -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 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); } diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java index 6c740bac50..6e0b71dca0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java @@ -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. * diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index e1bcbe23bf..3b1e6774b4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -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; }