From 8b820867220d07bf4a0e970ed1416bc8729fc9b7 Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Wed, 24 Mar 2021 12:17:02 -0700 Subject: [PATCH] Add reporting to monitor apps incorrectly using getRaw getRawX/Y are implementation specific and are always display relative. If any apps are using this, they should stop unless the app is specifically trying to handle raw events. Usage of getRaw will break under: multi-window, size-compat, letterbox, display-areas, and independent window rotation. Bug: 179274888 Test: adb shell dumpsys platform_compat Change-Id: I2d87d0a62d7a28e15811dda7f9d16996e8159f69 --- core/java/android/hardware/input/InputManager.java | 8 ++++++++ core/java/android/view/MotionEvent.java | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 01fd3964df1d2..c83ccfa81f957 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -222,6 +222,14 @@ public final class InputManager { @ChangeId public static final long BLOCK_FLAG_SLIPPERY = android.os.IInputConstants.BLOCK_FLAG_SLIPPERY; + /** + * Check whether apps are using MotionEvent.getRawX/Y. This is implementation-specific, and + * thus undefined for most 3p app usages. + * @hide + */ + @ChangeId + public static final long APP_USES_RAW_INPUT_COORDS = 179274888L; + /** * Input Event Injection Synchronization Mode: None. * Never blocks. Injection is asynchronous and is assumed always to be successful. diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index 6801c27851a9a..dea32cd96756e 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -16,6 +16,7 @@ package android.view; +import static android.hardware.input.InputManager.APP_USES_RAW_INPUT_COORDS; import static android.view.Display.DEFAULT_DISPLAY; import static java.lang.annotation.RetentionPolicy.SOURCE; @@ -23,6 +24,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.Nullable; import android.annotation.TestApi; +import android.compat.Compatibility; import android.compat.annotation.UnsupportedAppUsage; import android.graphics.Matrix; import android.os.Build; @@ -2672,6 +2674,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #AXIS_X */ public final float getRawX() { + Compatibility.reportChange(APP_USES_RAW_INPUT_COORDS); return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); } @@ -2685,6 +2688,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #AXIS_Y */ public final float getRawY() { + Compatibility.reportChange(APP_USES_RAW_INPUT_COORDS); return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); } @@ -2701,6 +2705,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #AXIS_X */ public float getRawX(int pointerIndex) { + Compatibility.reportChange(APP_USES_RAW_INPUT_COORDS); return nativeGetRawAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT); } @@ -2717,6 +2722,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #AXIS_Y */ public float getRawY(int pointerIndex) { + Compatibility.reportChange(APP_USES_RAW_INPUT_COORDS); return nativeGetRawAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT); }