From ada314d073946335e04681419dc1a8504c786cde Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 25 Apr 2024 16:01:54 -0700 Subject: Use aidl definitions for MotionEvent flag values This will ensure that there is a single source of truth for MotionEvent flags, and will help developers that add new flags understand that the constants need to be added in multiple places, instead of just in java. Bug: 309829647 Test: m sync Change-Id: I7dadde669ba936d44c284c2698c18a71548dc101 --- core/java/android/view/KeyEvent.java | 5 +++-- core/java/android/view/MotionEvent.java | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java index 1ee9509b116a..154f1fedbcfa 100644 --- a/core/java/android/view/KeyEvent.java +++ b/core/java/android/view/KeyEvent.java @@ -25,6 +25,7 @@ import android.annotation.Nullable; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; +import android.os.IInputConstants; import android.os.Parcel; import android.os.Parcelable; import android.text.method.MetaKeyKeyListener; @@ -1295,7 +1296,7 @@ public class KeyEvent extends InputEvent implements Parcelable { * action for a key until it receives an up or the long press timeout has * expired. */ - public static final int FLAG_CANCELED = 0x20; + public static final int FLAG_CANCELED = IInputConstants.INPUT_EVENT_FLAG_CANCELED; /** * This key event was generated by a virtual (on-screen) hard key area. @@ -1363,7 +1364,7 @@ public class KeyEvent extends InputEvent implements Parcelable { * @see #isTainted * @see #setTainted */ - public static final int FLAG_TAINTED = 0x80000000; + public static final int FLAG_TAINTED = IInputConstants.INPUT_EVENT_FLAG_TAINTED; /** * Returns the maximum keycode. diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index 56a24e4705b7..38f9a91ae44f 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -16,7 +16,15 @@ package android.view; +import static android.os.IInputConstants.INPUT_EVENT_FLAG_CANCELED; +import static android.os.IInputConstants.MOTION_EVENT_FLAG_HOVER_EXIT_PENDING; import static android.os.IInputConstants.INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT; +import static android.os.IInputConstants.MOTION_EVENT_FLAG_IS_GENERATED_GESTURE; +import static android.os.IInputConstants.MOTION_EVENT_FLAG_NO_FOCUS_CHANGE; +import static android.os.IInputConstants.INPUT_EVENT_FLAG_TAINTED; +import static android.os.IInputConstants.MOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS; +import static android.os.IInputConstants.MOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; +import static android.os.IInputConstants.MOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; import static android.view.Display.DEFAULT_DISPLAY; import static java.lang.annotation.RetentionPolicy.SOURCE; @@ -448,7 +456,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * to drop the suspect touches or to take additional precautions to confirm the user's * actual intent. */ - public static final int FLAG_WINDOW_IS_OBSCURED = 0x1; + public static final int FLAG_WINDOW_IS_OBSCURED = MOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; /** * This flag indicates that the window that received this motion event is partly @@ -464,7 +472,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { * Unlike FLAG_WINDOW_IS_OBSCURED, this is only true if the window that received this event is * obstructed in areas other than the touched location. */ - public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2; + public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = + MOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; /** * This private flag is only set on {@link #ACTION_HOVER_MOVE} events and indicates that @@ -472,7 +481,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * prevent generating redundant {@link #ACTION_HOVER_ENTER} events. * @hide */ - public static final int FLAG_HOVER_EXIT_PENDING = 0x4; + public static final int FLAG_HOVER_EXIT_PENDING = MOTION_EVENT_FLAG_HOVER_EXIT_PENDING; /** * This flag indicates that the event has been generated by a gesture generator. It @@ -480,7 +489,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * * @hide */ - public static final int FLAG_IS_GENERATED_GESTURE = 0x8; + public static final int FLAG_IS_GENERATED_GESTURE = MOTION_EVENT_FLAG_IS_GENERATED_GESTURE; /** * This flag is only set for events with {@link #ACTION_POINTER_UP} and {@link #ACTION_CANCEL}. @@ -493,7 +502,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #ACTION_POINTER_UP * @see #ACTION_CANCEL */ - public static final int FLAG_CANCELED = 0x20; + public static final int FLAG_CANCELED = INPUT_EVENT_FLAG_CANCELED; /** * This flag indicates that the event will not cause a focus change if it is directed to an @@ -502,7 +511,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * window into focus. * @hide */ - public static final int FLAG_NO_FOCUS_CHANGE = 0x40; + public static final int FLAG_NO_FOCUS_CHANGE = MOTION_EVENT_FLAG_NO_FOCUS_CHANGE; /** * This flag indicates that this event was modified by or generated from an accessibility @@ -521,7 +530,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #isTainted * @see #setTainted */ - public static final int FLAG_TAINTED = 0x80000000; + public static final int FLAG_TAINTED = INPUT_EVENT_FLAG_TAINTED; /** * Private flag indicating that this event was synthesized by the system and should be delivered @@ -536,7 +545,8 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @see #isTargetAccessibilityFocus() * @see #setTargetAccessibilityFocus(boolean) */ - public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000; + public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = + MOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS; /** * Flag indicating the motion event intersected the top edge of the screen. -- cgit v1.2.3-59-g8ed1b