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