From 35accb87d9e6a67fcb2ff1d11659deb0fbe3fa97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Ciche=C5=84ski?= Date: Mon, 28 Aug 2023 23:52:35 +0000 Subject: [PATCH] Add Assistant Home button support in Launcher TAPL When using apps that switch to car mode (e.g. Maps) while in 3 button navigation mode, the default navbar is not visible and instead the overlay from Assistant is being rendered that also has the Home button. For tests that involve apps switching to car mode, when we want to go home we want to be able to press that button. Bug: 282758103 Test: n/a Change-Id: I88c420f321dcfd39164e20e97d39f90bf1e5d8d8 --- .../tapl/LauncherInstrumentation.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index e6fc244aaa..ae4b6f2e9e 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -21,7 +21,6 @@ import static android.content.pm.PackageManager.DONT_KILL_APP; import static android.content.pm.PackageManager.MATCH_ALL; import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS; import static android.view.MotionEvent.AXIS_GESTURE_SWIPE_FINGER_COUNT; - import static com.android.launcher3.tapl.Folder.FOLDER_CONTENT_RES_ID; import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName; import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL; @@ -29,12 +28,14 @@ import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORD import android.app.ActivityManager; import android.app.Instrumentation; import android.app.UiAutomation; +import android.app.UiModeManager; import android.content.ComponentName; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Insets; import android.graphics.Point; @@ -181,6 +182,8 @@ public final class LauncherInstrumentation { static final long DEFAULT_POLL_INTERVAL = 1000; private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; private static final String ANDROID_PACKAGE = "android"; + private static final String ASSISTANT_PACKAGE = "com.google.android.googlequicksearchbox"; + private static final String ASSISTANT_GO_HOME_RES_ID = "home_icon"; private static WeakReference sActiveContainer = new WeakReference<>(null); @@ -1055,7 +1058,7 @@ public final class LauncherInstrumentation { action = "clicking home button"; runToState( - waitForNavigationUiObject("home")::click, + getHomeButton()::click, NORMAL_STATE_ORDINAL, !hasLauncherObject(WORKSPACE_RES_ID) && (hasLauncherObject(APPS_RES_ID) @@ -1238,6 +1241,28 @@ public final class LauncherInstrumentation { return object; } + @NonNull + private UiObject2 getHomeButton() { + UiModeManager uiManager = + (UiModeManager) getContext().getSystemService(Context.UI_MODE_SERVICE); + if (uiManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) { + return waitForAssistantHomeButton(); + } else { + return waitForNavigationUiObject("home"); + } + } + + /* Assistant Home button is present when system is in car mode. */ + @NonNull + UiObject2 waitForAssistantHomeButton() { + final UiObject2 object = mDevice.wait( + Until.findObject(By.res(ASSISTANT_PACKAGE, ASSISTANT_GO_HOME_RES_ID)), + WAIT_TIME_MS); + assertNotNull( + "Can't find an assistant UI object with id: " + ASSISTANT_GO_HOME_RES_ID, object); + return object; + } + @NonNull UiObject2 waitForNavigationUiObject(String resId) { String resPackage = getNavigationButtonResPackage();