Loading tests/tapl/com/android/launcher3/tapl/AllApps.java +13 −10 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import androidx.test.uiautomator.UiObject2; import com.android.launcher3.ResourceUtils; import com.android.launcher3.testing.TestProtocol; import java.util.stream.Collectors; /** * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview. */ Loading Loading @@ -75,7 +77,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { return false; } if (iconBounds.bottom > displayBottom) { LauncherInstrumentation.log("hasClickableIcon: icon center bellow bottom offset"); LauncherInstrumentation.log("hasClickableIcon: icon bottom below bottom offset"); return false; } LauncherInstrumentation.log("hasClickableIcon: icon is clickable"); Loading Loading @@ -108,11 +110,6 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1; int deviceHeight = mLauncher.getDevice().getDisplayHeight(); int displayBottom = deviceHeight - bottomGestureMargin; allAppsContainer.setGestureMargins( 0, getSearchBox(allAppsContainer).getVisibleBounds().bottom + 1, 0, bottomGestureMargin); final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher); if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, displayBottom)) { Loading @@ -124,7 +121,12 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { displayBottom)) { mLauncher.scrollToLastVisibleRow( allAppsContainer, mLauncher.getObjectsInContainer(allAppsContainer, "icon"), mLauncher.getObjectsInContainer(allAppsContainer, "icon") .stream() .filter(icon -> icon.getVisibleBounds().bottom <= displayBottom) .collect(Collectors.toList()), searchBox.getVisibleBounds().bottom - allAppsContainer.getVisibleBounds().top); final int newScroll = getAllAppsScroll(); Loading Loading @@ -171,7 +173,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, ++attempts <= MAX_SCROLL_ATTEMPTS); mLauncher.scroll(allAppsContainer, Direction.UP, margins, 12); mLauncher.scroll( allAppsContainer, Direction.UP, margins, 12, false); } try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled up")) { Loading Loading @@ -199,7 +202,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); // Start the gesture in the center to avoid starting at elements near the top. mLauncher.scroll( allAppsContainer, Direction.DOWN, new Rect(0, 0, 0, mHeight / 2), 10); allAppsContainer, Direction.DOWN, new Rect(0, 0, 0, mHeight / 2), 10, false); verifyActiveContainer(); } } Loading @@ -213,7 +216,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); // Start the gesture in the center, for symmetry with forward. mLauncher.scroll( allAppsContainer, Direction.UP, new Rect(0, mHeight / 2, 0, 0), 10); allAppsContainer, Direction.UP, new Rect(0, mHeight / 2, 0, 0), 10, false); verifyActiveContainer(); } } Loading tests/tapl/com/android/launcher3/tapl/Background.java +1 −1 Original line number Diff line number Diff line Loading @@ -106,7 +106,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } if (mLauncher.isFallbackOverview()) { mLauncher.linearGesture(startX, startY, endX, endY, 10); mLauncher.linearGesture(startX, startY, endX, endY, 10, false); new BaseOverview(mLauncher); } else { mLauncher.swipeToState(startX, startY, endX, endY, 10, expectedState); Loading tests/tapl/com/android/launcher3/tapl/BaseOverview.java +4 −2 Original line number Diff line number Diff line Loading @@ -55,7 +55,8 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int leftMargin = mLauncher.getTestInfo( TestProtocol.REQUEST_OVERVIEW_LEFT_GESTURE_MARGIN). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); mLauncher.scroll(overview, Direction.LEFT, new Rect(leftMargin + 1, 0, 0, 0), 20); mLauncher.scroll( overview, Direction.LEFT, new Rect(leftMargin + 1, 0, 0, 0), 20, false); verifyActiveContainer(); } } Loading Loading @@ -89,7 +90,8 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int rightMargin = mLauncher.getTestInfo( TestProtocol.REQUEST_OVERVIEW_RIGHT_GESTURE_MARGIN). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); mLauncher.scroll(overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20); mLauncher.scroll( overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false); verifyActiveContainer(); } } Loading tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +28 −18 Original line number Diff line number Diff line Loading @@ -544,7 +544,8 @@ public final class LauncherInstrumentation { linearGesture( displaySize.x / 2, displaySize.y - 1, displaySize.x / 2, 0, ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME); ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME, false); try (LauncherInstrumentation.Closable c = addContextLayer( "Swiped up from context menu to home")) { waitUntilGone("deep_shortcuts_container"); Loading Loading @@ -769,7 +770,7 @@ public final class LauncherInstrumentation { void swipeToState(int startX, int startY, int endX, int endY, int steps, int expectedState) { final Bundle parcel = (Bundle) executeAndWaitForEvent( () -> linearGesture(startX, startY, endX, endY, steps), () -> linearGesture(startX, startY, endX, endY, steps, false), event -> TestProtocol.SWITCHED_TO_STATE_MESSAGE.equals(event.getClassName()), "Swipe failed to receive an event for the swipe end"); assertEquals("Swipe switched launcher to a wrong state;", Loading @@ -782,33 +783,38 @@ public final class LauncherInstrumentation { ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, getResources()) + 1; } int getBottomGestureMargin(UiObject2 container) { return container.getVisibleBounds().bottom - getRealDisplaySize().y + getBottomGestureSize(); int getBottomGestureMarginInContainer(UiObject2 container) { final int bottomGestureStartOnScreen = getRealDisplaySize().y - getBottomGestureSize(); return container.getVisibleBounds().bottom - bottomGestureStartOnScreen; } void scrollToLastVisibleRow(UiObject2 container, Collection<UiObject2> items, int topPadding) { void scrollToLastVisibleRow( UiObject2 container, Collection<UiObject2> items, int topPaddingInContainer) { final UiObject2 lowestItem = Collections.max(items, (i1, i2) -> Integer.compare(i1.getVisibleBounds().top, i2.getVisibleBounds().top)); final int gestureStart = lowestItem.getVisibleBounds().top + getTouchSlop(); final int distance = gestureStart - container.getVisibleBounds().top - topPadding; final int bottomMargin = container.getVisibleBounds().height() - distance; final int itemRowCurrentTopOnScreen = lowestItem.getVisibleBounds().top; final Rect containerRect = container.getVisibleBounds(); final int itemRowNewTopOnScreen = containerRect.top + topPaddingInContainer; final int distance = itemRowCurrentTopOnScreen - itemRowNewTopOnScreen + getTouchSlop(); // TODO: Make the gesture steps dependent on the distance so that it can run for various // screen sizes final int bottomGestureMarginInContainer = getBottomGestureMarginInContainer(container); scroll( container, Direction.DOWN, new Rect( 0, containerRect.height() - distance - bottomGestureMarginInContainer, 0, 0, Math.max(bottomMargin, getBottomGestureMargin(container))), 80); bottomGestureMarginInContainer), 10, true); } void scroll(UiObject2 container, Direction direction, Rect margins, int steps) { void scroll( UiObject2 container, Direction direction, Rect margins, int steps, boolean slowDown) { final Rect rect = container.getVisibleBounds(); if (margins != null) { rect.left += margins.left; Loading Loading @@ -853,7 +859,7 @@ public final class LauncherInstrumentation { } executeAndWaitForEvent( () -> linearGesture(startX, startY, endX, endY, steps), () -> linearGesture(startX, startY, endX, endY, steps, slowDown), event -> TestProtocol.SCROLL_FINISHED_MESSAGE.equals(event.getClassName()), "Didn't receive a scroll end message: " + startX + ", " + startY + ", " + endX + ", " + endY); Loading @@ -861,13 +867,17 @@ public final class LauncherInstrumentation { // Inject a swipe gesture. Inject exactly 'steps' motion points, incrementing event time by a // fixed interval each time. void linearGesture(int startX, int startY, int endX, int endY, int steps) { void linearGesture(int startX, int startY, int endX, int endY, int steps, boolean slowDown) { log("linearGesture: " + startX + ", " + startY + " -> " + endX + ", " + endY); final long downTime = SystemClock.uptimeMillis(); final Point start = new Point(startX, startY); final Point end = new Point(endX, endY); sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start); final long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, start, end); long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, start, end); if (slowDown) { endTime = movePointer(downTime, endTime + GESTURE_STEP_MS, 5 * GESTURE_STEP_MS, end, end); } sendPointer(downTime, endTime, MotionEvent.ACTION_UP, end); } Loading tests/tapl/com/android/launcher3/tapl/OverviewTask.java +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public final class OverviewTask { final Rect taskBounds = mTask.getVisibleBounds(); final int centerX = taskBounds.centerX(); final int centerY = taskBounds.centerY(); mLauncher.linearGesture(centerX, centerY, centerX, 0, 10); mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false); mLauncher.waitForIdle(); } } Loading Loading
tests/tapl/com/android/launcher3/tapl/AllApps.java +13 −10 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import androidx.test.uiautomator.UiObject2; import com.android.launcher3.ResourceUtils; import com.android.launcher3.testing.TestProtocol; import java.util.stream.Collectors; /** * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview. */ Loading Loading @@ -75,7 +77,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { return false; } if (iconBounds.bottom > displayBottom) { LauncherInstrumentation.log("hasClickableIcon: icon center bellow bottom offset"); LauncherInstrumentation.log("hasClickableIcon: icon bottom below bottom offset"); return false; } LauncherInstrumentation.log("hasClickableIcon: icon is clickable"); Loading Loading @@ -108,11 +110,6 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1; int deviceHeight = mLauncher.getDevice().getDisplayHeight(); int displayBottom = deviceHeight - bottomGestureMargin; allAppsContainer.setGestureMargins( 0, getSearchBox(allAppsContainer).getVisibleBounds().bottom + 1, 0, bottomGestureMargin); final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher); if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, displayBottom)) { Loading @@ -124,7 +121,12 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { displayBottom)) { mLauncher.scrollToLastVisibleRow( allAppsContainer, mLauncher.getObjectsInContainer(allAppsContainer, "icon"), mLauncher.getObjectsInContainer(allAppsContainer, "icon") .stream() .filter(icon -> icon.getVisibleBounds().bottom <= displayBottom) .collect(Collectors.toList()), searchBox.getVisibleBounds().bottom - allAppsContainer.getVisibleBounds().top); final int newScroll = getAllAppsScroll(); Loading Loading @@ -171,7 +173,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, ++attempts <= MAX_SCROLL_ATTEMPTS); mLauncher.scroll(allAppsContainer, Direction.UP, margins, 12); mLauncher.scroll( allAppsContainer, Direction.UP, margins, 12, false); } try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled up")) { Loading Loading @@ -199,7 +202,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); // Start the gesture in the center to avoid starting at elements near the top. mLauncher.scroll( allAppsContainer, Direction.DOWN, new Rect(0, 0, 0, mHeight / 2), 10); allAppsContainer, Direction.DOWN, new Rect(0, 0, 0, mHeight / 2), 10, false); verifyActiveContainer(); } } Loading @@ -213,7 +216,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); // Start the gesture in the center, for symmetry with forward. mLauncher.scroll( allAppsContainer, Direction.UP, new Rect(0, mHeight / 2, 0, 0), 10); allAppsContainer, Direction.UP, new Rect(0, mHeight / 2, 0, 0), 10, false); verifyActiveContainer(); } } Loading
tests/tapl/com/android/launcher3/tapl/Background.java +1 −1 Original line number Diff line number Diff line Loading @@ -106,7 +106,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } if (mLauncher.isFallbackOverview()) { mLauncher.linearGesture(startX, startY, endX, endY, 10); mLauncher.linearGesture(startX, startY, endX, endY, 10, false); new BaseOverview(mLauncher); } else { mLauncher.swipeToState(startX, startY, endX, endY, 10, expectedState); Loading
tests/tapl/com/android/launcher3/tapl/BaseOverview.java +4 −2 Original line number Diff line number Diff line Loading @@ -55,7 +55,8 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int leftMargin = mLauncher.getTestInfo( TestProtocol.REQUEST_OVERVIEW_LEFT_GESTURE_MARGIN). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); mLauncher.scroll(overview, Direction.LEFT, new Rect(leftMargin + 1, 0, 0, 0), 20); mLauncher.scroll( overview, Direction.LEFT, new Rect(leftMargin + 1, 0, 0, 0), 20, false); verifyActiveContainer(); } } Loading Loading @@ -89,7 +90,8 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int rightMargin = mLauncher.getTestInfo( TestProtocol.REQUEST_OVERVIEW_RIGHT_GESTURE_MARGIN). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); mLauncher.scroll(overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20); mLauncher.scroll( overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false); verifyActiveContainer(); } } Loading
tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +28 −18 Original line number Diff line number Diff line Loading @@ -544,7 +544,8 @@ public final class LauncherInstrumentation { linearGesture( displaySize.x / 2, displaySize.y - 1, displaySize.x / 2, 0, ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME); ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME, false); try (LauncherInstrumentation.Closable c = addContextLayer( "Swiped up from context menu to home")) { waitUntilGone("deep_shortcuts_container"); Loading Loading @@ -769,7 +770,7 @@ public final class LauncherInstrumentation { void swipeToState(int startX, int startY, int endX, int endY, int steps, int expectedState) { final Bundle parcel = (Bundle) executeAndWaitForEvent( () -> linearGesture(startX, startY, endX, endY, steps), () -> linearGesture(startX, startY, endX, endY, steps, false), event -> TestProtocol.SWITCHED_TO_STATE_MESSAGE.equals(event.getClassName()), "Swipe failed to receive an event for the swipe end"); assertEquals("Swipe switched launcher to a wrong state;", Loading @@ -782,33 +783,38 @@ public final class LauncherInstrumentation { ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, getResources()) + 1; } int getBottomGestureMargin(UiObject2 container) { return container.getVisibleBounds().bottom - getRealDisplaySize().y + getBottomGestureSize(); int getBottomGestureMarginInContainer(UiObject2 container) { final int bottomGestureStartOnScreen = getRealDisplaySize().y - getBottomGestureSize(); return container.getVisibleBounds().bottom - bottomGestureStartOnScreen; } void scrollToLastVisibleRow(UiObject2 container, Collection<UiObject2> items, int topPadding) { void scrollToLastVisibleRow( UiObject2 container, Collection<UiObject2> items, int topPaddingInContainer) { final UiObject2 lowestItem = Collections.max(items, (i1, i2) -> Integer.compare(i1.getVisibleBounds().top, i2.getVisibleBounds().top)); final int gestureStart = lowestItem.getVisibleBounds().top + getTouchSlop(); final int distance = gestureStart - container.getVisibleBounds().top - topPadding; final int bottomMargin = container.getVisibleBounds().height() - distance; final int itemRowCurrentTopOnScreen = lowestItem.getVisibleBounds().top; final Rect containerRect = container.getVisibleBounds(); final int itemRowNewTopOnScreen = containerRect.top + topPaddingInContainer; final int distance = itemRowCurrentTopOnScreen - itemRowNewTopOnScreen + getTouchSlop(); // TODO: Make the gesture steps dependent on the distance so that it can run for various // screen sizes final int bottomGestureMarginInContainer = getBottomGestureMarginInContainer(container); scroll( container, Direction.DOWN, new Rect( 0, containerRect.height() - distance - bottomGestureMarginInContainer, 0, 0, Math.max(bottomMargin, getBottomGestureMargin(container))), 80); bottomGestureMarginInContainer), 10, true); } void scroll(UiObject2 container, Direction direction, Rect margins, int steps) { void scroll( UiObject2 container, Direction direction, Rect margins, int steps, boolean slowDown) { final Rect rect = container.getVisibleBounds(); if (margins != null) { rect.left += margins.left; Loading Loading @@ -853,7 +859,7 @@ public final class LauncherInstrumentation { } executeAndWaitForEvent( () -> linearGesture(startX, startY, endX, endY, steps), () -> linearGesture(startX, startY, endX, endY, steps, slowDown), event -> TestProtocol.SCROLL_FINISHED_MESSAGE.equals(event.getClassName()), "Didn't receive a scroll end message: " + startX + ", " + startY + ", " + endX + ", " + endY); Loading @@ -861,13 +867,17 @@ public final class LauncherInstrumentation { // Inject a swipe gesture. Inject exactly 'steps' motion points, incrementing event time by a // fixed interval each time. void linearGesture(int startX, int startY, int endX, int endY, int steps) { void linearGesture(int startX, int startY, int endX, int endY, int steps, boolean slowDown) { log("linearGesture: " + startX + ", " + startY + " -> " + endX + ", " + endY); final long downTime = SystemClock.uptimeMillis(); final Point start = new Point(startX, startY); final Point end = new Point(endX, endY); sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start); final long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, start, end); long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, start, end); if (slowDown) { endTime = movePointer(downTime, endTime + GESTURE_STEP_MS, 5 * GESTURE_STEP_MS, end, end); } sendPointer(downTime, endTime, MotionEvent.ACTION_UP, end); } Loading
tests/tapl/com/android/launcher3/tapl/OverviewTask.java +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public final class OverviewTask { final Rect taskBounds = mTask.getVisibleBounds(); final int centerX = taskBounds.centerX(); final int centerY = taskBounds.centerY(); mLauncher.linearGesture(centerX, centerY, centerX, 0, 10); mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false); mLauncher.waitForIdle(); } } Loading