From 6066c44ed8f835073755c74e40894f4f3f9a2430 Mon Sep 17 00:00:00 2001 From: Brian Isganitis Date: Wed, 13 Sep 2023 20:00:27 +0000 Subject: [PATCH] Support tapping outside container from above IME if visible. This is useful for tests where the keyboard is open, which can take up about half the screen. Test: Tapl Fix: 299514609 Flag: No Change-Id: I47e2fe7555140b4b54046d4d8ba6de1ebd38c6a4 --- .../launcher3/testing/TestInformationHandler.java | 9 +++++++++ .../launcher3/testing/shared/TestProtocol.java | 1 + .../launcher3/tapl/LauncherInstrumentation.java | 11 ++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 07a1b82f92..53fdb24452 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -32,6 +32,7 @@ import android.os.Bundle; import android.view.WindowInsets; import androidx.annotation.Nullable; +import androidx.core.view.WindowInsetsCompat; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; @@ -142,6 +143,14 @@ public class TestInformationHandler implements ResourceBasedOverride { }, this::getCurrentActivity); } + case TestProtocol.REQUEST_IME_INSETS: { + return getUIProperty(Bundle::putParcelable, activity -> { + WindowInsetsCompat insets = WindowInsetsCompat.toWindowInsetsCompat( + activity.getWindow().getDecorView().getRootWindowInsets()); + return insets.getInsets(WindowInsetsCompat.Type.ime()).toPlatformInsets(); + }, this::getCurrentActivity); + } + case TestProtocol.REQUEST_ICON_HEIGHT: { response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, mDeviceProfile.allAppsCellHeightPx); diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java index 9c95397a1b..5f5f598531 100644 --- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java +++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java @@ -102,6 +102,7 @@ public final class TestProtocol { public static final String REQUEST_WIDGETS_SCROLL_Y = "widgets-scroll-y"; public static final String REQUEST_TARGET_INSETS = "target-insets"; public static final String REQUEST_WINDOW_INSETS = "window-insets"; + public static final String REQUEST_IME_INSETS = "ime-insets"; public static final String REQUEST_PID = "pid"; public static final String REQUEST_FORCE_GC = "gc"; public static final String REQUEST_RECENT_TASKS_LIST = "recent-tasks-list"; diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 1bbef36be2..872fe6fe5c 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -341,6 +341,11 @@ public final class LauncherInstrumentation { .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD); } + Insets getImeInsets() { + return getTestInfo(TestProtocol.REQUEST_IME_INSETS) + .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD); + } + public boolean isTablet() { return getTestInfo(TestProtocol.REQUEST_IS_TABLET) .getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD); @@ -2111,7 +2116,11 @@ public final class LauncherInstrumentation { ? containerBounds.right + 1 : containerBounds.left - 1; } - int y = containerBounds.top + containerBounds.height() / 2; + // If IME is visible and overlaps the container bounds, touch above it. + int bottomBound = Math.min( + containerBounds.bottom, + getRealDisplaySize().y - getImeInsets().bottom); + int y = (bottomBound - containerBounds.top) / 2; final long downTime = SystemClock.uptimeMillis(); final Point tapTarget = new Point(x, y);