diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index a2991c79e5..a75f32602e 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);