blob: e04e4c3324f3b70b311f8610c1cd74ec575bbc25 [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 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 "InputManager-JNI"
18
Jeff Brown9c3cda02010-06-15 01:31:58 -070019//#define LOG_NDEBUG 0
20
21// Log debug messages about InputReaderPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070022#define DEBUG_INPUT_READER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070023
24// Log debug messages about InputDispatcherPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070025#define DEBUG_INPUT_DISPATCHER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070026
Jeff Brown83c09682010-12-23 17:50:18 -080027
Jeff Brown46b9ac02010-04-22 18:58:52 -070028#include "JNIHelp.h"
29#include "jni.h"
Jeff Brown349703e2010-06-22 01:27:15 -070030#include <limits.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070031#include <android_runtime/AndroidRuntime.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080032
Jeff Brown46b9ac02010-04-22 18:58:52 -070033#include <utils/Log.h>
34#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080035
Jeff Brownb4ff35d2011-01-02 16:37:43 -080036#include <input/InputManager.h>
37#include <input/PointerController.h>
38
39#include <android_view_KeyEvent.h>
40#include <android_view_MotionEvent.h>
41#include <android_view_InputChannel.h>
42#include <android/graphics/GraphicsJNI.h>
43
Jeff Brown00fa7bd2010-07-02 15:37:36 -070044#include "com_android_server_PowerManagerService.h"
Jeff Brown928e0542011-01-10 11:17:36 -080045#include "com_android_server_InputApplication.h"
46#include "com_android_server_InputApplicationHandle.h"
47#include "com_android_server_InputWindow.h"
48#include "com_android_server_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070049
50namespace android {
51
Jeff Brown46b9ac02010-04-22 18:58:52 -070052static struct {
53 jclass clazz;
54
Jeff Brown46b9ac02010-04-22 18:58:52 -070055 jmethodID notifyConfigurationChanged;
56 jmethodID notifyLidSwitchChanged;
Jeff Brown7fbdc842010-06-17 20:52:56 -070057 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070058 jmethodID notifyANR;
Jeff Brown349703e2010-06-22 01:27:15 -070059 jmethodID interceptKeyBeforeQueueing;
60 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070061 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070062 jmethodID checkInjectEventsPermission;
Jeff Brown46b9ac02010-04-22 18:58:52 -070063 jmethodID filterTouchEvents;
64 jmethodID filterJumpyTouchEvents;
Jeff Brown46b9ac02010-04-22 18:58:52 -070065 jmethodID getExcludedDeviceNames;
Jeff Brownae9fc032010-08-18 15:51:08 -070066 jmethodID getMaxEventsPerSecond;
Jeff Brown83c09682010-12-23 17:50:18 -080067 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080068 jmethodID getPointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070069} gCallbacksClassInfo;
70
71static struct {
72 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070073} gKeyEventClassInfo;
74
75static struct {
76 jclass clazz;
77} gMotionEventClassInfo;
78
Jeff Brown8d608662010-08-30 03:02:23 -070079static struct {
80 jclass clazz;
81
82 jmethodID ctor;
83 jmethodID addMotionRange;
84
85 jfieldID mId;
86 jfieldID mName;
87 jfieldID mSources;
88 jfieldID mKeyboardType;
89 jfieldID mMotionRanges;
90} gInputDeviceClassInfo;
91
Jeff Brown57c59372010-09-21 18:22:55 -070092static struct {
93 jclass clazz;
94
95 jfieldID touchscreen;
96 jfieldID keyboard;
97 jfieldID navigation;
98} gConfigurationClassInfo;
99
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800100static struct {
101 jclass clazz;
Jeff Brown349703e2010-06-22 01:27:15 -0700102
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800103 jfieldID bitmap;
104 jfieldID hotSpotX;
105 jfieldID hotSpotY;
106} gPointerIconClassInfo;
Jeff Brown83c09682010-12-23 17:50:18 -0800107
Jeff Brown928e0542011-01-10 11:17:36 -0800108
109// --- Global functions ---
110
111static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
112 const sp<InputApplicationHandle>& inputApplicationHandle) {
113 if (inputApplicationHandle == NULL) {
114 return NULL;
115 }
116 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
117 getInputApplicationHandleObjLocalRef(env);
118}
119
120static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
121 const sp<InputWindowHandle>& inputWindowHandle) {
122 if (inputWindowHandle == NULL) {
123 return NULL;
124 }
125 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
126 getInputWindowHandleObjLocalRef(env);
127}
128
129
130// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800131
Jeff Brown9c3cda02010-06-15 01:31:58 -0700132class NativeInputManager : public virtual RefBase,
133 public virtual InputReaderPolicyInterface,
134 public virtual InputDispatcherPolicyInterface {
135protected:
136 virtual ~NativeInputManager();
137
138public:
139 NativeInputManager(jobject callbacksObj);
140
141 inline sp<InputManager> getInputManager() const { return mInputManager; }
142
Jeff Brownb88102f2010-09-08 11:49:43 -0700143 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700144
Jeff Brown9c3cda02010-06-15 01:31:58 -0700145 void setDisplaySize(int32_t displayId, int32_t width, int32_t height);
146 void setDisplayOrientation(int32_t displayId, int32_t orientation);
147
Jeff Brown7fbdc842010-06-17 20:52:56 -0700148 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800149 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700150 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
151
Jeff Brown349703e2010-06-22 01:27:15 -0700152 void setInputWindows(JNIEnv* env, jobjectArray windowObjArray);
153 void setFocusedApplication(JNIEnv* env, jobject applicationObj);
154 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700155
Jeff Brown9c3cda02010-06-15 01:31:58 -0700156 /* --- InputReaderPolicyInterface implementation --- */
157
158 virtual bool getDisplayInfo(int32_t displayId,
159 int32_t* width, int32_t* height, int32_t* orientation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700160 virtual bool filterTouchEvents();
161 virtual bool filterJumpyTouchEvents();
Jeff Brown9c3cda02010-06-15 01:31:58 -0700162 virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames);
Jeff Brown83c09682010-12-23 17:50:18 -0800163 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700164
165 /* --- InputDispatcherPolicyInterface implementation --- */
166
Jeff Browne20c9e02010-10-11 14:20:19 -0700167 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
168 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700169 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700170 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800171 const sp<InputWindowHandle>& inputWindowHandle);
172 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700173 virtual nsecs_t getKeyRepeatTimeout();
Jeff Brownb21fb102010-09-07 10:44:57 -0700174 virtual nsecs_t getKeyRepeatDelay();
Jeff Brownae9fc032010-08-18 15:51:08 -0700175 virtual int32_t getMaxEventsPerSecond();
Jeff Brown1f245102010-11-18 20:53:46 -0800176 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brownb6997262010-10-08 22:31:17 -0700177 virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800178 virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700179 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800180 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800181 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700182 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700183 virtual bool checkInjectEventsPermissionNonReentrant(
184 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700185
186private:
187 sp<InputManager> mInputManager;
188
189 jobject mCallbacksObj;
190
191 // Cached filtering policies.
192 int32_t mFilterTouchEvents;
193 int32_t mFilterJumpyTouchEvents;
194
Jeff Brownae9fc032010-08-18 15:51:08 -0700195 // Cached throttling policy.
196 int32_t mMaxEventsPerSecond;
197
Jeff Brown83c09682010-12-23 17:50:18 -0800198 Mutex mLock;
199 struct Locked {
200 // Display size information.
201 int32_t displayWidth, displayHeight; // -1 when initialized
202 int32_t displayOrientation;
203
204 // Pointer controller singleton, created and destroyed as needed.
205 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800206 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700207
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700208 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700209 bool isScreenOn();
210 bool isScreenBright();
211
Jeff Brownb88102f2010-09-08 11:49:43 -0700212 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700213
Jeff Brown9c3cda02010-06-15 01:31:58 -0700214 static inline JNIEnv* jniEnv() {
215 return AndroidRuntime::getJNIEnv();
216 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700217};
218
Jeff Brown928e0542011-01-10 11:17:36 -0800219
Jeff Brown9c3cda02010-06-15 01:31:58 -0700220
221NativeInputManager::NativeInputManager(jobject callbacksObj) :
222 mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1),
Jeff Brown83c09682010-12-23 17:50:18 -0800223 mMaxEventsPerSecond(-1) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700224 JNIEnv* env = jniEnv();
225
226 mCallbacksObj = env->NewGlobalRef(callbacksObj);
227
Jeff Brown83c09682010-12-23 17:50:18 -0800228 {
229 AutoMutex _l(mLock);
230 mLocked.displayWidth = -1;
231 mLocked.displayHeight = -1;
232 mLocked.displayOrientation = ROTATION_0;
233 }
234
Jeff Brown9c3cda02010-06-15 01:31:58 -0700235 sp<EventHub> eventHub = new EventHub();
236 mInputManager = new InputManager(eventHub, this, this);
237}
238
239NativeInputManager::~NativeInputManager() {
240 JNIEnv* env = jniEnv();
241
242 env->DeleteGlobalRef(mCallbacksObj);
243}
244
Jeff Brownb88102f2010-09-08 11:49:43 -0700245void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700246 mInputManager->getReader()->dump(dump);
247 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700248
Jeff Brownb88102f2010-09-08 11:49:43 -0700249 mInputManager->getDispatcher()->dump(dump);
250 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700251}
252
Jeff Brown7fbdc842010-06-17 20:52:56 -0700253bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700254 if (env->ExceptionCheck()) {
255 LOGE("An exception was thrown by callback '%s'.", methodName);
256 LOGE_EX(env);
257 env->ExceptionClear();
258 return true;
259 }
260 return false;
261}
262
263void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height) {
264 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800265 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700266
Jeff Brown83c09682010-12-23 17:50:18 -0800267 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
268 mLocked.displayWidth = width;
269 mLocked.displayHeight = height;
270
271 sp<PointerController> controller = mLocked.pointerController.promote();
272 if (controller != NULL) {
273 controller->setDisplaySize(width, height);
274 }
275 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700276 }
277}
278
279void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
280 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800281 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700282
Jeff Brown83c09682010-12-23 17:50:18 -0800283 if (mLocked.displayOrientation != orientation) {
284 mLocked.displayOrientation = orientation;
285
286 sp<PointerController> controller = mLocked.pointerController.promote();
287 if (controller != NULL) {
288 controller->setDisplayOrientation(orientation);
289 }
290 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700291 }
292}
293
Jeff Brown7fbdc842010-06-17 20:52:56 -0700294status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800295 const sp<InputChannel>& inputChannel,
296 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
297 return mInputManager->getDispatcher()->registerInputChannel(
298 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700299}
300
301status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
302 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700303 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700304}
305
Jeff Brown9c3cda02010-06-15 01:31:58 -0700306bool NativeInputManager::getDisplayInfo(int32_t displayId,
307 int32_t* width, int32_t* height, int32_t* orientation) {
308 bool result = false;
309 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800310 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700311
Jeff Brown83c09682010-12-23 17:50:18 -0800312 if (mLocked.displayWidth > 0 && mLocked.displayHeight > 0) {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700313 if (width) {
Jeff Brown83c09682010-12-23 17:50:18 -0800314 *width = mLocked.displayWidth;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700315 }
316 if (height) {
Jeff Brown83c09682010-12-23 17:50:18 -0800317 *height = mLocked.displayHeight;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700318 }
319 if (orientation) {
Jeff Brown83c09682010-12-23 17:50:18 -0800320 *orientation = mLocked.displayOrientation;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700321 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700322 result = true;
323 }
324 }
325 return result;
326}
327
Jeff Brown9c3cda02010-06-15 01:31:58 -0700328bool NativeInputManager::filterTouchEvents() {
329 if (mFilterTouchEvents < 0) {
330 JNIEnv* env = jniEnv();
331
332 jboolean result = env->CallBooleanMethod(mCallbacksObj,
333 gCallbacksClassInfo.filterTouchEvents);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700334 if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700335 result = false;
336 }
337
338 mFilterTouchEvents = result ? 1 : 0;
339 }
340 return mFilterTouchEvents;
341}
342
343bool NativeInputManager::filterJumpyTouchEvents() {
344 if (mFilterJumpyTouchEvents < 0) {
345 JNIEnv* env = jniEnv();
346
347 jboolean result = env->CallBooleanMethod(mCallbacksObj,
348 gCallbacksClassInfo.filterJumpyTouchEvents);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700349 if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700350 result = false;
351 }
352
353 mFilterJumpyTouchEvents = result ? 1 : 0;
354 }
355 return mFilterJumpyTouchEvents;
356}
357
Jeff Brown9c3cda02010-06-15 01:31:58 -0700358void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) {
Jeff Brown8d608662010-08-30 03:02:23 -0700359 outExcludedDeviceNames.clear();
360
Jeff Brown9c3cda02010-06-15 01:31:58 -0700361 JNIEnv* env = jniEnv();
362
363 jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj,
364 gCallbacksClassInfo.getExcludedDeviceNames));
Jeff Brown7fbdc842010-06-17 20:52:56 -0700365 if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700366 jsize length = env->GetArrayLength(result);
367 for (jsize i = 0; i < length; i++) {
368 jstring item = jstring(env->GetObjectArrayElement(result, i));
369
370 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
371 outExcludedDeviceNames.add(String8(deviceNameChars));
372 env->ReleaseStringUTFChars(item, deviceNameChars);
373
374 env->DeleteLocalRef(item);
375 }
376 env->DeleteLocalRef(result);
377 }
378}
379
Jeff Brown83c09682010-12-23 17:50:18 -0800380sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
381 AutoMutex _l(mLock);
382
383 sp<PointerController> controller = mLocked.pointerController.promote();
384 if (controller == NULL) {
385 JNIEnv* env = jniEnv();
386 jint layer = env->CallIntMethod(mCallbacksObj, gCallbacksClassInfo.getPointerLayer);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800387 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
388 layer = -1;
389 }
Jeff Brown83c09682010-12-23 17:50:18 -0800390
391 controller = new PointerController(layer);
392 mLocked.pointerController = controller;
393
394 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
395 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800396
397 jobject iconObj = env->CallObjectMethod(mCallbacksObj, gCallbacksClassInfo.getPointerIcon);
398 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon") && iconObj) {
399 jfloat iconHotSpotX = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotX);
400 jfloat iconHotSpotY = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotY);
401 jobject iconBitmapObj = env->GetObjectField(iconObj, gPointerIconClassInfo.bitmap);
402 if (iconBitmapObj) {
403 SkBitmap* iconBitmap = GraphicsJNI::getNativeBitmap(env, iconBitmapObj);
404 if (iconBitmap) {
405 controller->setPointerIcon(iconBitmap, iconHotSpotX, iconHotSpotY);
406 }
407 env->DeleteLocalRef(iconBitmapObj);
408 }
409 env->DeleteLocalRef(iconObj);
410 }
Jeff Brown83c09682010-12-23 17:50:18 -0800411 }
412 return controller;
413}
414
Jeff Browne20c9e02010-10-11 14:20:19 -0700415void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
416 int32_t switchValue, uint32_t policyFlags) {
417#if DEBUG_INPUT_DISPATCHER_POLICY
418 LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
419 when, switchCode, switchValue, policyFlags);
420#endif
421
422 JNIEnv* env = jniEnv();
423
424 switch (switchCode) {
425 case SW_LID:
426 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged,
427 when, switchValue == 0);
428 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
429 break;
430 }
431}
432
Jeff Brown9c3cda02010-06-15 01:31:58 -0700433void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
434#if DEBUG_INPUT_DISPATCHER_POLICY
435 LOGD("notifyConfigurationChanged - when=%lld", when);
436#endif
437
438 JNIEnv* env = jniEnv();
439
Jeff Brown57c59372010-09-21 18:22:55 -0700440 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700441 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700442}
443
Jeff Brown519e0242010-09-15 15:18:56 -0700444nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800445 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700446#if DEBUG_INPUT_DISPATCHER_POLICY
447 LOGD("notifyANR");
448#endif
449
450 JNIEnv* env = jniEnv();
451
Jeff Brown928e0542011-01-10 11:17:36 -0800452 jobject inputApplicationHandleObj =
453 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
454 jobject inputWindowHandleObj =
455 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700456
Jeff Brown519e0242010-09-15 15:18:56 -0700457 jlong newTimeout = env->CallLongMethod(mCallbacksObj,
Jeff Brown928e0542011-01-10 11:17:36 -0800458 gCallbacksClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700459 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
460 newTimeout = 0; // abort dispatch
461 } else {
462 assert(newTimeout >= 0);
463 }
464
Jeff Brown928e0542011-01-10 11:17:36 -0800465 env->DeleteLocalRef(inputWindowHandleObj);
466 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700467 return newTimeout;
468}
469
Jeff Brown928e0542011-01-10 11:17:36 -0800470void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700471#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown928e0542011-01-10 11:17:36 -0800472 LOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700473#endif
474
Jeff Brown7fbdc842010-06-17 20:52:56 -0700475 JNIEnv* env = jniEnv();
476
Jeff Brown928e0542011-01-10 11:17:36 -0800477 jobject inputWindowHandleObj =
478 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
479 if (inputWindowHandleObj) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700480 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800481 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700482 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
483
Jeff Brown928e0542011-01-10 11:17:36 -0800484 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700485 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700486}
487
Jeff Brown9c3cda02010-06-15 01:31:58 -0700488nsecs_t NativeInputManager::getKeyRepeatTimeout() {
489 if (! isScreenOn()) {
490 // Disable key repeat when the screen is off.
491 return -1;
492 } else {
493 // TODO use ViewConfiguration.getLongPressTimeout()
494 return milliseconds_to_nanoseconds(500);
495 }
496}
497
Jeff Brownb21fb102010-09-07 10:44:57 -0700498nsecs_t NativeInputManager::getKeyRepeatDelay() {
499 return milliseconds_to_nanoseconds(50);
500}
501
Jeff Brownae9fc032010-08-18 15:51:08 -0700502int32_t NativeInputManager::getMaxEventsPerSecond() {
503 if (mMaxEventsPerSecond < 0) {
504 JNIEnv* env = jniEnv();
505
506 jint result = env->CallIntMethod(mCallbacksObj,
507 gCallbacksClassInfo.getMaxEventsPerSecond);
508 if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700509 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700510 }
511
512 mMaxEventsPerSecond = result;
513 }
514 return mMaxEventsPerSecond;
515}
516
Jeff Brown349703e2010-06-22 01:27:15 -0700517void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700518 Vector<InputWindow> windows;
Jeff Brown349703e2010-06-22 01:27:15 -0700519
Jeff Brownb88102f2010-09-08 11:49:43 -0700520 jsize length = env->GetArrayLength(windowObjArray);
521 for (jsize i = 0; i < length; i++) {
Jeff Brown928e0542011-01-10 11:17:36 -0800522 jobject windowObj = env->GetObjectArrayElement(windowObjArray, i);
523 if (! windowObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700524 break; // found null element indicating end of used portion of the array
Jeff Brown349703e2010-06-22 01:27:15 -0700525 }
526
Jeff Brownb88102f2010-09-08 11:49:43 -0700527 windows.push();
528 InputWindow& window = windows.editTop();
Jeff Brown928e0542011-01-10 11:17:36 -0800529 android_server_InputWindow_toNative(env, windowObj, &window);
530 if (window.inputChannel == NULL) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700531 windows.pop();
Jeff Brown349703e2010-06-22 01:27:15 -0700532 }
Jeff Brown928e0542011-01-10 11:17:36 -0800533 env->DeleteLocalRef(windowObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700534 }
Jeff Brown349703e2010-06-22 01:27:15 -0700535
Jeff Brownb88102f2010-09-08 11:49:43 -0700536 mInputManager->getDispatcher()->setInputWindows(windows);
Jeff Brown349703e2010-06-22 01:27:15 -0700537}
538
Jeff Brown349703e2010-06-22 01:27:15 -0700539void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700540 if (applicationObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700541 InputApplication application;
Jeff Brown928e0542011-01-10 11:17:36 -0800542 android_server_InputApplication_toNative(env, applicationObj, &application);
543 if (application.inputApplicationHandle != NULL) {
544 mInputManager->getDispatcher()->setFocusedApplication(&application);
545 }
Jeff Brown349703e2010-06-22 01:27:15 -0700546 }
Jeff Brown928e0542011-01-10 11:17:36 -0800547 mInputManager->getDispatcher()->setFocusedApplication(NULL);
Jeff Brown349703e2010-06-22 01:27:15 -0700548}
549
550void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700551 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700552}
553
Jeff Browne20c9e02010-10-11 14:20:19 -0700554bool NativeInputManager::isScreenOn() {
555 return android_server_PowerManagerService_isScreenOn();
556}
557
558bool NativeInputManager::isScreenBright() {
559 return android_server_PowerManagerService_isScreenBright();
560}
561
Jeff Brown1f245102010-11-18 20:53:46 -0800562void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
563 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700564 // Policy:
565 // - Ignore untrusted events and pass them along.
566 // - Ask the window manager what to do with normal events and trusted injected events.
567 // - For normal events wake and brighten the screen if currently off or dim.
568 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
569 const int32_t WM_ACTION_PASS_TO_USER = 1;
570 const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2;
571 const int32_t WM_ACTION_GO_TO_SLEEP = 4;
Jeff Browne20c9e02010-10-11 14:20:19 -0700572
Jeff Brown1f245102010-11-18 20:53:46 -0800573 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700574 bool isScreenOn = this->isScreenOn();
575 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700576
Jeff Brown3122e442010-10-11 23:32:49 -0700577 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800578 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
579 jint wmActions;
580 if (keyEventObj) {
581 wmActions = env->CallIntMethod(mCallbacksObj,
582 gCallbacksClassInfo.interceptKeyBeforeQueueing,
583 keyEventObj, policyFlags, isScreenOn);
584 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
585 wmActions = 0;
586 }
587 android_view_KeyEvent_recycle(env, keyEventObj);
588 env->DeleteLocalRef(keyEventObj);
589 } else {
590 LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700591 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700592 }
593
Jeff Brown1f245102010-11-18 20:53:46 -0800594 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700595 if (!isScreenOn) {
596 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700597 }
598
599 if (!isScreenBright) {
600 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
601 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700602 }
603
604 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
605 android_server_PowerManagerService_goToSleep(when);
606 }
607
608 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
609 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
610 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700611
Jeff Brown3122e442010-10-11 23:32:49 -0700612 if (wmActions & WM_ACTION_PASS_TO_USER) {
613 policyFlags |= POLICY_FLAG_PASS_TO_USER;
614 }
615 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700616 policyFlags |= POLICY_FLAG_PASS_TO_USER;
617 }
618}
619
620void NativeInputManager::interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700621 // Policy:
622 // - Ignore untrusted events and pass them along.
623 // - No special filtering for injected events required at this time.
624 // - Filter normal events based on screen state.
625 // - For normal events brighten (but do not wake) the screen if currently dim.
626 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
627 if (isScreenOn()) {
628 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700629
Jeff Brown3122e442010-10-11 23:32:49 -0700630 if (!isScreenBright()) {
631 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
632 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700633 }
Jeff Brown3122e442010-10-11 23:32:49 -0700634 } else {
635 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700636 }
637}
638
Jeff Brown928e0542011-01-10 11:17:36 -0800639bool NativeInputManager::interceptKeyBeforeDispatching(
640 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700641 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700642 // Policy:
643 // - Ignore untrusted events and pass them along.
644 // - Filter normal events and trusted injected events through the window manager policy to
645 // handle the HOME key and the like.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800646 bool result = false;
Jeff Brown3122e442010-10-11 23:32:49 -0700647 if (policyFlags & POLICY_FLAG_TRUSTED) {
648 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700649
Jeff Brown928e0542011-01-10 11:17:36 -0800650 // Note: inputWindowHandle may be null.
651 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800652 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
653 if (keyEventObj) {
654 jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
655 gCallbacksClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800656 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800657 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
658 android_view_KeyEvent_recycle(env, keyEventObj);
659 env->DeleteLocalRef(keyEventObj);
660 result = consumed && !error;
661 } else {
662 LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800663 }
Jeff Brown928e0542011-01-10 11:17:36 -0800664 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700665 }
Jeff Brown1f245102010-11-18 20:53:46 -0800666 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700667}
668
Jeff Brown928e0542011-01-10 11:17:36 -0800669bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800670 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700671 // Policy:
672 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800673 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700674 if (policyFlags & POLICY_FLAG_TRUSTED) {
675 JNIEnv* env = jniEnv();
676
Jeff Brown928e0542011-01-10 11:17:36 -0800677 // Note: inputWindowHandle may be null.
678 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800679 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
680 if (keyEventObj) {
Jeff Brown49ed71d2010-12-06 17:13:33 -0800681 jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800682 gCallbacksClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800683 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800684 checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey");
Jeff Brown1f245102010-11-18 20:53:46 -0800685 android_view_KeyEvent_recycle(env, keyEventObj);
686 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800687
688 if (fallbackKeyEventObj) {
689 // Note: outFallbackKeyEvent may be the same object as keyEvent.
690 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
691 outFallbackKeyEvent)) {
692 result = true;
693 }
694 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
695 env->DeleteLocalRef(fallbackKeyEventObj);
696 }
Jeff Brown1f245102010-11-18 20:53:46 -0800697 } else {
698 LOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800699 }
Jeff Brown928e0542011-01-10 11:17:36 -0800700 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700701 }
Jeff Brown1f245102010-11-18 20:53:46 -0800702 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700703}
704
Jeff Brown01ce2e92010-09-26 22:20:12 -0700705void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
706 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700707}
708
Jeff Brown349703e2010-06-22 01:27:15 -0700709
Jeff Brownb88102f2010-09-08 11:49:43 -0700710bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
711 int32_t injectorPid, int32_t injectorUid) {
712 JNIEnv* env = jniEnv();
713 jboolean result = env->CallBooleanMethod(mCallbacksObj,
714 gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
715 checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission");
Jeff Brown349703e2010-06-22 01:27:15 -0700716 return result;
717}
718
Jeff Brown83c09682010-12-23 17:50:18 -0800719
Jeff Brown9c3cda02010-06-15 01:31:58 -0700720// ----------------------------------------------------------------------------
721
722static sp<NativeInputManager> gNativeInputManager;
723
Jeff Brown46b9ac02010-04-22 18:58:52 -0700724static bool checkInputManagerUnitialized(JNIEnv* env) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700725 if (gNativeInputManager == NULL) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700726 LOGE("Input manager not initialized.");
727 jniThrowRuntimeException(env, "Input manager not initialized.");
728 return true;
729 }
730 return false;
731}
732
733static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
734 jobject callbacks) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700735 if (gNativeInputManager == NULL) {
736 gNativeInputManager = new NativeInputManager(callbacks);
737 } else {
738 LOGE("Input manager already initialized.");
739 jniThrowRuntimeException(env, "Input manager already initialized.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700740 }
741}
742
743static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
744 if (checkInputManagerUnitialized(env)) {
745 return;
746 }
747
Jeff Brown9c3cda02010-06-15 01:31:58 -0700748 status_t result = gNativeInputManager->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700749 if (result) {
750 jniThrowRuntimeException(env, "Input manager could not be started.");
751 }
752}
753
754static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz,
755 jint displayId, jint width, jint height) {
756 if (checkInputManagerUnitialized(env)) {
757 return;
758 }
759
760 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
761 // to be passed in like this, not sure which is better but leaving it like this
762 // keeps the window manager in direct control of when display transitions propagate down
763 // to the input dispatcher
Jeff Brown9c3cda02010-06-15 01:31:58 -0700764 gNativeInputManager->setDisplaySize(displayId, width, height);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700765}
766
767static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
768 jint displayId, jint orientation) {
769 if (checkInputManagerUnitialized(env)) {
770 return;
771 }
772
Jeff Brown9c3cda02010-06-15 01:31:58 -0700773 gNativeInputManager->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700774}
775
776static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700777 jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700778 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700779 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700780 }
781
Jeff Brownb88102f2010-09-08 11:49:43 -0700782 return gNativeInputManager->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700783 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700784}
785
786static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700787 jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700788 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700789 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700790 }
791
Jeff Brownb88102f2010-09-08 11:49:43 -0700792 return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700793 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700794}
795
796static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700797 jint deviceId, jint sourceMask, jint sw) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700798 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700799 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700800 }
801
Jeff Brownb88102f2010-09-08 11:49:43 -0700802 return gNativeInputManager->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700803 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700804}
805
806static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700807 jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700808 if (checkInputManagerUnitialized(env)) {
809 return JNI_FALSE;
810 }
811
812 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
813 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
814 jsize numCodes = env->GetArrayLength(keyCodes);
815 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700816 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700817 result = gNativeInputManager->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700818 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700819 } else {
820 result = JNI_FALSE;
821 }
822
823 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
824 env->ReleaseIntArrayElements(keyCodes, codes, 0);
825 return result;
826}
827
828static void throwInputChannelNotInitialized(JNIEnv* env) {
829 jniThrowException(env, "java/lang/IllegalStateException",
830 "inputChannel is not initialized");
831}
832
833static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env,
834 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
835 LOGW("Input channel object '%s' was disposed without first being unregistered with "
836 "the input manager!", inputChannel->getName().string());
837
Jeff Brown9c3cda02010-06-15 01:31:58 -0700838 if (gNativeInputManager != NULL) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700839 gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700840 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700841}
842
843static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800844 jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700845 if (checkInputManagerUnitialized(env)) {
846 return;
847 }
848
849 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
850 inputChannelObj);
851 if (inputChannel == NULL) {
852 throwInputChannelNotInitialized(env);
853 return;
854 }
855
Jeff Brown928e0542011-01-10 11:17:36 -0800856 sp<InputWindowHandle> inputWindowHandle =
857 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700858
859 status_t status = gNativeInputManager->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -0800860 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700861 if (status) {
862 jniThrowRuntimeException(env, "Failed to register input channel. "
863 "Check logs for details.");
864 return;
865 }
866
Jeff Browna41ca772010-08-11 14:46:32 -0700867 if (! monitor) {
868 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
869 android_server_InputManager_handleInputChannelDisposed, NULL);
870 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700871}
872
873static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
874 jobject inputChannelObj) {
875 if (checkInputManagerUnitialized(env)) {
876 return;
877 }
878
879 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
880 inputChannelObj);
881 if (inputChannel == NULL) {
882 throwInputChannelNotInitialized(env);
883 return;
884 }
885
886 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
887
Jeff Brown7fbdc842010-06-17 20:52:56 -0700888 status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700889 if (status) {
890 jniThrowRuntimeException(env, "Failed to unregister input channel. "
891 "Check logs for details.");
892 }
893}
894
Jeff Brown6ec402b2010-07-28 15:48:59 -0700895static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz,
896 jobject inputEventObj, jint injectorPid, jint injectorUid,
897 jint syncMode, jint timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700898 if (checkInputManagerUnitialized(env)) {
899 return INPUT_EVENT_INJECTION_FAILED;
900 }
901
Jeff Brown6ec402b2010-07-28 15:48:59 -0700902 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
903 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -0800904 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
905 if (status) {
906 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
907 return INPUT_EVENT_INJECTION_FAILED;
908 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700909
Jeff Brownb88102f2010-09-08 11:49:43 -0700910 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
911 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown6ec402b2010-07-28 15:48:59 -0700912 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
913 MotionEvent motionEvent;
Jeff Brown1f245102010-11-18 20:53:46 -0800914 status_t status = android_view_MotionEvent_toNative(env, inputEventObj, & motionEvent);
915 if (status) {
916 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
917 return INPUT_EVENT_INJECTION_FAILED;
918 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700919
Jeff Brownb88102f2010-09-08 11:49:43 -0700920 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
921 & motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown6ec402b2010-07-28 15:48:59 -0700922 } else {
923 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -0700924 return INPUT_EVENT_INJECTION_FAILED;
925 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700926}
927
Jeff Brown349703e2010-06-22 01:27:15 -0700928static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz,
929 jobjectArray windowObjArray) {
930 if (checkInputManagerUnitialized(env)) {
931 return;
932 }
933
934 gNativeInputManager->setInputWindows(env, windowObjArray);
935}
936
937static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
938 jobject applicationObj) {
939 if (checkInputManagerUnitialized(env)) {
940 return;
941 }
942
943 gNativeInputManager->setFocusedApplication(env, applicationObj);
944}
945
946static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env,
947 jclass clazz, jboolean enabled, jboolean frozen) {
948 if (checkInputManagerUnitialized(env)) {
949 return;
950 }
951
952 gNativeInputManager->setInputDispatchMode(enabled, frozen);
953}
954
Jeff Brown8d608662010-08-30 03:02:23 -0700955static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env,
956 jclass clazz, jint deviceId) {
957 if (checkInputManagerUnitialized(env)) {
958 return NULL;
959 }
960
961 InputDeviceInfo deviceInfo;
Jeff Brownb88102f2010-09-08 11:49:43 -0700962 status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -0700963 deviceId, & deviceInfo);
964 if (status) {
965 return NULL;
966 }
967
968 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
969 if (! deviceObj) {
970 return NULL;
971 }
972
973 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
974 if (! deviceNameObj) {
975 return NULL;
976 }
977
978 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
979 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
980 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
981 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
982
983 const KeyedVector<int, InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
984 for (size_t i = 0; i < ranges.size(); i++) {
985 int rangeType = ranges.keyAt(i);
986 const InputDeviceInfo::MotionRange& range = ranges.valueAt(i);
987 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
988 rangeType, range.min, range.max, range.flat, range.fuzz);
989 if (env->ExceptionCheck()) {
990 return NULL;
991 }
992 }
993
994 return deviceObj;
995}
996
997static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env,
998 jclass clazz) {
999 if (checkInputManagerUnitialized(env)) {
1000 return NULL;
1001 }
1002
1003 Vector<int> deviceIds;
Jeff Brownb88102f2010-09-08 11:49:43 -07001004 gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001005
1006 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1007 if (! deviceIdsObj) {
1008 return NULL;
1009 }
1010
1011 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1012 return deviceIdsObj;
1013}
1014
Jeff Brown57c59372010-09-21 18:22:55 -07001015static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env,
1016 jclass clazz, jobject configObj) {
1017 if (checkInputManagerUnitialized(env)) {
1018 return;
1019 }
1020
1021 InputConfiguration config;
1022 gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config);
1023
1024 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1025 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1026 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1027}
1028
Jeff Browne6504122010-09-27 14:52:15 -07001029static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env,
1030 jclass clazz, jobject fromChannelObj, jobject toChannelObj) {
1031 if (checkInputManagerUnitialized(env)) {
1032 return false;
1033 }
1034
1035 sp<InputChannel> fromChannel =
1036 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1037 sp<InputChannel> toChannel =
1038 android_view_InputChannel_getInputChannel(env, toChannelObj);
1039
1040 if (fromChannel == NULL || toChannel == NULL) {
1041 return false;
1042 }
1043
1044 return gNativeInputManager->getInputManager()->getDispatcher()->
1045 transferTouchFocus(fromChannel, toChannel);
1046}
1047
Jeff Browne33348b2010-07-15 23:54:05 -07001048static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
1049 if (checkInputManagerUnitialized(env)) {
1050 return NULL;
1051 }
1052
Jeff Brownb88102f2010-09-08 11:49:43 -07001053 String8 dump;
1054 gNativeInputManager->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001055 return env->NewStringUTF(dump.string());
1056}
1057
Jeff Brown9c3cda02010-06-15 01:31:58 -07001058// ----------------------------------------------------------------------------
1059
Jeff Brown46b9ac02010-04-22 18:58:52 -07001060static JNINativeMethod gInputManagerMethods[] = {
1061 /* name, signature, funcPtr */
1062 { "nativeInit", "(Lcom/android/server/InputManager$Callbacks;)V",
1063 (void*) android_server_InputManager_nativeInit },
1064 { "nativeStart", "()V",
1065 (void*) android_server_InputManager_nativeStart },
1066 { "nativeSetDisplaySize", "(III)V",
1067 (void*) android_server_InputManager_nativeSetDisplaySize },
1068 { "nativeSetDisplayOrientation", "(II)V",
1069 (void*) android_server_InputManager_nativeSetDisplayOrientation },
1070 { "nativeGetScanCodeState", "(III)I",
1071 (void*) android_server_InputManager_nativeGetScanCodeState },
1072 { "nativeGetKeyCodeState", "(III)I",
1073 (void*) android_server_InputManager_nativeGetKeyCodeState },
1074 { "nativeGetSwitchState", "(III)I",
1075 (void*) android_server_InputManager_nativeGetSwitchState },
Jeff Brown6d0fec22010-07-23 21:28:06 -07001076 { "nativeHasKeys", "(II[I[Z)Z",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001077 (void*) android_server_InputManager_nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001078 { "nativeRegisterInputChannel",
1079 "(Landroid/view/InputChannel;Lcom/android/server/InputWindowHandle;Z)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001080 (void*) android_server_InputManager_nativeRegisterInputChannel },
1081 { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V",
Jeff Brown7fbdc842010-06-17 20:52:56 -07001082 (void*) android_server_InputManager_nativeUnregisterInputChannel },
Jeff Brown6ec402b2010-07-28 15:48:59 -07001083 { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIII)I",
1084 (void*) android_server_InputManager_nativeInjectInputEvent },
Jeff Brown349703e2010-06-22 01:27:15 -07001085 { "nativeSetInputWindows", "([Lcom/android/server/InputWindow;)V",
1086 (void*) android_server_InputManager_nativeSetInputWindows },
1087 { "nativeSetFocusedApplication", "(Lcom/android/server/InputApplication;)V",
1088 (void*) android_server_InputManager_nativeSetFocusedApplication },
1089 { "nativeSetInputDispatchMode", "(ZZ)V",
1090 (void*) android_server_InputManager_nativeSetInputDispatchMode },
Jeff Brown8d608662010-08-30 03:02:23 -07001091 { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;",
1092 (void*) android_server_InputManager_nativeGetInputDevice },
1093 { "nativeGetInputDeviceIds", "()[I",
1094 (void*) android_server_InputManager_nativeGetInputDeviceIds },
Jeff Brown57c59372010-09-21 18:22:55 -07001095 { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V",
1096 (void*) android_server_InputManager_nativeGetInputConfiguration },
Jeff Browne6504122010-09-27 14:52:15 -07001097 { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1098 (void*) android_server_InputManager_nativeTransferTouchFocus },
Jeff Browne33348b2010-07-15 23:54:05 -07001099 { "nativeDump", "()Ljava/lang/String;",
1100 (void*) android_server_InputManager_nativeDump },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001101};
1102
1103#define FIND_CLASS(var, className) \
1104 var = env->FindClass(className); \
1105 LOG_FATAL_IF(! var, "Unable to find class " className); \
1106 var = jclass(env->NewGlobalRef(var));
1107
1108#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1109 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1110 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1111
1112#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1113 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1114 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1115
1116int register_android_server_InputManager(JNIEnv* env) {
1117 int res = jniRegisterNativeMethods(env, "com/android/server/InputManager",
1118 gInputManagerMethods, NELEM(gInputManagerMethods));
1119 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1120
Jeff Brown9c3cda02010-06-15 01:31:58 -07001121 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001122
1123 FIND_CLASS(gCallbacksClassInfo.clazz, "com/android/server/InputManager$Callbacks");
1124
Jeff Brown46b9ac02010-04-22 18:58:52 -07001125 GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, gCallbacksClassInfo.clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001126 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001127
1128 GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, gCallbacksClassInfo.clazz,
1129 "notifyLidSwitchChanged", "(JZ)V");
1130
Jeff Brown7fbdc842010-06-17 20:52:56 -07001131 GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, gCallbacksClassInfo.clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001132 "notifyInputChannelBroken", "(Lcom/android/server/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001133
Jeff Brown349703e2010-06-22 01:27:15 -07001134 GET_METHOD_ID(gCallbacksClassInfo.notifyANR, gCallbacksClassInfo.clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001135 "notifyANR",
1136 "(Lcom/android/server/InputApplicationHandle;Lcom/android/server/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001137
Jeff Brown349703e2010-06-22 01:27:15 -07001138 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, gCallbacksClassInfo.clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001139 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001140
1141 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, gCallbacksClassInfo.clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001142 "interceptKeyBeforeDispatching",
Jeff Brown928e0542011-01-10 11:17:36 -08001143 "(Lcom/android/server/InputWindowHandle;Landroid/view/KeyEvent;I)Z");
Jeff Brown349703e2010-06-22 01:27:15 -07001144
Jeff Brown3915bb82010-11-05 15:02:16 -07001145 GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, gCallbacksClassInfo.clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001146 "dispatchUnhandledKey",
Jeff Brown928e0542011-01-10 11:17:36 -08001147 "(Lcom/android/server/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001148
Jeff Brown349703e2010-06-22 01:27:15 -07001149 GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, gCallbacksClassInfo.clazz,
1150 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001151
Jeff Brown46b9ac02010-04-22 18:58:52 -07001152 GET_METHOD_ID(gCallbacksClassInfo.filterTouchEvents, gCallbacksClassInfo.clazz,
1153 "filterTouchEvents", "()Z");
1154
1155 GET_METHOD_ID(gCallbacksClassInfo.filterJumpyTouchEvents, gCallbacksClassInfo.clazz,
1156 "filterJumpyTouchEvents", "()Z");
1157
Jeff Brown46b9ac02010-04-22 18:58:52 -07001158 GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz,
1159 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1160
Jeff Brownae9fc032010-08-18 15:51:08 -07001161 GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz,
1162 "getMaxEventsPerSecond", "()I");
1163
Jeff Brown83c09682010-12-23 17:50:18 -08001164 GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, gCallbacksClassInfo.clazz,
1165 "getPointerLayer", "()I");
1166
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001167 GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, gCallbacksClassInfo.clazz,
1168 "getPointerIcon", "()Lcom/android/server/InputManager$PointerIcon;");
1169
Jeff Brown6ec402b2010-07-28 15:48:59 -07001170 // KeyEvent
1171
1172 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
1173
Jeff Brown8d608662010-08-30 03:02:23 -07001174 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001175
1176 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
1177
Jeff Brown8d608662010-08-30 03:02:23 -07001178 // InputDevice
1179
1180 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1181
1182 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1183 "<init>", "()V");
1184
1185 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
1186 "addMotionRange", "(IFFFF)V");
1187
1188 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1189 "mId", "I");
1190
1191 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1192 "mName", "Ljava/lang/String;");
1193
1194 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1195 "mSources", "I");
1196
1197 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1198 "mKeyboardType", "I");
1199
1200 GET_FIELD_ID(gInputDeviceClassInfo.mMotionRanges, gInputDeviceClassInfo.clazz,
1201 "mMotionRanges", "[Landroid/view/InputDevice$MotionRange;");
1202
Jeff Brown57c59372010-09-21 18:22:55 -07001203 // Configuration
1204
1205 FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration");
1206
1207 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz,
1208 "touchscreen", "I");
1209
1210 GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz,
1211 "keyboard", "I");
1212
1213 GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz,
1214 "navigation", "I");
1215
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001216 // PointerIcon
1217
1218 FIND_CLASS(gPointerIconClassInfo.clazz, "com/android/server/InputManager$PointerIcon");
1219
1220 GET_FIELD_ID(gPointerIconClassInfo.bitmap, gPointerIconClassInfo.clazz,
1221 "bitmap", "Landroid/graphics/Bitmap;");
1222
1223 GET_FIELD_ID(gPointerIconClassInfo.hotSpotX, gPointerIconClassInfo.clazz,
1224 "hotSpotX", "F");
1225
1226 GET_FIELD_ID(gPointerIconClassInfo.hotSpotY, gPointerIconClassInfo.clazz,
1227 "hotSpotY", "F");
1228
Jeff Brown46b9ac02010-04-22 18:58:52 -07001229 return 0;
1230}
1231
Jeff Brown46b9ac02010-04-22 18:58:52 -07001232} /* namespace android */