blob: c75c54beb8b97be8471c92be519fc0a666b0fcb6 [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
Jeff Brown48a3d982013-07-15 17:31:32 -070021#include <SkMatrix.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
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000333static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
334 jlong nativePtr,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800335 jint deviceId, jint source, jint displayId, jint action, jint flags, jint edgeFlags,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800336 jint metaState, jint buttonState, jint classification,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800337 jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
338 jlong downTimeNanos, jlong eventTimeNanos,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700339 jint pointerCount, jobjectArray pointerPropertiesObjArray,
340 jobjectArray pointerCoordsObjArray) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800341 if (!validatePointerCount(env, pointerCount)
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700342 || !validatePointerPropertiesArray(env, pointerPropertiesObjArray, pointerCount)
Jeff Brown91c69ab2011-02-14 17:03:18 -0800343 || !validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) {
344 return 0;
Jeff Brown20e987b2010-08-23 12:01:02 -0700345 }
346
George Burgess IVd657a382017-06-20 23:53:29 -0700347 MotionEvent* event;
348 if (nativePtr) {
349 event = reinterpret_cast<MotionEvent*>(nativePtr);
350 } else {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800351 event = new MotionEvent();
352 }
Jeff Brown20e987b2010-08-23 12:01:02 -0700353
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700354 PointerProperties pointerProperties[pointerCount];
Jeff Brown91c69ab2011-02-14 17:03:18 -0800355 PointerCoords rawPointerCoords[pointerCount];
Jeff Brown20e987b2010-08-23 12:01:02 -0700356
Jeff Brown91c69ab2011-02-14 17:03:18 -0800357 for (jint i = 0; i < pointerCount; i++) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700358 jobject pointerPropertiesObj = env->GetObjectArrayElement(pointerPropertiesObjArray, i);
359 if (!pointerPropertiesObj) {
360 goto Error;
361 }
362 pointerPropertiesToNative(env, pointerPropertiesObj, &pointerProperties[i]);
363 env->DeleteLocalRef(pointerPropertiesObj);
364
Jeff Brown91c69ab2011-02-14 17:03:18 -0800365 jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i);
366 if (!pointerCoordsObj) {
367 jniThrowNullPointerException(env, "pointerCoords");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700368 goto Error;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800369 }
370 pointerCoordsToNative(env, pointerCoordsObj, xOffset, yOffset, &rawPointerCoords[i]);
371 env->DeleteLocalRef(pointerCoordsObj);
372 }
373
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800374 event->initialize(deviceId, source, displayId, action, 0, flags, edgeFlags, metaState,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800375 buttonState, static_cast<MotionClassification>(classification),
376 xOffset, yOffset, xPrecision, yPrecision,
Garfield Tan66fa5e22019-06-18 17:01:39 -0700377 AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700378 downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, 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
574// ----------------- @CriticalNative ------------------------------
575
576static jlong android_view_MotionEvent_nativeCopy(jlong destNativePtr, jlong sourceNativePtr,
577 jboolean keepHistory) {
578 MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr);
579 if (!destEvent) {
580 destEvent = new MotionEvent();
581 }
582 MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr);
583 destEvent->copyFrom(sourceEvent, keepHistory);
584 return reinterpret_cast<jlong>(destEvent);
585}
586
587static jint android_view_MotionEvent_nativeGetDeviceId(jlong nativePtr) {
588 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
589 return event->getDeviceId();
590}
591
592static jint android_view_MotionEvent_nativeGetSource(jlong nativePtr) {
593 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
594 return event->getSource();
595}
596
597static void android_view_MotionEvent_nativeSetSource(jlong nativePtr, jint source) {
598 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
599 event->setSource(source);
600}
601
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800602static jint android_view_MotionEvent_nativeGetDisplayId(jlong nativePtr) {
603 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
604 return event->getDisplayId();
605}
606
607static void android_view_MotionEvent_nativeSetDisplayId(jlong nativePtr, jint displayId) {
608 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
609 return event->setDisplayId(displayId);
610}
611
John Reck09709972016-10-03 15:47:18 -0700612static jint android_view_MotionEvent_nativeGetAction(jlong nativePtr) {
613 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
614 return event->getAction();
615}
616
617static void android_view_MotionEvent_nativeSetAction(jlong nativePtr, jint action) {
618 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
619 event->setAction(action);
620}
621
622static int android_view_MotionEvent_nativeGetActionButton(jlong nativePtr) {
623 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
624 return event->getActionButton();
625}
626
627static void android_view_MotionEvent_nativeSetActionButton(jlong nativePtr, jint button) {
628 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
629 event->setActionButton(button);
630}
631
632static jboolean android_view_MotionEvent_nativeIsTouchEvent(jlong nativePtr) {
633 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
634 return event->isTouchEvent();
635}
636
637static jint android_view_MotionEvent_nativeGetFlags(jlong nativePtr) {
638 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
639 return event->getFlags();
640}
641
642static void android_view_MotionEvent_nativeSetFlags(jlong nativePtr, jint flags) {
643 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
644 event->setFlags(flags);
645}
646
647static jint android_view_MotionEvent_nativeGetEdgeFlags(jlong nativePtr) {
648 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
649 return event->getEdgeFlags();
650}
651
652static void android_view_MotionEvent_nativeSetEdgeFlags(jlong nativePtr, jint edgeFlags) {
653 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
654 event->setEdgeFlags(edgeFlags);
655}
656
657static jint android_view_MotionEvent_nativeGetMetaState(jlong nativePtr) {
658 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
659 return event->getMetaState();
660}
661
662static jint android_view_MotionEvent_nativeGetButtonState(jlong nativePtr) {
663 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
664 return event->getButtonState();
665}
666
667static void android_view_MotionEvent_nativeSetButtonState(jlong nativePtr, jint buttonState) {
668 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
669 event->setButtonState(buttonState);
670}
671
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800672static jint android_view_MotionEvent_nativeGetClassification(jlong nativePtr) {
673 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
674 return static_cast<jint>(event->getClassification());
675}
676
John Reck09709972016-10-03 15:47:18 -0700677static void android_view_MotionEvent_nativeOffsetLocation(jlong nativePtr, jfloat deltaX,
678 jfloat deltaY) {
679 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
680 return event->offsetLocation(deltaX, deltaY);
681}
682
683static jfloat android_view_MotionEvent_nativeGetXOffset(jlong nativePtr) {
684 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
685 return event->getXOffset();
686}
687
688static jfloat android_view_MotionEvent_nativeGetYOffset(jlong nativePtr) {
689 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
690 return event->getYOffset();
691}
692
693static jfloat android_view_MotionEvent_nativeGetXPrecision(jlong nativePtr) {
694 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
695 return event->getXPrecision();
696}
697
698static jfloat android_view_MotionEvent_nativeGetYPrecision(jlong nativePtr) {
699 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
700 return event->getYPrecision();
701}
702
Garfield Tan1da86282019-07-15 14:00:35 -0700703static jfloat android_view_MotionEvent_nativeGetXCursorPosition(jlong nativePtr) {
704 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
705 return event->getXCursorPosition();
706}
707
708static jfloat android_view_MotionEvent_nativeGetYCursorPosition(jlong nativePtr) {
709 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
710 return event->getYCursorPosition();
711}
712
713static void android_view_MotionEvent_nativeSetCursorPosition(jlong nativePtr, jfloat x, jfloat y) {
714 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
715 event->setCursorPosition(x, y);
716}
717
John Reck09709972016-10-03 15:47:18 -0700718static jlong android_view_MotionEvent_nativeGetDownTimeNanos(jlong nativePtr) {
719 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
720 return event->getDownTime();
721}
722
723static void android_view_MotionEvent_nativeSetDownTimeNanos(jlong nativePtr, jlong downTimeNanos) {
724 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
725 event->setDownTime(downTimeNanos);
726}
727
728static jint android_view_MotionEvent_nativeGetPointerCount(jlong nativePtr) {
729 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
730 return jint(event->getPointerCount());
731}
732
733static jint android_view_MotionEvent_nativeFindPointerIndex(jlong nativePtr, jint pointerId) {
734 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
735 return jint(event->findPointerIndex(pointerId));
736}
737
738static jint android_view_MotionEvent_nativeGetHistorySize(jlong nativePtr) {
739 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
740 return jint(event->getHistorySize());
741}
742
743static void android_view_MotionEvent_nativeScale(jlong nativePtr, jfloat scale) {
744 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
745 event->scale(scale);
746}
747
748static void android_view_MotionEvent_nativeTransform(jlong nativePtr, jlong matrixPtr) {
749 MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
750 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr);
751
752 static_assert(SkMatrix::kMScaleX == 0, "SkMatrix unexpected index");
753 static_assert(SkMatrix::kMSkewX == 1, "SkMatrix unexpected index");
754 static_assert(SkMatrix::kMTransX == 2, "SkMatrix unexpected index");
755 static_assert(SkMatrix::kMSkewY == 3, "SkMatrix unexpected index");
756 static_assert(SkMatrix::kMScaleY == 4, "SkMatrix unexpected index");
757 static_assert(SkMatrix::kMTransY == 5, "SkMatrix unexpected index");
758 static_assert(SkMatrix::kMPersp0 == 6, "SkMatrix unexpected index");
759 static_assert(SkMatrix::kMPersp1 == 7, "SkMatrix unexpected index");
760 static_assert(SkMatrix::kMPersp2 == 8, "SkMatrix unexpected index");
761 float m[9];
762 matrix->get9(m);
763 event->transform(m);
764}
765
Jeff Brown46b9ac02010-04-22 18:58:52 -0700766// ----------------------------------------------------------------------------
767
Daniel Micay76f6a862015-09-19 17:31:01 -0400768static const JNINativeMethod gMotionEventMethods[] = {
Jeff Brown20e987b2010-08-23 12:01:02 -0700769 /* name, signature, funcPtr */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800770 { "nativeInitialize",
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800771 "(JIIIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000772 "[Landroid/view/MotionEvent$PointerCoords;)J",
Jeff Brown91c69ab2011-02-14 17:03:18 -0800773 (void*)android_view_MotionEvent_nativeInitialize },
Jeff Brown91c69ab2011-02-14 17:03:18 -0800774 { "nativeDispose",
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000775 "(J)V",
Jeff Brown91c69ab2011-02-14 17:03:18 -0800776 (void*)android_view_MotionEvent_nativeDispose },
777 { "nativeAddBatch",
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000778 "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V",
Jeff Brown91c69ab2011-02-14 17:03:18 -0800779 (void*)android_view_MotionEvent_nativeAddBatch },
Jeff Brown91c69ab2011-02-14 17:03:18 -0800780 { "nativeReadFromParcel",
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000781 "(JLandroid/os/Parcel;)J",
Jeff Brown91c69ab2011-02-14 17:03:18 -0800782 (void*)android_view_MotionEvent_nativeReadFromParcel },
783 { "nativeWriteToParcel",
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000784 "(JLandroid/os/Parcel;)V",
Jeff Brown91c69ab2011-02-14 17:03:18 -0800785 (void*)android_view_MotionEvent_nativeWriteToParcel },
Michael Wright337d9d22014-04-22 15:03:48 -0700786 { "nativeAxisToString", "(I)Ljava/lang/String;",
787 (void*)android_view_MotionEvent_nativeAxisToString },
788 { "nativeAxisFromString", "(Ljava/lang/String;)I",
789 (void*)android_view_MotionEvent_nativeAxisFromString },
John Reck09709972016-10-03 15:47:18 -0700790 { "nativeGetPointerProperties",
791 "(JILandroid/view/MotionEvent$PointerProperties;)V",
792 (void*)android_view_MotionEvent_nativeGetPointerProperties },
793 { "nativeGetPointerCoords",
794 "(JIILandroid/view/MotionEvent$PointerCoords;)V",
795 (void*)android_view_MotionEvent_nativeGetPointerCoords },
796
797 // --------------- @FastNative ----------------------
798 { "nativeGetPointerId",
799 "(JI)I",
800 (void*)android_view_MotionEvent_nativeGetPointerId },
801 { "nativeGetToolType",
802 "(JI)I",
803 (void*)android_view_MotionEvent_nativeGetToolType },
804 { "nativeGetEventTimeNanos",
805 "(JI)J",
806 (void*)android_view_MotionEvent_nativeGetEventTimeNanos },
807 { "nativeGetRawAxisValue",
808 "(JIII)F",
809 (void*)android_view_MotionEvent_nativeGetRawAxisValue },
810 { "nativeGetAxisValue",
811 "(JIII)F",
812 (void*)android_view_MotionEvent_nativeGetAxisValue },
813
814 // --------------- @CriticalNative ------------------
815
816 { "nativeCopy",
817 "(JJZ)J",
818 (void*)android_view_MotionEvent_nativeCopy },
819 { "nativeGetDeviceId",
820 "(J)I",
821 (void*)android_view_MotionEvent_nativeGetDeviceId },
822 { "nativeGetSource",
823 "(J)I",
824 (void*)android_view_MotionEvent_nativeGetSource },
825 { "nativeSetSource",
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800826 "(JI)V",
John Reck09709972016-10-03 15:47:18 -0700827 (void*)android_view_MotionEvent_nativeSetSource },
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800828 { "nativeGetDisplayId",
829 "(J)I",
830 (void*)android_view_MotionEvent_nativeGetDisplayId },
831 { "nativeSetDisplayId",
832 "(JI)V",
833 (void*)android_view_MotionEvent_nativeSetDisplayId },
John Reck09709972016-10-03 15:47:18 -0700834 { "nativeGetAction",
835 "(J)I",
836 (void*)android_view_MotionEvent_nativeGetAction },
837 { "nativeSetAction",
838 "(JI)V",
839 (void*)android_view_MotionEvent_nativeSetAction },
840 { "nativeGetActionButton",
841 "(J)I",
842 (void*)android_view_MotionEvent_nativeGetActionButton},
843 { "nativeSetActionButton",
844 "(JI)V",
845 (void*)android_view_MotionEvent_nativeSetActionButton},
846 { "nativeIsTouchEvent",
847 "(J)Z",
848 (void*)android_view_MotionEvent_nativeIsTouchEvent },
849 { "nativeGetFlags",
850 "(J)I",
851 (void*)android_view_MotionEvent_nativeGetFlags },
852 { "nativeSetFlags",
853 "(JI)V",
854 (void*)android_view_MotionEvent_nativeSetFlags },
855 { "nativeGetEdgeFlags",
856 "(J)I",
857 (void*)android_view_MotionEvent_nativeGetEdgeFlags },
858 { "nativeSetEdgeFlags",
859 "(JI)V",
860 (void*)android_view_MotionEvent_nativeSetEdgeFlags },
861 { "nativeGetMetaState",
862 "(J)I",
863 (void*)android_view_MotionEvent_nativeGetMetaState },
864 { "nativeGetButtonState",
865 "(J)I",
866 (void*)android_view_MotionEvent_nativeGetButtonState },
867 { "nativeSetButtonState",
868 "(JI)V",
869 (void*)android_view_MotionEvent_nativeSetButtonState },
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800870 { "nativeGetClassification",
871 "(J)I",
872 (void*)android_view_MotionEvent_nativeGetClassification },
John Reck09709972016-10-03 15:47:18 -0700873 { "nativeOffsetLocation",
874 "(JFF)V",
875 (void*)android_view_MotionEvent_nativeOffsetLocation },
876 { "nativeGetXOffset",
877 "(J)F",
878 (void*)android_view_MotionEvent_nativeGetXOffset },
879 { "nativeGetYOffset",
880 "(J)F",
881 (void*)android_view_MotionEvent_nativeGetYOffset },
882 { "nativeGetXPrecision",
883 "(J)F",
884 (void*)android_view_MotionEvent_nativeGetXPrecision },
885 { "nativeGetYPrecision",
886 "(J)F",
887 (void*)android_view_MotionEvent_nativeGetYPrecision },
Garfield Tan1da86282019-07-15 14:00:35 -0700888 { "nativeGetXCursorPosition",
889 "(J)F",
890 (void*)android_view_MotionEvent_nativeGetXCursorPosition },
891 { "nativeGetYCursorPosition",
892 "(J)F",
893 (void*)android_view_MotionEvent_nativeGetYCursorPosition },
894 { "nativeSetCursorPosition",
895 "(JFF)V",
896 (void*)android_view_MotionEvent_nativeSetCursorPosition },
John Reck09709972016-10-03 15:47:18 -0700897 { "nativeGetDownTimeNanos",
898 "(J)J",
899 (void*)android_view_MotionEvent_nativeGetDownTimeNanos },
900 { "nativeSetDownTimeNanos",
901 "(JJ)V",
902 (void*)android_view_MotionEvent_nativeSetDownTimeNanos },
903 { "nativeGetPointerCount",
904 "(J)I",
905 (void*)android_view_MotionEvent_nativeGetPointerCount },
906 { "nativeFindPointerIndex",
907 "(JI)I",
908 (void*)android_view_MotionEvent_nativeFindPointerIndex },
909 { "nativeGetHistorySize",
910 "(J)I",
911 (void*)android_view_MotionEvent_nativeGetHistorySize },
912 { "nativeScale",
913 "(JF)V",
914 (void*)android_view_MotionEvent_nativeScale },
915 { "nativeTransform",
916 "(JJ)V",
917 (void*)android_view_MotionEvent_nativeTransform },
Jeff Brown20e987b2010-08-23 12:01:02 -0700918};
919
Jeff Brown46b9ac02010-04-22 18:58:52 -0700920int register_android_view_MotionEvent(JNIEnv* env) {
Andreas Gampe987f79f2014-11-18 17:29:46 -0800921 int res = RegisterMethodsOrDie(env, "android/view/MotionEvent", gMotionEventMethods,
922 NELEM(gMotionEventMethods));
Jeff Brown20e987b2010-08-23 12:01:02 -0700923
Andreas Gampe987f79f2014-11-18 17:29:46 -0800924 gMotionEventClassInfo.clazz = FindClassOrDie(env, "android/view/MotionEvent");
925 gMotionEventClassInfo.clazz = MakeGlobalRefOrDie(env, gMotionEventClassInfo.clazz);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700926
Andreas Gampe987f79f2014-11-18 17:29:46 -0800927 gMotionEventClassInfo.obtain = GetStaticMethodIDOrDie(env, gMotionEventClassInfo.clazz,
Jeff Brown91c69ab2011-02-14 17:03:18 -0800928 "obtain", "()Landroid/view/MotionEvent;");
Andreas Gampe987f79f2014-11-18 17:29:46 -0800929 gMotionEventClassInfo.recycle = GetMethodIDOrDie(env, gMotionEventClassInfo.clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700930 "recycle", "()V");
Andreas Gampe987f79f2014-11-18 17:29:46 -0800931 gMotionEventClassInfo.mNativePtr = GetFieldIDOrDie(env, gMotionEventClassInfo.clazz,
Ashok Bhat99a1ef22014-01-08 14:45:08 +0000932 "mNativePtr", "J");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700933
Andreas Gampe987f79f2014-11-18 17:29:46 -0800934 jclass clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerCoords");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800935
Andreas Gampe987f79f2014-11-18 17:29:46 -0800936 gPointerCoordsClassInfo.mPackedAxisBits = GetFieldIDOrDie(env, clazz, "mPackedAxisBits", "J");
937 gPointerCoordsClassInfo.mPackedAxisValues = GetFieldIDOrDie(env, clazz, "mPackedAxisValues",
938 "[F");
939 gPointerCoordsClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "F");
940 gPointerCoordsClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "F");
941 gPointerCoordsClassInfo.pressure = GetFieldIDOrDie(env, clazz, "pressure", "F");
942 gPointerCoordsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "F");
943 gPointerCoordsClassInfo.touchMajor = GetFieldIDOrDie(env, clazz, "touchMajor", "F");
944 gPointerCoordsClassInfo.touchMinor = GetFieldIDOrDie(env, clazz, "touchMinor", "F");
945 gPointerCoordsClassInfo.toolMajor = GetFieldIDOrDie(env, clazz, "toolMajor", "F");
946 gPointerCoordsClassInfo.toolMinor = GetFieldIDOrDie(env, clazz, "toolMinor", "F");
947 gPointerCoordsClassInfo.orientation = GetFieldIDOrDie(env, clazz, "orientation", "F");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700948
Andreas Gampe987f79f2014-11-18 17:29:46 -0800949 clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerProperties");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700950
Andreas Gampe987f79f2014-11-18 17:29:46 -0800951 gPointerPropertiesClassInfo.id = GetFieldIDOrDie(env, clazz, "id", "I");
952 gPointerPropertiesClassInfo.toolType = GetFieldIDOrDie(env, clazz, "toolType", "I");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700953
Andreas Gampe987f79f2014-11-18 17:29:46 -0800954 return res;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700955}
956
957} // namespace android