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
This commit is contained in:
Siarhei Vishniakou
2018-06-08 22:49:30 +01:00
parent beac1471aa
commit 91fa08ff1b
8 changed files with 135 additions and 16 deletions

View File

@@ -94,6 +94,19 @@ public abstract class InputEvent implements Parcelable {
return (getSource() & source) == source;
}
/**
* 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.
*

View File

@@ -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,10 +1583,25 @@ 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.
*
@@ -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);

View File

@@ -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);
}