diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index a15fc3e287..de762838af 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -30,7 +30,6 @@ import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.rule.ShellCommandRule.disableHeadsUpNotification; import static com.android.launcher3.util.rule.ShellCommandRule.getLauncherCommand; -import static com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -90,7 +89,6 @@ public class FallbackRecentsTest { public final SimpleActivityRule mActivityMonitor = new SimpleActivityRule(RecentsActivity.class); - public FallbackRecentsTest() throws RemoteException { Instrumentation instrumentation = getInstrumentation(); Context context = instrumentation.getContext(); @@ -161,8 +159,7 @@ public class FallbackRecentsTest { return mLauncher.getBackground().switchToOverview(); } - // TODO: Enable all modes after b/141184247 is fixed - @NavigationModeSwitch(mode = ZERO_BUTTON) + @NavigationModeSwitch @Test public void testOverview() throws Exception { startAppFast(getAppPackageName()); diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index d240a7256e..13b7b542f6 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -21,7 +21,6 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; -import android.os.Bundle; import android.os.Process; import android.text.Selection; import android.text.SpannableStringBuilder; @@ -33,6 +32,13 @@ import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.dynamicanimation.animation.DynamicAnimation; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.android.launcher3.AppInfo; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; @@ -45,9 +51,7 @@ import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.Utilities; -import com.android.launcher3.compat.AccessibilityManagerCompat; import com.android.launcher3.keyboard.FocusedItemDecorator; -import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.ItemInfoMatcher; @@ -58,13 +62,6 @@ import com.android.launcher3.views.BottomUserEducationView; import com.android.launcher3.views.RecyclerViewFastScroller; import com.android.launcher3.views.SpringRelativeLayout; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.dynamicanimation.animation.DynamicAnimation; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - /** * The all apps view container. */ @@ -612,17 +609,4 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo && verticalFadingEdge); } } - - @Override - public boolean performAccessibilityAction(int action, Bundle arguments) { - if (AccessibilityManagerCompat.processTestRequest( - mLauncher, TestProtocol.GET_SCROLL_MESSAGE, action, arguments, - response -> - response.putInt(TestProtocol.SCROLL_Y_FIELD, - getActiveRecyclerView().getCurrentScrollY()))) { - return true; - } - - return super.performAccessibilityAction(action, arguments); - } } diff --git a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java index 81c95cbdd4..d47a40e519 100644 --- a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java +++ b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java @@ -21,12 +21,9 @@ import android.os.Bundle; import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; -import android.view.accessibility.AccessibilityNodeInfo; -import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.Utilities; - -import java.util.function.Consumer; +import com.android.launcher3.testing.TestProtocol; public class AccessibilityManagerCompat { @@ -103,24 +100,6 @@ public class AccessibilityManagerCompat { return accessibilityManager; } - public static boolean processTestRequest(Context context, String eventTag, int action, - Bundle request, Consumer responseFiller) { - final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context); - if (accessibilityManager == null) return false; - - // The test sends a request via a ACTION_SET_TEXT. - if (action == AccessibilityNodeInfo.ACTION_SET_TEXT && - eventTag.equals(request.getCharSequence( - AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE))) { - final Bundle response = new Bundle(); - responseFiller.accept(response); - AccessibilityManagerCompat.sendEventToTest( - accessibilityManager, eventTag + TestProtocol.RESPONSE_MESSAGE_POSTFIX, response); - return true; - } - return false; - } - public static int getRecommendedTimeoutMillis(Context context, int originalTimeout, int flags) { if (Utilities.ATLEAST_Q) { return getManager(context).getRecommendedTimeoutMillis(originalTimeout, flags); diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 0d1d1a6709..f5f61cd4ca 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -15,9 +15,10 @@ */ package com.android.launcher3.testing; -import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static android.graphics.Bitmap.Config.ARGB_8888; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; + import android.content.Context; import android.graphics.Bitmap; import android.graphics.Color; @@ -120,6 +121,21 @@ public class TestInformationHandler implements ResourceBasedOverride { break; } + case TestProtocol.REQUEST_APPS_LIST_SCROLL_Y: { + try { + final int deferUpdatesFlags = MAIN_EXECUTOR.submit(() -> + mLauncher.getAppsView().getActiveRecyclerView().getCurrentScrollY()) + .get(); + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, + deferUpdatesFlags); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + break; + } + case TestProtocol.REQUEST_TOTAL_PSS_KB: { Debug.MemoryInfo mem = new Debug.MemoryInfo(); Debug.getMemoryInfo(mem); diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 19c557c9ff..8f7aa17100 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -20,13 +20,10 @@ package com.android.launcher3.testing; * Protocol for custom accessibility events for communication with UI Automation tests. */ public final class TestProtocol { - public static final String GET_SCROLL_MESSAGE = "TAPL_GET_SCROLL"; - public static final String SCROLL_Y_FIELD = "scrollY"; public static final String STATE_FIELD = "state"; public static final String SWITCHED_TO_STATE_MESSAGE = "TAPL_SWITCHED_TO_STATE"; public static final String SCROLL_FINISHED_MESSAGE = "TAPL_SCROLL_FINISHED"; public static final String PAUSE_DETECTED_MESSAGE = "TAPL_PAUSE_DETECTED"; - public static final String RESPONSE_MESSAGE_POSTFIX = "_RESPONSE"; 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; @@ -71,6 +68,7 @@ public final class TestProtocol { public static final String REQUEST_FREEZE_APP_LIST = "freeze-app-list"; public static final String REQUEST_UNFREEZE_APP_LIST = "unfreeze-app-list"; public static final String REQUEST_APP_LIST_FREEZE_FLAGS = "app-list-freeze-flags"; + public static final String REQUEST_APPS_LIST_SCROLL_Y = "apps-list-scroll-y"; public static final String REQUEST_OVERVIEW_LEFT_GESTURE_MARGIN = "overview-left-margin"; public static final String REQUEST_OVERVIEW_RIGHT_GESTURE_MARGIN = "overview-right-margin"; public static final String REQUEST_TOTAL_PSS_KB = "total_pss"; diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index f070280ea2..0359ff7e92 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -53,8 +53,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { return LauncherInstrumentation.ContainerType.ALL_APPS; } - private boolean hasClickableIcon( - UiObject2 allAppsContainer, UiObject2 appListRecycler, BySelector appIconSelector) { + private boolean hasClickableIcon(UiObject2 allAppsContainer, UiObject2 appListRecycler, + BySelector appIconSelector, int bottomOffset) { final UiObject2 icon = appListRecycler.findObject(appIconSelector); if (icon == null) { LauncherInstrumentation.log("hasClickableIcon: icon not visible"); @@ -66,6 +66,10 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { LauncherInstrumentation.log("hasClickableIcon: icon center is under search box"); return false; } + if (iconBounds.bottom > bottomOffset) { + LauncherInstrumentation.log("hasClickableIcon: icon center bellow bottom offset"); + return false; + } LauncherInstrumentation.log("hasClickableIcon: icon is clickable"); return true; } @@ -90,21 +94,26 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); final UiObject2 appListRecycler = mLauncher.waitForObjectInContainer(allAppsContainer, "apps_list_view"); + + int bottomGestureMargin = ResourceUtils.getNavbarSize( + ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1; + int bottomOffset = mLauncher.getDevice().getDisplayHeight() - bottomGestureMargin; allAppsContainer.setGestureMargins( 0, getSearchBox(allAppsContainer).getVisibleBounds().bottom + 1, 0, - ResourceUtils.getNavbarSize(ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, - mLauncher.getResources()) + 1); + bottomGestureMargin); final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher); - if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector)) { + if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, + bottomOffset)) { scrollBackToBeginning(); int attempts = 0; - int scroll = getScroll(allAppsContainer); + int scroll = getAllAppsScroll(); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) { - while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector)) { + while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, + bottomOffset)) { mLauncher.scroll(allAppsContainer, Direction.DOWN, 0.8f, null, 50); - final int newScroll = getScroll(allAppsContainer); + final int newScroll = getAllAppsScroll(); if (newScroll == scroll) break; mLauncher.assertTrue( @@ -118,7 +127,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { } mLauncher.assertTrue("Unable to scroll to a clickable icon: " + appName, - hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector)); + hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, + bottomOffset)); final UiObject2 appIcon = mLauncher.waitForObjectInContainer(appListRecycler, appIconSelector); @@ -136,9 +146,9 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { int attempts = 0; final Rect margins = new Rect(0, searchBox.getVisibleBounds().bottom + 1, 0, 5); - for (int scroll = getScroll(allAppsContainer); + for (int scroll = getAllAppsScroll(); scroll != 0; - scroll = getScroll(allAppsContainer)) { + scroll = getAllAppsScroll()) { mLauncher.assertTrue("Negative scroll position", scroll > 0); mLauncher.assertTrue( @@ -154,9 +164,10 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { } } - private int getScroll(UiObject2 allAppsContainer) { - return mLauncher.getAnswerFromLauncher(allAppsContainer, TestProtocol.GET_SCROLL_MESSAGE). - getInt(TestProtocol.SCROLL_Y_FIELD, -1); + private int getAllAppsScroll() { + return mLauncher.getTestInfo( + TestProtocol.REQUEST_APPS_LIST_SCROLL_Y) + .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); } private UiObject2 getSearchBox(UiObject2 allAppsContainer) { diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index bcce8ef579..9e66740b4b 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -104,7 +104,12 @@ public class Background extends LauncherInstrumentation.VisibleContainer { startY = endY = mLauncher.getDevice().getDisplayHeight() / 2; } - mLauncher.swipeToState(startX, startY, endX, endY, 10, expectedState); + if (mLauncher.isFallbackOverview()) { + mLauncher.linearGesture(startX, startY, endX, endY, 10); + new BaseOverview(mLauncher); + } else { + mLauncher.swipeToState(startX, startY, endX, endY, 10, expectedState); + } break; } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 383c3cef31..1c81b1096f 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -512,15 +512,6 @@ public final class LauncherInstrumentation { } } - Bundle getAnswerFromLauncher(UiObject2 view, String requestTag) { - // Send a fake set-text request to Launcher to initiate a response with requested data. - final String responseTag = requestTag + TestProtocol.RESPONSE_MESSAGE_POSTFIX; - return (Bundle) executeAndWaitForEvent( - () -> view.setText(requestTag), - event -> responseTag.equals(event.getClassName()), - "Launcher didn't respond to request: " + requestTag); - } - /** * Presses nav bar home button. * diff --git a/tests/tapl/com/android/launcher3/tapl/TestHelpers.java b/tests/tapl/com/android/launcher3/tapl/TestHelpers.java index a089a527ef..ba0dd73206 100644 --- a/tests/tapl/com/android/launcher3/tapl/TestHelpers.java +++ b/tests/tapl/com/android/launcher3/tapl/TestHelpers.java @@ -77,13 +77,18 @@ public class TestHelpers { return launchers.get(0).activityInfo; } - public static String getOverviewPackageName() { + public static ComponentName getOverviewComponentName() { Resources res = Resources.getSystem(); int id = res.getIdentifier("config_recentsComponentName", "string", "android"); if (id != 0) { - return ComponentName.unflattenFromString(res.getString(id)).getPackageName(); + return ComponentName.unflattenFromString(res.getString(id)); } - return "com.android.systemui"; + return new ComponentName("com.android.systemui", + "com.android.systemui.recents.RecentsActivity"); + } + + public static String getOverviewPackageName() { + return getOverviewComponentName().getPackageName(); } private static String truncateCrash(String text, int maxLines) {