summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorSiarhei Vishniakou <svv@google.com>2018-06-08 22:49:30 +0100
committerSiarhei Vishniakou <svv@google.com>2018-07-05 16:29:51 +0100
commit91fa08ff1bd85ae41d71e1ed5ee72357c975ee3b (patch)
tree78a1d48c0aac3feeeb6212d1af5ac57a4986221f /core/java
parentbeac1471aab97797a66542e9fd22e5cfc5447c02 (diff)
Move displayId into InputEvent
Now both KeyEvent and MotionEvent will contain displayId. This will help with dispatching input events to specific displays. There are use cases where a particular input device is used for a specific display only, and it sends key events to the system. This will help with those usages. Test: atest view.MotionEventTest view.KeyEventTest Bug: 64258305 Change-Id: I75891037617ed60820d60736216a0d615ab5e3b0
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/InputEvent.java13
-rw-r--r--core/java/android/view/KeyEvent.java41
-rw-r--r--core/java/android/view/MotionEvent.java2
3 files changed, 55 insertions, 1 deletions
diff --git a/core/java/android/view/InputEvent.java b/core/java/android/view/InputEvent.java
index 1f2aab94958c..c25736495b0e 100644
--- a/core/java/android/view/InputEvent.java
+++ b/core/java/android/view/InputEvent.java
@@ -95,6 +95,19 @@ public abstract class InputEvent implements Parcelable {
}
/**
+ * Gets the display id of the event.
+ * @return The display id associated with the event.
+ * @hide
+ */
+ public abstract int getDisplayId();
+
+ /**
+ * Modifies the display id associated with the event
+ * @param displayId
+ * @hide
+ */
+ public abstract void setDisplayId(int displayId);
+ /**
* Copies the event.
*
* @return A deep copy of the event.
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 35546f8bf186..2c00391e7450 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -16,6 +16,8 @@
package android.view;
+import static android.view.Display.INVALID_DISPLAY;
+
import android.annotation.NonNull;
import android.annotation.TestApi;
import android.os.Parcel;
@@ -1246,6 +1248,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
private int mDeviceId;
private int mSource;
+ private int mDisplayId;
private int mMetaState;
private int mAction;
private int mKeyCode;
@@ -1473,6 +1476,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mScanCode = scancode;
mFlags = flags;
mSource = source;
+ mDisplayId = INVALID_DISPLAY;
}
/**
@@ -1497,6 +1501,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mDeviceId = deviceId;
mFlags = flags;
mSource = InputDevice.SOURCE_KEYBOARD;
+ mDisplayId = INVALID_DISPLAY;
}
/**
@@ -1511,6 +1516,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mMetaState = origEvent.mMetaState;
mDeviceId = origEvent.mDeviceId;
mSource = origEvent.mSource;
+ mDisplayId = origEvent.mDisplayId;
mScanCode = origEvent.mScanCode;
mFlags = origEvent.mFlags;
mCharacters = origEvent.mCharacters;
@@ -1537,6 +1543,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mMetaState = origEvent.mMetaState;
mDeviceId = origEvent.mDeviceId;
mSource = origEvent.mSource;
+ mDisplayId = origEvent.mDisplayId;
mScanCode = origEvent.mScanCode;
mFlags = origEvent.mFlags;
mCharacters = origEvent.mCharacters;
@@ -1564,7 +1571,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
*/
public static KeyEvent obtain(long downTime, long eventTime, int action,
int code, int repeat, int metaState,
- int deviceId, int scancode, int flags, int source, String characters) {
+ int deviceId, int scancode, int flags, int source, int displayId, String characters) {
KeyEvent ev = obtain();
ev.mDownTime = downTime;
ev.mEventTime = eventTime;
@@ -1576,11 +1583,26 @@ public class KeyEvent extends InputEvent implements Parcelable {
ev.mScanCode = scancode;
ev.mFlags = flags;
ev.mSource = source;
+ ev.mDisplayId = displayId;
ev.mCharacters = characters;
return ev;
}
/**
+ * Obtains a (potentially recycled) key event.
+ *
+ * @hide
+ */
+ public static KeyEvent obtain(long downTime, long eventTime, int action,
+ int code, int repeat, int metaState,
+ int deviceId, int scancode, int flags, int source, String characters) {
+ return obtain(downTime, eventTime, action, code, repeat, metaState, deviceId, scancode,
+ flags, source, INVALID_DISPLAY, characters);
+ }
+
+ /**
+
+ /**
* Obtains a (potentially recycled) copy of another key event.
*
* @hide
@@ -1597,6 +1619,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
ev.mScanCode = other.mScanCode;
ev.mFlags = other.mFlags;
ev.mSource = other.mSource;
+ ev.mDisplayId = other.mDisplayId;
ev.mCharacters = other.mCharacters;
return ev;
}
@@ -1683,6 +1706,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mMetaState = origEvent.mMetaState;
mDeviceId = origEvent.mDeviceId;
mSource = origEvent.mSource;
+ mDisplayId = origEvent.mDisplayId;
mScanCode = origEvent.mScanCode;
mFlags = origEvent.mFlags;
// Don't copy mCharacters, since one way or the other we'll lose it
@@ -1917,6 +1941,18 @@ public class KeyEvent extends InputEvent implements Parcelable {
mSource = source;
}
+ /** @hide */
+ @Override
+ public final int getDisplayId() {
+ return mDisplayId;
+ }
+
+ /** @hide */
+ @Override
+ public final void setDisplayId(int displayId) {
+ mDisplayId = displayId;
+ }
+
/**
* <p>Returns the state of the meta keys.</p>
*
@@ -2852,6 +2888,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
msg.append(", downTime=").append(mDownTime);
msg.append(", deviceId=").append(mDeviceId);
msg.append(", source=0x").append(Integer.toHexString(mSource));
+ msg.append(", displayId=").append(mDisplayId);
msg.append(" }");
return msg.toString();
}
@@ -2983,6 +3020,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
private KeyEvent(Parcel in) {
mDeviceId = in.readInt();
mSource = in.readInt();
+ mDisplayId = in.readInt();
mAction = in.readInt();
mKeyCode = in.readInt();
mRepeatCount = in.readInt();
@@ -2999,6 +3037,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
out.writeInt(mDeviceId);
out.writeInt(mSource);
+ out.writeInt(mDisplayId);
out.writeInt(mAction);
out.writeInt(mKeyCode);
out.writeInt(mRepeatCount);
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index 9148c27f6006..344806aa4d50 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -1943,11 +1943,13 @@ public final class MotionEvent extends InputEvent implements Parcelable {
}
/** @hide */
+ @Override
public int getDisplayId() {
return nativeGetDisplayId(mNativePtr);
}
/** @hide */
+ @Override
public void setDisplayId(int displayId) {
nativeSetDisplayId(mNativePtr, displayId);
}