diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java index 9be9294d7c..221ce480f8 100644 --- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -161,6 +161,10 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, SystemUiProxy.INSTANCE.get(mContext).isDragAndDropReady()); return response; + + case TestProtocol.REQUEST_REFRESH_OVERVIEW_TARGET: + runOnTISBinder(TouchInteractionService.TISBinder::refreshOverviewTarget); + return response; } return super.call(method, arg, extras); diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 02d0f39373..02fcc68cee 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -409,18 +409,16 @@ public class TouchInteractionService extends Service { * Sets a proxy to bypass swipe up behavior */ public void setSwipeUpProxy(Function proxy) { - TouchInteractionService tis = mTis.get(); - if (tis == null) return; - tis.mSwipeUpProxyProvider = proxy != null ? proxy : (i -> null); + executeForTouchInteractionService( + tis -> tis.mSwipeUpProxyProvider = proxy != null ? proxy : (i -> null)); } /** * Sets the task id where gestures should be blocked */ public void setGestureBlockedTaskId(int taskId) { - TouchInteractionService tis = mTis.get(); - if (tis == null) return; - tis.mDeviceState.setGestureBlockingTaskId(taskId); + executeForTouchInteractionService( + tis -> tis.mDeviceState.setGestureBlockingTaskId(taskId)); } /** Sets a listener to be run on Overview Target updates. */ @@ -434,6 +432,12 @@ public class TouchInteractionService extends Service { mOnOverviewTargetChangeListener = null; } } + + /** Refreshes the current overview target. */ + public void refreshOverviewTarget() { + executeForTouchInteractionService(tis -> tis.onOverviewTargetChange( + tis.mOverviewComponentObserver.isHomeAndOverviewSame())); + } } private static boolean sConnected = false; diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java index f5aa8206a8..54a1c08e56 100644 --- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java +++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java @@ -126,6 +126,7 @@ public final class TestProtocol { "taskbar-all-apps-top-padding"; public static final String REQUEST_ALL_APPS_TOP_PADDING = "all-apps-top-padding"; public static final String REQUEST_ALL_APPS_BOTTOM_PADDING = "all-apps-bottom-padding"; + public static final String REQUEST_REFRESH_OVERVIEW_TARGET = "refresh-overview-target"; public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center"; diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index b82fa35b14..dbb3cc366f 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -16,6 +16,8 @@ package com.android.launcher3.tapl; +import static android.view.KeyEvent.KEYCODE_META_RIGHT; + import static com.android.launcher3.tapl.LauncherInstrumentation.DEFAULT_POLL_INTERVAL; import static com.android.launcher3.tapl.LauncherInstrumentation.WAIT_TIME_MS; @@ -370,6 +372,17 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer } } + /** Presses the meta keyboard shortcut to dismiss AllApps. */ + public void dismissByKeyboardShortcut() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + mLauncher.getDevice().pressKeyCode(KEYCODE_META_RIGHT); + try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "pressed meta key")) { + verifyVisibleContainerOnDismiss(); + } + } + } + protected abstract void verifyVisibleContainerOnDismiss(); /** diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index bbd74679a9..86b4f90fd9 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -1343,6 +1343,16 @@ public final class LauncherInstrumentation { } } + void waitForObjectFocused(UiObject2 object, String waitReason) { + try { + assertTrue("Timed out waiting for object to be focused for " + waitReason + " " + + object.getResourceName(), + object.wait(Until.focused(true), WAIT_TIME_MS)); + } catch (StaleObjectException e) { + fail("The object disappeared from screen"); + } + } + @NonNull UiObject2 waitForObjectInContainer(UiObject2 container, BySelector selector) { return waitForObjectsInContainer(container, selector).get(0); @@ -2043,6 +2053,12 @@ public final class LauncherInstrumentation { getTestInfo(TestProtocol.REQUEST_RECREATE_TASKBAR); } + // TODO(b/270393900): Remove with ENABLE_ALL_APPS_SEARCH_IN_TASKBAR flag cleanup. + /** Refreshes the known overview target in TIS. */ + public void refreshOverviewTarget() { + getTestInfo(TestProtocol.REQUEST_REFRESH_OVERVIEW_TARGET); + } + public List getHotseatIconNames() { return getTestInfo(TestProtocol.REQUEST_HOTSEAT_ICON_NAMES) .getStringArrayList(TestProtocol.TEST_INFO_RESPONSE_FIELD); diff --git a/tests/tapl/com/android/launcher3/tapl/Qsb.java b/tests/tapl/com/android/launcher3/tapl/Qsb.java index 0f2aff8b62..5ca80a3fde 100644 --- a/tests/tapl/com/android/launcher3/tapl/Qsb.java +++ b/tests/tapl/com/android/launcher3/tapl/Qsb.java @@ -25,7 +25,7 @@ import androidx.test.uiautomator.Until; /** * Operations on qsb from either Home screen or AllApp screen. */ -public abstract class Qsb { +public abstract class Qsb implements SearchInputSource { private static final String ASSISTANT_APP_PACKAGE = "com.google.android.googlequicksearchbox"; private static final String ASSISTANT_ICON_RES_ID = "mic_icon"; @@ -125,6 +125,16 @@ public abstract class Qsb { } } + @Override + public LauncherInstrumentation getLauncher() { + return mLauncher; + } + + @Override + public SearchResultFromQsb getSearchResultForInput() { + return createSearchResult(); + } + protected SearchResultFromQsb createSearchResult() { return new SearchResultFromQsb(mLauncher); } diff --git a/tests/tapl/com/android/launcher3/tapl/SearchInputSource.java b/tests/tapl/com/android/launcher3/tapl/SearchInputSource.java new file mode 100644 index 0000000000..032948f851 --- /dev/null +++ b/tests/tapl/com/android/launcher3/tapl/SearchInputSource.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.tapl; + +import androidx.test.uiautomator.UiObject2; + +import com.android.launcher3.testing.shared.TestProtocol; + +/** + * Container that can be used to input a search query and retrieve a {@link SearchResultFromQsb} + * instance. + */ +interface SearchInputSource { + String INPUT_RES = "input"; + + /** Set the already focused search input edit text and update search results. */ + default SearchResultFromQsb searchForInput(String input) { + LauncherInstrumentation launcher = getLauncher(); + try (LauncherInstrumentation.Closable c = launcher.addContextLayer( + "want to search for result with an input"); + LauncherInstrumentation.Closable e = launcher.eventsCheck()) { + launcher.executeAndWaitForLauncherEvent( + () -> { + UiObject2 editText = launcher.waitForLauncherObject(INPUT_RES); + launcher.waitForObjectFocused(editText, "search input"); + editText.setText(input); + }, + event -> TestProtocol.SEARCH_RESULT_COMPLETE.equals(event.getClassName()), + () -> "Didn't receive a search result completed message", "searching"); + return getSearchResultForInput(); + } + } + + /** This method requires public access, however should not be called in tests. */ + LauncherInstrumentation getLauncher(); + + /** This method requires public access, however should not be called in tests. */ + SearchResultFromQsb getSearchResultForInput(); +} diff --git a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java index 513d6bb3fa..f0a8aa26c0 100644 --- a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java +++ b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java @@ -20,16 +20,12 @@ import android.widget.TextView; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; -import com.android.launcher3.testing.shared.TestProtocol; - import java.util.ArrayList; /** * Operations on search result page opened from qsb. */ -public class SearchResultFromQsb { - // The input resource id in the search box. - private static final String INPUT_RES = "input"; +public class SearchResultFromQsb implements SearchInputSource { private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background"; // This particular ID change should happen with caution @@ -41,18 +37,6 @@ public class SearchResultFromQsb { mLauncher.waitForLauncherObject("search_container_all_apps"); } - /** Set the input to the search input edit text and update search results. */ - public void searchForInput(String input) { - try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( - "want to search for result with an input"); - LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { - mLauncher.executeAndWaitForLauncherEvent( - () -> mLauncher.waitForLauncherObject(INPUT_RES).setText(input), - event -> TestProtocol.SEARCH_RESULT_COMPLETE.equals(event.getClassName()), - () -> "Didn't receive a search result completed message", "searching"); - } - } - /** Find the app from search results with app name. */ public AppIcon findAppIcon(String appName) { UiObject2 icon = mLauncher.waitForLauncherObject(By.clazz(TextView.class).text(appName)); @@ -114,4 +98,14 @@ public class SearchResultFromQsb { protected void verifyVisibleContainerOnDismiss() { mLauncher.getWorkspace(); } + + @Override + public LauncherInstrumentation getLauncher() { + return mLauncher; + } + + @Override + public SearchResultFromQsb getSearchResultForInput() { + return this; + } } diff --git a/tests/tapl/com/android/launcher3/tapl/Taskbar.java b/tests/tapl/com/android/launcher3/tapl/Taskbar.java index 4293ee880f..da26694aae 100644 --- a/tests/tapl/com/android/launcher3/tapl/Taskbar.java +++ b/tests/tapl/com/android/launcher3/tapl/Taskbar.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.tapl; +import static android.view.KeyEvent.KEYCODE_META_RIGHT; + import static com.android.launcher3.tapl.LauncherInstrumentation.TASKBAR_RES_ID; import static com.android.launcher3.testing.shared.TestProtocol.REQUEST_DISABLE_MANUAL_TASKBAR_STASHING; import static com.android.launcher3.testing.shared.TestProtocol.REQUEST_ENABLE_MANUAL_TASKBAR_STASHING; @@ -105,6 +107,17 @@ public final class Taskbar { } } + /** Opens the Taskbar all apps page with the meta keyboard shortcut. */ + public TaskbarAllApps openAllAppsFromKeyboardShortcut() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + mLauncher.getDevice().pressKeyCode(KEYCODE_META_RIGHT); + try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "pressed meta key")) { + return getAllApps(); + } + } + } + /** Returns {@link TaskbarAllApps} if it is open, otherwise fails. */ public TaskbarAllApps getAllApps() { try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index cf48ebc8a6..fc589bd108 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -16,6 +16,7 @@ package com.android.launcher3.tapl; +import static android.view.KeyEvent.KEYCODE_META_RIGHT; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_SCROLLED; import static com.android.launcher3.testing.shared.TestProtocol.ALL_APPS_STATE_ORDINAL; @@ -115,6 +116,20 @@ public final class Workspace extends Home { } } + /** Opens the Launcher all apps page with the meta keyboard shortcut. */ + public HomeAllApps openAllAppsFromKeyboardShortcut() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = + mLauncher.addContextLayer("want to open all apps search")) { + verifyActiveContainer(); + mLauncher.getDevice().pressKeyCode(KEYCODE_META_RIGHT); + try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( + "pressed meta key")) { + return new HomeAllApps(mLauncher); + } + } + } + /** * Returns the home qsb. *