diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java index 8145695c0e..eff0619d0c 100644 --- a/src/com/android/launcher3/LauncherStateManager.java +++ b/src/com/android/launcher3/LauncherStateManager.java @@ -140,6 +140,10 @@ public class LauncherStateManager { return mState; } + public LauncherState getCurrentStableState() { + return mCurrentStableState; + } + public StateHandler[] getStateHandlers() { if (mStateHandlers == null) { mStateHandlers = UiFactory.getStateHandler(mLauncher); diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 4a9df989c3..ab2808d443 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -280,7 +280,7 @@ public abstract class AbstractLauncherUiTest { // the results of that gesture because the wait can hide flakeness. protected void waitForState(String message, LauncherState state) { waitForLauncherCondition(message, - launcher -> launcher.getStateManager().getState() == state); + launcher -> launcher.getStateManager().getCurrentStableState() == state); } protected void waitForResumed(String message) { @@ -301,6 +301,19 @@ public abstract class AbstractLauncherUiTest { Wait.atMost(message, () -> getFromLauncher(condition), timeout); } + // Cannot be used in TaplTests after injecting any gesture using Tapl because this can hide + // flakiness. + protected void waitForLauncherCondition( + String message, + Runnable testThreadAction, Function condition, + long timeout) { + if (!TestHelpers.isInLauncherProcess()) return; + Wait.atMost(message, () -> { + testThreadAction.run(); + return getFromLauncher(condition); + }, timeout); + } + protected LauncherActivityInfo getSettingsApp() { return LauncherAppsCompat.getInstance(mTargetContext) .getActivityList("com.android.settings",