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