input.cpp revision 9d3b1a424c5c61e24e9659d15fb353026a00d925
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
33using android::InputEvent;
34using android::InputQueue;
35using android::KeyEvent;
36using android::Looper;
37using android::MotionEvent;
38using android::sp;
39using android::Vector;
40
41int32_t AInputEvent_getType(const AInputEvent* event) {
42    return static_cast<const InputEvent*>(event)->getType();
43}
44
45int32_t AInputEvent_getDeviceId(const AInputEvent* event) {
46    return static_cast<const InputEvent*>(event)->getDeviceId();
47}
48
49int32_t AInputEvent_getSource(const AInputEvent* event) {
50    return static_cast<const InputEvent*>(event)->getSource();
51}
52
53int32_t AKeyEvent_getAction(const AInputEvent* key_event) {
54    return static_cast<const KeyEvent*>(key_event)->getAction();
55}
56
57int32_t AKeyEvent_getFlags(const AInputEvent* key_event) {
58    return static_cast<const KeyEvent*>(key_event)->getFlags();
59}
60
61int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) {
62    return static_cast<const KeyEvent*>(key_event)->getKeyCode();
63}
64
65int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) {
66    return static_cast<const KeyEvent*>(key_event)->getScanCode();
67}
68
69int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) {
70    return static_cast<const KeyEvent*>(key_event)->getMetaState();
71}
72int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) {
73    return static_cast<const KeyEvent*>(key_event)->getRepeatCount();
74}
75
76int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) {
77    return static_cast<const KeyEvent*>(key_event)->getDownTime();
78}
79
80
81int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) {
82    return static_cast<const KeyEvent*>(key_event)->getEventTime();
83}
84
85int32_t AMotionEvent_getAction(const AInputEvent* motion_event) {
86    return static_cast<const MotionEvent*>(motion_event)->getAction();
87}
88
89int32_t AMotionEvent_getFlags(const AInputEvent* motion_event) {
90    return static_cast<const MotionEvent*>(motion_event)->getFlags();
91}
92
93int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) {
94    return static_cast<const MotionEvent*>(motion_event)->getMetaState();
95}
96
97int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) {
98    return static_cast<const MotionEvent*>(motion_event)->getButtonState();
99}
100
101int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) {
102    return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags();
103}
104
105int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) {
106    return static_cast<const MotionEvent*>(motion_event)->getDownTime();
107}
108
109int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) {
110    return static_cast<const MotionEvent*>(motion_event)->getEventTime();
111}
112
113float AMotionEvent_getXOffset(const AInputEvent* motion_event) {
114    return static_cast<const MotionEvent*>(motion_event)->getXOffset();
115}
116
117float AMotionEvent_getYOffset(const AInputEvent* motion_event) {
118    return static_cast<const MotionEvent*>(motion_event)->getYOffset();
119}
120
121float AMotionEvent_getXPrecision(const AInputEvent* motion_event) {
122    return static_cast<const MotionEvent*>(motion_event)->getXPrecision();
123}
124
125float AMotionEvent_getYPrecision(const AInputEvent* motion_event) {
126    return static_cast<const MotionEvent*>(motion_event)->getYPrecision();
127}
128
129size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) {
130    return static_cast<const MotionEvent*>(motion_event)->getPointerCount();
131}
132
133int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) {
134    return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index);
135}
136
137int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) {
138    return static_cast<const MotionEvent*>(motion_event)->getToolType(pointer_index);
139}
140
141float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) {
142    return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index);
143}
144
145float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) {
146    return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index);
147}
148
149float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) {
150    return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index);
151}
152
153float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) {
154    return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index);
155}
156
157float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) {
158    return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index);
159}
160
161float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) {
162    return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index);
163}
164
165float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) {
166    return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index);
167}
168
169float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) {
170    return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index);
171}
172
173float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) {
174    return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index);
175}
176
177float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) {
178    return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index);
179}
180
181float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) {
182    return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index);
183}
184
185float 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
190size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) {
191    return static_cast<const MotionEvent*>(motion_event)->getHistorySize();
192}
193
194int64_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
200float 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
206float 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
212float 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
218float 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
224float 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
230float 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
236float 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
242float 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
248float 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
254float 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
260float 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
266float 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
273void 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
280void AInputQueue_detachLooper(AInputQueue* queue) {
281    InputQueue* iq = static_cast<InputQueue*>(queue);
282    iq->detachLooper();
283}
284
285int32_t AInputQueue_hasEvents(AInputQueue* queue) {
286    InputQueue* iq = static_cast<InputQueue*>(queue);
287    return iq->hasEvents();
288}
289
290int32_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
298int32_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
304void 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