Merge "Add hmac to InputEvent and scale to MotionEvent"

This commit is contained in:
TreeHugger Robot
2020-01-28 05:23:31 +00:00
committed by Android (Google) Code Review
8 changed files with 228 additions and 214 deletions

View File

@@ -19,6 +19,7 @@ package android.view;
import static android.view.Display.INVALID_DISPLAY;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
@@ -1269,6 +1270,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private int mSource;
private int mDisplayId;
private @Nullable byte[] mHmac;
@UnsupportedAppUsage
private int mMetaState;
@UnsupportedAppUsage
@@ -1546,6 +1548,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mDeviceId = origEvent.mDeviceId;
mSource = origEvent.mSource;
mDisplayId = origEvent.mDisplayId;
mHmac = origEvent.mHmac == null ? null : origEvent.mHmac.clone();
mScanCode = origEvent.mScanCode;
mFlags = origEvent.mFlags;
mCharacters = origEvent.mCharacters;
@@ -1573,6 +1576,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mDeviceId = origEvent.mDeviceId;
mSource = origEvent.mSource;
mDisplayId = origEvent.mDisplayId;
mHmac = null; // Don't copy HMAC, it will be invalid because eventTime is changing
mScanCode = origEvent.mScanCode;
mFlags = origEvent.mFlags;
mCharacters = origEvent.mCharacters;
@@ -1600,7 +1604,8 @@ 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, int displayId, String characters) {
int deviceId, int scancode, int flags, int source, int displayId, @Nullable byte[] hmac,
String characters) {
KeyEvent ev = obtain();
ev.mDownTime = downTime;
ev.mEventTime = eventTime;
@@ -1613,6 +1618,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
ev.mFlags = flags;
ev.mSource = source;
ev.mDisplayId = displayId;
ev.mHmac = hmac;
ev.mCharacters = characters;
return ev;
}
@@ -1627,7 +1633,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
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);
flags, source, INVALID_DISPLAY, null /* hmac */, characters);
}
/**
@@ -1650,6 +1656,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
ev.mFlags = other.mFlags;
ev.mSource = other.mSource;
ev.mDisplayId = other.mDisplayId;
ev.mHmac = other.mHmac == null ? null : other.mHmac.clone();
ev.mCharacters = other.mCharacters;
return ev;
}
@@ -1738,6 +1745,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mDeviceId = origEvent.mDeviceId;
mSource = origEvent.mSource;
mDisplayId = origEvent.mDisplayId;
mHmac = null; // Don't copy the hmac, it will be invalid since action is changing
mScanCode = origEvent.mScanCode;
mFlags = origEvent.mFlags;
// Don't copy mCharacters, since one way or the other we'll lose it
@@ -3091,6 +3099,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
mDeviceId = in.readInt();
mSource = in.readInt();
mDisplayId = in.readInt();
mHmac = in.createByteArray();
mAction = in.readInt();
mKeyCode = in.readInt();
mRepeatCount = in.readInt();
@@ -3109,6 +3118,7 @@ public class KeyEvent extends InputEvent implements Parcelable {
out.writeInt(mDeviceId);
out.writeInt(mSource);
out.writeInt(mDisplayId);
out.writeByteArray(mHmac);
out.writeInt(mAction);
out.writeInt(mKeyCode);
out.writeInt(mRepeatCount);

View File

@@ -113,10 +113,13 @@ status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* even
}
uint32_t publishedSeq = mNextPublishedSeq++;
status_t status = mInputPublisher.publishKeyEvent(publishedSeq,
event->getDeviceId(), event->getSource(), event->getDisplayId(), event->getAction(),
event->getFlags(), event->getKeyCode(), event->getScanCode(), event->getMetaState(),
event->getRepeatCount(), event->getDownTime(), event->getEventTime());
status_t status =
mInputPublisher.publishKeyEvent(publishedSeq, event->getDeviceId(), event->getSource(),
event->getDisplayId(), event->getHmac(),
event->getAction(), event->getFlags(),
event->getKeyCode(), event->getScanCode(),
event->getMetaState(), event->getRepeatCount(),
event->getDownTime(), event->getEventTime());
if (status) {
ALOGW("Failed to send key event on channel '%s'. status=%d",
getInputChannelName().c_str(), status);
@@ -134,17 +137,24 @@ status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent
uint32_t publishedSeq;
for (size_t i = 0; i <= event->getHistorySize(); i++) {
publishedSeq = mNextPublishedSeq++;
status_t status = mInputPublisher.publishMotionEvent(publishedSeq,
event->getDeviceId(), event->getSource(), event->getDisplayId(),
event->getAction(), event->getActionButton(), event->getFlags(),
event->getEdgeFlags(), event->getMetaState(), event->getButtonState(),
event->getClassification(),
event->getXOffset(), event->getYOffset(),
event->getXPrecision(), event->getYPrecision(),
event->getRawXCursorPosition(), event->getRawYCursorPosition(),
event->getDownTime(), event->getHistoricalEventTime(i),
event->getPointerCount(), event->getPointerProperties(),
event->getHistoricalRawPointerCoords(0, i));
status_t status =
mInputPublisher.publishMotionEvent(publishedSeq, event->getDeviceId(),
event->getSource(), event->getDisplayId(),
event->getHmac(), event->getAction(),
event->getActionButton(), event->getFlags(),
event->getEdgeFlags(), event->getMetaState(),
event->getButtonState(),
event->getClassification(), event->getXScale(),
event->getYScale(), event->getXOffset(),
event->getYOffset(), event->getXPrecision(),
event->getYPrecision(),
event->getRawXCursorPosition(),
event->getRawYCursorPosition(),
event->getDownTime(),
event->getHistoricalEventTime(i),
event->getPointerCount(),
event->getPointerProperties(),
event->getHistoricalRawPointerCoords(0, i));
if (status) {
ALOGW("Failed to send motion event sample on channel '%s'. status=%d",
getInputChannelName().c_str(), status);

View File

@@ -20,15 +20,53 @@
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/Log.h>
#include <utils/Log.h>
#include <input/Input.h>
#include <nativehelper/ScopedPrimitiveArray.h>
#include <nativehelper/ScopedUtfChars.h>
#include <utils/Log.h>
#include <optional>
#include "android_view_KeyEvent.h"
#include "core_jni_helpers.h"
namespace android {
/**
* Convert an std::array of bytes into a Java object.
*/
template <size_t N>
static ScopedLocalRef<jbyteArray> toJbyteArray(JNIEnv* env, const std::array<uint8_t, N>& data) {
ScopedLocalRef<jbyteArray> array(env, env->NewByteArray(N));
if (array.get() == nullptr) {
jniThrowException(env, "java/lang/OutOfMemoryError", nullptr);
return array;
}
static_assert(sizeof(char) == sizeof(uint8_t));
env->SetByteArrayRegion(array.get(), 0, N, reinterpret_cast<const signed char*>(data.data()));
return array;
}
/**
* Convert a Java object into an std::array of bytes of size N.
* If the object is null, or the length is unexpected, return std::nullopt.
*/
template <size_t N>
static std::optional<std::array<uint8_t, N>> fromJobject(JNIEnv* env, jobject object) {
if (object == nullptr) {
return std::nullopt;
}
jbyteArray javaArray = reinterpret_cast<jbyteArray>(object);
ScopedByteArrayRO bytes(env, javaArray);
if (bytes.size() != N) {
ALOGE("Could not initialize array from java object, expected length %zu but got %zu", N,
bytes.size());
return std::nullopt;
}
std::array<uint8_t, N> array;
std::move(bytes.get(), bytes.get() + N, array.begin());
return array;
}
// ----------------------------------------------------------------------------
static struct {
@@ -40,6 +78,7 @@ static struct {
jfieldID mDeviceId;
jfieldID mSource;
jfieldID mDisplayId;
jfieldID mHmac;
jfieldID mMetaState;
jfieldID mAction;
jfieldID mKeyCode;
@@ -54,20 +93,16 @@ static struct {
// ----------------------------------------------------------------------------
jobject android_view_KeyEvent_fromNative(JNIEnv* env, const KeyEvent* event) {
jobject eventObj = env->CallStaticObjectMethod(gKeyEventClassInfo.clazz,
gKeyEventClassInfo.obtain,
nanoseconds_to_milliseconds(event->getDownTime()),
nanoseconds_to_milliseconds(event->getEventTime()),
event->getAction(),
event->getKeyCode(),
event->getRepeatCount(),
event->getMetaState(),
event->getDeviceId(),
event->getScanCode(),
event->getFlags(),
event->getSource(),
event->getDisplayId(),
NULL);
ScopedLocalRef<jbyteArray> hmac = toJbyteArray(env, event->getHmac());
jobject eventObj =
env->CallStaticObjectMethod(gKeyEventClassInfo.clazz, gKeyEventClassInfo.obtain,
nanoseconds_to_milliseconds(event->getDownTime()),
nanoseconds_to_milliseconds(event->getEventTime()),
event->getAction(), event->getKeyCode(),
event->getRepeatCount(), event->getMetaState(),
event->getDeviceId(), event->getScanCode(),
event->getFlags(), event->getSource(),
event->getDisplayId(), hmac.get(), NULL);
if (env->ExceptionCheck()) {
ALOGE("An exception occurred while obtaining a key event.");
LOGE_EX(env);
@@ -82,6 +117,11 @@ status_t android_view_KeyEvent_toNative(JNIEnv* env, jobject eventObj,
jint deviceId = env->GetIntField(eventObj, gKeyEventClassInfo.mDeviceId);
jint source = env->GetIntField(eventObj, gKeyEventClassInfo.mSource);
jint displayId = env->GetIntField(eventObj, gKeyEventClassInfo.mDisplayId);
jobject hmacObj = env->GetObjectField(eventObj, gKeyEventClassInfo.mHmac);
std::optional<std::array<uint8_t, 32>> hmac = fromJobject<32>(env, hmacObj);
if (!hmac) {
hmac = INVALID_HMAC;
}
jint metaState = env->GetIntField(eventObj, gKeyEventClassInfo.mMetaState);
jint action = env->GetIntField(eventObj, gKeyEventClassInfo.mAction);
jint keyCode = env->GetIntField(eventObj, gKeyEventClassInfo.mKeyCode);
@@ -91,10 +131,9 @@ status_t android_view_KeyEvent_toNative(JNIEnv* env, jobject eventObj,
jlong downTime = env->GetLongField(eventObj, gKeyEventClassInfo.mDownTime);
jlong eventTime = env->GetLongField(eventObj, gKeyEventClassInfo.mEventTime);
event->initialize(deviceId, source, displayId, action, flags, keyCode, scanCode, metaState,
repeatCount,
milliseconds_to_nanoseconds(downTime),
milliseconds_to_nanoseconds(eventTime));
event->initialize(deviceId, source, displayId, *hmac, action, flags, keyCode, scanCode,
metaState, repeatCount, milliseconds_to_nanoseconds(downTime),
milliseconds_to_nanoseconds(eventTime));
return OK;
}
@@ -134,8 +173,9 @@ int register_android_view_KeyEvent(JNIEnv* env) {
jclass clazz = FindClassOrDie(env, "android/view/KeyEvent");
gKeyEventClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
gKeyEventClassInfo.obtain = GetStaticMethodIDOrDie(env, gKeyEventClassInfo.clazz,
"obtain", "(JJIIIIIIIIILjava/lang/String;)Landroid/view/KeyEvent;");
gKeyEventClassInfo.obtain =
GetStaticMethodIDOrDie(env, gKeyEventClassInfo.clazz, "obtain",
"(JJIIIIIIIII[BLjava/lang/String;)Landroid/view/KeyEvent;");
gKeyEventClassInfo.recycle = GetMethodIDOrDie(env, gKeyEventClassInfo.clazz,
"recycle", "()V");
@@ -143,6 +183,7 @@ int register_android_view_KeyEvent(JNIEnv* env) {
gKeyEventClassInfo.mSource = GetFieldIDOrDie(env, gKeyEventClassInfo.clazz, "mSource", "I");
gKeyEventClassInfo.mDisplayId = GetFieldIDOrDie(env, gKeyEventClassInfo.clazz, "mDisplayId",
"I");
gKeyEventClassInfo.mHmac = GetFieldIDOrDie(env, gKeyEventClassInfo.clazz, "mHmac", "[B");
gKeyEventClassInfo.mMetaState = GetFieldIDOrDie(env, gKeyEventClassInfo.clazz, "mMetaState",
"I");
gKeyEventClassInfo.mAction = GetFieldIDOrDie(env, gKeyEventClassInfo.clazz, "mAction", "I");

View File

@@ -42,4 +42,4 @@ extern status_t android_view_KeyEvent_recycle(JNIEnv* env, jobject eventObj);
} // namespace android
#endif // _ANDROID_OS_KEYEVENT_H
#endif // _ANDROID_VIEW_KEYEVENT_H

View File

@@ -330,14 +330,12 @@ static void pointerPropertiesFromNative(JNIEnv* env, const PointerProperties* po
// ----------------------------------------------------------------------------
static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
jlong nativePtr,
jint deviceId, jint source, jint displayId, jint action, jint flags, jint edgeFlags,
jint metaState, jint buttonState, jint classification,
jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
jlong downTimeNanos, jlong eventTimeNanos,
jint pointerCount, jobjectArray pointerPropertiesObjArray,
jobjectArray pointerCoordsObjArray) {
static jlong android_view_MotionEvent_nativeInitialize(
JNIEnv* env, jclass clazz, jlong nativePtr, jint deviceId, jint source, jint displayId,
jint action, jint flags, jint edgeFlags, jint metaState, jint buttonState,
jint classification, jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
jlong downTimeNanos, jlong eventTimeNanos, jint pointerCount,
jobjectArray pointerPropertiesObjArray, jobjectArray pointerCoordsObjArray) {
if (!validatePointerCount(env, pointerCount)
|| !validatePointerPropertiesArray(env, pointerPropertiesObjArray, pointerCount)
|| !validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) {
@@ -371,11 +369,12 @@ static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz
env->DeleteLocalRef(pointerCoordsObj);
}
event->initialize(deviceId, source, displayId, action, 0, flags, edgeFlags, metaState,
buttonState, static_cast<MotionClassification>(classification),
xOffset, yOffset, xPrecision, yPrecision,
AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, rawPointerCoords);
event->initialize(deviceId, source, displayId, INVALID_HMAC, action, 0, flags, edgeFlags,
metaState, buttonState, static_cast<MotionClassification>(classification),
1 /*xScale*/, 1 /*yScale*/, xOffset, yOffset, xPrecision, yPrecision,
AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
downTimeNanos, eventTimeNanos, pointerCount, pointerProperties,
rawPointerCoords);
return reinterpret_cast<jlong>(event);
@@ -757,155 +756,76 @@ static void android_view_MotionEvent_nativeScale(jlong nativePtr, jfloat scale)
// ----------------------------------------------------------------------------
static const JNINativeMethod gMotionEventMethods[] = {
/* name, signature, funcPtr */
{ "nativeInitialize",
"(JIIIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
"[Landroid/view/MotionEvent$PointerCoords;)J",
(void*)android_view_MotionEvent_nativeInitialize },
{ "nativeDispose",
"(J)V",
(void*)android_view_MotionEvent_nativeDispose },
{ "nativeAddBatch",
"(JJ[Landroid/view/MotionEvent$PointerCoords;I)V",
(void*)android_view_MotionEvent_nativeAddBatch },
{ "nativeReadFromParcel",
"(JLandroid/os/Parcel;)J",
(void*)android_view_MotionEvent_nativeReadFromParcel },
{ "nativeWriteToParcel",
"(JLandroid/os/Parcel;)V",
(void*)android_view_MotionEvent_nativeWriteToParcel },
{ "nativeAxisToString", "(I)Ljava/lang/String;",
(void*)android_view_MotionEvent_nativeAxisToString },
{ "nativeAxisFromString", "(Ljava/lang/String;)I",
(void*)android_view_MotionEvent_nativeAxisFromString },
{ "nativeGetPointerProperties",
"(JILandroid/view/MotionEvent$PointerProperties;)V",
(void*)android_view_MotionEvent_nativeGetPointerProperties },
{ "nativeGetPointerCoords",
"(JIILandroid/view/MotionEvent$PointerCoords;)V",
(void*)android_view_MotionEvent_nativeGetPointerCoords },
/* name, signature, funcPtr */
{"nativeInitialize",
"(JIIIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
"[Landroid/view/MotionEvent$PointerCoords;)J",
(void*)android_view_MotionEvent_nativeInitialize},
{"nativeDispose", "(J)V", (void*)android_view_MotionEvent_nativeDispose},
{"nativeAddBatch", "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V",
(void*)android_view_MotionEvent_nativeAddBatch},
{"nativeReadFromParcel", "(JLandroid/os/Parcel;)J",
(void*)android_view_MotionEvent_nativeReadFromParcel},
{"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
(void*)android_view_MotionEvent_nativeWriteToParcel},
{"nativeAxisToString", "(I)Ljava/lang/String;",
(void*)android_view_MotionEvent_nativeAxisToString},
{"nativeAxisFromString", "(Ljava/lang/String;)I",
(void*)android_view_MotionEvent_nativeAxisFromString},
{"nativeGetPointerProperties", "(JILandroid/view/MotionEvent$PointerProperties;)V",
(void*)android_view_MotionEvent_nativeGetPointerProperties},
{"nativeGetPointerCoords", "(JIILandroid/view/MotionEvent$PointerCoords;)V",
(void*)android_view_MotionEvent_nativeGetPointerCoords},
// --------------- @FastNative ----------------------
{ "nativeGetPointerId",
"(JI)I",
(void*)android_view_MotionEvent_nativeGetPointerId },
{ "nativeGetToolType",
"(JI)I",
(void*)android_view_MotionEvent_nativeGetToolType },
{ "nativeGetEventTimeNanos",
"(JI)J",
(void*)android_view_MotionEvent_nativeGetEventTimeNanos },
{ "nativeGetRawAxisValue",
"(JIII)F",
(void*)android_view_MotionEvent_nativeGetRawAxisValue },
{ "nativeGetAxisValue",
"(JIII)F",
(void*)android_view_MotionEvent_nativeGetAxisValue },
{ "nativeTransform",
"(JLandroid/graphics/Matrix;)V",
(void*)android_view_MotionEvent_nativeTransform },
// --------------- @FastNative ----------------------
{"nativeGetPointerId", "(JI)I", (void*)android_view_MotionEvent_nativeGetPointerId},
{"nativeGetToolType", "(JI)I", (void*)android_view_MotionEvent_nativeGetToolType},
{"nativeGetEventTimeNanos", "(JI)J",
(void*)android_view_MotionEvent_nativeGetEventTimeNanos},
{"nativeGetRawAxisValue", "(JIII)F", (void*)android_view_MotionEvent_nativeGetRawAxisValue},
{"nativeGetAxisValue", "(JIII)F", (void*)android_view_MotionEvent_nativeGetAxisValue},
{"nativeTransform", "(JLandroid/graphics/Matrix;)V",
(void*)android_view_MotionEvent_nativeTransform},
// --------------- @CriticalNative ------------------
// --------------- @CriticalNative ------------------
{ "nativeCopy",
"(JJZ)J",
(void*)android_view_MotionEvent_nativeCopy },
{ "nativeGetDeviceId",
"(J)I",
(void*)android_view_MotionEvent_nativeGetDeviceId },
{ "nativeGetSource",
"(J)I",
(void*)android_view_MotionEvent_nativeGetSource },
{ "nativeSetSource",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetSource },
{ "nativeGetDisplayId",
"(J)I",
(void*)android_view_MotionEvent_nativeGetDisplayId },
{ "nativeSetDisplayId",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetDisplayId },
{ "nativeGetAction",
"(J)I",
(void*)android_view_MotionEvent_nativeGetAction },
{ "nativeSetAction",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetAction },
{ "nativeGetActionButton",
"(J)I",
(void*)android_view_MotionEvent_nativeGetActionButton},
{ "nativeSetActionButton",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetActionButton},
{ "nativeIsTouchEvent",
"(J)Z",
(void*)android_view_MotionEvent_nativeIsTouchEvent },
{ "nativeGetFlags",
"(J)I",
(void*)android_view_MotionEvent_nativeGetFlags },
{ "nativeSetFlags",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetFlags },
{ "nativeGetEdgeFlags",
"(J)I",
(void*)android_view_MotionEvent_nativeGetEdgeFlags },
{ "nativeSetEdgeFlags",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetEdgeFlags },
{ "nativeGetMetaState",
"(J)I",
(void*)android_view_MotionEvent_nativeGetMetaState },
{ "nativeGetButtonState",
"(J)I",
(void*)android_view_MotionEvent_nativeGetButtonState },
{ "nativeSetButtonState",
"(JI)V",
(void*)android_view_MotionEvent_nativeSetButtonState },
{ "nativeGetClassification",
"(J)I",
(void*)android_view_MotionEvent_nativeGetClassification },
{ "nativeOffsetLocation",
"(JFF)V",
(void*)android_view_MotionEvent_nativeOffsetLocation },
{ "nativeGetXOffset",
"(J)F",
(void*)android_view_MotionEvent_nativeGetXOffset },
{ "nativeGetYOffset",
"(J)F",
(void*)android_view_MotionEvent_nativeGetYOffset },
{ "nativeGetXPrecision",
"(J)F",
(void*)android_view_MotionEvent_nativeGetXPrecision },
{ "nativeGetYPrecision",
"(J)F",
(void*)android_view_MotionEvent_nativeGetYPrecision },
{ "nativeGetXCursorPosition",
"(J)F",
(void*)android_view_MotionEvent_nativeGetXCursorPosition },
{ "nativeGetYCursorPosition",
"(J)F",
(void*)android_view_MotionEvent_nativeGetYCursorPosition },
{ "nativeSetCursorPosition",
"(JFF)V",
(void*)android_view_MotionEvent_nativeSetCursorPosition },
{ "nativeGetDownTimeNanos",
"(J)J",
(void*)android_view_MotionEvent_nativeGetDownTimeNanos },
{ "nativeSetDownTimeNanos",
"(JJ)V",
(void*)android_view_MotionEvent_nativeSetDownTimeNanos },
{ "nativeGetPointerCount",
"(J)I",
(void*)android_view_MotionEvent_nativeGetPointerCount },
{ "nativeFindPointerIndex",
"(JI)I",
(void*)android_view_MotionEvent_nativeFindPointerIndex },
{ "nativeGetHistorySize",
"(J)I",
(void*)android_view_MotionEvent_nativeGetHistorySize },
{ "nativeScale",
"(JF)V",
(void*)android_view_MotionEvent_nativeScale },
{"nativeCopy", "(JJZ)J", (void*)android_view_MotionEvent_nativeCopy},
{"nativeGetDeviceId", "(J)I", (void*)android_view_MotionEvent_nativeGetDeviceId},
{"nativeGetSource", "(J)I", (void*)android_view_MotionEvent_nativeGetSource},
{"nativeSetSource", "(JI)V", (void*)android_view_MotionEvent_nativeSetSource},
{"nativeGetDisplayId", "(J)I", (void*)android_view_MotionEvent_nativeGetDisplayId},
{"nativeSetDisplayId", "(JI)V", (void*)android_view_MotionEvent_nativeSetDisplayId},
{"nativeGetAction", "(J)I", (void*)android_view_MotionEvent_nativeGetAction},
{"nativeSetAction", "(JI)V", (void*)android_view_MotionEvent_nativeSetAction},
{"nativeGetActionButton", "(J)I", (void*)android_view_MotionEvent_nativeGetActionButton},
{"nativeSetActionButton", "(JI)V", (void*)android_view_MotionEvent_nativeSetActionButton},
{"nativeIsTouchEvent", "(J)Z", (void*)android_view_MotionEvent_nativeIsTouchEvent},
{"nativeGetFlags", "(J)I", (void*)android_view_MotionEvent_nativeGetFlags},
{"nativeSetFlags", "(JI)V", (void*)android_view_MotionEvent_nativeSetFlags},
{"nativeGetEdgeFlags", "(J)I", (void*)android_view_MotionEvent_nativeGetEdgeFlags},
{"nativeSetEdgeFlags", "(JI)V", (void*)android_view_MotionEvent_nativeSetEdgeFlags},
{"nativeGetMetaState", "(J)I", (void*)android_view_MotionEvent_nativeGetMetaState},
{"nativeGetButtonState", "(J)I", (void*)android_view_MotionEvent_nativeGetButtonState},
{"nativeSetButtonState", "(JI)V", (void*)android_view_MotionEvent_nativeSetButtonState},
{"nativeGetClassification", "(J)I",
(void*)android_view_MotionEvent_nativeGetClassification},
{"nativeOffsetLocation", "(JFF)V", (void*)android_view_MotionEvent_nativeOffsetLocation},
{"nativeGetXOffset", "(J)F", (void*)android_view_MotionEvent_nativeGetXOffset},
{"nativeGetYOffset", "(J)F", (void*)android_view_MotionEvent_nativeGetYOffset},
{"nativeGetXPrecision", "(J)F", (void*)android_view_MotionEvent_nativeGetXPrecision},
{"nativeGetYPrecision", "(J)F", (void*)android_view_MotionEvent_nativeGetYPrecision},
{"nativeGetXCursorPosition", "(J)F",
(void*)android_view_MotionEvent_nativeGetXCursorPosition},
{"nativeGetYCursorPosition", "(J)F",
(void*)android_view_MotionEvent_nativeGetYCursorPosition},
{"nativeSetCursorPosition", "(JFF)V",
(void*)android_view_MotionEvent_nativeSetCursorPosition},
{"nativeGetDownTimeNanos", "(J)J", (void*)android_view_MotionEvent_nativeGetDownTimeNanos},
{"nativeSetDownTimeNanos", "(JJ)V", (void*)android_view_MotionEvent_nativeSetDownTimeNanos},
{"nativeGetPointerCount", "(J)I", (void*)android_view_MotionEvent_nativeGetPointerCount},
{"nativeFindPointerIndex", "(JI)I", (void*)android_view_MotionEvent_nativeFindPointerIndex},
{"nativeGetHistorySize", "(J)I", (void*)android_view_MotionEvent_nativeGetHistorySize},
{"nativeScale", "(JF)V", (void*)android_view_MotionEvent_nativeScale},
};
int register_android_view_MotionEvent(JNIEnv* env) {

View File

@@ -38,4 +38,4 @@ extern status_t android_view_MotionEvent_recycle(JNIEnv* env, jobject eventObj);
} // namespace android
#endif // _ANDROID_OS_KEYEVENT_H
#endif // _ANDROID_VIEW_MOTIONEVENT_H

View File

@@ -20,8 +20,10 @@ import static android.view.Display.INVALID_DISPLAY;
import static org.junit.Assert.assertEquals;
import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,6 +42,7 @@ public class KeyEventTest {
private static final int SCAN_CODE = 0;
private static final int FLAGS = 0;
private static final int SOURCE = InputDevice.SOURCE_KEYBOARD;
private static final byte[] HMAC = null;
private static final String CHARACTERS = null;
@Test
@@ -65,25 +68,15 @@ public class KeyEventTest {
KeyEvent keyEvent = KeyEvent.obtain(DOWN_TIME, EVENT_TIME, ACTION, KEYCODE, REPEAT,
METASTATE, DEVICE_ID, SCAN_CODE, FLAGS, SOURCE, CHARACTERS);
KeyEvent keyEvent2 = KeyEvent.obtain(keyEvent);
assertEquals(keyEvent.getDownTime(), keyEvent2.getDownTime());
assertEquals(keyEvent.getEventTime(), keyEvent2.getEventTime());
assertEquals(keyEvent.getAction(), keyEvent2.getAction());
assertEquals(keyEvent.getKeyCode(), keyEvent2.getKeyCode());
assertEquals(keyEvent.getRepeatCount(), keyEvent2.getRepeatCount());
assertEquals(keyEvent.getMetaState(), keyEvent2.getMetaState());
assertEquals(keyEvent.getDeviceId(), keyEvent2.getDeviceId());
assertEquals(keyEvent.getScanCode(), keyEvent2.getScanCode());
assertEquals(keyEvent.getFlags(), keyEvent2.getFlags());
assertEquals(keyEvent.getSource(), keyEvent2.getSource());
assertEquals(keyEvent.getDisplayId(), keyEvent2.getDisplayId());
assertEquals(keyEvent.getCharacters(), keyEvent2.getCharacters());
compareKeys(keyEvent, keyEvent2);
}
@Test
public void testObtainWithDisplayId() {
final int displayId = 5;
KeyEvent keyEvent = KeyEvent.obtain(DOWN_TIME, EVENT_TIME, ACTION, KEYCODE, REPEAT,
METASTATE, DEVICE_ID, SCAN_CODE, FLAGS, SOURCE, displayId, CHARACTERS);
METASTATE, DEVICE_ID, SCAN_CODE, FLAGS, SOURCE, displayId, null /* hmac*/,
CHARACTERS);
assertEquals(DOWN_TIME, keyEvent.getDownTime());
assertEquals(EVENT_TIME, keyEvent.getEventTime());
assertEquals(ACTION, keyEvent.getAction());
@@ -97,4 +90,44 @@ public class KeyEventTest {
assertEquals(displayId, keyEvent.getDisplayId());
assertEquals(CHARACTERS, keyEvent.getCharacters());
}
@Test
public void testParcelUnparcel() {
KeyEvent key1 = createKey();
Parcel parcel = Parcel.obtain();
key1.writeToParcel(parcel, 0 /*flags*/);
parcel.setDataPosition(0);
KeyEvent key2 = KeyEvent.CREATOR.createFromParcel(parcel);
parcel.recycle();
compareKeys(key1, key2);
}
@Test
public void testConstructor() {
KeyEvent key1 = createKey();
KeyEvent key2 = new KeyEvent(key1);
compareKeys(key1, key2);
}
private static KeyEvent createKey() {
return KeyEvent.obtain(DOWN_TIME, EVENT_TIME, ACTION, KEYCODE, REPEAT,
METASTATE, DEVICE_ID, SCAN_CODE, FLAGS, SOURCE, INVALID_DISPLAY, HMAC, CHARACTERS);
}
private static void compareKeys(KeyEvent key1, KeyEvent key2) {
assertEquals(key1.getDownTime(), key2.getDownTime());
assertEquals(key1.getEventTime(), key2.getEventTime());
assertEquals(key1.getAction(), key2.getAction());
assertEquals(key1.getKeyCode(), key2.getKeyCode());
assertEquals(key1.getRepeatCount(), key2.getRepeatCount());
assertEquals(key1.getMetaState(), key2.getMetaState());
assertEquals(key1.getDeviceId(), key2.getDeviceId());
assertEquals(key1.getScanCode(), key2.getScanCode());
assertEquals(key1.getFlags(), key2.getFlags());
assertEquals(key1.getSource(), key2.getSource());
assertEquals(key1.getDisplayId(), key2.getDisplayId());
assertEquals(key1.getCharacters(), key2.getCharacters());
}
}

View File

@@ -3075,7 +3075,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
event.getAction(), fallbackAction.keyCode,
event.getRepeatCount(), fallbackAction.metaState,
event.getDeviceId(), event.getScanCode(),
flags, event.getSource(), event.getDisplayId(), null);
flags, event.getSource(), event.getDisplayId(), null /* hmac */, null);
if (!interceptFallback(focusedToken, fallbackEvent, policyFlags)) {
fallbackEvent.recycle();