blob: 5ef234a89db75ad7dd10f2a4e482639609981948 [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>
Jeff Brown05dc66a2011-03-02 14:41:58 -080034#include <utils/Looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070035#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080036
Jeff Brownb4ff35d2011-01-02 16:37:43 -080037#include <input/InputManager.h>
38#include <input/PointerController.h>
39
Jeff Brown05dc66a2011-03-02 14:41:58 -080040#include <android_os_MessageQueue.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080041#include <android_view_KeyEvent.h>
42#include <android_view_MotionEvent.h>
43#include <android_view_InputChannel.h>
44#include <android/graphics/GraphicsJNI.h>
45
Jeff Brown00fa7bd2010-07-02 15:37:36 -070046#include "com_android_server_PowerManagerService.h"
Jeff Brown928e0542011-01-10 11:17:36 -080047#include "com_android_server_InputApplication.h"
48#include "com_android_server_InputApplicationHandle.h"
49#include "com_android_server_InputWindow.h"
50#include "com_android_server_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070051
52namespace android {
53
Jeff Brown46b9ac02010-04-22 18:58:52 -070054static struct {
55 jclass clazz;
56
Jeff Brown46b9ac02010-04-22 18:58:52 -070057 jmethodID notifyConfigurationChanged;
58 jmethodID notifyLidSwitchChanged;
Jeff Brown7fbdc842010-06-17 20:52:56 -070059 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070060 jmethodID notifyANR;
Jeff Brown349703e2010-06-22 01:27:15 -070061 jmethodID interceptKeyBeforeQueueing;
62 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070063 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070064 jmethodID checkInjectEventsPermission;
Jeff Brown46b9ac02010-04-22 18:58:52 -070065 jmethodID filterTouchEvents;
66 jmethodID filterJumpyTouchEvents;
Jeff Brownfe508922011-01-18 15:10:10 -080067 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070068 jmethodID getExcludedDeviceNames;
Jeff Brownae9fc032010-08-18 15:51:08 -070069 jmethodID getMaxEventsPerSecond;
Jeff Brown83c09682010-12-23 17:50:18 -080070 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080071 jmethodID getPointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070072} gCallbacksClassInfo;
73
74static struct {
75 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070076} gKeyEventClassInfo;
77
78static struct {
79 jclass clazz;
80} gMotionEventClassInfo;
81
Jeff Brown8d608662010-08-30 03:02:23 -070082static struct {
83 jclass clazz;
84
85 jmethodID ctor;
86 jmethodID addMotionRange;
87
88 jfieldID mId;
89 jfieldID mName;
90 jfieldID mSources;
91 jfieldID mKeyboardType;
Jeff Brown8d608662010-08-30 03:02:23 -070092} gInputDeviceClassInfo;
93
Jeff Brown57c59372010-09-21 18:22:55 -070094static struct {
95 jclass clazz;
96
97 jfieldID touchscreen;
98 jfieldID keyboard;
99 jfieldID navigation;
100} gConfigurationClassInfo;
101
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800102static struct {
103 jclass clazz;
Jeff Brown349703e2010-06-22 01:27:15 -0700104
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800105 jfieldID bitmap;
106 jfieldID hotSpotX;
107 jfieldID hotSpotY;
108} gPointerIconClassInfo;
Jeff Brown83c09682010-12-23 17:50:18 -0800109
Jeff Brown928e0542011-01-10 11:17:36 -0800110
111// --- Global functions ---
112
113static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
114 const sp<InputApplicationHandle>& inputApplicationHandle) {
115 if (inputApplicationHandle == NULL) {
116 return NULL;
117 }
118 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
119 getInputApplicationHandleObjLocalRef(env);
120}
121
122static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
123 const sp<InputWindowHandle>& inputWindowHandle) {
124 if (inputWindowHandle == NULL) {
125 return NULL;
126 }
127 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
128 getInputWindowHandleObjLocalRef(env);
129}
130
131
132// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800133
Jeff Brown9c3cda02010-06-15 01:31:58 -0700134class NativeInputManager : public virtual RefBase,
135 public virtual InputReaderPolicyInterface,
136 public virtual InputDispatcherPolicyInterface {
137protected:
138 virtual ~NativeInputManager();
139
140public:
Jeff Brown05dc66a2011-03-02 14:41:58 -0800141 NativeInputManager(jobject callbacksObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700142
143 inline sp<InputManager> getInputManager() const { return mInputManager; }
144
Jeff Brownb88102f2010-09-08 11:49:43 -0700145 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700146
Jeff Brown9c3cda02010-06-15 01:31:58 -0700147 void setDisplaySize(int32_t displayId, int32_t width, int32_t height);
148 void setDisplayOrientation(int32_t displayId, int32_t orientation);
149
Jeff Brown7fbdc842010-06-17 20:52:56 -0700150 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800151 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700152 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
153
Jeff Brown349703e2010-06-22 01:27:15 -0700154 void setInputWindows(JNIEnv* env, jobjectArray windowObjArray);
155 void setFocusedApplication(JNIEnv* env, jobject applicationObj);
156 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800157 void setSystemUiVisibility(int32_t visibility);
Jeff Brown349703e2010-06-22 01:27:15 -0700158
Jeff Brown9c3cda02010-06-15 01:31:58 -0700159 /* --- InputReaderPolicyInterface implementation --- */
160
161 virtual bool getDisplayInfo(int32_t displayId,
162 int32_t* width, int32_t* height, int32_t* orientation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700163 virtual bool filterTouchEvents();
164 virtual bool filterJumpyTouchEvents();
Jeff Brownfe508922011-01-18 15:10:10 -0800165 virtual nsecs_t getVirtualKeyQuietTime();
Jeff Brown9c3cda02010-06-15 01:31:58 -0700166 virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames);
Jeff Brown83c09682010-12-23 17:50:18 -0800167 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700168
169 /* --- InputDispatcherPolicyInterface implementation --- */
170
Jeff Browne20c9e02010-10-11 14:20:19 -0700171 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
172 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700173 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700174 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800175 const sp<InputWindowHandle>& inputWindowHandle);
176 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700177 virtual nsecs_t getKeyRepeatTimeout();
Jeff Brownb21fb102010-09-07 10:44:57 -0700178 virtual nsecs_t getKeyRepeatDelay();
Jeff Brownae9fc032010-08-18 15:51:08 -0700179 virtual int32_t getMaxEventsPerSecond();
Jeff Brown1f245102010-11-18 20:53:46 -0800180 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brownb6997262010-10-08 22:31:17 -0700181 virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800182 virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700183 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800184 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800185 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700186 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700187 virtual bool checkInjectEventsPermissionNonReentrant(
188 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700189
190private:
191 sp<InputManager> mInputManager;
192
193 jobject mCallbacksObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800194 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700195
196 // Cached filtering policies.
197 int32_t mFilterTouchEvents;
198 int32_t mFilterJumpyTouchEvents;
Jeff Brownfe508922011-01-18 15:10:10 -0800199 nsecs_t mVirtualKeyQuietTime;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700200
Jeff Brownae9fc032010-08-18 15:51:08 -0700201 // Cached throttling policy.
202 int32_t mMaxEventsPerSecond;
203
Jeff Brown83c09682010-12-23 17:50:18 -0800204 Mutex mLock;
205 struct Locked {
206 // Display size information.
207 int32_t displayWidth, displayHeight; // -1 when initialized
208 int32_t displayOrientation;
209
Jeff Brown05dc66a2011-03-02 14:41:58 -0800210 // System UI visibility.
211 int32_t systemUiVisibility;
212
Jeff Brown83c09682010-12-23 17:50:18 -0800213 // Pointer controller singleton, created and destroyed as needed.
214 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800215 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700216
Jeff Brown05dc66a2011-03-02 14:41:58 -0800217 void updateInactivityFadeDelayLocked(const sp<PointerController>& controller);
218
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700219 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700220 bool isScreenOn();
221 bool isScreenBright();
222
Jeff Brownb88102f2010-09-08 11:49:43 -0700223 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700224
Jeff Brown9c3cda02010-06-15 01:31:58 -0700225 static inline JNIEnv* jniEnv() {
226 return AndroidRuntime::getJNIEnv();
227 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700228};
229
Jeff Brown928e0542011-01-10 11:17:36 -0800230
Jeff Brown9c3cda02010-06-15 01:31:58 -0700231
Jeff Brown05dc66a2011-03-02 14:41:58 -0800232NativeInputManager::NativeInputManager(jobject callbacksObj, const sp<Looper>& looper) :
233 mLooper(looper),
234 mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1), mVirtualKeyQuietTime(-1),
235 mMaxEventsPerSecond(-1) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700236 JNIEnv* env = jniEnv();
237
238 mCallbacksObj = env->NewGlobalRef(callbacksObj);
239
Jeff Brown83c09682010-12-23 17:50:18 -0800240 {
241 AutoMutex _l(mLock);
242 mLocked.displayWidth = -1;
243 mLocked.displayHeight = -1;
244 mLocked.displayOrientation = ROTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800245
246 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown83c09682010-12-23 17:50:18 -0800247 }
248
Jeff Brown9c3cda02010-06-15 01:31:58 -0700249 sp<EventHub> eventHub = new EventHub();
250 mInputManager = new InputManager(eventHub, this, this);
251}
252
253NativeInputManager::~NativeInputManager() {
254 JNIEnv* env = jniEnv();
255
256 env->DeleteGlobalRef(mCallbacksObj);
257}
258
Jeff Brownb88102f2010-09-08 11:49:43 -0700259void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700260 mInputManager->getReader()->dump(dump);
261 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700262
Jeff Brownb88102f2010-09-08 11:49:43 -0700263 mInputManager->getDispatcher()->dump(dump);
264 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700265}
266
Jeff Brown7fbdc842010-06-17 20:52:56 -0700267bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700268 if (env->ExceptionCheck()) {
269 LOGE("An exception was thrown by callback '%s'.", methodName);
270 LOGE_EX(env);
271 env->ExceptionClear();
272 return true;
273 }
274 return false;
275}
276
277void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height) {
278 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800279 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700280
Jeff Brown83c09682010-12-23 17:50:18 -0800281 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
282 mLocked.displayWidth = width;
283 mLocked.displayHeight = height;
284
285 sp<PointerController> controller = mLocked.pointerController.promote();
286 if (controller != NULL) {
287 controller->setDisplaySize(width, height);
288 }
289 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700290 }
291}
292
293void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
294 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800295 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700296
Jeff Brown83c09682010-12-23 17:50:18 -0800297 if (mLocked.displayOrientation != orientation) {
298 mLocked.displayOrientation = orientation;
299
300 sp<PointerController> controller = mLocked.pointerController.promote();
301 if (controller != NULL) {
302 controller->setDisplayOrientation(orientation);
303 }
304 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700305 }
306}
307
Jeff Brown7fbdc842010-06-17 20:52:56 -0700308status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800309 const sp<InputChannel>& inputChannel,
310 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
311 return mInputManager->getDispatcher()->registerInputChannel(
312 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700313}
314
315status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
316 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700317 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700318}
319
Jeff Brown9c3cda02010-06-15 01:31:58 -0700320bool NativeInputManager::getDisplayInfo(int32_t displayId,
321 int32_t* width, int32_t* height, int32_t* orientation) {
322 bool result = false;
323 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800324 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700325
Jeff Brown83c09682010-12-23 17:50:18 -0800326 if (mLocked.displayWidth > 0 && mLocked.displayHeight > 0) {
Jeff Brown6d0fec22010-07-23 21:28:06 -0700327 if (width) {
Jeff Brown83c09682010-12-23 17:50:18 -0800328 *width = mLocked.displayWidth;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700329 }
330 if (height) {
Jeff Brown83c09682010-12-23 17:50:18 -0800331 *height = mLocked.displayHeight;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700332 }
333 if (orientation) {
Jeff Brown83c09682010-12-23 17:50:18 -0800334 *orientation = mLocked.displayOrientation;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700335 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700336 result = true;
337 }
338 }
339 return result;
340}
341
Jeff Brown9c3cda02010-06-15 01:31:58 -0700342bool NativeInputManager::filterTouchEvents() {
343 if (mFilterTouchEvents < 0) {
344 JNIEnv* env = jniEnv();
345
346 jboolean result = env->CallBooleanMethod(mCallbacksObj,
347 gCallbacksClassInfo.filterTouchEvents);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700348 if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700349 result = false;
350 }
351
352 mFilterTouchEvents = result ? 1 : 0;
353 }
354 return mFilterTouchEvents;
355}
356
357bool NativeInputManager::filterJumpyTouchEvents() {
358 if (mFilterJumpyTouchEvents < 0) {
359 JNIEnv* env = jniEnv();
360
361 jboolean result = env->CallBooleanMethod(mCallbacksObj,
362 gCallbacksClassInfo.filterJumpyTouchEvents);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700363 if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700364 result = false;
365 }
366
367 mFilterJumpyTouchEvents = result ? 1 : 0;
368 }
369 return mFilterJumpyTouchEvents;
370}
371
Jeff Brownfe508922011-01-18 15:10:10 -0800372nsecs_t NativeInputManager::getVirtualKeyQuietTime() {
373 if (mVirtualKeyQuietTime < 0) {
374 JNIEnv* env = jniEnv();
375
376 jint result = env->CallIntMethod(mCallbacksObj,
377 gCallbacksClassInfo.getVirtualKeyQuietTimeMillis);
378 if (checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
379 result = 0;
380 }
381 if (result < 0) {
382 result = 0;
383 }
384
385 mVirtualKeyQuietTime = milliseconds_to_nanoseconds(result);
386 }
387 return mVirtualKeyQuietTime;
388}
389
Jeff Brown9c3cda02010-06-15 01:31:58 -0700390void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) {
Jeff Brown8d608662010-08-30 03:02:23 -0700391 outExcludedDeviceNames.clear();
392
Jeff Brown9c3cda02010-06-15 01:31:58 -0700393 JNIEnv* env = jniEnv();
394
395 jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj,
396 gCallbacksClassInfo.getExcludedDeviceNames));
Jeff Brown7fbdc842010-06-17 20:52:56 -0700397 if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700398 jsize length = env->GetArrayLength(result);
399 for (jsize i = 0; i < length; i++) {
400 jstring item = jstring(env->GetObjectArrayElement(result, i));
401
402 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
403 outExcludedDeviceNames.add(String8(deviceNameChars));
404 env->ReleaseStringUTFChars(item, deviceNameChars);
405
406 env->DeleteLocalRef(item);
407 }
408 env->DeleteLocalRef(result);
409 }
410}
411
Jeff Brown83c09682010-12-23 17:50:18 -0800412sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
413 AutoMutex _l(mLock);
414
415 sp<PointerController> controller = mLocked.pointerController.promote();
416 if (controller == NULL) {
417 JNIEnv* env = jniEnv();
418 jint layer = env->CallIntMethod(mCallbacksObj, gCallbacksClassInfo.getPointerLayer);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800419 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
420 layer = -1;
421 }
Jeff Brown83c09682010-12-23 17:50:18 -0800422
Jeff Brown05dc66a2011-03-02 14:41:58 -0800423 controller = new PointerController(mLooper, layer);
Jeff Brown83c09682010-12-23 17:50:18 -0800424 mLocked.pointerController = controller;
425
426 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
427 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800428
429 jobject iconObj = env->CallObjectMethod(mCallbacksObj, gCallbacksClassInfo.getPointerIcon);
430 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon") && iconObj) {
431 jfloat iconHotSpotX = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotX);
432 jfloat iconHotSpotY = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotY);
433 jobject iconBitmapObj = env->GetObjectField(iconObj, gPointerIconClassInfo.bitmap);
434 if (iconBitmapObj) {
435 SkBitmap* iconBitmap = GraphicsJNI::getNativeBitmap(env, iconBitmapObj);
436 if (iconBitmap) {
437 controller->setPointerIcon(iconBitmap, iconHotSpotX, iconHotSpotY);
438 }
439 env->DeleteLocalRef(iconBitmapObj);
440 }
441 env->DeleteLocalRef(iconObj);
442 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800443
444 updateInactivityFadeDelayLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800445 }
446 return controller;
447}
448
Jeff Browne20c9e02010-10-11 14:20:19 -0700449void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
450 int32_t switchValue, uint32_t policyFlags) {
451#if DEBUG_INPUT_DISPATCHER_POLICY
452 LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
453 when, switchCode, switchValue, policyFlags);
454#endif
455
456 JNIEnv* env = jniEnv();
457
458 switch (switchCode) {
459 case SW_LID:
460 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged,
461 when, switchValue == 0);
462 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
463 break;
464 }
465}
466
Jeff Brown9c3cda02010-06-15 01:31:58 -0700467void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
468#if DEBUG_INPUT_DISPATCHER_POLICY
469 LOGD("notifyConfigurationChanged - when=%lld", when);
470#endif
471
472 JNIEnv* env = jniEnv();
473
Jeff Brown57c59372010-09-21 18:22:55 -0700474 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700475 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700476}
477
Jeff Brown519e0242010-09-15 15:18:56 -0700478nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800479 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700480#if DEBUG_INPUT_DISPATCHER_POLICY
481 LOGD("notifyANR");
482#endif
483
484 JNIEnv* env = jniEnv();
485
Jeff Brown928e0542011-01-10 11:17:36 -0800486 jobject inputApplicationHandleObj =
487 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
488 jobject inputWindowHandleObj =
489 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700490
Jeff Brown519e0242010-09-15 15:18:56 -0700491 jlong newTimeout = env->CallLongMethod(mCallbacksObj,
Jeff Brown928e0542011-01-10 11:17:36 -0800492 gCallbacksClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700493 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
494 newTimeout = 0; // abort dispatch
495 } else {
496 assert(newTimeout >= 0);
497 }
498
Jeff Brown928e0542011-01-10 11:17:36 -0800499 env->DeleteLocalRef(inputWindowHandleObj);
500 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700501 return newTimeout;
502}
503
Jeff Brown928e0542011-01-10 11:17:36 -0800504void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700505#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown928e0542011-01-10 11:17:36 -0800506 LOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700507#endif
508
Jeff Brown7fbdc842010-06-17 20:52:56 -0700509 JNIEnv* env = jniEnv();
510
Jeff Brown928e0542011-01-10 11:17:36 -0800511 jobject inputWindowHandleObj =
512 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
513 if (inputWindowHandleObj) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700514 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800515 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700516 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
517
Jeff Brown928e0542011-01-10 11:17:36 -0800518 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700519 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700520}
521
Jeff Brown9c3cda02010-06-15 01:31:58 -0700522nsecs_t NativeInputManager::getKeyRepeatTimeout() {
523 if (! isScreenOn()) {
524 // Disable key repeat when the screen is off.
525 return -1;
526 } else {
527 // TODO use ViewConfiguration.getLongPressTimeout()
528 return milliseconds_to_nanoseconds(500);
529 }
530}
531
Jeff Brownb21fb102010-09-07 10:44:57 -0700532nsecs_t NativeInputManager::getKeyRepeatDelay() {
533 return milliseconds_to_nanoseconds(50);
534}
535
Jeff Brownae9fc032010-08-18 15:51:08 -0700536int32_t NativeInputManager::getMaxEventsPerSecond() {
537 if (mMaxEventsPerSecond < 0) {
538 JNIEnv* env = jniEnv();
539
540 jint result = env->CallIntMethod(mCallbacksObj,
541 gCallbacksClassInfo.getMaxEventsPerSecond);
542 if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700543 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700544 }
545
546 mMaxEventsPerSecond = result;
547 }
548 return mMaxEventsPerSecond;
549}
550
Jeff Brown349703e2010-06-22 01:27:15 -0700551void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700552 Vector<InputWindow> windows;
Jeff Brown349703e2010-06-22 01:27:15 -0700553
Jeff Brownb88102f2010-09-08 11:49:43 -0700554 jsize length = env->GetArrayLength(windowObjArray);
555 for (jsize i = 0; i < length; i++) {
Jeff Brown928e0542011-01-10 11:17:36 -0800556 jobject windowObj = env->GetObjectArrayElement(windowObjArray, i);
557 if (! windowObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700558 break; // found null element indicating end of used portion of the array
Jeff Brown349703e2010-06-22 01:27:15 -0700559 }
560
Jeff Brownb88102f2010-09-08 11:49:43 -0700561 windows.push();
562 InputWindow& window = windows.editTop();
Jeff Brown928e0542011-01-10 11:17:36 -0800563 android_server_InputWindow_toNative(env, windowObj, &window);
564 if (window.inputChannel == NULL) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700565 windows.pop();
Jeff Brown349703e2010-06-22 01:27:15 -0700566 }
Jeff Brown928e0542011-01-10 11:17:36 -0800567 env->DeleteLocalRef(windowObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700568 }
Jeff Brown349703e2010-06-22 01:27:15 -0700569
Jeff Brownb88102f2010-09-08 11:49:43 -0700570 mInputManager->getDispatcher()->setInputWindows(windows);
Jeff Brown349703e2010-06-22 01:27:15 -0700571}
572
Jeff Brown349703e2010-06-22 01:27:15 -0700573void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700574 if (applicationObj) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700575 InputApplication application;
Jeff Brown928e0542011-01-10 11:17:36 -0800576 android_server_InputApplication_toNative(env, applicationObj, &application);
577 if (application.inputApplicationHandle != NULL) {
578 mInputManager->getDispatcher()->setFocusedApplication(&application);
579 }
Jeff Brown349703e2010-06-22 01:27:15 -0700580 }
Jeff Brown928e0542011-01-10 11:17:36 -0800581 mInputManager->getDispatcher()->setFocusedApplication(NULL);
Jeff Brown349703e2010-06-22 01:27:15 -0700582}
583
584void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700585 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700586}
587
Jeff Brown05dc66a2011-03-02 14:41:58 -0800588void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
589 AutoMutex _l(mLock);
590
591 if (mLocked.systemUiVisibility != visibility) {
592 mLocked.systemUiVisibility = visibility;
593
594 sp<PointerController> controller = mLocked.pointerController.promote();
595 if (controller != NULL) {
596 updateInactivityFadeDelayLocked(controller);
597 }
598 }
599}
600
601void NativeInputManager::updateInactivityFadeDelayLocked(const sp<PointerController>& controller) {
602 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
603 controller->setInactivityFadeDelay(lightsOut
604 ? PointerController::INACTIVITY_FADE_DELAY_SHORT
605 : PointerController::INACTIVITY_FADE_DELAY_NORMAL);
606}
607
Jeff Browne20c9e02010-10-11 14:20:19 -0700608bool NativeInputManager::isScreenOn() {
609 return android_server_PowerManagerService_isScreenOn();
610}
611
612bool NativeInputManager::isScreenBright() {
613 return android_server_PowerManagerService_isScreenBright();
614}
615
Jeff Brown1f245102010-11-18 20:53:46 -0800616void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
617 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700618 // Policy:
619 // - Ignore untrusted events and pass them along.
620 // - Ask the window manager what to do with normal events and trusted injected events.
621 // - For normal events wake and brighten the screen if currently off or dim.
622 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
623 const int32_t WM_ACTION_PASS_TO_USER = 1;
624 const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2;
625 const int32_t WM_ACTION_GO_TO_SLEEP = 4;
Jeff Browne20c9e02010-10-11 14:20:19 -0700626
Jeff Brown1f245102010-11-18 20:53:46 -0800627 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700628 bool isScreenOn = this->isScreenOn();
629 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700630
Jeff Brown3122e442010-10-11 23:32:49 -0700631 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800632 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
633 jint wmActions;
634 if (keyEventObj) {
635 wmActions = env->CallIntMethod(mCallbacksObj,
636 gCallbacksClassInfo.interceptKeyBeforeQueueing,
637 keyEventObj, policyFlags, isScreenOn);
638 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
639 wmActions = 0;
640 }
641 android_view_KeyEvent_recycle(env, keyEventObj);
642 env->DeleteLocalRef(keyEventObj);
643 } else {
644 LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700645 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700646 }
647
Jeff Brown1f245102010-11-18 20:53:46 -0800648 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700649 if (!isScreenOn) {
650 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700651 }
652
653 if (!isScreenBright) {
654 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
655 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700656 }
657
658 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
659 android_server_PowerManagerService_goToSleep(when);
660 }
661
662 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
663 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
664 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700665
Jeff Brown3122e442010-10-11 23:32:49 -0700666 if (wmActions & WM_ACTION_PASS_TO_USER) {
667 policyFlags |= POLICY_FLAG_PASS_TO_USER;
668 }
669 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700670 policyFlags |= POLICY_FLAG_PASS_TO_USER;
671 }
672}
673
674void NativeInputManager::interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700675 // Policy:
676 // - Ignore untrusted events and pass them along.
677 // - No special filtering for injected events required at this time.
678 // - Filter normal events based on screen state.
679 // - For normal events brighten (but do not wake) the screen if currently dim.
680 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
681 if (isScreenOn()) {
682 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700683
Jeff Brown3122e442010-10-11 23:32:49 -0700684 if (!isScreenBright()) {
685 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
686 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700687 }
Jeff Brown3122e442010-10-11 23:32:49 -0700688 } else {
689 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700690 }
691}
692
Jeff Brown928e0542011-01-10 11:17:36 -0800693bool NativeInputManager::interceptKeyBeforeDispatching(
694 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700695 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700696 // Policy:
697 // - Ignore untrusted events and pass them along.
698 // - Filter normal events and trusted injected events through the window manager policy to
699 // handle the HOME key and the like.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800700 bool result = false;
Jeff Brown3122e442010-10-11 23:32:49 -0700701 if (policyFlags & POLICY_FLAG_TRUSTED) {
702 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700703
Jeff Brown928e0542011-01-10 11:17:36 -0800704 // Note: inputWindowHandle may be null.
705 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800706 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
707 if (keyEventObj) {
708 jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
709 gCallbacksClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800710 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800711 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
712 android_view_KeyEvent_recycle(env, keyEventObj);
713 env->DeleteLocalRef(keyEventObj);
714 result = consumed && !error;
715 } else {
716 LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800717 }
Jeff Brown928e0542011-01-10 11:17:36 -0800718 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700719 }
Jeff Brown1f245102010-11-18 20:53:46 -0800720 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700721}
722
Jeff Brown928e0542011-01-10 11:17:36 -0800723bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800724 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700725 // Policy:
726 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800727 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700728 if (policyFlags & POLICY_FLAG_TRUSTED) {
729 JNIEnv* env = jniEnv();
730
Jeff Brown928e0542011-01-10 11:17:36 -0800731 // Note: inputWindowHandle may be null.
732 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800733 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
734 if (keyEventObj) {
Jeff Brown49ed71d2010-12-06 17:13:33 -0800735 jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800736 gCallbacksClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800737 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800738 checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey");
Jeff Brown1f245102010-11-18 20:53:46 -0800739 android_view_KeyEvent_recycle(env, keyEventObj);
740 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800741
742 if (fallbackKeyEventObj) {
743 // Note: outFallbackKeyEvent may be the same object as keyEvent.
744 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
745 outFallbackKeyEvent)) {
746 result = true;
747 }
748 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
749 env->DeleteLocalRef(fallbackKeyEventObj);
750 }
Jeff Brown1f245102010-11-18 20:53:46 -0800751 } else {
752 LOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800753 }
Jeff Brown928e0542011-01-10 11:17:36 -0800754 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700755 }
Jeff Brown1f245102010-11-18 20:53:46 -0800756 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700757}
758
Jeff Brown01ce2e92010-09-26 22:20:12 -0700759void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
760 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700761}
762
Jeff Brown349703e2010-06-22 01:27:15 -0700763
Jeff Brownb88102f2010-09-08 11:49:43 -0700764bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
765 int32_t injectorPid, int32_t injectorUid) {
766 JNIEnv* env = jniEnv();
767 jboolean result = env->CallBooleanMethod(mCallbacksObj,
768 gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
769 checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission");
Jeff Brown349703e2010-06-22 01:27:15 -0700770 return result;
771}
772
Jeff Brown83c09682010-12-23 17:50:18 -0800773
Jeff Brown9c3cda02010-06-15 01:31:58 -0700774// ----------------------------------------------------------------------------
775
776static sp<NativeInputManager> gNativeInputManager;
777
Jeff Brown46b9ac02010-04-22 18:58:52 -0700778static bool checkInputManagerUnitialized(JNIEnv* env) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700779 if (gNativeInputManager == NULL) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700780 LOGE("Input manager not initialized.");
781 jniThrowRuntimeException(env, "Input manager not initialized.");
782 return true;
783 }
784 return false;
785}
786
787static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
Jeff Brown05dc66a2011-03-02 14:41:58 -0800788 jobject callbacks, jobject messageQueueObj) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700789 if (gNativeInputManager == NULL) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800790 sp<Looper> looper = android_os_MessageQueue_getLooper(env, messageQueueObj);
791 gNativeInputManager = new NativeInputManager(callbacks, looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700792 } else {
793 LOGE("Input manager already initialized.");
794 jniThrowRuntimeException(env, "Input manager already initialized.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700795 }
796}
797
798static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
799 if (checkInputManagerUnitialized(env)) {
800 return;
801 }
802
Jeff Brown9c3cda02010-06-15 01:31:58 -0700803 status_t result = gNativeInputManager->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700804 if (result) {
805 jniThrowRuntimeException(env, "Input manager could not be started.");
806 }
807}
808
809static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz,
810 jint displayId, jint width, jint height) {
811 if (checkInputManagerUnitialized(env)) {
812 return;
813 }
814
815 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
816 // to be passed in like this, not sure which is better but leaving it like this
817 // keeps the window manager in direct control of when display transitions propagate down
818 // to the input dispatcher
Jeff Brown9c3cda02010-06-15 01:31:58 -0700819 gNativeInputManager->setDisplaySize(displayId, width, height);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700820}
821
822static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
823 jint displayId, jint orientation) {
824 if (checkInputManagerUnitialized(env)) {
825 return;
826 }
827
Jeff Brown9c3cda02010-06-15 01:31:58 -0700828 gNativeInputManager->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700829}
830
831static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700832 jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700833 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700834 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700835 }
836
Jeff Brownb88102f2010-09-08 11:49:43 -0700837 return gNativeInputManager->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700838 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700839}
840
841static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700842 jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700843 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700844 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700845 }
846
Jeff Brownb88102f2010-09-08 11:49:43 -0700847 return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700848 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700849}
850
851static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700852 jint deviceId, jint sourceMask, jint sw) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700853 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700854 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700855 }
856
Jeff Brownb88102f2010-09-08 11:49:43 -0700857 return gNativeInputManager->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700858 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700859}
860
861static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -0700862 jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700863 if (checkInputManagerUnitialized(env)) {
864 return JNI_FALSE;
865 }
866
867 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
868 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
869 jsize numCodes = env->GetArrayLength(keyCodes);
870 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -0700871 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700872 result = gNativeInputManager->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700873 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700874 } else {
875 result = JNI_FALSE;
876 }
877
878 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
879 env->ReleaseIntArrayElements(keyCodes, codes, 0);
880 return result;
881}
882
883static void throwInputChannelNotInitialized(JNIEnv* env) {
884 jniThrowException(env, "java/lang/IllegalStateException",
885 "inputChannel is not initialized");
886}
887
888static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env,
889 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
890 LOGW("Input channel object '%s' was disposed without first being unregistered with "
891 "the input manager!", inputChannel->getName().string());
892
Jeff Brown9c3cda02010-06-15 01:31:58 -0700893 if (gNativeInputManager != NULL) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700894 gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700895 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700896}
897
898static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
Jeff Brown928e0542011-01-10 11:17:36 -0800899 jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700900 if (checkInputManagerUnitialized(env)) {
901 return;
902 }
903
904 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
905 inputChannelObj);
906 if (inputChannel == NULL) {
907 throwInputChannelNotInitialized(env);
908 return;
909 }
910
Jeff Brown928e0542011-01-10 11:17:36 -0800911 sp<InputWindowHandle> inputWindowHandle =
912 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700913
914 status_t status = gNativeInputManager->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -0800915 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700916 if (status) {
917 jniThrowRuntimeException(env, "Failed to register input channel. "
918 "Check logs for details.");
919 return;
920 }
921
Jeff Browna41ca772010-08-11 14:46:32 -0700922 if (! monitor) {
923 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
924 android_server_InputManager_handleInputChannelDisposed, NULL);
925 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700926}
927
928static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
929 jobject inputChannelObj) {
930 if (checkInputManagerUnitialized(env)) {
931 return;
932 }
933
934 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
935 inputChannelObj);
936 if (inputChannel == NULL) {
937 throwInputChannelNotInitialized(env);
938 return;
939 }
940
941 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
942
Jeff Brown7fbdc842010-06-17 20:52:56 -0700943 status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700944 if (status) {
945 jniThrowRuntimeException(env, "Failed to unregister input channel. "
946 "Check logs for details.");
947 }
948}
949
Jeff Brown6ec402b2010-07-28 15:48:59 -0700950static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz,
951 jobject inputEventObj, jint injectorPid, jint injectorUid,
952 jint syncMode, jint timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700953 if (checkInputManagerUnitialized(env)) {
954 return INPUT_EVENT_INJECTION_FAILED;
955 }
956
Jeff Brown6ec402b2010-07-28 15:48:59 -0700957 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
958 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -0800959 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
960 if (status) {
961 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
962 return INPUT_EVENT_INJECTION_FAILED;
963 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700964
Jeff Brownb88102f2010-09-08 11:49:43 -0700965 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
966 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown6ec402b2010-07-28 15:48:59 -0700967 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
968 MotionEvent motionEvent;
Jeff Brown1f245102010-11-18 20:53:46 -0800969 status_t status = android_view_MotionEvent_toNative(env, inputEventObj, & motionEvent);
970 if (status) {
971 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
972 return INPUT_EVENT_INJECTION_FAILED;
973 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700974
Jeff Brownb88102f2010-09-08 11:49:43 -0700975 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
976 & motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown6ec402b2010-07-28 15:48:59 -0700977 } else {
978 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -0700979 return INPUT_EVENT_INJECTION_FAILED;
980 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700981}
982
Jeff Brown349703e2010-06-22 01:27:15 -0700983static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz,
984 jobjectArray windowObjArray) {
985 if (checkInputManagerUnitialized(env)) {
986 return;
987 }
988
989 gNativeInputManager->setInputWindows(env, windowObjArray);
990}
991
992static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
993 jobject applicationObj) {
994 if (checkInputManagerUnitialized(env)) {
995 return;
996 }
997
998 gNativeInputManager->setFocusedApplication(env, applicationObj);
999}
1000
1001static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env,
1002 jclass clazz, jboolean enabled, jboolean frozen) {
1003 if (checkInputManagerUnitialized(env)) {
1004 return;
1005 }
1006
1007 gNativeInputManager->setInputDispatchMode(enabled, frozen);
1008}
1009
Jeff Brown05dc66a2011-03-02 14:41:58 -08001010static void android_server_InputManager_nativeSetSystemUiVisibility(JNIEnv* env,
1011 jclass clazz, jint visibility) {
1012 if (checkInputManagerUnitialized(env)) {
1013 return;
1014 }
1015
1016 gNativeInputManager->setSystemUiVisibility(visibility);
1017}
1018
Jeff Brown8d608662010-08-30 03:02:23 -07001019static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env,
1020 jclass clazz, jint deviceId) {
1021 if (checkInputManagerUnitialized(env)) {
1022 return NULL;
1023 }
1024
1025 InputDeviceInfo deviceInfo;
Jeff Brownb88102f2010-09-08 11:49:43 -07001026 status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -07001027 deviceId, & deviceInfo);
1028 if (status) {
1029 return NULL;
1030 }
1031
1032 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
1033 if (! deviceObj) {
1034 return NULL;
1035 }
1036
1037 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
1038 if (! deviceNameObj) {
1039 return NULL;
1040 }
1041
1042 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
1043 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
1044 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
1045 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
1046
1047 const KeyedVector<int, InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
1048 for (size_t i = 0; i < ranges.size(); i++) {
1049 int rangeType = ranges.keyAt(i);
1050 const InputDeviceInfo::MotionRange& range = ranges.valueAt(i);
1051 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
1052 rangeType, range.min, range.max, range.flat, range.fuzz);
1053 if (env->ExceptionCheck()) {
1054 return NULL;
1055 }
1056 }
1057
1058 return deviceObj;
1059}
1060
1061static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env,
1062 jclass clazz) {
1063 if (checkInputManagerUnitialized(env)) {
1064 return NULL;
1065 }
1066
1067 Vector<int> deviceIds;
Jeff Brownb88102f2010-09-08 11:49:43 -07001068 gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001069
1070 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1071 if (! deviceIdsObj) {
1072 return NULL;
1073 }
1074
1075 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1076 return deviceIdsObj;
1077}
1078
Jeff Brown57c59372010-09-21 18:22:55 -07001079static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env,
1080 jclass clazz, jobject configObj) {
1081 if (checkInputManagerUnitialized(env)) {
1082 return;
1083 }
1084
1085 InputConfiguration config;
1086 gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config);
1087
1088 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1089 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1090 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1091}
1092
Jeff Browne6504122010-09-27 14:52:15 -07001093static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env,
1094 jclass clazz, jobject fromChannelObj, jobject toChannelObj) {
1095 if (checkInputManagerUnitialized(env)) {
1096 return false;
1097 }
1098
1099 sp<InputChannel> fromChannel =
1100 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1101 sp<InputChannel> toChannel =
1102 android_view_InputChannel_getInputChannel(env, toChannelObj);
1103
1104 if (fromChannel == NULL || toChannel == NULL) {
1105 return false;
1106 }
1107
1108 return gNativeInputManager->getInputManager()->getDispatcher()->
1109 transferTouchFocus(fromChannel, toChannel);
1110}
1111
Jeff Browne33348b2010-07-15 23:54:05 -07001112static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
1113 if (checkInputManagerUnitialized(env)) {
1114 return NULL;
1115 }
1116
Jeff Brownb88102f2010-09-08 11:49:43 -07001117 String8 dump;
1118 gNativeInputManager->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001119 return env->NewStringUTF(dump.string());
1120}
1121
Jeff Brown9c3cda02010-06-15 01:31:58 -07001122// ----------------------------------------------------------------------------
1123
Jeff Brown46b9ac02010-04-22 18:58:52 -07001124static JNINativeMethod gInputManagerMethods[] = {
1125 /* name, signature, funcPtr */
Jeff Brown05dc66a2011-03-02 14:41:58 -08001126 { "nativeInit", "(Lcom/android/server/wm/InputManager$Callbacks;Landroid/os/MessageQueue;)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001127 (void*) android_server_InputManager_nativeInit },
1128 { "nativeStart", "()V",
1129 (void*) android_server_InputManager_nativeStart },
1130 { "nativeSetDisplaySize", "(III)V",
1131 (void*) android_server_InputManager_nativeSetDisplaySize },
1132 { "nativeSetDisplayOrientation", "(II)V",
1133 (void*) android_server_InputManager_nativeSetDisplayOrientation },
1134 { "nativeGetScanCodeState", "(III)I",
1135 (void*) android_server_InputManager_nativeGetScanCodeState },
1136 { "nativeGetKeyCodeState", "(III)I",
1137 (void*) android_server_InputManager_nativeGetKeyCodeState },
1138 { "nativeGetSwitchState", "(III)I",
1139 (void*) android_server_InputManager_nativeGetSwitchState },
Jeff Brown6d0fec22010-07-23 21:28:06 -07001140 { "nativeHasKeys", "(II[I[Z)Z",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001141 (void*) android_server_InputManager_nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001142 { "nativeRegisterInputChannel",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001143 "(Landroid/view/InputChannel;Lcom/android/server/wm/InputWindowHandle;Z)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001144 (void*) android_server_InputManager_nativeRegisterInputChannel },
1145 { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V",
Jeff Brown7fbdc842010-06-17 20:52:56 -07001146 (void*) android_server_InputManager_nativeUnregisterInputChannel },
Jeff Brown6ec402b2010-07-28 15:48:59 -07001147 { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIII)I",
1148 (void*) android_server_InputManager_nativeInjectInputEvent },
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001149 { "nativeSetInputWindows", "([Lcom/android/server/wm/InputWindow;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001150 (void*) android_server_InputManager_nativeSetInputWindows },
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001151 { "nativeSetFocusedApplication", "(Lcom/android/server/wm/InputApplication;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001152 (void*) android_server_InputManager_nativeSetFocusedApplication },
1153 { "nativeSetInputDispatchMode", "(ZZ)V",
1154 (void*) android_server_InputManager_nativeSetInputDispatchMode },
Jeff Brown05dc66a2011-03-02 14:41:58 -08001155 { "nativeSetSystemUiVisibility", "(I)V",
1156 (void*) android_server_InputManager_nativeSetSystemUiVisibility },
Jeff Brown8d608662010-08-30 03:02:23 -07001157 { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;",
1158 (void*) android_server_InputManager_nativeGetInputDevice },
1159 { "nativeGetInputDeviceIds", "()[I",
1160 (void*) android_server_InputManager_nativeGetInputDeviceIds },
Jeff Brown57c59372010-09-21 18:22:55 -07001161 { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V",
1162 (void*) android_server_InputManager_nativeGetInputConfiguration },
Jeff Browne6504122010-09-27 14:52:15 -07001163 { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1164 (void*) android_server_InputManager_nativeTransferTouchFocus },
Jeff Browne33348b2010-07-15 23:54:05 -07001165 { "nativeDump", "()Ljava/lang/String;",
1166 (void*) android_server_InputManager_nativeDump },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001167};
1168
1169#define FIND_CLASS(var, className) \
1170 var = env->FindClass(className); \
1171 LOG_FATAL_IF(! var, "Unable to find class " className); \
1172 var = jclass(env->NewGlobalRef(var));
1173
1174#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1175 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1176 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1177
1178#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1179 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1180 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1181
1182int register_android_server_InputManager(JNIEnv* env) {
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001183 int res = jniRegisterNativeMethods(env, "com/android/server/wm/InputManager",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001184 gInputManagerMethods, NELEM(gInputManagerMethods));
1185 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1186
Jeff Brown9c3cda02010-06-15 01:31:58 -07001187 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001188
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001189 FIND_CLASS(gCallbacksClassInfo.clazz, "com/android/server/wm/InputManager$Callbacks");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001190
Jeff Brown46b9ac02010-04-22 18:58:52 -07001191 GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, gCallbacksClassInfo.clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001192 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001193
1194 GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, gCallbacksClassInfo.clazz,
1195 "notifyLidSwitchChanged", "(JZ)V");
1196
Jeff Brown7fbdc842010-06-17 20:52:56 -07001197 GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, gCallbacksClassInfo.clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001198 "notifyInputChannelBroken", "(Lcom/android/server/wm/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001199
Jeff Brown349703e2010-06-22 01:27:15 -07001200 GET_METHOD_ID(gCallbacksClassInfo.notifyANR, gCallbacksClassInfo.clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001201 "notifyANR",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001202 "(Lcom/android/server/wm/InputApplicationHandle;Lcom/android/server/wm/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001203
Jeff Brown349703e2010-06-22 01:27:15 -07001204 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, gCallbacksClassInfo.clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001205 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001206
1207 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, gCallbacksClassInfo.clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001208 "interceptKeyBeforeDispatching",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001209 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Z");
Jeff Brown349703e2010-06-22 01:27:15 -07001210
Jeff Brown3915bb82010-11-05 15:02:16 -07001211 GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, gCallbacksClassInfo.clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001212 "dispatchUnhandledKey",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001213 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001214
Jeff Brown349703e2010-06-22 01:27:15 -07001215 GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, gCallbacksClassInfo.clazz,
1216 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001217
Jeff Brown46b9ac02010-04-22 18:58:52 -07001218 GET_METHOD_ID(gCallbacksClassInfo.filterTouchEvents, gCallbacksClassInfo.clazz,
1219 "filterTouchEvents", "()Z");
1220
1221 GET_METHOD_ID(gCallbacksClassInfo.filterJumpyTouchEvents, gCallbacksClassInfo.clazz,
1222 "filterJumpyTouchEvents", "()Z");
1223
Jeff Brownfe508922011-01-18 15:10:10 -08001224 GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyQuietTimeMillis, gCallbacksClassInfo.clazz,
1225 "getVirtualKeyQuietTimeMillis", "()I");
1226
Jeff Brown46b9ac02010-04-22 18:58:52 -07001227 GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz,
1228 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1229
Jeff Brownae9fc032010-08-18 15:51:08 -07001230 GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz,
1231 "getMaxEventsPerSecond", "()I");
1232
Jeff Brown83c09682010-12-23 17:50:18 -08001233 GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, gCallbacksClassInfo.clazz,
1234 "getPointerLayer", "()I");
1235
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001236 GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, gCallbacksClassInfo.clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001237 "getPointerIcon", "()Lcom/android/server/wm/InputManager$PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001238
Jeff Brown6ec402b2010-07-28 15:48:59 -07001239 // KeyEvent
1240
1241 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
1242
Jeff Brown8d608662010-08-30 03:02:23 -07001243 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001244
1245 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
1246
Jeff Brown8d608662010-08-30 03:02:23 -07001247 // InputDevice
1248
1249 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1250
1251 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1252 "<init>", "()V");
1253
1254 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
1255 "addMotionRange", "(IFFFF)V");
1256
1257 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1258 "mId", "I");
1259
1260 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1261 "mName", "Ljava/lang/String;");
1262
1263 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1264 "mSources", "I");
1265
1266 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1267 "mKeyboardType", "I");
1268
Jeff Brown57c59372010-09-21 18:22:55 -07001269 // Configuration
1270
1271 FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration");
1272
1273 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz,
1274 "touchscreen", "I");
1275
1276 GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz,
1277 "keyboard", "I");
1278
1279 GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz,
1280 "navigation", "I");
1281
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001282 // PointerIcon
1283
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001284 FIND_CLASS(gPointerIconClassInfo.clazz, "com/android/server/wm/InputManager$PointerIcon");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001285
1286 GET_FIELD_ID(gPointerIconClassInfo.bitmap, gPointerIconClassInfo.clazz,
1287 "bitmap", "Landroid/graphics/Bitmap;");
1288
1289 GET_FIELD_ID(gPointerIconClassInfo.hotSpotX, gPointerIconClassInfo.clazz,
1290 "hotSpotX", "F");
1291
1292 GET_FIELD_ID(gPointerIconClassInfo.hotSpotY, gPointerIconClassInfo.clazz,
1293 "hotSpotY", "F");
1294
Jeff Brown46b9ac02010-04-22 18:58:52 -07001295 return 0;
1296}
1297
Jeff Brown46b9ac02010-04-22 18:58:52 -07001298} /* namespace android */