blob: 9816d713c6dc28133dfc8d8d282dea093e4f0df9 [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "MotionEvent-JNI"
18
Steven Moreland2279b252017-07-19 09:50:45 -070019#include <nativehelper/JNIHelp.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070020
Derek Sollenberger4dc0aae2019-12-27 15:15:18 -050021#include <android/graphics/matrix.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070022#include <android_runtime/AndroidRuntime.h>
Ruben Brunk87eac992013-09-09 17:44:59 -070023#include <android_runtime/Log.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070024#include <utils/Log.h>
Jeff Brown9d3b1a42013-07-01 19:07:15 -070025#include <input/Input.h>
Steven Moreland2279b252017-07-19 09:50:45 -070026#include <nativehelper/ScopedUtfChars.h>
Jeff Sharkeyd84e1ce2012-03-06 18:26:19 -080027#include "android_os_Parcel.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070028#include "android_view_MotionEvent.h"
Jeff Brown91c69ab2011-02-14 17:03:18 -080029#include "android_util_Binder.h"
Jeff Brown20e987b2010-08-23 12:01:02 -070030
Andreas Gampe987f79f2014-11-18 17:29:46 -080031#include "core_jni_helpers.h"
32
Jeff Brown46b9ac02010-04-22 18:58:52 -070033namespace android {
34
35// ----------------------------------------------------------------------------
36
37static struct {
38 jclass clazz;
39
40 jmethodID obtain;
41 jmethodID recycle;
42
Jeff Brown91c69ab2011-02-14 17:03:18 -080043 jfieldID mNativePtr;
Jeff Brown46b9ac02010-04-22 18:58:52 -070044} gMotionEventClassInfo;
45
Jeff Brown91c69ab2011-02-14 17:03:18 -080046static struct {
Jeff Brown91c69ab2011-02-14 17:03:18 -080047 jfieldID mPackedAxisBits;
48 jfieldID mPackedAxisValues;
49 jfieldID x;
50 jfieldID y;
51 jfieldID pressure;
52 jfieldID size;
53 jfieldID touchMajor;
54 jfieldID touchMinor;
55 jfieldID toolMajor;
56 jfieldID toolMinor;
57 jfieldID orientation;
58} gPointerCoordsClassInfo;
59
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070060static struct {
61 jfieldID id;
62 jfieldID toolType;
63} gPointerPropertiesClassInfo;
64
Jeff Brown46b9ac02010-04-22 18:58:52 -070065// ----------------------------------------------------------------------------
66
Jeff Brown2ed24622011-03-14 19:39:54 -070067MotionEvent* android_view_MotionEvent_getNativePtr(JNIEnv* env, jobject eventObj) {
68 if (!eventObj) {
69 return NULL;
70 }
Jeff Brown91c69ab2011-02-14 17:03:18 -080071 return reinterpret_cast<MotionEvent*>(
Ashok Bhat99a1ef22014-01-08 14:45:08 +000072 env->GetLongField(eventObj, gMotionEventClassInfo.mNativePtr));
Jeff Brown91c69ab2011-02-14 17:03:18 -080073}
Jeff Brown46b9ac02010-04-22 18:58:52 -070074
Jeff Brown91c69ab2011-02-14 17:03:18 -080075static void android_view_MotionEvent_setNativePtr(JNIEnv* env, jobject eventObj,
76 MotionEvent* event) {
Ashok Bhat99a1ef22014-01-08 14:45:08 +000077 env->SetLongField(eventObj, gMotionEventClassInfo.mNativePtr,
78 reinterpret_cast<jlong>(event));
Jeff Brown91c69ab2011-02-14 17:03:18 -080079}
80
Jeff Brown2ed24622011-03-14 19:39:54 -070081jobject android_view_MotionEvent_obtainAsCopy(JNIEnv* env, const MotionEvent* event) {
Jeff Brown46b9ac02010-04-22 18:58:52 -070082 jobject eventObj = env->CallStaticObjectMethod(gMotionEventClassInfo.clazz,
Jeff Brown91c69ab2011-02-14 17:03:18 -080083 gMotionEventClassInfo.obtain);
Jeff Brown2ed24622011-03-14 19:39:54 -070084 if (env->ExceptionCheck() || !eventObj) {
Steve Block3762c312012-01-06 19:20:56 +000085 ALOGE("An exception occurred while obtaining a motion event.");
Jeff Brown46b9ac02010-04-22 18:58:52 -070086 LOGE_EX(env);
87 env->ExceptionClear();
88 return NULL;
89 }
90
Jeff Brown91c69ab2011-02-14 17:03:18 -080091 MotionEvent* destEvent = android_view_MotionEvent_getNativePtr(env, eventObj);
92 if (!destEvent) {
93 destEvent = new MotionEvent();
94 android_view_MotionEvent_setNativePtr(env, eventObj, destEvent);
Jeff Brown46b9ac02010-04-22 18:58:52 -070095 }
96
Jeff Brown91c69ab2011-02-14 17:03:18 -080097 destEvent->copyFrom(event, true);
Jeff Brown46b9ac02010-04-22 18:58:52 -070098 return eventObj;
99}
100
Jeff Brown1f245102010-11-18 20:53:46 -0800101status_t android_view_MotionEvent_recycle(JNIEnv* env, jobject eventObj) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700102 env->CallVoidMethod(eventObj, gMotionEventClassInfo.recycle);
103 if (env->ExceptionCheck()) {
Steve Block8564c8d2012-01-05 23:22:43 +0000104 ALOGW("An exception occurred while recycling a motion event.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700105 LOGW_EX(env);
106 env->ExceptionClear();
Jeff Brown1f245102010-11-18 20:53:46 -0800107 return UNKNOWN_ERROR;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700108 }
Jeff Brown1f245102010-11-18 20:53:46 -0800109 return OK;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700110}
111
Jeff Brown91c69ab2011-02-14 17:03:18 -0800112// ----------------------------------------------------------------------------
Jeff Brown20e987b2010-08-23 12:01:02 -0700113
Jeff Brown91c69ab2011-02-14 17:03:18 -0800114static const jint HISTORY_CURRENT = -0x80000000;
115
116static bool validatePointerCount(JNIEnv* env, jint pointerCount) {
117 if (pointerCount < 1) {
118 jniThrowException(env, "java/lang/IllegalArgumentException",
119 "pointerCount must be at least 1");
120 return false;
Jeff Brown20e987b2010-08-23 12:01:02 -0700121 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800122 return true;
Jeff Brown20e987b2010-08-23 12:01:02 -0700123}
124
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700125static bool validatePointerPropertiesArray(JNIEnv* env, jobjectArray pointerPropertiesObjArray,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800126 size_t pointerCount) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700127 if (!pointerPropertiesObjArray) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800128 jniThrowException(env, "java/lang/IllegalArgumentException",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700129 "pointerProperties array must not be null");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800130 return false;
131 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700132 size_t length = size_t(env->GetArrayLength(pointerPropertiesObjArray));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800133 if (length < pointerCount) {
134 jniThrowException(env, "java/lang/IllegalArgumentException",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700135 "pointerProperties array must be large enough to hold all pointers");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800136 return false;
137 }
138 return true;
139}
Jeff Brown20e987b2010-08-23 12:01:02 -0700140
Jeff Brown91c69ab2011-02-14 17:03:18 -0800141static bool validatePointerCoordsObjArray(JNIEnv* env, jobjectArray pointerCoordsObjArray,
142 size_t pointerCount) {
143 if (!pointerCoordsObjArray) {
144 jniThrowException(env, "java/lang/IllegalArgumentException",
145 "pointerCoords array must not be null");
146 return false;
147 }
148 size_t length = size_t(env->GetArrayLength(pointerCoordsObjArray));
149 if (length < pointerCount) {
150 jniThrowException(env, "java/lang/IllegalArgumentException",
151 "pointerCoords array must be large enough to hold all pointers");
152 return false;
153 }
154 return true;
155}
Jeff Brown20e987b2010-08-23 12:01:02 -0700156
Jeff Brown91c69ab2011-02-14 17:03:18 -0800157static bool validatePointerIndex(JNIEnv* env, jint pointerIndex, size_t pointerCount) {
158 if (pointerIndex < 0 || size_t(pointerIndex) >= pointerCount) {
159 jniThrowException(env, "java/lang/IllegalArgumentException",
160 "pointerIndex out of range");
161 return false;
162 }
163 return true;
164}
Jeff Brown20e987b2010-08-23 12:01:02 -0700165
Jeff Brown91c69ab2011-02-14 17:03:18 -0800166static bool validateHistoryPos(JNIEnv* env, jint historyPos, size_t historySize) {
167 if (historyPos < 0 || size_t(historyPos) >= historySize) {
168 jniThrowException(env, "java/lang/IllegalArgumentException",
169 "historyPos out of range");
170 return false;
171 }
172 return true;
173}
Jeff Brown20e987b2010-08-23 12:01:02 -0700174
Jeff Brown91c69ab2011-02-14 17:03:18 -0800175static bool validatePointerCoords(JNIEnv* env, jobject pointerCoordsObj) {
176 if (!pointerCoordsObj) {
177 jniThrowException(env, "java/lang/IllegalArgumentException",
178 "pointerCoords must not be null");
179 return false;
180 }
181 return true;
182}
183
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700184static bool validatePointerProperties(JNIEnv* env, jobject pointerPropertiesObj) {
185 if (!pointerPropertiesObj) {
186 jniThrowException(env, "java/lang/IllegalArgumentException",
187 "pointerProperties must not be null");
188 return false;
189 }
190 return true;
191}
192
Jeff Brown91c69ab2011-02-14 17:03:18 -0800193static void pointerCoordsToNative(JNIEnv* env, jobject pointerCoordsObj,
194 float xOffset, float yOffset, PointerCoords* outRawPointerCoords) {
195 outRawPointerCoords->clear();
Jeff Brownebbd5d12011-02-17 13:01:34 -0800196 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_X,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800197 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.x) - xOffset);
Jeff Brownebbd5d12011-02-17 13:01:34 -0800198 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_Y,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800199 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.y) - yOffset);
Jeff Brownebbd5d12011-02-17 13:01:34 -0800200 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_PRESSURE,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800201 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.pressure));
Jeff Brownebbd5d12011-02-17 13:01:34 -0800202 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_SIZE,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800203 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.size));
Jeff Brownebbd5d12011-02-17 13:01:34 -0800204 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800205 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.touchMajor));
Jeff Brownebbd5d12011-02-17 13:01:34 -0800206 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800207 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.touchMinor));
Jeff Brownebbd5d12011-02-17 13:01:34 -0800208 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800209 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.toolMajor));
Jeff Brownebbd5d12011-02-17 13:01:34 -0800210 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800211 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.toolMinor));
Jeff Brownebbd5d12011-02-17 13:01:34 -0800212 outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800213 env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.orientation));
214
Michael Wrightcbf14862014-05-19 15:42:01 -0700215 BitSet64 bits =
216 BitSet64(env->GetLongField(pointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits));
217 if (!bits.isEmpty()) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800218 jfloatArray valuesArray = jfloatArray(env->GetObjectField(pointerCoordsObj,
219 gPointerCoordsClassInfo.mPackedAxisValues));
220 if (valuesArray) {
221 jfloat* values = static_cast<jfloat*>(
222 env->GetPrimitiveArrayCritical(valuesArray, NULL));
223
224 uint32_t index = 0;
225 do {
Michael Wrightcbf14862014-05-19 15:42:01 -0700226 uint32_t axis = bits.clearFirstMarkedBit();
Jeff Brown91c69ab2011-02-14 17:03:18 -0800227 outRawPointerCoords->setAxisValue(axis, values[index++]);
Michael Wrightcbf14862014-05-19 15:42:01 -0700228 } while (!bits.isEmpty());
Jeff Brown91c69ab2011-02-14 17:03:18 -0800229
230 env->ReleasePrimitiveArrayCritical(valuesArray, values, JNI_ABORT);
231 env->DeleteLocalRef(valuesArray);
232 }
233 }
234}
235
236static jfloatArray obtainPackedAxisValuesArray(JNIEnv* env, uint32_t minSize,
237 jobject outPointerCoordsObj) {
238 jfloatArray outValuesArray = jfloatArray(env->GetObjectField(outPointerCoordsObj,
239 gPointerCoordsClassInfo.mPackedAxisValues));
240 if (outValuesArray) {
241 uint32_t size = env->GetArrayLength(outValuesArray);
242 if (minSize <= size) {
243 return outValuesArray;
244 }
245 env->DeleteLocalRef(outValuesArray);
246 }
247 uint32_t size = 8;
248 while (size < minSize) {
249 size *= 2;
250 }
251 outValuesArray = env->NewFloatArray(size);
252 env->SetObjectField(outPointerCoordsObj,
253 gPointerCoordsClassInfo.mPackedAxisValues, outValuesArray);
254 return outValuesArray;
255}
256
257static void pointerCoordsFromNative(JNIEnv* env, const PointerCoords* rawPointerCoords,
258 float xOffset, float yOffset, jobject outPointerCoordsObj) {
259 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.x,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800260 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800261 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.y,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800262 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800263 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.pressure,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800264 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800265 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.size,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800266 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_SIZE));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800267 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.touchMajor,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800268 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800269 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.touchMinor,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800270 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800271 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.toolMajor,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800272 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800273 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.toolMinor,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800274 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800275 env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.orientation,
Jeff Brownebbd5d12011-02-17 13:01:34 -0800276 rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
Jeff Brown91c69ab2011-02-14 17:03:18 -0800277
Jeff Brown6f2fba42011-02-19 01:08:02 -0800278 uint64_t outBits = 0;
Michael Wrightcbf14862014-05-19 15:42:01 -0700279 BitSet64 bits = BitSet64(rawPointerCoords->bits);
280 bits.clearBit(AMOTION_EVENT_AXIS_X);
281 bits.clearBit(AMOTION_EVENT_AXIS_Y);
282 bits.clearBit(AMOTION_EVENT_AXIS_PRESSURE);
283 bits.clearBit(AMOTION_EVENT_AXIS_SIZE);
284 bits.clearBit(AMOTION_EVENT_AXIS_TOUCH_MAJOR);
285 bits.clearBit(AMOTION_EVENT_AXIS_TOUCH_MINOR);
286 bits.clearBit(AMOTION_EVENT_AXIS_TOOL_MAJOR);
287 bits.clearBit(AMOTION_EVENT_AXIS_TOOL_MINOR);
288 bits.clearBit(AMOTION_EVENT_AXIS_ORIENTATION);
289 if (!bits.isEmpty()) {
290 uint32_t packedAxesCount = bits.count();
Jeff Brown91c69ab2011-02-14 17:03:18 -0800291 jfloatArray outValuesArray = obtainPackedAxisValuesArray(env, packedAxesCount,
292 outPointerCoordsObj);
293 if (!outValuesArray) {
294 return; // OOM
Jeff Brown20e987b2010-08-23 12:01:02 -0700295 }
296
Jeff Brown91c69ab2011-02-14 17:03:18 -0800297 jfloat* outValues = static_cast<jfloat*>(env->GetPrimitiveArrayCritical(
298 outValuesArray, NULL));
Jeff Brown20e987b2010-08-23 12:01:02 -0700299
Jeff Brown91c69ab2011-02-14 17:03:18 -0800300 uint32_t index = 0;
301 do {
Michael Wrightcbf14862014-05-19 15:42:01 -0700302 uint32_t axis = bits.clearFirstMarkedBit();
303 outBits |= BitSet64::valueForBit(axis);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800304 outValues[index++] = rawPointerCoords->getAxisValue(axis);
Michael Wrightcbf14862014-05-19 15:42:01 -0700305 } while (!bits.isEmpty());
Jeff Brown91c69ab2011-02-14 17:03:18 -0800306
307 env->ReleasePrimitiveArrayCritical(outValuesArray, outValues, 0);
308 env->DeleteLocalRef(outValuesArray);
309 }
Jeff Brown6f2fba42011-02-19 01:08:02 -0800310 env->SetLongField(outPointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits, outBits);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800311}
312
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700313static void pointerPropertiesToNative(JNIEnv* env, jobject pointerPropertiesObj,
314 PointerProperties* outPointerProperties) {
315 outPointerProperties->clear();
316 outPointerProperties->id = env->GetIntField(pointerPropertiesObj,
317 gPointerPropertiesClassInfo.id);
318 outPointerProperties->toolType = env->GetIntField(pointerPropertiesObj,
319 gPointerPropertiesClassInfo.toolType);
320}
321
322static void pointerPropertiesFromNative(JNIEnv* env, const PointerProperties* pointerProperties,
323 jobject outPointerPropertiesObj) {
324 env->SetIntField(outPointerPropertiesObj, gPointerPropertiesClassInfo.id,
325 pointerProperties->id);
326 env->SetIntField(outPointerPropertiesObj, gPointerPropertiesClassInfo.toolType,
327 pointerProperties->toolType);
328}
329
Jeff Brown91c69ab2011-02-14 17:03:18 -0800330
331// ----------------------------------------------------------------------------
332
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600333static jlong android_view_MotionEvent_nativeInitialize(
334 JNIEnv* env, jclass clazz, jlong nativePtr, jint deviceId, jint source, jint displayId,
335 jint action, jint flags, jint edgeFlags, jint metaState, jint buttonState,
336 jint classification, jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
337 jlong downTimeNanos, jlong eventTimeNanos, jint pointerCount,
338 jobjectArray pointerPropertiesObjArray, jobjectArray pointerCoordsObjArray) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800339 if (!validatePointerCount(env, pointerCount)
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700340 || !validatePointerPropertiesArray(env, pointerPropertiesObjArray, pointerCount)
Jeff Brown91c69ab2011-02-14 17:03:18 -0800341 || !validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) {
342 return 0;
Jeff Brown20e987b2010-08-23 12:01:02 -0700343 }
344
George Burgess IVd657a382017-06-20 23:53:29 -0700345 MotionEvent* event;
346 if (nativePtr) {
347 event = reinterpret_cast<MotionEvent*>(nativePtr);
348 } else {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800349 event = new MotionEvent();
350 }
Jeff Brown20e987b2010-08-23 12:01:02 -0700351
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700352 PointerProperties pointerProperties[pointerCount];
Jeff Brown91c69ab2011-02-14 17:03:18 -0800353 PointerCoords rawPointerCoords[pointerCount];
Jeff Brown20e987b2010-08-23 12:01:02 -0700354
Jeff Brown91c69ab2011-02-14 17:03:18 -0800355 for (jint i = 0; i < pointerCount; i++) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700356 jobject pointerPropertiesObj = env->GetObjectArrayElement(pointerPropertiesObjArray, i);
357 if (!pointerPropertiesObj) {
358 goto Error;
359 }
360 pointerPropertiesToNative(env, pointerPropertiesObj, &pointerProperties[i]);
361 env->DeleteLocalRef(pointerPropertiesObj);
362
Jeff Brown91c69ab2011-02-14 17:03:18 -0800363 jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i);
364 if (!pointerCoordsObj) {
365 jniThrowNullPointerException(env, "pointerCoords");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700366 goto Error;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800367 }
368 pointerCoordsToNative(env, pointerCoordsObj, xOffset, yOffset, &rawPointerCoords[i]);
369 env->DeleteLocalRef(pointerCoordsObj);
370 }
371
Garfield Tanc8362b22020-01-24 11:32:14 -0800372 event->initialize(InputEvent::nextId(), deviceId, source, displayId, INVALID_HMAC, action, 0,
373 flags, edgeFlags, metaState, buttonState,
374 static_cast<MotionClassification>(classification), 1 /*xScale*/, 1 /*yScale*/,
375 xOffset, yOffset, xPrecision, yPrecision,
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600376 AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
377 downTimeNanos, eventTimeNanos, pointerCount, pointerProperties,
378 rawPointerCoords);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800379
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000380 return reinterpret_cast<jlong>(event);
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700381
382Error:
383 if (!nativePtr) {
384 delete event;
385 }
386 return 0;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800387}
388
Jeff Brown91c69ab2011-02-14 17:03:18 -0800389static void android_view_MotionEvent_nativeDispose(JNIEnv* env, jclass clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000390 jlong nativePtr) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800391 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
392 delete event;
393}
394
395static void android_view_MotionEvent_nativeAddBatch(JNIEnv* env, jclass clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000396 jlong nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800397 jint metaState) {
398 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
399 size_t pointerCount = event->getPointerCount();
400 if (!validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) {
401 return;
402 }
403
404 PointerCoords rawPointerCoords[pointerCount];
405
406 for (size_t i = 0; i < pointerCount; i++) {
407 jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i);
408 if (!pointerCoordsObj) {
409 jniThrowNullPointerException(env, "pointerCoords");
410 return;
411 }
412 pointerCoordsToNative(env, pointerCoordsObj,
413 event->getXOffset(), event->getYOffset(), &rawPointerCoords[i]);
414 env->DeleteLocalRef(pointerCoordsObj);
415 }
416
417 event->addSample(eventTimeNanos, rawPointerCoords);
418 event->setMetaState(event->getMetaState() | metaState);
419}
420
Jeff Brown91c69ab2011-02-14 17:03:18 -0800421static void android_view_MotionEvent_nativeGetPointerCoords(JNIEnv* env, jclass clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000422 jlong nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800423 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
424 size_t pointerCount = event->getPointerCount();
425 if (!validatePointerIndex(env, pointerIndex, pointerCount)
426 || !validatePointerCoords(env, outPointerCoordsObj)) {
427 return;
428 }
429
430 const PointerCoords* rawPointerCoords;
431 if (historyPos == HISTORY_CURRENT) {
432 rawPointerCoords = event->getRawPointerCoords(pointerIndex);
433 } else {
434 size_t historySize = event->getHistorySize();
435 if (!validateHistoryPos(env, historyPos, historySize)) {
436 return;
437 }
438 rawPointerCoords = event->getHistoricalRawPointerCoords(pointerIndex, historyPos);
439 }
440 pointerCoordsFromNative(env, rawPointerCoords, event->getXOffset(), event->getYOffset(),
441 outPointerCoordsObj);
442}
443
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700444static void android_view_MotionEvent_nativeGetPointerProperties(JNIEnv* env, jclass clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000445 jlong nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700446 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
447 size_t pointerCount = event->getPointerCount();
448 if (!validatePointerIndex(env, pointerIndex, pointerCount)
449 || !validatePointerProperties(env, outPointerPropertiesObj)) {
450 return;
451 }
452
453 const PointerProperties* pointerProperties = event->getPointerProperties(pointerIndex);
454 pointerPropertiesFromNative(env, pointerProperties, outPointerPropertiesObj);
455}
456
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000457static jlong android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz,
458 jlong nativePtr, jobject parcelObj) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800459 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
460 if (!event) {
461 event = new MotionEvent();
462 }
463
464 Parcel* parcel = parcelForJavaObject(env, parcelObj);
465
466 status_t status = event->readFromParcel(parcel);
Jeff Brownebbd5d12011-02-17 13:01:34 -0800467 if (status) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800468 if (!nativePtr) {
469 delete event;
470 }
471 jniThrowRuntimeException(env, "Failed to read MotionEvent parcel.");
472 return 0;
473 }
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000474 return reinterpret_cast<jlong>(event);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800475}
476
477static void android_view_MotionEvent_nativeWriteToParcel(JNIEnv* env, jclass clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000478 jlong nativePtr, jobject parcelObj) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800479 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
480 Parcel* parcel = parcelForJavaObject(env, parcelObj);
481
482 status_t status = event->writeToParcel(parcel);
Jeff Brownebbd5d12011-02-17 13:01:34 -0800483 if (status) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800484 jniThrowRuntimeException(env, "Failed to write MotionEvent parcel.");
485 }
Jeff Brown20e987b2010-08-23 12:01:02 -0700486}
487
Michael Wright337d9d22014-04-22 15:03:48 -0700488static jstring android_view_MotionEvent_nativeAxisToString(JNIEnv* env, jclass clazz,
489 jint axis) {
490 return env->NewStringUTF(MotionEvent::getLabel(static_cast<int32_t>(axis)));
491}
492
493static jint android_view_MotionEvent_nativeAxisFromString(JNIEnv* env, jclass clazz,
494 jstring label) {
495 ScopedUtfChars axisLabel(env, label);
496 return static_cast<jint>(MotionEvent::getAxisFromLabel(axisLabel.c_str()));
497}
498
John Reck09709972016-10-03 15:47:18 -0700499// ---------------- @FastNative ----------------------------------
500
501static jint android_view_MotionEvent_nativeGetPointerId(JNIEnv* env, jclass clazz,
502 jlong nativePtr, jint pointerIndex) {
503 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
504 size_t pointerCount = event->getPointerCount();
505 if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
506 return -1;
507 }
508 return event->getPointerId(pointerIndex);
509}
510
511static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz,
512 jlong nativePtr, jint pointerIndex) {
513 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
514 size_t pointerCount = event->getPointerCount();
515 if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
516 return -1;
517 }
518 return event->getToolType(pointerIndex);
519}
520
521static jlong android_view_MotionEvent_nativeGetEventTimeNanos(JNIEnv* env, jclass clazz,
522 jlong nativePtr, jint historyPos) {
523 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
524 if (historyPos == HISTORY_CURRENT) {
525 return event->getEventTime();
526 } else {
527 size_t historySize = event->getHistorySize();
528 if (!validateHistoryPos(env, historyPos, historySize)) {
529 return 0;
530 }
531 return event->getHistoricalEventTime(historyPos);
532 }
533}
534
535static jfloat android_view_MotionEvent_nativeGetRawAxisValue(JNIEnv* env, jclass clazz,
536 jlong nativePtr, jint axis,
537 jint pointerIndex, jint historyPos) {
538 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
539 size_t pointerCount = event->getPointerCount();
540 if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
541 return 0;
542 }
543
544 if (historyPos == HISTORY_CURRENT) {
545 return event->getRawAxisValue(axis, pointerIndex);
546 } else {
547 size_t historySize = event->getHistorySize();
548 if (!validateHistoryPos(env, historyPos, historySize)) {
549 return 0;
550 }
551 return event->getHistoricalRawAxisValue(axis, pointerIndex, historyPos);
552 }
553}
554
555static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz,
556 jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) {
557 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
558 size_t pointerCount = event->getPointerCount();
559 if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
560 return 0;
561 }
562
563 if (historyPos == HISTORY_CURRENT) {
564 return event->getAxisValue(axis, pointerIndex);
565 } else {
566 size_t historySize = event->getHistorySize();
567 if (!validateHistoryPos(env, historyPos, historySize)) {
568 return 0;
569 }
570 return event->getHistoricalAxisValue(axis, pointerIndex, historyPos);
571 }
572}
573
Derek Sollenberger4dc0aae2019-12-27 15:15:18 -0500574static void android_view_MotionEvent_nativeTransform(JNIEnv* env, jclass clazz,
575 jlong nativePtr, jobject matrixObj) {
576 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
577
578 float m[9];
579 AMatrix_getContents(env, matrixObj, m);
580 event->transform(m);
581}
582
John Reck09709972016-10-03 15:47:18 -0700583// ----------------- @CriticalNative ------------------------------
584
585static jlong android_view_MotionEvent_nativeCopy(jlong destNativePtr, jlong sourceNativePtr,
586 jboolean keepHistory) {
587 MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr);
588 if (!destEvent) {
589 destEvent = new MotionEvent();
590 }
591 MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr);
592 destEvent->copyFrom(sourceEvent, keepHistory);
593 return reinterpret_cast<jlong>(destEvent);
594}
595
Garfield Tanc8362b22020-01-24 11:32:14 -0800596static jint android_view_MotionEvent_nativeGetId(jlong nativePtr) {
597 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
598 return event->getId();
599}
600
John Reck09709972016-10-03 15:47:18 -0700601static jint android_view_MotionEvent_nativeGetDeviceId(jlong nativePtr) {
602 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
603 return event->getDeviceId();
604}
605
606static jint android_view_MotionEvent_nativeGetSource(jlong nativePtr) {
607 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
608 return event->getSource();
609}
610
611static void android_view_MotionEvent_nativeSetSource(jlong nativePtr, jint source) {
612 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
613 event->setSource(source);
614}
615
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800616static jint android_view_MotionEvent_nativeGetDisplayId(jlong nativePtr) {
617 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
618 return event->getDisplayId();
619}
620
621static void android_view_MotionEvent_nativeSetDisplayId(jlong nativePtr, jint displayId) {
622 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
623 return event->setDisplayId(displayId);
624}
625
John Reck09709972016-10-03 15:47:18 -0700626static jint android_view_MotionEvent_nativeGetAction(jlong nativePtr) {
627 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
628 return event->getAction();
629}
630
631static void android_view_MotionEvent_nativeSetAction(jlong nativePtr, jint action) {
632 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
633 event->setAction(action);
634}
635
636static int android_view_MotionEvent_nativeGetActionButton(jlong nativePtr) {
637 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
638 return event->getActionButton();
639}
640
641static void android_view_MotionEvent_nativeSetActionButton(jlong nativePtr, jint button) {
642 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
643 event->setActionButton(button);
644}
645
646static jboolean android_view_MotionEvent_nativeIsTouchEvent(jlong nativePtr) {
647 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
648 return event->isTouchEvent();
649}
650
651static jint android_view_MotionEvent_nativeGetFlags(jlong nativePtr) {
652 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
653 return event->getFlags();
654}
655
656static void android_view_MotionEvent_nativeSetFlags(jlong nativePtr, jint flags) {
657 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
658 event->setFlags(flags);
659}
660
661static jint android_view_MotionEvent_nativeGetEdgeFlags(jlong nativePtr) {
662 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
663 return event->getEdgeFlags();
664}
665
666static void android_view_MotionEvent_nativeSetEdgeFlags(jlong nativePtr, jint edgeFlags) {
667 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
668 event->setEdgeFlags(edgeFlags);
669}
670
671static jint android_view_MotionEvent_nativeGetMetaState(jlong nativePtr) {
672 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
673 return event->getMetaState();
674}
675
676static jint android_view_MotionEvent_nativeGetButtonState(jlong nativePtr) {
677 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
678 return event->getButtonState();
679}
680
681static void android_view_MotionEvent_nativeSetButtonState(jlong nativePtr, jint buttonState) {
682 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
683 event->setButtonState(buttonState);
684}
685
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800686static jint android_view_MotionEvent_nativeGetClassification(jlong nativePtr) {
687 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
688 return static_cast<jint>(event->getClassification());
689}
690
John Reck09709972016-10-03 15:47:18 -0700691static void android_view_MotionEvent_nativeOffsetLocation(jlong nativePtr, jfloat deltaX,
692 jfloat deltaY) {
693 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
694 return event->offsetLocation(deltaX, deltaY);
695}
696
697static jfloat android_view_MotionEvent_nativeGetXOffset(jlong nativePtr) {
698 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
699 return event->getXOffset();
700}
701
702static jfloat android_view_MotionEvent_nativeGetYOffset(jlong nativePtr) {
703 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
704 return event->getYOffset();
705}
706
707static jfloat android_view_MotionEvent_nativeGetXPrecision(jlong nativePtr) {
708 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
709 return event->getXPrecision();
710}
711
712static jfloat android_view_MotionEvent_nativeGetYPrecision(jlong nativePtr) {
713 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
714 return event->getYPrecision();
715}
716
Garfield Tan1da86282019-07-15 14:00:35 -0700717static jfloat android_view_MotionEvent_nativeGetXCursorPosition(jlong nativePtr) {
718 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
719 return event->getXCursorPosition();
720}
721
722static jfloat android_view_MotionEvent_nativeGetYCursorPosition(jlong nativePtr) {
723 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
724 return event->getYCursorPosition();
725}
726
727static void android_view_MotionEvent_nativeSetCursorPosition(jlong nativePtr, jfloat x, jfloat y) {
728 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
729 event->setCursorPosition(x, y);
730}
731
John Reck09709972016-10-03 15:47:18 -0700732static jlong android_view_MotionEvent_nativeGetDownTimeNanos(jlong nativePtr) {
733 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
734 return event->getDownTime();
735}
736
737static void android_view_MotionEvent_nativeSetDownTimeNanos(jlong nativePtr, jlong downTimeNanos) {
738 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
739 event->setDownTime(downTimeNanos);
740}
741
742static jint android_view_MotionEvent_nativeGetPointerCount(jlong nativePtr) {
743 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
744 return jint(event->getPointerCount());
745}
746
747static jint android_view_MotionEvent_nativeFindPointerIndex(jlong nativePtr, jint pointerId) {
748 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
749 return jint(event->findPointerIndex(pointerId));
750}
751
752static jint android_view_MotionEvent_nativeGetHistorySize(jlong nativePtr) {
753 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
754 return jint(event->getHistorySize());
755}
756
757static void android_view_MotionEvent_nativeScale(jlong nativePtr, jfloat scale) {
758 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
759 event->scale(scale);
760}
761
Jeff Brown46b9ac02010-04-22 18:58:52 -0700762// ----------------------------------------------------------------------------
763
Daniel Micay76f6a862015-09-19 17:31:01 -0400764static const JNINativeMethod gMotionEventMethods[] = {
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600765 /* name, signature, funcPtr */
766 {"nativeInitialize",
767 "(JIIIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
768 "[Landroid/view/MotionEvent$PointerCoords;)J",
769 (void*)android_view_MotionEvent_nativeInitialize},
770 {"nativeDispose", "(J)V", (void*)android_view_MotionEvent_nativeDispose},
771 {"nativeAddBatch", "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V",
772 (void*)android_view_MotionEvent_nativeAddBatch},
773 {"nativeReadFromParcel", "(JLandroid/os/Parcel;)J",
774 (void*)android_view_MotionEvent_nativeReadFromParcel},
775 {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
776 (void*)android_view_MotionEvent_nativeWriteToParcel},
777 {"nativeAxisToString", "(I)Ljava/lang/String;",
778 (void*)android_view_MotionEvent_nativeAxisToString},
779 {"nativeAxisFromString", "(Ljava/lang/String;)I",
780 (void*)android_view_MotionEvent_nativeAxisFromString},
781 {"nativeGetPointerProperties", "(JILandroid/view/MotionEvent$PointerProperties;)V",
782 (void*)android_view_MotionEvent_nativeGetPointerProperties},
783 {"nativeGetPointerCoords", "(JIILandroid/view/MotionEvent$PointerCoords;)V",
784 (void*)android_view_MotionEvent_nativeGetPointerCoords},
John Reck09709972016-10-03 15:47:18 -0700785
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600786 // --------------- @FastNative ----------------------
787 {"nativeGetPointerId", "(JI)I", (void*)android_view_MotionEvent_nativeGetPointerId},
788 {"nativeGetToolType", "(JI)I", (void*)android_view_MotionEvent_nativeGetToolType},
789 {"nativeGetEventTimeNanos", "(JI)J",
790 (void*)android_view_MotionEvent_nativeGetEventTimeNanos},
791 {"nativeGetRawAxisValue", "(JIII)F", (void*)android_view_MotionEvent_nativeGetRawAxisValue},
792 {"nativeGetAxisValue", "(JIII)F", (void*)android_view_MotionEvent_nativeGetAxisValue},
793 {"nativeTransform", "(JLandroid/graphics/Matrix;)V",
794 (void*)android_view_MotionEvent_nativeTransform},
John Reck09709972016-10-03 15:47:18 -0700795
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600796 // --------------- @CriticalNative ------------------
John Reck09709972016-10-03 15:47:18 -0700797
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600798 {"nativeCopy", "(JJZ)J", (void*)android_view_MotionEvent_nativeCopy},
Garfield Tanc8362b22020-01-24 11:32:14 -0800799 {"nativeGetId", "(J)I", (void*)android_view_MotionEvent_nativeGetId},
Siarhei Vishniakou6a3346d2020-01-23 19:49:39 -0600800 {"nativeGetDeviceId", "(J)I", (void*)android_view_MotionEvent_nativeGetDeviceId},
801 {"nativeGetSource", "(J)I", (void*)android_view_MotionEvent_nativeGetSource},
802 {"nativeSetSource", "(JI)V", (void*)android_view_MotionEvent_nativeSetSource},
803 {"nativeGetDisplayId", "(J)I", (void*)android_view_MotionEvent_nativeGetDisplayId},
804 {"nativeSetDisplayId", "(JI)V", (void*)android_view_MotionEvent_nativeSetDisplayId},
805 {"nativeGetAction", "(J)I", (void*)android_view_MotionEvent_nativeGetAction},
806 {"nativeSetAction", "(JI)V", (void*)android_view_MotionEvent_nativeSetAction},
807 {"nativeGetActionButton", "(J)I", (void*)android_view_MotionEvent_nativeGetActionButton},
808 {"nativeSetActionButton", "(JI)V", (void*)android_view_MotionEvent_nativeSetActionButton},
809 {"nativeIsTouchEvent", "(J)Z", (void*)android_view_MotionEvent_nativeIsTouchEvent},
810 {"nativeGetFlags", "(J)I", (void*)android_view_MotionEvent_nativeGetFlags},
811 {"nativeSetFlags", "(JI)V", (void*)android_view_MotionEvent_nativeSetFlags},
812 {"nativeGetEdgeFlags", "(J)I", (void*)android_view_MotionEvent_nativeGetEdgeFlags},
813 {"nativeSetEdgeFlags", "(JI)V", (void*)android_view_MotionEvent_nativeSetEdgeFlags},
814 {"nativeGetMetaState", "(J)I", (void*)android_view_MotionEvent_nativeGetMetaState},
815 {"nativeGetButtonState", "(J)I", (void*)android_view_MotionEvent_nativeGetButtonState},
816 {"nativeSetButtonState", "(JI)V", (void*)android_view_MotionEvent_nativeSetButtonState},
817 {"nativeGetClassification", "(J)I",
818 (void*)android_view_MotionEvent_nativeGetClassification},
819 {"nativeOffsetLocation", "(JFF)V", (void*)android_view_MotionEvent_nativeOffsetLocation},
820 {"nativeGetXOffset", "(J)F", (void*)android_view_MotionEvent_nativeGetXOffset},
821 {"nativeGetYOffset", "(J)F", (void*)android_view_MotionEvent_nativeGetYOffset},
822 {"nativeGetXPrecision", "(J)F", (void*)android_view_MotionEvent_nativeGetXPrecision},
823 {"nativeGetYPrecision", "(J)F", (void*)android_view_MotionEvent_nativeGetYPrecision},
824 {"nativeGetXCursorPosition", "(J)F",
825 (void*)android_view_MotionEvent_nativeGetXCursorPosition},
826 {"nativeGetYCursorPosition", "(J)F",
827 (void*)android_view_MotionEvent_nativeGetYCursorPosition},
828 {"nativeSetCursorPosition", "(JFF)V",
829 (void*)android_view_MotionEvent_nativeSetCursorPosition},
830 {"nativeGetDownTimeNanos", "(J)J", (void*)android_view_MotionEvent_nativeGetDownTimeNanos},
831 {"nativeSetDownTimeNanos", "(JJ)V", (void*)android_view_MotionEvent_nativeSetDownTimeNanos},
832 {"nativeGetPointerCount", "(J)I", (void*)android_view_MotionEvent_nativeGetPointerCount},
833 {"nativeFindPointerIndex", "(JI)I", (void*)android_view_MotionEvent_nativeFindPointerIndex},
834 {"nativeGetHistorySize", "(J)I", (void*)android_view_MotionEvent_nativeGetHistorySize},
835 {"nativeScale", "(JF)V", (void*)android_view_MotionEvent_nativeScale},
Jeff Brown20e987b2010-08-23 12:01:02 -0700836};
837
Jeff Brown46b9ac02010-04-22 18:58:52 -0700838int register_android_view_MotionEvent(JNIEnv* env) {
Andreas Gampe987f79f2014-11-18 17:29:46 -0800839 int res = RegisterMethodsOrDie(env, "android/view/MotionEvent", gMotionEventMethods,
840 NELEM(gMotionEventMethods));
Jeff Brown20e987b2010-08-23 12:01:02 -0700841
Andreas Gampe987f79f2014-11-18 17:29:46 -0800842 gMotionEventClassInfo.clazz = FindClassOrDie(env, "android/view/MotionEvent");
843 gMotionEventClassInfo.clazz = MakeGlobalRefOrDie(env, gMotionEventClassInfo.clazz);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700844
Andreas Gampe987f79f2014-11-18 17:29:46 -0800845 gMotionEventClassInfo.obtain = GetStaticMethodIDOrDie(env, gMotionEventClassInfo.clazz,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800846 "obtain", "()Landroid/view/MotionEvent;");
Andreas Gampe987f79f2014-11-18 17:29:46 -0800847 gMotionEventClassInfo.recycle = GetMethodIDOrDie(env, gMotionEventClassInfo.clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700848 "recycle", "()V");
Andreas Gampe987f79f2014-11-18 17:29:46 -0800849 gMotionEventClassInfo.mNativePtr = GetFieldIDOrDie(env, gMotionEventClassInfo.clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000850 "mNativePtr", "J");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700851
Andreas Gampe987f79f2014-11-18 17:29:46 -0800852 jclass clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerCoords");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800853
Andreas Gampe987f79f2014-11-18 17:29:46 -0800854 gPointerCoordsClassInfo.mPackedAxisBits = GetFieldIDOrDie(env, clazz, "mPackedAxisBits", "J");
855 gPointerCoordsClassInfo.mPackedAxisValues = GetFieldIDOrDie(env, clazz, "mPackedAxisValues",
856 "[F");
857 gPointerCoordsClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "F");
858 gPointerCoordsClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "F");
859 gPointerCoordsClassInfo.pressure = GetFieldIDOrDie(env, clazz, "pressure", "F");
860 gPointerCoordsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "F");
861 gPointerCoordsClassInfo.touchMajor = GetFieldIDOrDie(env, clazz, "touchMajor", "F");
862 gPointerCoordsClassInfo.touchMinor = GetFieldIDOrDie(env, clazz, "touchMinor", "F");
863 gPointerCoordsClassInfo.toolMajor = GetFieldIDOrDie(env, clazz, "toolMajor", "F");
864 gPointerCoordsClassInfo.toolMinor = GetFieldIDOrDie(env, clazz, "toolMinor", "F");
865 gPointerCoordsClassInfo.orientation = GetFieldIDOrDie(env, clazz, "orientation", "F");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700866
Andreas Gampe987f79f2014-11-18 17:29:46 -0800867 clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerProperties");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700868
Andreas Gampe987f79f2014-11-18 17:29:46 -0800869 gPointerPropertiesClassInfo.id = GetFieldIDOrDie(env, clazz, "id", "I");
870 gPointerPropertiesClassInfo.toolType = GetFieldIDOrDie(env, clazz, "toolType", "I");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700871
Andreas Gampe987f79f2014-11-18 17:29:46 -0800872 return res;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700873}
874
875} // namespace android