Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 "input" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <android/input.h> |
Jeff Brown | 9d3b1a4 | 2013-07-01 19:07:15 -0700 | [diff] [blame] | 21 | #include <input/Input.h> |
| 22 | #include <input/InputTransport.h> |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 23 | #include <utils/Looper.h> |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Vector.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 26 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 27 | #include <android_runtime/android_app_NativeActivity.h> |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 28 | #include <android_runtime/android_view_InputQueue.h> |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 29 | #include <android_view_MotionEvent.h> |
| 30 | #include <android_view_KeyEvent.h> |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 31 | |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 32 | #include <poll.h> |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 33 | #include <errno.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 34 | |
| 35 | using android::InputEvent; |
Siarhei Vishniakou | 10acd4a | 2023-04-12 11:01:15 -0700 | [diff] [blame] | 36 | using android::InputEventType; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 37 | using android::InputQueue; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 38 | using android::KeyEvent; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 39 | using android::Looper; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 40 | using android::MotionEvent; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 41 | using android::sp; |
| 42 | using android::Vector; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 43 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 44 | int32_t AInputEvent_getType(const AInputEvent* event) { |
Siarhei Vishniakou | 10acd4a | 2023-04-12 11:01:15 -0700 | [diff] [blame] | 45 | const InputEventType eventType = static_cast<const InputEvent*>(event)->getType(); |
| 46 | return static_cast<int32_t>(eventType); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 49 | int32_t AInputEvent_getDeviceId(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 50 | return static_cast<const InputEvent*>(event)->getDeviceId(); |
| 51 | } |
| 52 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 53 | int32_t AInputEvent_getSource(const AInputEvent* event) { |
| 54 | return static_cast<const InputEvent*>(event)->getSource(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 57 | void AInputEvent_release(const AInputEvent* event) { |
| 58 | delete event; |
| 59 | } |
| 60 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 61 | int32_t AKeyEvent_getAction(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 62 | return static_cast<const KeyEvent*>(key_event)->getAction(); |
| 63 | } |
| 64 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 65 | int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 66 | return static_cast<const KeyEvent*>(key_event)->getFlags(); |
| 67 | } |
| 68 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 69 | int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 70 | return static_cast<const KeyEvent*>(key_event)->getKeyCode(); |
| 71 | } |
| 72 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 73 | int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 74 | return static_cast<const KeyEvent*>(key_event)->getScanCode(); |
| 75 | } |
| 76 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 77 | int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 78 | return static_cast<const KeyEvent*>(key_event)->getMetaState(); |
| 79 | } |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 80 | int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 81 | return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); |
| 82 | } |
| 83 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 84 | int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 85 | return static_cast<const KeyEvent*>(key_event)->getDownTime(); |
| 86 | } |
| 87 | |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 88 | const AInputEvent* AKeyEvent_fromJava(JNIEnv* env, jobject keyEvent) { |
| 89 | std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); |
Arpit Singh | 14ee29a | 2024-02-16 12:10:39 +0000 | [diff] [blame] | 90 | *event = android::android_view_KeyEvent_obtainAsCopy(env, keyEvent); |
Prabir Pradhan | f5c06a1 | 2023-04-24 16:12:38 +0000 | [diff] [blame] | 91 | return event.release(); |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 92 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 93 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 94 | int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 95 | return static_cast<const KeyEvent*>(key_event)->getEventTime(); |
| 96 | } |
| 97 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 98 | int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 99 | return static_cast<const MotionEvent*>(motion_event)->getAction(); |
| 100 | } |
| 101 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 102 | int32_t AMotionEvent_getFlags(const AInputEvent* motion_event) { |
Prabir Pradhan | 43a8350 | 2024-06-06 02:20:17 +0000 | [diff] [blame] | 103 | return static_cast<const MotionEvent*>(motion_event)->getFlags() & |
| 104 | ~AMOTION_EVENT_PRIVATE_FLAG_MASK; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 107 | int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 108 | return static_cast<const MotionEvent*>(motion_event)->getMetaState(); |
| 109 | } |
| 110 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 111 | int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) { |
| 112 | return static_cast<const MotionEvent*>(motion_event)->getButtonState(); |
| 113 | } |
| 114 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 115 | int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 116 | return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); |
| 117 | } |
| 118 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 119 | int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 120 | return static_cast<const MotionEvent*>(motion_event)->getDownTime(); |
| 121 | } |
| 122 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 123 | int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 124 | return static_cast<const MotionEvent*>(motion_event)->getEventTime(); |
| 125 | } |
| 126 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 127 | float AMotionEvent_getXOffset(const AInputEvent* motion_event) { |
Prabir Pradhan | de54d1a | 2024-03-05 22:04:52 +0000 | [diff] [blame] | 128 | return static_cast<const MotionEvent*>(motion_event)->getRawXOffset(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 131 | float AMotionEvent_getYOffset(const AInputEvent* motion_event) { |
Prabir Pradhan | de54d1a | 2024-03-05 22:04:52 +0000 | [diff] [blame] | 132 | return static_cast<const MotionEvent*>(motion_event)->getRawYOffset(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 135 | float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 136 | return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); |
| 137 | } |
| 138 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 139 | float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 140 | return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); |
| 141 | } |
| 142 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 143 | size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 144 | return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); |
| 145 | } |
| 146 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 147 | int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 148 | return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); |
| 149 | } |
| 150 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 151 | int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) { |
Siarhei Vishniakou | d1be50b | 2022-11-01 14:40:03 -0700 | [diff] [blame] | 152 | const MotionEvent& motion = static_cast<const MotionEvent&>(*motion_event); |
| 153 | return static_cast<int32_t>(motion.getToolType(pointer_index)); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 156 | float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 157 | return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); |
| 158 | } |
| 159 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 160 | float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 161 | return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); |
| 162 | } |
| 163 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 164 | float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 165 | return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); |
| 166 | } |
| 167 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 168 | float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 169 | return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); |
| 170 | } |
| 171 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 172 | float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 173 | return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); |
| 174 | } |
| 175 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 176 | float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 177 | return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); |
| 178 | } |
| 179 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 180 | float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 181 | return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); |
| 182 | } |
| 183 | |
| 184 | float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 185 | return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); |
| 186 | } |
| 187 | |
| 188 | float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 189 | return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); |
| 190 | } |
| 191 | |
| 192 | float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 193 | return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); |
| 194 | } |
| 195 | |
| 196 | float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { |
| 197 | return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); |
| 198 | } |
| 199 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 200 | float AMotionEvent_getAxisValue(const AInputEvent* motion_event, |
| 201 | int32_t axis, size_t pointer_index) { |
| 202 | return static_cast<const MotionEvent*>(motion_event)->getAxisValue(axis, pointer_index); |
| 203 | } |
| 204 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 205 | size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 206 | return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); |
| 207 | } |
| 208 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 209 | int64_t AMotionEvent_getHistoricalEventTime(const AInputEvent* motion_event, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 210 | size_t history_index) { |
| 211 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( |
| 212 | history_index); |
| 213 | } |
| 214 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 215 | float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 216 | size_t history_index) { |
| 217 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( |
| 218 | pointer_index, history_index); |
| 219 | } |
| 220 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 221 | float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 222 | size_t history_index) { |
| 223 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( |
| 224 | pointer_index, history_index); |
| 225 | } |
| 226 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 227 | float AMotionEvent_getHistoricalX(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 228 | size_t history_index) { |
| 229 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( |
| 230 | pointer_index, history_index); |
| 231 | } |
| 232 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 233 | float AMotionEvent_getHistoricalY(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 234 | size_t history_index) { |
| 235 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( |
| 236 | pointer_index, history_index); |
| 237 | } |
| 238 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 239 | float AMotionEvent_getHistoricalPressure(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 240 | size_t history_index) { |
| 241 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( |
| 242 | pointer_index, history_index); |
| 243 | } |
| 244 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 245 | float AMotionEvent_getHistoricalSize(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 246 | size_t history_index) { |
| 247 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( |
| 248 | pointer_index, history_index); |
| 249 | } |
| 250 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 251 | float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 252 | size_t history_index) { |
| 253 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( |
| 254 | pointer_index, history_index); |
| 255 | } |
| 256 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 257 | float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 258 | size_t history_index) { |
| 259 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( |
| 260 | pointer_index, history_index); |
| 261 | } |
| 262 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 263 | float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 264 | size_t history_index) { |
| 265 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( |
| 266 | pointer_index, history_index); |
| 267 | } |
| 268 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 269 | float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 270 | size_t history_index) { |
| 271 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( |
| 272 | pointer_index, history_index); |
| 273 | } |
| 274 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 275 | float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 276 | size_t history_index) { |
| 277 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( |
| 278 | pointer_index, history_index); |
| 279 | } |
| 280 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 281 | float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, |
| 282 | int32_t axis, size_t pointer_index, size_t history_index) { |
| 283 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalAxisValue( |
| 284 | axis, pointer_index, history_index); |
| 285 | } |
| 286 | |
Vaibhav | e85c348 | 2022-02-11 17:50:41 +0530 | [diff] [blame] | 287 | int32_t AMotionEvent_getActionButton(const AInputEvent* motion_event) { |
| 288 | return static_cast<const MotionEvent*>(motion_event)->getActionButton(); |
| 289 | } |
| 290 | |
| 291 | int32_t AMotionEvent_getClassification(const AInputEvent* motion_event) { |
| 292 | switch (static_cast<const MotionEvent*>(motion_event)->getClassification()) { |
| 293 | case android::MotionClassification::NONE: |
| 294 | return AMOTION_EVENT_CLASSIFICATION_NONE; |
| 295 | case android::MotionClassification::AMBIGUOUS_GESTURE: |
| 296 | return AMOTION_EVENT_CLASSIFICATION_AMBIGUOUS_GESTURE; |
| 297 | case android::MotionClassification::DEEP_PRESS: |
| 298 | return AMOTION_EVENT_CLASSIFICATION_DEEP_PRESS; |
Harry Cutts | 7013c86 | 2022-09-15 13:59:09 +0000 | [diff] [blame] | 299 | case android::MotionClassification::TWO_FINGER_SWIPE: |
| 300 | return AMOTION_EVENT_CLASSIFICATION_TWO_FINGER_SWIPE; |
Harry Cutts | e2da408 | 2022-12-02 17:24:34 +0000 | [diff] [blame] | 301 | case android::MotionClassification::MULTI_FINGER_SWIPE: |
| 302 | return AMOTION_EVENT_CLASSIFICATION_MULTI_FINGER_SWIPE; |
Harry Cutts | 7ef8111 | 2022-12-20 11:04:20 +0000 | [diff] [blame] | 303 | case android::MotionClassification::PINCH: |
| 304 | return AMOTION_EVENT_CLASSIFICATION_PINCH; |
Vaibhav | e85c348 | 2022-02-11 17:50:41 +0530 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 308 | const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent) { |
| 309 | MotionEvent* eventSrc = android::android_view_MotionEvent_getNativePtr(env, motionEvent); |
| 310 | if (eventSrc == nullptr) { |
| 311 | return nullptr; |
| 312 | } |
| 313 | MotionEvent* event = new MotionEvent(); |
| 314 | event->copyFrom(eventSrc, true); |
| 315 | return event; |
| 316 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 317 | |
Arpit Singh | 982aa9d | 2024-01-17 15:30:41 +0000 | [diff] [blame] | 318 | jobject AInputEvent_toJava(JNIEnv* env, const AInputEvent* aInputEvent) { |
| 319 | LOG_ALWAYS_FATAL_IF(aInputEvent == nullptr, "Expected aInputEvent to be non-null"); |
| 320 | const int32_t eventType = AInputEvent_getType(aInputEvent); |
| 321 | switch (eventType) { |
| 322 | case AINPUT_EVENT_TYPE_MOTION: |
| 323 | return android::android_view_MotionEvent_obtainAsCopy(env, |
| 324 | static_cast<const MotionEvent&>( |
Arpit Singh | 43c34c8 | 2024-02-21 17:25:23 +0000 | [diff] [blame] | 325 | *aInputEvent)) |
| 326 | .release(); |
Arpit Singh | 982aa9d | 2024-01-17 15:30:41 +0000 | [diff] [blame] | 327 | case AINPUT_EVENT_TYPE_KEY: |
Arpit Singh | 14ee29a | 2024-02-16 12:10:39 +0000 | [diff] [blame] | 328 | return android::android_view_KeyEvent_obtainAsCopy(env, |
| 329 | static_cast<const KeyEvent&>( |
Arpit Singh | 43c34c8 | 2024-02-21 17:25:23 +0000 | [diff] [blame] | 330 | *aInputEvent)) |
| 331 | .release(); |
Arpit Singh | 982aa9d | 2024-01-17 15:30:41 +0000 | [diff] [blame] | 332 | default: |
| 333 | LOG_ALWAYS_FATAL("Unexpected event type %d in AInputEvent_toJava.", eventType); |
| 334 | } |
| 335 | } |
| 336 | |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 337 | void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 338 | int ident, ALooper_callbackFunc callback, void* data) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 339 | InputQueue* iq = static_cast<InputQueue*>(queue); |
Brian Carlstrom | 82b007d | 2013-12-12 23:12:55 -0800 | [diff] [blame] | 340 | Looper* l = reinterpret_cast<Looper*>(looper); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 341 | iq->attachLooper(l, ident, callback, data); |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | void AInputQueue_detachLooper(AInputQueue* queue) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 345 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 346 | iq->detachLooper(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 349 | int32_t AInputQueue_hasEvents(AInputQueue* queue) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 350 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 351 | return iq->hasEvents(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 354 | int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 355 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 356 | InputEvent* event; |
| 357 | int32_t res = iq->getEvent(&event); |
| 358 | *outEvent = event; |
| 359 | return res; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 362 | int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 363 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 364 | InputEvent* e = static_cast<InputEvent*>(event); |
| 365 | return iq->preDispatchEvent(e) ? 1 : 0; |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 368 | void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 369 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 370 | InputEvent* e = static_cast<InputEvent*>(event); |
| 371 | iq->finishEvent(e, handled != 0); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 372 | } |
Jim Blackler | 86df7e4 | 2021-09-01 16:24:23 +0100 | [diff] [blame] | 373 | |
Prabir Pradhan | d0c5dba | 2021-12-16 03:22:38 -0800 | [diff] [blame] | 374 | AInputQueue* AInputQueue_fromJava(JNIEnv* env, jobject inputQueue) { |
| 375 | return android::android_view_InputQueue_getNativePtr(env, inputQueue); |
Jim Blackler | 86df7e4 | 2021-09-01 16:24:23 +0100 | [diff] [blame] | 376 | } |