Waiting for Launcher activity to stop when starting a Launchable

This will help to ensure that Launcher state has settled before continuing the test.

Bug: 313926097
Flag: N/A
Test: presubmit
Change-Id: I8bed0225617a225c2dc9587a75d004b98395fe1f
This commit is contained in:
Vadim Tryshev
2023-11-28 18:26:43 -08:00
parent dacb076588
commit 1b058fd467
6 changed files with 34 additions and 1 deletions

View File

@@ -98,6 +98,7 @@ import static com.android.launcher3.popup.SystemShortcut.INSTALL;
import static com.android.launcher3.popup.SystemShortcut.WIDGETS;
import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK;
import static com.android.launcher3.states.RotationHelper.REQUEST_NONE;
import static com.android.launcher3.testing.shared.TestProtocol.LAUNCHER_ACTIVITY_STOPPED_MESSAGE;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.ItemInfoMatcher.forFolderMatch;
import static com.android.launcher3.util.SettingsCache.TOUCHPAD_NATURAL_SCROLLING;
@@ -1034,6 +1035,8 @@ public class Launcher extends StatefulActivity<LauncherState>
mAppWidgetHolder.setActivityStarted(false);
NotificationListener.removeNotificationsChangedListener(getPopupDataProvider());
FloatingIconView.resetIconLoadResult();
AccessibilityManagerCompat.sendTestProtocolEventToTest(
this, LAUNCHER_ACTIVITY_STOPPED_MESSAGE);
}
@Override

View File

@@ -29,6 +29,7 @@ public final class TestProtocol {
public static final String DISMISS_ANIMATION_ENDS_MESSAGE = "TAPL_DISMISS_ANIMATION_ENDS";
public static final String FOLDER_OPENED_MESSAGE = "TAPL_FOLDER_OPENED";
public static final String SEARCH_RESULT_COMPLETE = "SEARCH_RESULT_COMPLETE";
public static final String LAUNCHER_ACTIVITY_STOPPED_MESSAGE = "TAPL_LAUNCHER_ACTIVITY_STOPPED";
public static final int NORMAL_STATE_ORDINAL = 0;
public static final int SPRING_LOADED_STATE_ORDINAL = 1;
public static final int OVERVIEW_STATE_ORDINAL = 2;

View File

@@ -47,8 +47,14 @@ public abstract class Launchable {
return mObject;
}
protected boolean launcherStopsAfterLaunch() {
return true;
}
/**
* Clicks the object to launch its app.
* We are assuming non-translucent app launches because only such launches generate
* LAUNCHER_ACTIVITY_STOPPED_MESSAGE.
*/
public LaunchedAppState launch(String expectedPackageName) {
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
@@ -58,7 +64,15 @@ public abstract class Launchable {
+ mObject.getVisibleCenter() + " in "
+ mLauncher.getVisibleBounds(mObject));
mLauncher.clickLauncherObject(mObject);
if (launcherStopsAfterLaunch()) {
mLauncher.executeAndWaitForLauncherEvent(
() -> mLauncher.clickLauncherObject(mObject),
event -> TestProtocol.LAUNCHER_ACTIVITY_STOPPED_MESSAGE
.equals(event.getClassName().toString()),
() -> "Launcher activity didn't stop", "clicking the launchable");
} else {
mLauncher.clickLauncherObject(mObject);
}
try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer("clicked")) {
expectActivityStartEvents();

View File

@@ -49,4 +49,9 @@ public final class TaskbarAppIcon extends AppIcon implements SplitscreenDragSour
public Launchable getLaunchable() {
return this;
}
@Override
protected boolean launcherStopsAfterLaunch() {
return false;
}
}

View File

@@ -54,4 +54,9 @@ public final class TaskbarAppIconMenuItem extends AppIconMenuItem implements Spl
public Launchable getLaunchable() {
return this;
}
@Override
protected boolean launcherStopsAfterLaunch() {
return false;
}
}

View File

@@ -42,4 +42,9 @@ public class TaskbarSearchWebSuggestion extends SearchWebSuggestion implements
public Launchable getLaunchable() {
return this;
}
@Override
protected boolean launcherStopsAfterLaunch() {
return false;
}
}