summaryrefslogtreecommitdiff
path: root/core/java/android/view/InputEvent.java
diff options
context:
space:
mode:
authorGarfield Tan <xutan@google.com>2020-01-24 11:32:14 -0800
committerGarfield Tan <xutan@google.com>2020-02-24 12:45:27 -0800
commitc8362b24f672710a96b12c004577c91da587f0f8 (patch)
tree73d3a4bfb1a15121eed3a7dc3061b8f935c7a9c3 /core/java/android/view/InputEvent.java
parent27f83cdbcefd687632811996e25ece99f7e1ac69 (diff)
Add ID to InputEvent.
The interaction between Java and native code for KeyEvent and MotionEvent is different, so I used different arrangement to pass sequence number across JNI that keeps the consistency with other metadata. Unfortunately this new ID doesn't have absolute uniqueness guarantee so it can't replace InputEvent#getSequenceNumber() which is used with a strict in-process uniqueness assumption. Therefore only convert systrace related use to ID. Also expose ID generator through a static function in InputEvent so that everyone can use it. InputReader and InputDispatcher will use different instances. Bug: 144889238 Test: Build and run. Test: atest FrameworksCoreTests:KeyEventTest Test: atest FrameworksCoreTests:MotionEventTest Change-Id: Icbdcaee1d98948c05484865a4e15e55161ecfa69 Merged-In: Icbdcaee1d98948c05484865a4e15e55161ecfa69 (cherry picked from 29d21d4062f90a1c79971e5380426fc54b307807)
Diffstat (limited to 'core/java/android/view/InputEvent.java')
-rw-r--r--core/java/android/view/InputEvent.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/java/android/view/InputEvent.java b/core/java/android/view/InputEvent.java
index 5f9c4801ee66..cb9e746543f6 100644
--- a/core/java/android/view/InputEvent.java
+++ b/core/java/android/view/InputEvent.java
@@ -233,6 +233,21 @@ public abstract class InputEvent implements Parcelable {
return mSeq;
}
+ /**
+ * Gets the ID of this event. This is generated when an event is created and preserved until its
+ * last stage. It won't change just because the event crosses process boundary, but should
+ * change when making a copy with modifications.
+ * <p>
+ * To avoid exposing app usage to other processes this ID is generated from a CSPRNG. Therefore
+ * there isn't 100% guarantee on the uniqueness of this ID, though the chance of ID collisions
+ * is considerably low. The rule of thumb is not to rely on the uniqueness for production logic,
+ * but a good source for tracking an event (e.g. logging and profiling).
+ *
+ * @return The ID of this event.
+ * @hide
+ */
+ public abstract int getId();
+
public int describeContents() {
return 0;
}