blob: fc521386e6e1a343e23b28775c55b147ef1ce82f [file] [log] [blame]
Dianne Hackborna95e4cb2010-06-18 18:09:33 -07001/*
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 Brown9d3b1a42013-07-01 19:07:15 -070021#include <input/Input.h>
22#include <input/InputTransport.h>
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070023#include <utils/Looper.h>
Jeff Brown6d0fec22010-07-23 21:28:06 -070024#include <utils/RefBase.h>
25#include <utils/Vector.h>
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070026
Dianne Hackbornd76b67c2010-07-13 17:48:30 -070027#include <android_runtime/android_app_NativeActivity.h>
Michael Wrighta44dd262013-04-10 21:12:00 -070028#include <android_runtime/android_view_InputQueue.h>
Dianne Hackbornd76b67c2010-07-13 17:48:30 -070029
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070030#include <poll.h>
Jeff Brown6d0fec22010-07-23 21:28:06 -070031#include <errno.h>
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070032
33using android::InputEvent;
Michael Wrighta44dd262013-04-10 21:12:00 -070034using android::InputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070035using android::KeyEvent;
Michael Wrighta44dd262013-04-10 21:12:00 -070036using android::Looper;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070037using android::MotionEvent;
Jeff Brown6d0fec22010-07-23 21:28:06 -070038using android::sp;
39using android::Vector;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070040
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070041int32_t AInputEvent_getType(const AInputEvent* event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070042 return static_cast<const InputEvent*>(event)->getType();
43}
44
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070045int32_t AInputEvent_getDeviceId(const AInputEvent* event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070046 return static_cast<const InputEvent*>(event)->getDeviceId();
47}
48
Jeff Brownc5ed5912010-07-14 18:48:53 -070049int32_t AInputEvent_getSource(const AInputEvent* event) {
50 return static_cast<const InputEvent*>(event)->getSource();
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070051}
52
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070053int32_t AKeyEvent_getAction(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070054 return static_cast<const KeyEvent*>(key_event)->getAction();
55}
56
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070057int32_t AKeyEvent_getFlags(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070058 return static_cast<const KeyEvent*>(key_event)->getFlags();
59}
60
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070061int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070062 return static_cast<const KeyEvent*>(key_event)->getKeyCode();
63}
64
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070065int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070066 return static_cast<const KeyEvent*>(key_event)->getScanCode();
67}
68
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070069int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070070 return static_cast<const KeyEvent*>(key_event)->getMetaState();
71}
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070072int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070073 return static_cast<const KeyEvent*>(key_event)->getRepeatCount();
74}
75
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070076int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070077 return static_cast<const KeyEvent*>(key_event)->getDownTime();
78}
79
Jeff Brownc5ed5912010-07-14 18:48:53 -070080
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070081int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070082 return static_cast<const KeyEvent*>(key_event)->getEventTime();
83}
84
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070085int32_t AMotionEvent_getAction(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070086 return static_cast<const MotionEvent*>(motion_event)->getAction();
87}
88
Jeff Brown85a31762010-09-01 17:01:00 -070089int32_t AMotionEvent_getFlags(const AInputEvent* motion_event) {
90 return static_cast<const MotionEvent*>(motion_event)->getFlags();
91}
92
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -070093int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -070094 return static_cast<const MotionEvent*>(motion_event)->getMetaState();
95}
96
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070097int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) {
98 return static_cast<const MotionEvent*>(motion_event)->getButtonState();
99}
100
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700101int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700102 return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags();
103}
104
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700105int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700106 return static_cast<const MotionEvent*>(motion_event)->getDownTime();
107}
108
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700109int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700110 return static_cast<const MotionEvent*>(motion_event)->getEventTime();
111}
112
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700113float AMotionEvent_getXOffset(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700114 return static_cast<const MotionEvent*>(motion_event)->getXOffset();
115}
116
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700117float AMotionEvent_getYOffset(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700118 return static_cast<const MotionEvent*>(motion_event)->getYOffset();
119}
120
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700121float AMotionEvent_getXPrecision(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700122 return static_cast<const MotionEvent*>(motion_event)->getXPrecision();
123}
124
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700125float AMotionEvent_getYPrecision(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700126 return static_cast<const MotionEvent*>(motion_event)->getYPrecision();
127}
128
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700129size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700130 return static_cast<const MotionEvent*>(motion_event)->getPointerCount();
131}
132
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700133int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700134 return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index);
135}
136
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700137int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) {
138 return static_cast<const MotionEvent*>(motion_event)->getToolType(pointer_index);
139}
140
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700141float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700142 return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index);
143}
144
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700145float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700146 return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index);
147}
148
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700149float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700150 return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index);
151}
152
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700153float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700154 return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index);
155}
156
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700157float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700158 return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index);
159}
160
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700161float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700162 return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index);
163}
164
Jeff Brownc5ed5912010-07-14 18:48:53 -0700165float 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
Jeff Brown91c69ab2011-02-14 17:03:18 -0800185float 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
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700190size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) {
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700191 return static_cast<const MotionEvent*>(motion_event)->getHistorySize();
192}
193
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800194int64_t AMotionEvent_getHistoricalEventTime(const AInputEvent* motion_event,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700195 size_t history_index) {
196 return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime(
197 history_index);
198}
199
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800200float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700201 size_t history_index) {
202 return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX(
203 pointer_index, history_index);
204}
205
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800206float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700207 size_t history_index) {
208 return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY(
209 pointer_index, history_index);
210}
211
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800212float AMotionEvent_getHistoricalX(const AInputEvent* motion_event, size_t pointer_index,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700213 size_t history_index) {
214 return static_cast<const MotionEvent*>(motion_event)->getHistoricalX(
215 pointer_index, history_index);
216}
217
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800218float AMotionEvent_getHistoricalY(const AInputEvent* motion_event, size_t pointer_index,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700219 size_t history_index) {
220 return static_cast<const MotionEvent*>(motion_event)->getHistoricalY(
221 pointer_index, history_index);
222}
223
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800224float AMotionEvent_getHistoricalPressure(const AInputEvent* motion_event, size_t pointer_index,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700225 size_t history_index) {
226 return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure(
227 pointer_index, history_index);
228}
229
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800230float AMotionEvent_getHistoricalSize(const AInputEvent* motion_event, size_t pointer_index,
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700231 size_t history_index) {
232 return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize(
233 pointer_index, history_index);
234}
235
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800236float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700237 size_t history_index) {
238 return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor(
239 pointer_index, history_index);
240}
241
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800242float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700243 size_t history_index) {
244 return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor(
245 pointer_index, history_index);
246}
247
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800248float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700249 size_t history_index) {
250 return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor(
251 pointer_index, history_index);
252}
253
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800254float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700255 size_t history_index) {
256 return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor(
257 pointer_index, history_index);
258}
259
Andrew Hsiehc01e1ed2013-05-27 12:27:10 +0800260float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700261 size_t history_index) {
262 return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation(
263 pointer_index, history_index);
264}
265
Jeff Brown91c69ab2011-02-14 17:03:18 -0800266float 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
Jeff Brownc5ed5912010-07-14 18:48:53 -0700272
Dianne Hackborn68267412010-07-02 18:52:01 -0700273void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
Jeff Brown4fe6c3e2010-09-13 23:17:30 -0700274 int ident, ALooper_callbackFunc callback, void* data) {
Michael Wrighta44dd262013-04-10 21:12:00 -0700275 InputQueue* iq = static_cast<InputQueue*>(queue);
Brian Carlstrom82b007d2013-12-12 23:12:55 -0800276 Looper* l = reinterpret_cast<Looper*>(looper);
Michael Wrighta44dd262013-04-10 21:12:00 -0700277 iq->attachLooper(l, ident, callback, data);
Dianne Hackborn68267412010-07-02 18:52:01 -0700278}
279
280void AInputQueue_detachLooper(AInputQueue* queue) {
Michael Wrighta44dd262013-04-10 21:12:00 -0700281 InputQueue* iq = static_cast<InputQueue*>(queue);
282 iq->detachLooper();
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700283}
284
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700285int32_t AInputQueue_hasEvents(AInputQueue* queue) {
Michael Wrighta44dd262013-04-10 21:12:00 -0700286 InputQueue* iq = static_cast<InputQueue*>(queue);
287 return iq->hasEvents();
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700288}
289
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700290int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) {
Michael Wrighta44dd262013-04-10 21:12:00 -0700291 InputQueue* iq = static_cast<InputQueue*>(queue);
292 InputEvent* event;
293 int32_t res = iq->getEvent(&event);
294 *outEvent = event;
295 return res;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700296}
297
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700298int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) {
Michael Wrighta44dd262013-04-10 21:12:00 -0700299 InputQueue* iq = static_cast<InputQueue*>(queue);
300 InputEvent* e = static_cast<InputEvent*>(event);
301 return iq->preDispatchEvent(e) ? 1 : 0;
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700302}
303
Dianne Hackbornd76b67c2010-07-13 17:48:30 -0700304void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) {
Michael Wrighta44dd262013-04-10 21:12:00 -0700305 InputQueue* iq = static_cast<InputQueue*>(queue);
306 InputEvent* e = static_cast<InputEvent*>(event);
307 iq->finishEvent(e, handled != 0);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700308}