From 42a88b9681f8f7c6aa5ae5d4f868203d1e94a15d Mon Sep 17 00:00:00 2001 From: vadimt Date: Wed, 13 Feb 2019 15:10:20 -0800 Subject: [PATCH] Sending state ordinals from Launcher to TAPL This improves diagnostics. Test: TAPL tests Change-Id: I0ebb533513405372ea7c58a36910160cfb6d8368 --- .../quickstep/LauncherActivityControllerHelper.java | 3 +-- src/com/android/launcher3/TestProtocol.java | 1 + .../launcher3/compat/AccessibilityManagerCompat.java | 7 +++++-- .../touch/AbstractStateChangeTouchController.java | 3 +-- .../android/launcher3/tapl/AllAppsFromOverview.java | 3 ++- tests/tapl/com/android/launcher3/tapl/Background.java | 7 ++++--- tests/tapl/com/android/launcher3/tapl/Home.java | 2 +- .../launcher3/tapl/LauncherInstrumentation.java | 11 ++++++++--- tests/tapl/com/android/launcher3/tapl/Overview.java | 3 ++- tests/tapl/com/android/launcher3/tapl/Workspace.java | 3 ++- 10 files changed, 27 insertions(+), 16 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java index a3c942e2c9..b50c381b3e 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java @@ -210,8 +210,7 @@ public final class LauncherActivityControllerHelper implements ActivityControlHe // Optimization, hide the all apps view to prevent layout while initializing activity.getAppsView().getContentView().setVisibility(View.GONE); - AccessibilityManagerCompat.sendEventToTest( - activity, TestProtocol.SWITCHED_TO_STATE_MESSAGE); + AccessibilityManagerCompat.sendStateEventToTest(activity, fromState.ordinal); } else { fromState = startState; } diff --git a/src/com/android/launcher3/TestProtocol.java b/src/com/android/launcher3/TestProtocol.java index 0a3b86d630..008b624d11 100644 --- a/src/com/android/launcher3/TestProtocol.java +++ b/src/com/android/launcher3/TestProtocol.java @@ -22,6 +22,7 @@ package com.android.launcher3; 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 RESPONSE_MESSAGE_POSTFIX = "_RESPONSE"; } diff --git a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java index 6feb1e97ef..51e914c441 100644 --- a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java +++ b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java @@ -52,11 +52,14 @@ public class AccessibilityManagerCompat { return (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); } - public static void sendEventToTest(Context context, String eventTag) { + public static void sendStateEventToTest(Context context, int stateOrdinal) { final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context); if (accessibilityManager == null) return; - sendEventToTest(accessibilityManager, eventTag, null); + final Bundle parcel = new Bundle(); + parcel.putInt(TestProtocol.STATE_FIELD, stateOrdinal); + + sendEventToTest(accessibilityManager, TestProtocol.SWITCHED_TO_STATE_MESSAGE, parcel); } private static void sendEventToTest( diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java index 0e2ed6cc2b..c125c10d7a 100644 --- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java +++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java @@ -522,8 +522,7 @@ public abstract class AbstractStateChangeTouchController } mLauncher.getStateManager().goToState(targetState, false /* animated */); - AccessibilityManagerCompat.sendEventToTest( - mLauncher, TestProtocol.SWITCHED_TO_STATE_MESSAGE); + AccessibilityManagerCompat.sendStateEventToTest(mLauncher, targetState.ordinal); } } diff --git a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java index 42817c1af7..3e4b1f3caa 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java @@ -45,7 +45,8 @@ public final class AllAppsFromOverview extends AllApps { final Point start = qsb.getVisibleCenter(); final int endY = (int) (mLauncher.getDevice().getDisplayHeight() * 0.6); LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe"); - mLauncher.swipe(start.x, start.y, start.x, endY); + mLauncher.swipe( + start.x, start.y, start.x, endY, LauncherInstrumentation.OVERVIEW_STATE_ORDINAL); return new Overview(mLauncher); } diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 08d28897b1..790e938f86 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -50,21 +50,22 @@ public class Background extends LauncherInstrumentation.VisibleContainer { @NonNull public BaseOverview switchToOverview() { verifyActiveContainer(); - goToOverviewUnchecked(); + goToOverviewUnchecked(LauncherInstrumentation.BACKGROUND_APP_STATE_ORDINAL); assertTrue("Overview not visible", mLauncher.getDevice().wait( Until.hasObject(By.pkg(getOverviewPackageName())), WAIT_TIME_MS)); return new BaseOverview(mLauncher); } - protected void goToOverviewUnchecked() { + protected void goToOverviewUnchecked(int expectedState) { if (mLauncher.isSwipeUpEnabled()) { final int height = mLauncher.getDevice().getDisplayHeight(); final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame"); mLauncher.swipe( navBar.getVisibleBounds().centerX(), navBar.getVisibleBounds().centerY(), - navBar.getVisibleBounds().centerX(), height - 400); + navBar.getVisibleBounds().centerX(), height - 400, + expectedState); } else { mLauncher.getSystemUiObject("recent_apps").click(); } diff --git a/tests/tapl/com/android/launcher3/tapl/Home.java b/tests/tapl/com/android/launcher3/tapl/Home.java index 522ce14908..bf857f0c39 100644 --- a/tests/tapl/com/android/launcher3/tapl/Home.java +++ b/tests/tapl/com/android/launcher3/tapl/Home.java @@ -47,7 +47,7 @@ public abstract class Home extends Background { @Override public Overview switchToOverview() { verifyActiveContainer(); - goToOverviewUnchecked(); + goToOverviewUnchecked(LauncherInstrumentation.OVERVIEW_STATE_ORDINAL); return new Overview(mLauncher); } } \ No newline at end of file diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 6b76012ce8..6aa18d35fa 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -54,6 +54,9 @@ import java.util.concurrent.TimeoutException; public final class LauncherInstrumentation { private static final String TAG = "Tapl"; + static final int OVERVIEW_STATE_ORDINAL = 2; + static final int APPS_LIST_STATE_ORDINAL = 4; + static final int BACKGROUND_APP_STATE_ORDINAL = 5; // Types for launcher containers that the user is interacting with. "Background" is a // pseudo-container corresponding to inactive launcher covered by another app. @@ -154,7 +157,7 @@ public final class LauncherInstrumentation { fail(message + ". " + "Actual: " + actual); } - static public void assertEquals(String message, int expected, int actual) { + static private void assertEquals(String message, int expected, int actual) { if (expected != actual) { fail(message + " expected: " + expected + " but was: " + actual); } @@ -416,12 +419,14 @@ public final class LauncherInstrumentation { return mDevice; } - void swipe(int startX, int startY, int endX, int endY) { - executeAndWaitForEvent( + void swipe(int startX, int startY, int endX, int endY, int expectedState) { + final Bundle parcel = (Bundle) executeAndWaitForEvent( () -> mDevice.swipe(startX, startY, endX, endY, 60), event -> TestProtocol.SWITCHED_TO_STATE_MESSAGE.equals(event.getClassName()), "Swipe failed to receive an event for the swipe end: " + startX + ", " + startY + ", " + endX + ", " + endY); + assertEquals("Swipe switched launcher to a wrong state", + expectedState, parcel.getInt(TestProtocol.STATE_FIELD)); } void waitForIdle() { diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java index 9e0c07ffe7..1f7ed29086 100644 --- a/tests/tapl/com/android/launcher3/tapl/Overview.java +++ b/tests/tapl/com/android/launcher3/tapl/Overview.java @@ -51,7 +51,8 @@ public final class Overview extends BaseOverview { final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame"); final Point start = navBar.getVisibleCenter(); LauncherInstrumentation.log("Overview.switchToAllApps before swipe"); - mLauncher.swipe(start.x, start.y, start.x, 0); + mLauncher.swipe( + start.x, start.y, start.x, 0, LauncherInstrumentation.APPS_LIST_STATE_ORDINAL); return new AllAppsFromOverview(mLauncher); } diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index e10c4fb2e5..4f86603dcd 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -55,7 +55,8 @@ public final class Workspace extends Home { start.x, start.y, start.x, - endY + endY, + LauncherInstrumentation.APPS_LIST_STATE_ORDINAL ); return new AllApps(mLauncher);