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> 21 #include <androidfw/Input.h> 22 #include <androidfw/InputTransport.h> 23 #include <utils/Looper.h> 24 #include <utils/RefBase.h> 25 #include <utils/Vector.h> 26 27 #include <android_runtime/android_app_NativeActivity.h> 28 29 #include <poll.h> 30 #include <errno.h> 31 32 using android::InputEvent; 33 using android::KeyEvent; 34 using android::MotionEvent; 35 using android::sp; 36 using android::Vector; 37 38 int32_t AInputEvent_getType(const AInputEvent* event) { 39 return static_cast<const InputEvent*>(event)->getType(); 40 } 41 42 int32_t AInputEvent_getDeviceId(const AInputEvent* event) { 43 return static_cast<const InputEvent*>(event)->getDeviceId(); 44 } 45 46 int32_t AInputEvent_getSource(const AInputEvent* event) { 47 return static_cast<const InputEvent*>(event)->getSource(); 48 } 49 50 int32_t AKeyEvent_getAction(const AInputEvent* key_event) { 51 return static_cast<const KeyEvent*>(key_event)->getAction(); 52 } 53 54 int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { 55 return static_cast<const KeyEvent*>(key_event)->getFlags(); 56 } 57 58 int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { 59 return static_cast<const KeyEvent*>(key_event)->getKeyCode(); 60 } 61 62 int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { 63 return static_cast<const KeyEvent*>(key_event)->getScanCode(); 64 } 65 66 int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { 67 return static_cast<const KeyEvent*>(key_event)->getMetaState(); 68 } 69 int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { 70 return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); 71 } 72 73 int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { 74 return static_cast<const KeyEvent*>(key_event)->getDownTime(); 75 } 76 77 78 int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { 79 return static_cast<const KeyEvent*>(key_event)->getEventTime(); 80 } 81 82 int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { 83 return static_cast<const MotionEvent*>(motion_event)->getAction(); 84 } 85 86 int32_t AMotionEvent_getFlags(const AInputEvent* motion_event) { 87 return static_cast<const MotionEvent*>(motion_event)->getFlags(); 88 } 89 90 int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { 91 return static_cast<const MotionEvent*>(motion_event)->getMetaState(); 92 } 93 94 int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) { 95 return static_cast<const MotionEvent*>(motion_event)->getButtonState(); 96 } 97 98 int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { 99 return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); 100 } 101 102 int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { 103 return static_cast<const MotionEvent*>(motion_event)->getDownTime(); 104 } 105 106 int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { 107 return static_cast<const MotionEvent*>(motion_event)->getEventTime(); 108 } 109 110 float AMotionEvent_getXOffset(const AInputEvent* motion_event) { 111 return static_cast<const MotionEvent*>(motion_event)->getXOffset(); 112 } 113 114 float AMotionEvent_getYOffset(const AInputEvent* motion_event) { 115 return static_cast<const MotionEvent*>(motion_event)->getYOffset(); 116 } 117 118 float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { 119 return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); 120 } 121 122 float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { 123 return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); 124 } 125 126 size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { 127 return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); 128 } 129 130 int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { 131 return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); 132 } 133 134 int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) { 135 return static_cast<const MotionEvent*>(motion_event)->getToolType(pointer_index); 136 } 137 138 float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { 139 return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); 140 } 141 142 float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { 143 return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); 144 } 145 146 float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { 147 return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); 148 } 149 150 float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { 151 return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); 152 } 153 154 float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { 155 return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); 156 } 157 158 float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { 159 return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); 160 } 161 162 float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { 163 return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); 164 } 165 166 float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { 167 return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); 168 } 169 170 float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { 171 return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); 172 } 173 174 float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { 175 return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); 176 } 177 178 float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { 179 return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); 180 } 181 182 float AMotionEvent_getAxisValue(const AInputEvent* motion_event, 183 int32_t axis, size_t pointer_index) { 184 return static_cast<const MotionEvent*>(motion_event)->getAxisValue(axis, pointer_index); 185 } 186 187 size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { 188 return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); 189 } 190 191 int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, 192 size_t history_index) { 193 return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( 194 history_index); 195 } 196 197 float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index, 198 size_t history_index) { 199 return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( 200 pointer_index, history_index); 201 } 202 203 float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index, 204 size_t history_index) { 205 return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( 206 pointer_index, history_index); 207 } 208 209 float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, 210 size_t history_index) { 211 return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( 212 pointer_index, history_index); 213 } 214 215 float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, 216 size_t history_index) { 217 return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( 218 pointer_index, history_index); 219 } 220 221 float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, 222 size_t history_index) { 223 return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( 224 pointer_index, history_index); 225 } 226 227 float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, 228 size_t history_index) { 229 return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( 230 pointer_index, history_index); 231 } 232 233 float AMotionEvent_getHistoricalTouchMajor(AInputEvent* motion_event, size_t pointer_index, 234 size_t history_index) { 235 return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( 236 pointer_index, history_index); 237 } 238 239 float AMotionEvent_getHistoricalTouchMinor(AInputEvent* motion_event, size_t pointer_index, 240 size_t history_index) { 241 return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( 242 pointer_index, history_index); 243 } 244 245 float AMotionEvent_getHistoricalToolMajor(AInputEvent* motion_event, size_t pointer_index, 246 size_t history_index) { 247 return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( 248 pointer_index, history_index); 249 } 250 251 float AMotionEvent_getHistoricalToolMinor(AInputEvent* motion_event, size_t pointer_index, 252 size_t history_index) { 253 return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( 254 pointer_index, history_index); 255 } 256 257 float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t pointer_index, 258 size_t history_index) { 259 return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( 260 pointer_index, history_index); 261 } 262 263 float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, 264 int32_t axis, size_t pointer_index, size_t history_index) { 265 return static_cast<const MotionEvent*>(motion_event)->getHistoricalAxisValue( 266 axis, pointer_index, history_index); 267 } 268 269 270 void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, 271 int ident, ALooper_callbackFunc callback, void* data) { 272 queue->attachLooper(looper, ident, callback, data); 273 } 274 275 void AInputQueue_detachLooper(AInputQueue* queue) { 276 queue->detachLooper(); 277 } 278 279 int32_t AInputQueue_hasEvents(AInputQueue* queue) { 280 return queue->hasEvents(); 281 } 282 283 int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { 284 return queue->getEvent(outEvent); 285 } 286 287 int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { 288 return queue->preDispatchEvent(event) ? 1 : 0; 289 } 290 291 void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { 292 queue->finishEvent(event, handled != 0, false); 293 } 294