blob: 5b329bb4eefc343d87ef2f294b39d1ccc5f02633 [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 Brownfe508922011-01-18 15:10:10 -080065 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070066 jmethodID getExcludedDeviceNames;
Jeff Brownae9fc032010-08-18 15:51:08 -070067 jmethodID getMaxEventsPerSecond;
Jeff Brown83c09682010-12-23 17:50:18 -080068 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080069 jmethodID getPointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070070} gCallbacksClassInfo;
71
72static struct {
73 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070074} gKeyEventClassInfo;
75
76static struct {
77 jclass clazz;
78} gMotionEventClassInfo;
79
Jeff Brown8d608662010-08-30 03:02:23 -070080static struct {
81 jclass clazz;
82
83 jmethodID ctor;
84 jmethodID addMotionRange;
85
86 jfieldID mId;
87 jfieldID mName;
88 jfieldID mSources;
89 jfieldID mKeyboardType;
90 jfieldID mMotionRanges;
91} gInputDeviceClassInfo;
92
Jeff Brown57c59372010-09-21 18:22:55 -070093static struct {
94 jclass clazz;
95
96 jfieldID touchscreen;
97 jfieldID keyboard;
98 jfieldID navigation;
99} gConfigurationClassInfo;
100
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800101static struct {
102 jclass clazz;
Jeff Brown349703e2010-06-22 01:27:15 -0700103
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800104 jfieldID bitmap;
105 jfieldID hotSpotX;
106 jfieldID hotSpotY;
107} gPointerIconClassInfo;
Jeff Brown83c09682010-12-23 17:50:18 -0800108
Jeff Brown928e0542011-01-10 11:17:36 -0800109
110// --- Global functions ---
111
112static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
113 const sp<InputApplicationHandle>& inputApplicationHandle) {
114 if (inputApplicationHandle == NULL) {
115 return NULL;
116 }
117 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
118 getInputApplicationHandleObjLocalRef(env);
119}
120
121static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
122 const sp<InputWindowHandle>& inputWindowHandle) {
123 if (inputWindowHandle == NULL) {
124 return NULL;
125 }
126 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
127 getInputWindowHandleObjLocalRef(env);
128}
129
130
131// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800132
Jeff Brown9c3cda02010-06-15 01:31:58 -0700133class NativeInputManager : public virtual RefBase,
134 public virtual InputReaderPolicyInterface,
135 public virtual InputDispatcherPolicyInterface {
136protected:
137 virtual ~NativeInputManager();
138
139public:
140 NativeInputManager(jobject callbacksObj);
141
142 inline sp<InputManager> getInputManager() const { return mInputManager; }
143
Jeff Brownb88102f2010-09-08 11:49:43 -0700144 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700145
Jeff Brown9c3cda02010-06-15 01:31:58 -0700146 void setDisplaySize(int32_t displayId, int32_t width, int32_t height);
147 void setDisplayOrientation(int32_t displayId, int32_t orientation);
148
Jeff Brown7fbdc842010-06-17 20:52:56 -0700149 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800150 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700151 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
152
Jeff Brown349703e2010-06-22 01:27:15 -0700153 void setInputWindows(JNIEnv* env, jobjectArray windowObjArray);
154 void setFocusedApplication(JNIEnv* env, jobject applicationObj);
155 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700156
Jeff Brown9c3cda02010-06-15 01:31:58 -0700157 /* --- InputReaderPolicyInterface implementation --- */
158
159 virtual bool getDisplayInfo(int32_t displayId,
160 int32_t* width, int32_t* height, int32_t* orientation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700161 virtual bool filterTouchEvents();
162 virtual bool filterJumpyTouchEvents();
Jeff Brownfe508922011-01-18 15:10:10 -0800163 virtual nsecs_t getVirtualKeyQuietTime();
Jeff Brown9c3cda02010-06-15 01:31:58 -0700164 virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames);
Jeff Brown83c09682010-12-23 17:50:18 -0800165 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700166
167 /* --- InputDispatcherPolicyInterface implementation --- */
168
Jeff Browne20c9e02010-10-11 14:20:19 -0700169 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
170 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700171 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700172 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800173 const sp<InputWindowHandle>& inputWindowHandle);
174 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700175 virtual nsecs_t getKeyRepeatTimeout();
Jeff Brownb21fb102010-09-07 10:44:57 -0700176 virtual nsecs_t getKeyRepeatDelay();
Jeff Brownae9fc032010-08-18 15:51:08 -0700177 virtual int32_t getMaxEventsPerSecond();
Jeff Brown1f245102010-11-18 20:53:46 -0800178 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brownb6997262010-10-08 22:31:17 -0700179 virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800180 virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700181 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800182 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800183 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700184 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700185 virtual bool checkInjectEventsPermissionNonReentrant(
186 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700187
188private:
189 sp<InputManager> mInputManager;
190
191 jobject mCallbacksObj;
192
193 // Cached filtering policies.
194 int32_t mFilterTouchEvents;
195 int32_t mFilterJumpyTouchEvents;
Jeff Brownfe508922011-01-18 15:10:10 -0800196 nsecs_t mVirtualKeyQuietTime;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700197
Jeff Brownae9fc032010-08-18 15:51:08 -0700198 // Cached throttling policy.
199 int32_t mMaxEventsPerSecond;
200
Jeff Brown83c09682010-12-23 17:50:18 -0800201 Mutex mLock;
202 struct Locked {
203 // Display size information.
204 int32_t displayWidth, displayHeight; // -1 when initialized
205 int32_t displayOrientation;
206
207 // Pointer controller singleton, created and destroyed as needed.
208 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800209 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700210
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700211 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700212 bool isScreenOn();
213 bool isScreenBright();
214
Jeff Brownb88102f2010-09-08 11:49:43 -0700215 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700216
Jeff Brown9c3cda02010-06-15 01:31:58 -0700217 static inline JNIEnv* jniEnv() {
218 return AndroidRuntime::getJNIEnv();
219 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700220};
221
Jeff Brown928e0542011-01-10 11:17:36 -0800222
Jeff Brown9c3cda02010-06-15 01:31:58 -0700223
224NativeInputManager::NativeInputManager(jobject callbacksObj) :
Jeff Brownfe508922011-01-18 15:10:10 -0800225 mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1), mVirtualKeyQuietTime(-1),
Jeff Brown83c09682010-12-23 17:50:18 -0800226 mMaxEventsPerSecond(-1) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700227 JNIEnv* env = jniEnv();
228
229 mCallbacksObj = env->NewGlobalRef(callbacksObj);
230
Jeff Brown83c09682010-12-23 17:50:18 -0800231 {
232 AutoMutex _l(mLock);
233 mLocked.displayWidth = -1;
234 mLocked.displayHeight = -1;
235 mLocked.displayOrientation = ROTATION_0;
236 }
237
Jeff Brown9c3cda02010-06-15 01:31:58 -0700238 sp<EventHub> eventHub = new EventHub();
239 mInputManager = new InputManager(eventHub, this, this);
240}
241
242NativeInputManager::~NativeInputManager() {
243 JNIEnv* env = jniEnv();
244
245 env->DeleteGlobalRef(mCallbacksObj);
246}
247
Jeff Brownb88102f2010-09-08 11:49:43 -0700248void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700249 mInputManager->getReader()->dump(dump);
250 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700251
Jeff Brownb88102f2010-09-08 11:49:43 -0700252 mInputManager->getDispatcher()->dump(dump);
253 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700254}
255
Jeff Brown7fbdc842010-06-17 20:52:56 -0700256bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700257 if (env->ExceptionCheck()) {
258 LOGE("An exception was thrown by callback '%s'.", methodName);
259 LOGE_EX(env);
260 env->ExceptionClear();
261 return true;
262 }
263 return false;
264}
265
266void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height) {
267 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800268 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700269
Jeff Brown83c09682010-12-23 17:50:18 -0800270 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
271 mLocked.displayWidth = width;
272 mLocked.displayHeight = height;
273
274 sp<PointerController> controller = mLocked.pointerController.promote();
275 if (controller != NULL) {
276 controller->setDisplaySize(width, height);
277 }
278 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700279 }
280}
281
282void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
283 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800284 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700285
Jeff Brown83c09682010-12-23 17:50:18 -0800286 if (mLocked.displayOrientation != orientation) {
287 mLocked.displayOrientation = orientation;
288
289 sp<PointerController> controller = mLocked.pointerController.promote();
290 if (controller != NULL) {
291 controller->setDisplayOrientation(orientation);
292 }
293 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700294 }
295}
296
Jeff Brown7fbdc842010-06-17 20:52:56 -0700297status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800298 const sp<InputChannel>& inputChannel,
299 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
300 return mInputManager->getDispatcher()->registerInputChannel(
301 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700302}
303
304status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
305 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700306 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700307}
308
Jeff Brown9c3cda02010-06-15 01:31:58 -0700309bool NativeInputManager::getDisplayInfo(int32_t displayId,
310 int32_t* width, int32_t* height, int32_t* orientation) {
311 bool result = false;
312 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800313 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700314
Jeff Brown83c09682010-12-23 17:50:18 -0800315 if (mLocked.displayWidth > 0 && mLocked.displayHeight > 0) {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700316 if (width) {
Jeff Brown83c09682010-12-23 17:50:18 -0800317 *width = mLocked.displayWidth;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700318 }
319 if (height) {
Jeff Brown83c09682010-12-23 17:50:18 -0800320 *height = mLocked.displayHeight;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700321 }
322 if (orientation) {
Jeff Brown83c09682010-12-23 17:50:18 -0800323 *orientation = mLocked.displayOrientation;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700324 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700325 result = true;
326 }
327 }
328 return result;
329}
330
Jeff Brown9c3cda02010-06-15 01:31:58 -0700331bool NativeInputManager::filterTouchEvents() {
332 if (mFilterTouchEvents < 0) {
333 JNIEnv* env = jniEnv();
334
335 jboolean result = env->CallBooleanMethod(mCallbacksObj,
336 gCallbacksClassInfo.filterTouchEvents);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700337 if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700338 result = false;
339 }
340
341 mFilterTouchEvents = result ? 1 : 0;
342 }
343 return mFilterTouchEvents;
344}
345
346bool NativeInputManager::filterJumpyTouchEvents() {
347 if (mFilterJumpyTouchEvents < 0) {
348 JNIEnv* env = jniEnv();
349
350 jboolean result = env->CallBooleanMethod(mCallbacksObj,
351 gCallbacksClassInfo.filterJumpyTouchEvents);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700352 if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700353 result = false;
354 }
355
356 mFilterJumpyTouchEvents = result ? 1 : 0;
357 }
358 return mFilterJumpyTouchEvents;
359}
360
Jeff Brownfe508922011-01-18 15:10:10 -0800361nsecs_t NativeInputManager::getVirtualKeyQuietTime() {
362 if (mVirtualKeyQuietTime < 0) {
363 JNIEnv* env = jniEnv();
364
365 jint result = env->CallIntMethod(mCallbacksObj,
366 gCallbacksClassInfo.getVirtualKeyQuietTimeMillis);
367 if (checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
368 result = 0;
369 }
370 if (result < 0) {
371 result = 0;
372 }
373
374 mVirtualKeyQuietTime = milliseconds_to_nanoseconds(result);
375 }
376 return mVirtualKeyQuietTime;
377}
378
Jeff Brown9c3cda02010-06-15 01:31:58 -0700379void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) {
Jeff Brown8d608662010-08-30 03:02:23 -0700380 outExcludedDeviceNames.clear();
381
Jeff Brown9c3cda02010-06-15 01:31:58 -0700382 JNIEnv* env = jniEnv();
383
384 jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj,
385 gCallbacksClassInfo.getExcludedDeviceNames));
Jeff Brown7fbdc842010-06-17 20:52:56 -0700386 if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700387 jsize length = env->GetArrayLength(result);
388 for (jsize i = 0; i < length; i++) {
389 jstring item = jstring(env->GetObjectArrayElement(result, i));
390
391 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
392 outExcludedDeviceNames.add(String8(deviceNameChars));
393 env->ReleaseStringUTFChars(item, deviceNameChars);
394
395 env->DeleteLocalRef(item);
396 }
397 env->DeleteLocalRef(result);
398 }
399}
400
Jeff Brown83c09682010-12-23 17:50:18 -0800401sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
402 AutoMutex _l(mLock);
403
404 sp<PointerController> controller = mLocked.pointerController.promote();
405 if (controller == NULL) {
406 JNIEnv* env = jniEnv();
407 jint layer = env->CallIntMethod(mCallbacksObj, gCallbacksClassInfo.getPointerLayer);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800408 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
409 layer = -1;
410 }
Jeff Brown83c09682010-12-23 17:50:18 -0800411
412 controller = new PointerController(layer);
413 mLocked.pointerController = controller;
414
415 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
416 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800417
418 jobject iconObj = env->CallObjectMethod(mCallbacksObj, gCallbacksClassInfo.getPointerIcon);
419 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon") && iconObj) {
420 jfloat iconHotSpotX = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotX);
421 jfloat iconHotSpotY = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotY);
422 jobject iconBitmapObj = env->GetObjectField(iconObj, gPointerIconClassInfo.bitmap);
423 if (iconBitmapObj) {
424 SkBitmap* iconBitmap = GraphicsJNI::getNativeBitmap(env, iconBitmapObj);
425 if (iconBitmap) {
426 controller->setPointerIcon(iconBitmap, iconHotSpotX, iconHotSpotY);
427 }
428 env->DeleteLocalRef(iconBitmapObj);
429 }
430 env->DeleteLocalRef(iconObj);
431 }
Jeff Brown83c09682010-12-23 17:50:18 -0800432 }
433 return controller;
434}
435
Jeff Browne20c9e02010-10-11 14:20:19 -0700436void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
437 int32_t switchValue, uint32_t policyFlags) {
438#if DEBUG_INPUT_DISPATCHER_POLICY
439 LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
440 when, switchCode, switchValue, policyFlags);
441#endif
442
443 JNIEnv* env = jniEnv();
444
445 switch (switchCode) {
446 case SW_LID:
447 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged,
448 when, switchValue == 0);
449 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
450 break;
451 }
452}
453
Jeff Brown9c3cda02010-06-15 01:31:58 -0700454void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
455#if DEBUG_INPUT_DISPATCHER_POLICY
456 LOGD("notifyConfigurationChanged - when=%lld", when);
457#endif
458
459 JNIEnv* env = jniEnv();
460
Jeff Brown57c59372010-09-21 18:22:55 -0700461 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700462 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700463}
464
Jeff Brown519e0242010-09-15 15:18:56 -0700465nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800466 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700467#if DEBUG_INPUT_DISPATCHER_POLICY
468 LOGD("notifyANR");
469#endif
470
471 JNIEnv* env = jniEnv();
472
Jeff Brown928e0542011-01-10 11:17:36 -0800473 jobject inputApplicationHandleObj =
474 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
475 jobject inputWindowHandleObj =
476 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700477
Jeff Brown519e0242010-09-15 15:18:56 -0700478 jlong newTimeout = env->CallLongMethod(mCallbacksObj,
Jeff Brown928e0542011-01-10 11:17:36 -0800479 gCallbacksClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700480 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
481 newTimeout = 0; // abort dispatch
482 } else {
483 assert(newTimeout >= 0);
484 }
485
Jeff Brown928e0542011-01-10 11:17:36 -0800486 env->DeleteLocalRef(inputWindowHandleObj);
487 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700488 return newTimeout;
489}
490
Jeff Brown928e0542011-01-10 11:17:36 -0800491void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700492#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown928e0542011-01-10 11:17:36 -0800493 LOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700494#endif
495
Jeff Brown7fbdc842010-06-17 20:52:56 -0700496 JNIEnv* env = jniEnv();
497
Jeff Brown928e0542011-01-10 11:17:36 -0800498 jobject inputWindowHandleObj =
499 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
500 if (inputWindowHandleObj) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700501 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800502 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700503 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
504
Jeff Brown928e0542011-01-10 11:17:36 -0800505 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700506 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700507}
508
Jeff Brown9c3cda02010-06-15 01:31:58 -0700509nsecs_t NativeInputManager::getKeyRepeatTimeout() {
510 if (! isScreenOn()) {
511 // Disable key repeat when the screen is off.
512 return -1;
513 } else {
514 // TODO use ViewConfiguration.getLongPressTimeout()
515 return milliseconds_to_nanoseconds(500);
516 }
517}
518
Jeff Brownb21fb102010-09-07 10:44:57 -0700519nsecs_t NativeInputManager::getKeyRepeatDelay() {
520 return milliseconds_to_nanoseconds(50);
521}
522
Jeff Brownae9fc032010-08-18 15:51:08 -0700523int32_t NativeInputManager::getMaxEventsPerSecond() {
524 if (mMaxEventsPerSecond < 0) {
525 JNIEnv* env = jniEnv();
526
527 jint result = env->CallIntMethod(mCallbacksObj,
528 gCallbacksClassInfo.getMaxEventsPerSecond);
529 if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700530 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700531 }
532
533 mMaxEventsPerSecond = result;
534 }
535 return mMaxEventsPerSecond;
536}
537
Jeff Brown349703e2010-06-22 01:27:15 -0700538void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700539 Vector<InputWindow> windows;
Jeff Brown349703e2010-06-22 01:27:15 -0700540
Jeff Brownb88102f2010-09-08 11:49:43 -0700541 jsize length = env->GetArrayLength(windowObjArray);
542 for (jsize i = 0; i < length; i++) {
Jeff Brown928e0542011-01-10 11:17:36 -0800543 jobject windowObj = env->GetObjectArrayElement(windowObjArray, i);
544 if (! windowObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700545 break; // found null element indicating end of used portion of the array
Jeff Brown349703e2010-06-22 01:27:15 -0700546 }
547
Jeff Brownb88102f2010-09-08 11:49:43 -0700548 windows.push();
549 InputWindow& window = windows.editTop();
Jeff Brown928e0542011-01-10 11:17:36 -0800550 android_server_InputWindow_toNative(env, windowObj, &window);
551 if (window.inputChannel == NULL) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700552 windows.pop();
Jeff Brown349703e2010-06-22 01:27:15 -0700553 }
Jeff Brown928e0542011-01-10 11:17:36 -0800554 env->DeleteLocalRef(windowObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700555 }
Jeff Brown349703e2010-06-22 01:27:15 -0700556
Jeff Brownb88102f2010-09-08 11:49:43 -0700557 mInputManager->getDispatcher()->setInputWindows(windows);
Jeff Brown349703e2010-06-22 01:27:15 -0700558}
559
Jeff Brown349703e2010-06-22 01:27:15 -0700560void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700561 if (applicationObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700562 InputApplication application;
Jeff Brown928e0542011-01-10 11:17:36 -0800563 android_server_InputApplication_toNative(env, applicationObj, &application);
564 if (application.inputApplicationHandle != NULL) {
565 mInputManager->getDispatcher()->setFocusedApplication(&application);
566 }
Jeff Brown349703e2010-06-22 01:27:15 -0700567 }
Jeff Brown928e0542011-01-10 11:17:36 -0800568 mInputManager->getDispatcher()->setFocusedApplication(NULL);
Jeff Brown349703e2010-06-22 01:27:15 -0700569}
570
571void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700572 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700573}
574
Jeff Browne20c9e02010-10-11 14:20:19 -0700575bool NativeInputManager::isScreenOn() {
576 return android_server_PowerManagerService_isScreenOn();
577}
578
579bool NativeInputManager::isScreenBright() {
580 return android_server_PowerManagerService_isScreenBright();
581}
582
Jeff Brown1f245102010-11-18 20:53:46 -0800583void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
584 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700585 // Policy:
586 // - Ignore untrusted events and pass them along.
587 // - Ask the window manager what to do with normal events and trusted injected events.
588 // - For normal events wake and brighten the screen if currently off or dim.
589 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
590 const int32_t WM_ACTION_PASS_TO_USER = 1;
591 const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2;
592 const int32_t WM_ACTION_GO_TO_SLEEP = 4;
Jeff Browne20c9e02010-10-11 14:20:19 -0700593
Jeff Brown1f245102010-11-18 20:53:46 -0800594 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700595 bool isScreenOn = this->isScreenOn();
596 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700597
Jeff Brown3122e442010-10-11 23:32:49 -0700598 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800599 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
600 jint wmActions;
601 if (keyEventObj) {
602 wmActions = env->CallIntMethod(mCallbacksObj,
603 gCallbacksClassInfo.interceptKeyBeforeQueueing,
604 keyEventObj, policyFlags, isScreenOn);
605 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
606 wmActions = 0;
607 }
608 android_view_KeyEvent_recycle(env, keyEventObj);
609 env->DeleteLocalRef(keyEventObj);
610 } else {
611 LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700612 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700613 }
614
Jeff Brown1f245102010-11-18 20:53:46 -0800615 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700616 if (!isScreenOn) {
617 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700618 }
619
620 if (!isScreenBright) {
621 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
622 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700623 }
624
625 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
626 android_server_PowerManagerService_goToSleep(when);
627 }
628
629 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
630 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
631 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700632
Jeff Brown3122e442010-10-11 23:32:49 -0700633 if (wmActions & WM_ACTION_PASS_TO_USER) {
634 policyFlags |= POLICY_FLAG_PASS_TO_USER;
635 }
636 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700637 policyFlags |= POLICY_FLAG_PASS_TO_USER;
638 }
639}
640
641void NativeInputManager::interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700642 // Policy:
643 // - Ignore untrusted events and pass them along.
644 // - No special filtering for injected events required at this time.
645 // - Filter normal events based on screen state.
646 // - For normal events brighten (but do not wake) the screen if currently dim.
647 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
648 if (isScreenOn()) {
649 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700650
Jeff Brown3122e442010-10-11 23:32:49 -0700651 if (!isScreenBright()) {
652 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
653 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700654 }
Jeff Brown3122e442010-10-11 23:32:49 -0700655 } else {
656 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700657 }
658}
659
Jeff Brown928e0542011-01-10 11:17:36 -0800660bool NativeInputManager::interceptKeyBeforeDispatching(
661 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700662 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700663 // Policy:
664 // - Ignore untrusted events and pass them along.
665 // - Filter normal events and trusted injected events through the window manager policy to
666 // handle the HOME key and the like.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800667 bool result = false;
Jeff Brown3122e442010-10-11 23:32:49 -0700668 if (policyFlags & POLICY_FLAG_TRUSTED) {
669 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700670
Jeff Brown928e0542011-01-10 11:17:36 -0800671 // Note: inputWindowHandle may be null.
672 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800673 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
674 if (keyEventObj) {
675 jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
676 gCallbacksClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800677 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800678 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
679 android_view_KeyEvent_recycle(env, keyEventObj);
680 env->DeleteLocalRef(keyEventObj);
681 result = consumed && !error;
682 } else {
683 LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800684 }
Jeff Brown928e0542011-01-10 11:17:36 -0800685 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700686 }
Jeff Brown1f245102010-11-18 20:53:46 -0800687 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700688}
689
Jeff Brown928e0542011-01-10 11:17:36 -0800690bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800691 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700692 // Policy:
693 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800694 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700695 if (policyFlags & POLICY_FLAG_TRUSTED) {
696 JNIEnv* env = jniEnv();
697
Jeff Brown928e0542011-01-10 11:17:36 -0800698 // Note: inputWindowHandle may be null.
699 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800700 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
701 if (keyEventObj) {
Jeff Brown49ed71d2010-12-06 17:13:33 -0800702 jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800703 gCallbacksClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800704 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800705 checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey");
Jeff Brown1f245102010-11-18 20:53:46 -0800706 android_view_KeyEvent_recycle(env, keyEventObj);
707 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800708
709 if (fallbackKeyEventObj) {
710 // Note: outFallbackKeyEvent may be the same object as keyEvent.
711 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
712 outFallbackKeyEvent)) {
713 result = true;
714 }
715 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
716 env->DeleteLocalRef(fallbackKeyEventObj);
717 }
Jeff Brown1f245102010-11-18 20:53:46 -0800718 } else {
719 LOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800720 }
Jeff Brown928e0542011-01-10 11:17:36 -0800721 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700722 }
Jeff Brown1f245102010-11-18 20:53:46 -0800723 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700724}
725
Jeff Brown01ce2e92010-09-26 22:20:12 -0700726void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
727 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700728}
729
Jeff Brown349703e2010-06-22 01:27:15 -0700730
Jeff Brownb88102f2010-09-08 11:49:43 -0700731bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
732 int32_t injectorPid, int32_t injectorUid) {
733 JNIEnv* env = jniEnv();
734 jboolean result = env->CallBooleanMethod(mCallbacksObj,
735 gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
736 checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission");
Jeff Brown349703e2010-06-22 01:27:15 -0700737 return result;
738}
739
Jeff Brown83c09682010-12-23 17:50:18 -0800740
Jeff Brown9c3cda02010-06-15 01:31:58 -0700741// ----------------------------------------------------------------------------
742
743static sp<NativeInputManager> gNativeInputManager;
744
Jeff Brown46b9ac02010-04-22 18:58:52 -0700745static bool checkInputManagerUnitialized(JNIEnv* env) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700746 if (gNativeInputManager == NULL) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700747 LOGE("Input manager not initialized.");
748 jniThrowRuntimeException(env, "Input manager not initialized.");
749 return true;
750 }
751 return false;
752}
753
754static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
755 jobject callbacks) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700756 if (gNativeInputManager == NULL) {
757 gNativeInputManager = new NativeInputManager(callbacks);
758 } else {
759 LOGE("Input manager already initialized.");
760 jniThrowRuntimeException(env, "Input manager already initialized.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700761 }
762}
763
764static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
765 if (checkInputManagerUnitialized(env)) {
766 return;
767 }
768
Jeff Brown9c3cda02010-06-15 01:31:58 -0700769 status_t result = gNativeInputManager->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700770 if (result) {
771 jniThrowRuntimeException(env, "Input manager could not be started.");
772 }
773}
774
775static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz,
776 jint displayId, jint width, jint height) {
777 if (checkInputManagerUnitialized(env)) {
778 return;
779 }
780
781 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
782 // to be passed in like this, not sure which is better but leaving it like this
783 // keeps the window manager in direct control of when display transitions propagate down
784 // to the input dispatcher
Jeff Brown9c3cda02010-06-15 01:31:58 -0700785 gNativeInputManager->setDisplaySize(displayId, width, height);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700786}
787
788static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
789 jint displayId, jint orientation) {
790 if (checkInputManagerUnitialized(env)) {
791 return;
792 }
793
Jeff Brown9c3cda02010-06-15 01:31:58 -0700794 gNativeInputManager->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700795}
796
797static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700798 jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700799 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700800 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700801 }
802
Jeff Brownb88102f2010-09-08 11:49:43 -0700803 return gNativeInputManager->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700804 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700805}
806
807static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700808 jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700809 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700810 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700811 }
812
Jeff Brownb88102f2010-09-08 11:49:43 -0700813 return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700814 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700815}
816
817static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700818 jint deviceId, jint sourceMask, jint sw) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700819 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700820 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700821 }
822
Jeff Brownb88102f2010-09-08 11:49:43 -0700823 return gNativeInputManager->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700824 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700825}
826
827static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700828 jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700829 if (checkInputManagerUnitialized(env)) {
830 return JNI_FALSE;
831 }
832
833 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
834 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
835 jsize numCodes = env->GetArrayLength(keyCodes);
836 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700837 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700838 result = gNativeInputManager->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700839 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700840 } else {
841 result = JNI_FALSE;
842 }
843
844 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
845 env->ReleaseIntArrayElements(keyCodes, codes, 0);
846 return result;
847}
848
849static void throwInputChannelNotInitialized(JNIEnv* env) {
850 jniThrowException(env, "java/lang/IllegalStateException",
851 "inputChannel is not initialized");
852}
853
854static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env,
855 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
856 LOGW("Input channel object '%s' was disposed without first being unregistered with "
857 "the input manager!", inputChannel->getName().string());
858
Jeff Brown9c3cda02010-06-15 01:31:58 -0700859 if (gNativeInputManager != NULL) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700860 gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700861 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700862}
863
864static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800865 jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700866 if (checkInputManagerUnitialized(env)) {
867 return;
868 }
869
870 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
871 inputChannelObj);
872 if (inputChannel == NULL) {
873 throwInputChannelNotInitialized(env);
874 return;
875 }
876
Jeff Brown928e0542011-01-10 11:17:36 -0800877 sp<InputWindowHandle> inputWindowHandle =
878 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700879
880 status_t status = gNativeInputManager->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -0800881 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700882 if (status) {
883 jniThrowRuntimeException(env, "Failed to register input channel. "
884 "Check logs for details.");
885 return;
886 }
887
Jeff Browna41ca772010-08-11 14:46:32 -0700888 if (! monitor) {
889 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
890 android_server_InputManager_handleInputChannelDisposed, NULL);
891 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700892}
893
894static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
895 jobject inputChannelObj) {
896 if (checkInputManagerUnitialized(env)) {
897 return;
898 }
899
900 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
901 inputChannelObj);
902 if (inputChannel == NULL) {
903 throwInputChannelNotInitialized(env);
904 return;
905 }
906
907 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
908
Jeff Brown7fbdc842010-06-17 20:52:56 -0700909 status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700910 if (status) {
911 jniThrowRuntimeException(env, "Failed to unregister input channel. "
912 "Check logs for details.");
913 }
914}
915
Jeff Brown6ec402b2010-07-28 15:48:59 -0700916static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz,
917 jobject inputEventObj, jint injectorPid, jint injectorUid,
918 jint syncMode, jint timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700919 if (checkInputManagerUnitialized(env)) {
920 return INPUT_EVENT_INJECTION_FAILED;
921 }
922
Jeff Brown6ec402b2010-07-28 15:48:59 -0700923 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
924 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -0800925 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
926 if (status) {
927 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
928 return INPUT_EVENT_INJECTION_FAILED;
929 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700930
Jeff Brownb88102f2010-09-08 11:49:43 -0700931 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
932 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown6ec402b2010-07-28 15:48:59 -0700933 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
934 MotionEvent motionEvent;
Jeff Brown1f245102010-11-18 20:53:46 -0800935 status_t status = android_view_MotionEvent_toNative(env, inputEventObj, & motionEvent);
936 if (status) {
937 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
938 return INPUT_EVENT_INJECTION_FAILED;
939 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700940
Jeff Brownb88102f2010-09-08 11:49:43 -0700941 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
942 & motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown6ec402b2010-07-28 15:48:59 -0700943 } else {
944 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -0700945 return INPUT_EVENT_INJECTION_FAILED;
946 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700947}
948
Jeff Brown349703e2010-06-22 01:27:15 -0700949static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz,
950 jobjectArray windowObjArray) {
951 if (checkInputManagerUnitialized(env)) {
952 return;
953 }
954
955 gNativeInputManager->setInputWindows(env, windowObjArray);
956}
957
958static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
959 jobject applicationObj) {
960 if (checkInputManagerUnitialized(env)) {
961 return;
962 }
963
964 gNativeInputManager->setFocusedApplication(env, applicationObj);
965}
966
967static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env,
968 jclass clazz, jboolean enabled, jboolean frozen) {
969 if (checkInputManagerUnitialized(env)) {
970 return;
971 }
972
973 gNativeInputManager->setInputDispatchMode(enabled, frozen);
974}
975
Jeff Brown8d608662010-08-30 03:02:23 -0700976static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env,
977 jclass clazz, jint deviceId) {
978 if (checkInputManagerUnitialized(env)) {
979 return NULL;
980 }
981
982 InputDeviceInfo deviceInfo;
Jeff Brownb88102f2010-09-08 11:49:43 -0700983 status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -0700984 deviceId, & deviceInfo);
985 if (status) {
986 return NULL;
987 }
988
989 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
990 if (! deviceObj) {
991 return NULL;
992 }
993
994 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
995 if (! deviceNameObj) {
996 return NULL;
997 }
998
999 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
1000 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
1001 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
1002 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
1003
1004 const KeyedVector<int, InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
1005 for (size_t i = 0; i < ranges.size(); i++) {
1006 int rangeType = ranges.keyAt(i);
1007 const InputDeviceInfo::MotionRange& range = ranges.valueAt(i);
1008 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
1009 rangeType, range.min, range.max, range.flat, range.fuzz);
1010 if (env->ExceptionCheck()) {
1011 return NULL;
1012 }
1013 }
1014
1015 return deviceObj;
1016}
1017
1018static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env,
1019 jclass clazz) {
1020 if (checkInputManagerUnitialized(env)) {
1021 return NULL;
1022 }
1023
1024 Vector<int> deviceIds;
Jeff Brownb88102f2010-09-08 11:49:43 -07001025 gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001026
1027 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1028 if (! deviceIdsObj) {
1029 return NULL;
1030 }
1031
1032 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1033 return deviceIdsObj;
1034}
1035
Jeff Brown57c59372010-09-21 18:22:55 -07001036static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env,
1037 jclass clazz, jobject configObj) {
1038 if (checkInputManagerUnitialized(env)) {
1039 return;
1040 }
1041
1042 InputConfiguration config;
1043 gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config);
1044
1045 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1046 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1047 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1048}
1049
Jeff Browne6504122010-09-27 14:52:15 -07001050static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env,
1051 jclass clazz, jobject fromChannelObj, jobject toChannelObj) {
1052 if (checkInputManagerUnitialized(env)) {
1053 return false;
1054 }
1055
1056 sp<InputChannel> fromChannel =
1057 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1058 sp<InputChannel> toChannel =
1059 android_view_InputChannel_getInputChannel(env, toChannelObj);
1060
1061 if (fromChannel == NULL || toChannel == NULL) {
1062 return false;
1063 }
1064
1065 return gNativeInputManager->getInputManager()->getDispatcher()->
1066 transferTouchFocus(fromChannel, toChannel);
1067}
1068
Jeff Browne33348b2010-07-15 23:54:05 -07001069static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
1070 if (checkInputManagerUnitialized(env)) {
1071 return NULL;
1072 }
1073
Jeff Brownb88102f2010-09-08 11:49:43 -07001074 String8 dump;
1075 gNativeInputManager->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001076 return env->NewStringUTF(dump.string());
1077}
1078
Jeff Brown9c3cda02010-06-15 01:31:58 -07001079// ----------------------------------------------------------------------------
1080
Jeff Brown46b9ac02010-04-22 18:58:52 -07001081static JNINativeMethod gInputManagerMethods[] = {
1082 /* name, signature, funcPtr */
1083 { "nativeInit", "(Lcom/android/server/InputManager$Callbacks;)V",
1084 (void*) android_server_InputManager_nativeInit },
1085 { "nativeStart", "()V",
1086 (void*) android_server_InputManager_nativeStart },
1087 { "nativeSetDisplaySize", "(III)V",
1088 (void*) android_server_InputManager_nativeSetDisplaySize },
1089 { "nativeSetDisplayOrientation", "(II)V",
1090 (void*) android_server_InputManager_nativeSetDisplayOrientation },
1091 { "nativeGetScanCodeState", "(III)I",
1092 (void*) android_server_InputManager_nativeGetScanCodeState },
1093 { "nativeGetKeyCodeState", "(III)I",
1094 (void*) android_server_InputManager_nativeGetKeyCodeState },
1095 { "nativeGetSwitchState", "(III)I",
1096 (void*) android_server_InputManager_nativeGetSwitchState },
Jeff Brown6d0fec22010-07-23 21:28:06 -07001097 { "nativeHasKeys", "(II[I[Z)Z",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001098 (void*) android_server_InputManager_nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001099 { "nativeRegisterInputChannel",
1100 "(Landroid/view/InputChannel;Lcom/android/server/InputWindowHandle;Z)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001101 (void*) android_server_InputManager_nativeRegisterInputChannel },
1102 { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V",
Jeff Brown7fbdc842010-06-17 20:52:56 -07001103 (void*) android_server_InputManager_nativeUnregisterInputChannel },
Jeff Brown6ec402b2010-07-28 15:48:59 -07001104 { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIII)I",
1105 (void*) android_server_InputManager_nativeInjectInputEvent },
Jeff Brown349703e2010-06-22 01:27:15 -07001106 { "nativeSetInputWindows", "([Lcom/android/server/InputWindow;)V",
1107 (void*) android_server_InputManager_nativeSetInputWindows },
1108 { "nativeSetFocusedApplication", "(Lcom/android/server/InputApplication;)V",
1109 (void*) android_server_InputManager_nativeSetFocusedApplication },
1110 { "nativeSetInputDispatchMode", "(ZZ)V",
1111 (void*) android_server_InputManager_nativeSetInputDispatchMode },
Jeff Brown8d608662010-08-30 03:02:23 -07001112 { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;",
1113 (void*) android_server_InputManager_nativeGetInputDevice },
1114 { "nativeGetInputDeviceIds", "()[I",
1115 (void*) android_server_InputManager_nativeGetInputDeviceIds },
Jeff Brown57c59372010-09-21 18:22:55 -07001116 { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V",
1117 (void*) android_server_InputManager_nativeGetInputConfiguration },
Jeff Browne6504122010-09-27 14:52:15 -07001118 { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1119 (void*) android_server_InputManager_nativeTransferTouchFocus },
Jeff Browne33348b2010-07-15 23:54:05 -07001120 { "nativeDump", "()Ljava/lang/String;",
1121 (void*) android_server_InputManager_nativeDump },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001122};
1123
1124#define FIND_CLASS(var, className) \
1125 var = env->FindClass(className); \
1126 LOG_FATAL_IF(! var, "Unable to find class " className); \
1127 var = jclass(env->NewGlobalRef(var));
1128
1129#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1130 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1131 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1132
1133#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1134 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1135 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1136
1137int register_android_server_InputManager(JNIEnv* env) {
1138 int res = jniRegisterNativeMethods(env, "com/android/server/InputManager",
1139 gInputManagerMethods, NELEM(gInputManagerMethods));
1140 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1141
Jeff Brown9c3cda02010-06-15 01:31:58 -07001142 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001143
1144 FIND_CLASS(gCallbacksClassInfo.clazz, "com/android/server/InputManager$Callbacks");
1145
Jeff Brown46b9ac02010-04-22 18:58:52 -07001146 GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, gCallbacksClassInfo.clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001147 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001148
1149 GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, gCallbacksClassInfo.clazz,
1150 "notifyLidSwitchChanged", "(JZ)V");
1151
Jeff Brown7fbdc842010-06-17 20:52:56 -07001152 GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, gCallbacksClassInfo.clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001153 "notifyInputChannelBroken", "(Lcom/android/server/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001154
Jeff Brown349703e2010-06-22 01:27:15 -07001155 GET_METHOD_ID(gCallbacksClassInfo.notifyANR, gCallbacksClassInfo.clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001156 "notifyANR",
1157 "(Lcom/android/server/InputApplicationHandle;Lcom/android/server/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001158
Jeff Brown349703e2010-06-22 01:27:15 -07001159 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, gCallbacksClassInfo.clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001160 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001161
1162 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, gCallbacksClassInfo.clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001163 "interceptKeyBeforeDispatching",
Jeff Brown928e0542011-01-10 11:17:36 -08001164 "(Lcom/android/server/InputWindowHandle;Landroid/view/KeyEvent;I)Z");
Jeff Brown349703e2010-06-22 01:27:15 -07001165
Jeff Brown3915bb82010-11-05 15:02:16 -07001166 GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, gCallbacksClassInfo.clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001167 "dispatchUnhandledKey",
Jeff Brown928e0542011-01-10 11:17:36 -08001168 "(Lcom/android/server/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001169
Jeff Brown349703e2010-06-22 01:27:15 -07001170 GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, gCallbacksClassInfo.clazz,
1171 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001172
Jeff Brown46b9ac02010-04-22 18:58:52 -07001173 GET_METHOD_ID(gCallbacksClassInfo.filterTouchEvents, gCallbacksClassInfo.clazz,
1174 "filterTouchEvents", "()Z");
1175
1176 GET_METHOD_ID(gCallbacksClassInfo.filterJumpyTouchEvents, gCallbacksClassInfo.clazz,
1177 "filterJumpyTouchEvents", "()Z");
1178
Jeff Brownfe508922011-01-18 15:10:10 -08001179 GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyQuietTimeMillis, gCallbacksClassInfo.clazz,
1180 "getVirtualKeyQuietTimeMillis", "()I");
1181
Jeff Brown46b9ac02010-04-22 18:58:52 -07001182 GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz,
1183 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1184
Jeff Brownae9fc032010-08-18 15:51:08 -07001185 GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz,
1186 "getMaxEventsPerSecond", "()I");
1187
Jeff Brown83c09682010-12-23 17:50:18 -08001188 GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, gCallbacksClassInfo.clazz,
1189 "getPointerLayer", "()I");
1190
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001191 GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, gCallbacksClassInfo.clazz,
1192 "getPointerIcon", "()Lcom/android/server/InputManager$PointerIcon;");
1193
Jeff Brown6ec402b2010-07-28 15:48:59 -07001194 // KeyEvent
1195
1196 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
1197
Jeff Brown8d608662010-08-30 03:02:23 -07001198 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001199
1200 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
1201
Jeff Brown8d608662010-08-30 03:02:23 -07001202 // InputDevice
1203
1204 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1205
1206 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1207 "<init>", "()V");
1208
1209 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
1210 "addMotionRange", "(IFFFF)V");
1211
1212 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1213 "mId", "I");
1214
1215 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1216 "mName", "Ljava/lang/String;");
1217
1218 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1219 "mSources", "I");
1220
1221 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1222 "mKeyboardType", "I");
1223
1224 GET_FIELD_ID(gInputDeviceClassInfo.mMotionRanges, gInputDeviceClassInfo.clazz,
1225 "mMotionRanges", "[Landroid/view/InputDevice$MotionRange;");
1226
Jeff Brown57c59372010-09-21 18:22:55 -07001227 // Configuration
1228
1229 FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration");
1230
1231 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz,
1232 "touchscreen", "I");
1233
1234 GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz,
1235 "keyboard", "I");
1236
1237 GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz,
1238 "navigation", "I");
1239
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001240 // PointerIcon
1241
1242 FIND_CLASS(gPointerIconClassInfo.clazz, "com/android/server/InputManager$PointerIcon");
1243
1244 GET_FIELD_ID(gPointerIconClassInfo.bitmap, gPointerIconClassInfo.clazz,
1245 "bitmap", "Landroid/graphics/Bitmap;");
1246
1247 GET_FIELD_ID(gPointerIconClassInfo.hotSpotX, gPointerIconClassInfo.clazz,
1248 "hotSpotX", "F");
1249
1250 GET_FIELD_ID(gPointerIconClassInfo.hotSpotY, gPointerIconClassInfo.clazz,
1251 "hotSpotY", "F");
1252
Jeff Brown46b9ac02010-04-22 18:58:52 -07001253 return 0;
1254}
1255
Jeff Brown46b9ac02010-04-22 18:58:52 -07001256} /* namespace android */