blob: f9763016cebab4b5cd466d30e7fbf5a0dcd161bb [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>
Jeff Brown5541de92011-04-11 11:54:25 -070039#include <input/SpriteController.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040
Jeff Brown05dc66a2011-03-02 14:41:58 -080041#include <android_os_MessageQueue.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080042#include <android_view_KeyEvent.h>
43#include <android_view_MotionEvent.h>
44#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070045#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080046#include <android/graphics/GraphicsJNI.h>
47
Jeff Brown00fa7bd2010-07-02 15:37:36 -070048#include "com_android_server_PowerManagerService.h"
Jeff Brown928e0542011-01-10 11:17:36 -080049#include "com_android_server_InputApplicationHandle.h"
Jeff Brown928e0542011-01-10 11:17:36 -080050#include "com_android_server_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070051
52namespace android {
53
Jeff Brown1a84fd12011-06-02 01:26:32 -070054// The exponent used to calculate the pointer speed scaling factor.
55// The scaling factor is calculated as 2 ^ (speed * exponent),
56// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070057static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070058
Jeff Brown46b9ac02010-04-22 18:58:52 -070059static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070060 jmethodID notifyConfigurationChanged;
61 jmethodID notifyLidSwitchChanged;
Jeff Brown7fbdc842010-06-17 20:52:56 -070062 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070063 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070064 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070065 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080066 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070067 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070068 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070069 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080070 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070071 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080072 jmethodID getKeyRepeatTimeout;
73 jmethodID getKeyRepeatDelay;
Jeff Brownae9fc032010-08-18 15:51:08 -070074 jmethodID getMaxEventsPerSecond;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070075 jmethodID getHoverTapTimeout;
76 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070077 jmethodID getDoubleTapTimeout;
78 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080079 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080080 jmethodID getPointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070081} gCallbacksClassInfo;
82
83static struct {
84 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070085} gKeyEventClassInfo;
86
87static struct {
88 jclass clazz;
89} gMotionEventClassInfo;
90
Jeff Brown8d608662010-08-30 03:02:23 -070091static struct {
92 jclass clazz;
93
94 jmethodID ctor;
95 jmethodID addMotionRange;
96
97 jfieldID mId;
98 jfieldID mName;
99 jfieldID mSources;
100 jfieldID mKeyboardType;
Jeff Brown8d608662010-08-30 03:02:23 -0700101} gInputDeviceClassInfo;
102
Jeff Brown57c59372010-09-21 18:22:55 -0700103static struct {
Jeff Brown57c59372010-09-21 18:22:55 -0700104 jfieldID touchscreen;
105 jfieldID keyboard;
106 jfieldID navigation;
107} gConfigurationClassInfo;
108
Jeff Brown928e0542011-01-10 11:17:36 -0800109
110// --- Global functions ---
111
Jeff Brown214eaf42011-05-26 19:17:02 -0700112template<typename T>
113inline static T min(const T& a, const T& b) {
114 return a < b ? a : b;
115}
116
117template<typename T>
118inline static T max(const T& a, const T& b) {
119 return a > b ? a : b;
120}
121
Jeff Brown928e0542011-01-10 11:17:36 -0800122static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
123 const sp<InputApplicationHandle>& inputApplicationHandle) {
124 if (inputApplicationHandle == NULL) {
125 return NULL;
126 }
127 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
128 getInputApplicationHandleObjLocalRef(env);
129}
130
131static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
132 const sp<InputWindowHandle>& inputWindowHandle) {
133 if (inputWindowHandle == NULL) {
134 return NULL;
135 }
136 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
137 getInputWindowHandleObjLocalRef(env);
138}
139
Jeff Brown2352b972011-04-12 22:39:53 -0700140static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
141 SpriteIcon* outSpriteIcon) {
142 PointerIcon pointerIcon;
143 status_t status = android_view_PointerIcon_loadSystemIcon(env,
144 contextObj, style, &pointerIcon);
145 if (!status) {
146 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
147 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
148 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
149 }
150}
151
Jeff Brown928e0542011-01-10 11:17:36 -0800152
153// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800154
Jeff Brown9c3cda02010-06-15 01:31:58 -0700155class NativeInputManager : public virtual RefBase,
156 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700157 public virtual InputDispatcherPolicyInterface,
158 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700159protected:
160 virtual ~NativeInputManager();
161
162public:
Jeff Brown2352b972011-04-12 22:39:53 -0700163 NativeInputManager(jobject contextObj, jobject callbacksObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700164
165 inline sp<InputManager> getInputManager() const { return mInputManager; }
166
Jeff Brownb88102f2010-09-08 11:49:43 -0700167 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700168
Jeff Brownbc68a592011-07-25 12:58:12 -0700169 void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
170 int32_t externalWidth, int32_t externalHeight);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700171 void setDisplayOrientation(int32_t displayId, int32_t orientation);
172
Jeff Brown7fbdc842010-06-17 20:52:56 -0700173 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800174 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700175 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
176
Jeff Brown9302c872011-07-13 22:51:29 -0700177 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
178 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700179 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800180 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700181 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700182 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700183
Jeff Brown9c3cda02010-06-15 01:31:58 -0700184 /* --- InputReaderPolicyInterface implementation --- */
185
Jeff Brown214eaf42011-05-26 19:17:02 -0700186 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800187 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700188
189 /* --- InputDispatcherPolicyInterface implementation --- */
190
Jeff Browne20c9e02010-10-11 14:20:19 -0700191 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
192 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700193 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700194 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800195 const sp<InputWindowHandle>& inputWindowHandle);
196 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700197 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700198 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
199 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800200 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800201 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800202 virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700203 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800204 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800205 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700206 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700207 virtual bool checkInjectEventsPermissionNonReentrant(
208 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700209
Jeff Brown2352b972011-04-12 22:39:53 -0700210 /* --- PointerControllerPolicyInterface implementation --- */
211
212 virtual void loadPointerResources(PointerResources* outResources);
213
Jeff Brown9c3cda02010-06-15 01:31:58 -0700214private:
215 sp<InputManager> mInputManager;
216
Jeff Brown2352b972011-04-12 22:39:53 -0700217 jobject mContextObj;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700218 jobject mCallbacksObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800219 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700220
Jeff Brown83c09682010-12-23 17:50:18 -0800221 Mutex mLock;
222 struct Locked {
223 // Display size information.
Jeff Brownbc68a592011-07-25 12:58:12 -0700224 int32_t displayWidth, displayHeight; // -1 when not initialized
225 int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
Jeff Brown83c09682010-12-23 17:50:18 -0800226 int32_t displayOrientation;
227
Jeff Brown05dc66a2011-03-02 14:41:58 -0800228 // System UI visibility.
229 int32_t systemUiVisibility;
230
Jeff Brown1a84fd12011-06-02 01:26:32 -0700231 // Pointer speed.
232 int32_t pointerSpeed;
233
Jeff Brown474dcb52011-06-14 20:22:50 -0700234 // True if pointer gestures are enabled.
235 bool pointerGesturesEnabled;
236
Jeff Browndaf4a122011-08-26 17:14:14 -0700237 // Show touches feature enable/disable.
238 bool showTouches;
239
Jeff Brown5541de92011-04-11 11:54:25 -0700240 // Sprite controller singleton, created on first use.
241 sp<SpriteController> spriteController;
242
Jeff Brown83c09682010-12-23 17:50:18 -0800243 // Pointer controller singleton, created and destroyed as needed.
244 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800245 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700246
Jeff Brown2352b972011-04-12 22:39:53 -0700247 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800248 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700249 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800250
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700251 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700252 bool isScreenOn();
253 bool isScreenBright();
254
Jeff Brownb88102f2010-09-08 11:49:43 -0700255 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700256
Jeff Brown9c3cda02010-06-15 01:31:58 -0700257 static inline JNIEnv* jniEnv() {
258 return AndroidRuntime::getJNIEnv();
259 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700260};
261
Jeff Brown928e0542011-01-10 11:17:36 -0800262
Jeff Brown9c3cda02010-06-15 01:31:58 -0700263
Jeff Brown2352b972011-04-12 22:39:53 -0700264NativeInputManager::NativeInputManager(jobject contextObj,
265 jobject callbacksObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700266 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700267 JNIEnv* env = jniEnv();
268
Jeff Brown2352b972011-04-12 22:39:53 -0700269 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270 mCallbacksObj = env->NewGlobalRef(callbacksObj);
271
Jeff Brown83c09682010-12-23 17:50:18 -0800272 {
273 AutoMutex _l(mLock);
274 mLocked.displayWidth = -1;
275 mLocked.displayHeight = -1;
Jeff Brownbc68a592011-07-25 12:58:12 -0700276 mLocked.displayExternalWidth = -1;
277 mLocked.displayExternalHeight = -1;
Jeff Brown65fd2512011-08-18 11:20:58 -0700278 mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800279
280 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700281 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700282 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700283 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800284 }
285
Jeff Brown9c3cda02010-06-15 01:31:58 -0700286 sp<EventHub> eventHub = new EventHub();
287 mInputManager = new InputManager(eventHub, this, this);
288}
289
290NativeInputManager::~NativeInputManager() {
291 JNIEnv* env = jniEnv();
292
Jeff Brown2352b972011-04-12 22:39:53 -0700293 env->DeleteGlobalRef(mContextObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700294 env->DeleteGlobalRef(mCallbacksObj);
295}
296
Jeff Brownb88102f2010-09-08 11:49:43 -0700297void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700298 mInputManager->getReader()->dump(dump);
299 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700300
Jeff Brownb88102f2010-09-08 11:49:43 -0700301 mInputManager->getDispatcher()->dump(dump);
302 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700303}
304
Jeff Brown7fbdc842010-06-17 20:52:56 -0700305bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700306 if (env->ExceptionCheck()) {
307 LOGE("An exception was thrown by callback '%s'.", methodName);
308 LOGE_EX(env);
309 env->ExceptionClear();
310 return true;
311 }
312 return false;
313}
314
Jeff Brownbc68a592011-07-25 12:58:12 -0700315void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
316 int32_t externalWidth, int32_t externalHeight) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700317 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700318 if (displayId == 0) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700319 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700320
Jeff Brown65fd2512011-08-18 11:20:58 -0700321 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
322 changed = true;
323 mLocked.displayWidth = width;
324 mLocked.displayHeight = height;
Jeff Brownbc68a592011-07-25 12:58:12 -0700325
Jeff Brown65fd2512011-08-18 11:20:58 -0700326 sp<PointerController> controller = mLocked.pointerController.promote();
327 if (controller != NULL) {
328 controller->setDisplaySize(width, height);
Jeff Brown2352b972011-04-12 22:39:53 -0700329 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700330 }
Jeff Brown2352b972011-04-12 22:39:53 -0700331
Jeff Brown65fd2512011-08-18 11:20:58 -0700332 if (mLocked.displayExternalWidth != externalWidth
333 || mLocked.displayExternalHeight != externalHeight) {
334 changed = true;
Jeff Brownbc68a592011-07-25 12:58:12 -0700335 mLocked.displayExternalWidth = externalWidth;
336 mLocked.displayExternalHeight = externalHeight;
Jeff Brown65fd2512011-08-18 11:20:58 -0700337 }
338 }
339
340 if (changed) {
341 mInputManager->getReader()->requestRefreshConfiguration(
342 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700343 }
344}
345
346void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700347 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700348 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800349 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700350
Jeff Brown83c09682010-12-23 17:50:18 -0800351 if (mLocked.displayOrientation != orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700352 changed = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800353 mLocked.displayOrientation = orientation;
354
355 sp<PointerController> controller = mLocked.pointerController.promote();
356 if (controller != NULL) {
357 controller->setDisplayOrientation(orientation);
358 }
359 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700360 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700361
362 if (changed) {
363 mInputManager->getReader()->requestRefreshConfiguration(
364 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
365 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700366}
367
Jeff Brown7fbdc842010-06-17 20:52:56 -0700368status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800369 const sp<InputChannel>& inputChannel,
370 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
371 return mInputManager->getDispatcher()->registerInputChannel(
372 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700373}
374
375status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
376 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700377 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700378}
379
Jeff Brown214eaf42011-05-26 19:17:02 -0700380void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700381 JNIEnv* env = jniEnv();
382
Jeff Brown214eaf42011-05-26 19:17:02 -0700383 jint virtualKeyQuietTime = env->CallIntMethod(mCallbacksObj,
384 gCallbacksClassInfo.getVirtualKeyQuietTimeMillis);
385 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
386 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
387 }
388
389 outConfig->excludedDeviceNames.clear();
390 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mCallbacksObj,
Jeff Brown9c3cda02010-06-15 01:31:58 -0700391 gCallbacksClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700392 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
393 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700394 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700395 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700396 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700397 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700398 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700399 env->DeleteLocalRef(item);
400 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700401 env->DeleteLocalRef(excludedDeviceNames);
402 }
403
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700404 jint hoverTapTimeout = env->CallIntMethod(mCallbacksObj,
405 gCallbacksClassInfo.getHoverTapTimeout);
406 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700407 jint doubleTapTimeout = env->CallIntMethod(mCallbacksObj,
408 gCallbacksClassInfo.getDoubleTapTimeout);
409 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
410 jint longPressTimeout = env->CallIntMethod(mCallbacksObj,
411 gCallbacksClassInfo.getLongPressTimeout);
412 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700413 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700414
415 // We must ensure that the tap-drag interval is significantly shorter than
416 // the long-press timeout because the tap is held down for the entire duration
417 // of the double-tap timeout.
418 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700419 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700420 outConfig->pointerGestureTapDragInterval =
421 milliseconds_to_nanoseconds(tapDragInterval);
422 }
423 }
424 }
425
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700426 jint hoverTapSlop = env->CallIntMethod(mCallbacksObj,
427 gCallbacksClassInfo.getHoverTapSlop);
428 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
429 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700430 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700431
432 { // acquire lock
433 AutoMutex _l(mLock);
434
435 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
436 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700437 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700438
Jeff Browndaf4a122011-08-26 17:14:14 -0700439 outConfig->showTouches = mLocked.showTouches;
440
Jeff Brown65fd2512011-08-18 11:20:58 -0700441 outConfig->setDisplayInfo(0, false /*external*/,
442 mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
443 outConfig->setDisplayInfo(0, true /*external*/,
444 mLocked.displayExternalWidth, mLocked.displayExternalHeight,
445 mLocked.displayOrientation);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700446 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700447}
448
Jeff Brown83c09682010-12-23 17:50:18 -0800449sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
450 AutoMutex _l(mLock);
451
452 sp<PointerController> controller = mLocked.pointerController.promote();
453 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700454 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800455
Jeff Brown2352b972011-04-12 22:39:53 -0700456 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800457 mLocked.pointerController = controller;
458
459 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
460 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800461
Jeff Brown5541de92011-04-11 11:54:25 -0700462 JNIEnv* env = jniEnv();
Jeff Brown2352b972011-04-12 22:39:53 -0700463 jobject pointerIconObj = env->CallObjectMethod(mCallbacksObj,
464 gCallbacksClassInfo.getPointerIcon);
465 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
466 PointerIcon pointerIcon;
467 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
468 mContextObj, &pointerIcon);
469 if (!status && !pointerIcon.isNullIcon()) {
470 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
471 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
472 } else {
473 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800474 }
Jeff Brown2352b972011-04-12 22:39:53 -0700475 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800476 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800477
Jeff Brown2352b972011-04-12 22:39:53 -0700478 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800479 }
480 return controller;
481}
482
Jeff Brown5541de92011-04-11 11:54:25 -0700483void NativeInputManager::ensureSpriteControllerLocked() {
484 if (mLocked.spriteController == NULL) {
485 JNIEnv* env = jniEnv();
486 jint layer = env->CallIntMethod(mCallbacksObj, gCallbacksClassInfo.getPointerLayer);
487 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
488 layer = -1;
489 }
490 mLocked.spriteController = new SpriteController(mLooper, layer);
491 }
492}
493
Jeff Browne20c9e02010-10-11 14:20:19 -0700494void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
495 int32_t switchValue, uint32_t policyFlags) {
496#if DEBUG_INPUT_DISPATCHER_POLICY
497 LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
498 when, switchCode, switchValue, policyFlags);
499#endif
500
501 JNIEnv* env = jniEnv();
502
503 switch (switchCode) {
504 case SW_LID:
505 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged,
506 when, switchValue == 0);
507 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
508 break;
509 }
510}
511
Jeff Brown9c3cda02010-06-15 01:31:58 -0700512void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
513#if DEBUG_INPUT_DISPATCHER_POLICY
514 LOGD("notifyConfigurationChanged - when=%lld", when);
515#endif
516
517 JNIEnv* env = jniEnv();
518
Jeff Brown57c59372010-09-21 18:22:55 -0700519 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700520 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700521}
522
Jeff Brown519e0242010-09-15 15:18:56 -0700523nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800524 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700525#if DEBUG_INPUT_DISPATCHER_POLICY
526 LOGD("notifyANR");
527#endif
528
529 JNIEnv* env = jniEnv();
530
Jeff Brown928e0542011-01-10 11:17:36 -0800531 jobject inputApplicationHandleObj =
532 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
533 jobject inputWindowHandleObj =
534 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700535
Jeff Brown519e0242010-09-15 15:18:56 -0700536 jlong newTimeout = env->CallLongMethod(mCallbacksObj,
Jeff Brown928e0542011-01-10 11:17:36 -0800537 gCallbacksClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700538 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
539 newTimeout = 0; // abort dispatch
540 } else {
541 assert(newTimeout >= 0);
542 }
543
Jeff Brown928e0542011-01-10 11:17:36 -0800544 env->DeleteLocalRef(inputWindowHandleObj);
545 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700546 return newTimeout;
547}
548
Jeff Brown928e0542011-01-10 11:17:36 -0800549void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700550#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown928e0542011-01-10 11:17:36 -0800551 LOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700552#endif
553
Jeff Brown7fbdc842010-06-17 20:52:56 -0700554 JNIEnv* env = jniEnv();
555
Jeff Brown928e0542011-01-10 11:17:36 -0800556 jobject inputWindowHandleObj =
557 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
558 if (inputWindowHandleObj) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700559 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800560 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700561 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
562
Jeff Brown928e0542011-01-10 11:17:36 -0800563 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700564 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700565}
566
Jeff Brown214eaf42011-05-26 19:17:02 -0700567void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
568 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800569
Jeff Brown214eaf42011-05-26 19:17:02 -0700570 jint keyRepeatTimeout = env->CallIntMethod(mCallbacksObj,
571 gCallbacksClassInfo.getKeyRepeatTimeout);
572 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
573 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
574 }
Jeff Browna4547672011-03-02 21:38:11 -0800575
Jeff Brown214eaf42011-05-26 19:17:02 -0700576 jint keyRepeatDelay = env->CallIntMethod(mCallbacksObj,
577 gCallbacksClassInfo.getKeyRepeatDelay);
578 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
579 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
580 }
581
582 jint maxEventsPerSecond = env->CallIntMethod(mCallbacksObj,
583 gCallbacksClassInfo.getMaxEventsPerSecond);
584 if (!checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
585 outConfig->maxEventsPerSecond = maxEventsPerSecond;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700586 }
587}
588
Jeff Brown214eaf42011-05-26 19:17:02 -0700589bool NativeInputManager::isKeyRepeatEnabled() {
590 // Only enable automatic key repeating when the screen is on.
591 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700592}
593
Jeff Brown9302c872011-07-13 22:51:29 -0700594void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
595 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700596
Jeff Brown9302c872011-07-13 22:51:29 -0700597 if (windowHandleObjArray) {
598 jsize length = env->GetArrayLength(windowHandleObjArray);
599 for (jsize i = 0; i < length; i++) {
600 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
601 if (! windowHandleObj) {
602 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700603 }
Jeff Brown9302c872011-07-13 22:51:29 -0700604
605 sp<InputWindowHandle> windowHandle =
606 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
607 if (windowHandle != NULL) {
608 windowHandles.push(windowHandle);
609 }
610 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700611 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700612 }
Jeff Brown349703e2010-06-22 01:27:15 -0700613
Jeff Brown9302c872011-07-13 22:51:29 -0700614 mInputManager->getDispatcher()->setInputWindows(windowHandles);
615
616 // Do this after the dispatcher has updated the window handle state.
617 bool newPointerGesturesEnabled = true;
618 size_t numWindows = windowHandles.size();
619 for (size_t i = 0; i < numWindows; i++) {
620 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700621 const InputWindowInfo* windowInfo = windowHandle->getInfo();
622 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
623 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700624 newPointerGesturesEnabled = false;
625 }
626 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700627
628 uint32_t changes = 0;
629 { // acquire lock
630 AutoMutex _l(mLock);
631
632 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
633 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
634 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
635 }
636 } // release lock
637
638 if (changes) {
639 mInputManager->getReader()->requestRefreshConfiguration(changes);
640 }
Jeff Brown349703e2010-06-22 01:27:15 -0700641}
642
Jeff Brown9302c872011-07-13 22:51:29 -0700643void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
644 sp<InputApplicationHandle> applicationHandle =
645 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
646 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700647}
648
649void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700650 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700651}
652
Jeff Brown05dc66a2011-03-02 14:41:58 -0800653void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
654 AutoMutex _l(mLock);
655
656 if (mLocked.systemUiVisibility != visibility) {
657 mLocked.systemUiVisibility = visibility;
658
659 sp<PointerController> controller = mLocked.pointerController.promote();
660 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700661 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800662 }
663 }
664}
665
Jeff Brown2352b972011-04-12 22:39:53 -0700666void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800667 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700668 controller->setInactivityTimeout(lightsOut
669 ? PointerController::INACTIVITY_TIMEOUT_SHORT
670 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800671}
672
Jeff Brown1a84fd12011-06-02 01:26:32 -0700673void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700674 { // acquire lock
675 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700676
Jeff Brown474dcb52011-06-14 20:22:50 -0700677 if (mLocked.pointerSpeed == speed) {
678 return;
679 }
680
Jeff Brown1a84fd12011-06-02 01:26:32 -0700681 LOGI("Setting pointer speed to %d.", speed);
682 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700683 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700684
Jeff Brown474dcb52011-06-14 20:22:50 -0700685 mInputManager->getReader()->requestRefreshConfiguration(
686 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700687}
688
Jeff Browndaf4a122011-08-26 17:14:14 -0700689void NativeInputManager::setShowTouches(bool enabled) {
690 { // acquire lock
691 AutoMutex _l(mLock);
692
693 if (mLocked.showTouches == enabled) {
694 return;
695 }
696
697 LOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
698 mLocked.showTouches = enabled;
699 } // release lock
700
701 mInputManager->getReader()->requestRefreshConfiguration(
702 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
703}
704
Jeff Browne20c9e02010-10-11 14:20:19 -0700705bool NativeInputManager::isScreenOn() {
706 return android_server_PowerManagerService_isScreenOn();
707}
708
709bool NativeInputManager::isScreenBright() {
710 return android_server_PowerManagerService_isScreenBright();
711}
712
Jeff Brown0029c662011-03-30 02:25:18 -0700713bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
714 jobject inputEventObj;
715
716 JNIEnv* env = jniEnv();
717 switch (inputEvent->getType()) {
718 case AINPUT_EVENT_TYPE_KEY:
719 inputEventObj = android_view_KeyEvent_fromNative(env,
720 static_cast<const KeyEvent*>(inputEvent));
721 break;
722 case AINPUT_EVENT_TYPE_MOTION:
723 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
724 static_cast<const MotionEvent*>(inputEvent));
725 break;
726 default:
727 return true; // dispatch the event normally
728 }
729
730 if (!inputEventObj) {
731 LOGE("Failed to obtain input event object for filterInputEvent.");
732 return true; // dispatch the event normally
733 }
734
735 // The callee is responsible for recycling the event.
736 jboolean pass = env->CallBooleanMethod(mCallbacksObj, gCallbacksClassInfo.filterInputEvent,
737 inputEventObj, policyFlags);
738 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
739 pass = true;
740 }
741 env->DeleteLocalRef(inputEventObj);
742 return pass;
743}
744
Jeff Brown1f245102010-11-18 20:53:46 -0800745void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
746 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700747 // Policy:
748 // - Ignore untrusted events and pass them along.
749 // - Ask the window manager what to do with normal events and trusted injected events.
750 // - For normal events wake and brighten the screen if currently off or dim.
751 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800752 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700753 bool isScreenOn = this->isScreenOn();
754 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700755
Jeff Brown3122e442010-10-11 23:32:49 -0700756 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800757 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
758 jint wmActions;
759 if (keyEventObj) {
760 wmActions = env->CallIntMethod(mCallbacksObj,
761 gCallbacksClassInfo.interceptKeyBeforeQueueing,
762 keyEventObj, policyFlags, isScreenOn);
763 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
764 wmActions = 0;
765 }
766 android_view_KeyEvent_recycle(env, keyEventObj);
767 env->DeleteLocalRef(keyEventObj);
768 } else {
769 LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700770 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700771 }
772
Jeff Brown1f245102010-11-18 20:53:46 -0800773 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700774 if (!isScreenOn) {
775 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700776 }
777
778 if (!isScreenBright) {
779 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
780 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700781 }
782
Jeff Brown56194eb2011-03-02 19:23:13 -0800783 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700784 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700785 policyFlags |= POLICY_FLAG_PASS_TO_USER;
786 }
787}
788
Jeff Brown56194eb2011-03-02 19:23:13 -0800789void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700790 // Policy:
791 // - Ignore untrusted events and pass them along.
792 // - No special filtering for injected events required at this time.
793 // - Filter normal events based on screen state.
794 // - For normal events brighten (but do not wake) the screen if currently dim.
795 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
796 if (isScreenOn()) {
797 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700798
Jeff Brown3122e442010-10-11 23:32:49 -0700799 if (!isScreenBright()) {
800 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
801 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800802 } else {
803 JNIEnv* env = jniEnv();
804 jint wmActions = env->CallIntMethod(mCallbacksObj,
805 gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
806 policyFlags);
807 if (checkAndClearExceptionFromCallback(env,
808 "interceptMotionBeforeQueueingWhenScreenOff")) {
809 wmActions = 0;
810 }
811
812 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
813 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700814 }
Jeff Brown3122e442010-10-11 23:32:49 -0700815 } else {
816 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700817 }
818}
819
Jeff Brown56194eb2011-03-02 19:23:13 -0800820void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
821 uint32_t& policyFlags) {
822 enum {
823 WM_ACTION_PASS_TO_USER = 1,
824 WM_ACTION_POKE_USER_ACTIVITY = 2,
825 WM_ACTION_GO_TO_SLEEP = 4,
826 };
827
828 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800829#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800830 LOGD("handleInterceptActions: Going to sleep.");
831#endif
832 android_server_PowerManagerService_goToSleep(when);
833 }
834
835 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800836#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800837 LOGD("handleInterceptActions: Poking user activity.");
838#endif
839 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
840 }
841
842 if (wmActions & WM_ACTION_PASS_TO_USER) {
843 policyFlags |= POLICY_FLAG_PASS_TO_USER;
844 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800845#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800846 LOGD("handleInterceptActions: Not passing key to user.");
847#endif
848 }
849}
850
Jeff Brown928e0542011-01-10 11:17:36 -0800851bool NativeInputManager::interceptKeyBeforeDispatching(
852 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700853 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700854 // Policy:
855 // - Ignore untrusted events and pass them along.
856 // - Filter normal events and trusted injected events through the window manager policy to
857 // handle the HOME key and the like.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800858 bool result = false;
Jeff Brown3122e442010-10-11 23:32:49 -0700859 if (policyFlags & POLICY_FLAG_TRUSTED) {
860 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700861
Jeff Brown928e0542011-01-10 11:17:36 -0800862 // Note: inputWindowHandle may be null.
863 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800864 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
865 if (keyEventObj) {
866 jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
867 gCallbacksClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800868 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800869 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
870 android_view_KeyEvent_recycle(env, keyEventObj);
871 env->DeleteLocalRef(keyEventObj);
872 result = consumed && !error;
873 } else {
874 LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800875 }
Jeff Brown928e0542011-01-10 11:17:36 -0800876 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700877 }
Jeff Brown1f245102010-11-18 20:53:46 -0800878 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700879}
880
Jeff Brown928e0542011-01-10 11:17:36 -0800881bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800882 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700883 // Policy:
884 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800885 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700886 if (policyFlags & POLICY_FLAG_TRUSTED) {
887 JNIEnv* env = jniEnv();
888
Jeff Brown928e0542011-01-10 11:17:36 -0800889 // Note: inputWindowHandle may be null.
890 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800891 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
892 if (keyEventObj) {
Jeff Brown49ed71d2010-12-06 17:13:33 -0800893 jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800894 gCallbacksClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800895 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700896 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
897 fallbackKeyEventObj = NULL;
898 }
Jeff Brown1f245102010-11-18 20:53:46 -0800899 android_view_KeyEvent_recycle(env, keyEventObj);
900 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800901
902 if (fallbackKeyEventObj) {
903 // Note: outFallbackKeyEvent may be the same object as keyEvent.
904 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
905 outFallbackKeyEvent)) {
906 result = true;
907 }
908 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
909 env->DeleteLocalRef(fallbackKeyEventObj);
910 }
Jeff Brown1f245102010-11-18 20:53:46 -0800911 } else {
912 LOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800913 }
Jeff Brown928e0542011-01-10 11:17:36 -0800914 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700915 }
Jeff Brown1f245102010-11-18 20:53:46 -0800916 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700917}
918
Jeff Brown01ce2e92010-09-26 22:20:12 -0700919void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
920 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700921}
922
Jeff Brown349703e2010-06-22 01:27:15 -0700923
Jeff Brownb88102f2010-09-08 11:49:43 -0700924bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
925 int32_t injectorPid, int32_t injectorUid) {
926 JNIEnv* env = jniEnv();
927 jboolean result = env->CallBooleanMethod(mCallbacksObj,
928 gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700929 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
930 result = false;
931 }
Jeff Brown349703e2010-06-22 01:27:15 -0700932 return result;
933}
934
Jeff Brown2352b972011-04-12 22:39:53 -0700935void NativeInputManager::loadPointerResources(PointerResources* outResources) {
936 JNIEnv* env = jniEnv();
937
938 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
939 &outResources->spotHover);
940 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
941 &outResources->spotTouch);
942 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
943 &outResources->spotAnchor);
944}
945
Jeff Brown83c09682010-12-23 17:50:18 -0800946
Jeff Brown9c3cda02010-06-15 01:31:58 -0700947// ----------------------------------------------------------------------------
948
949static sp<NativeInputManager> gNativeInputManager;
950
Jeff Brown46b9ac02010-04-22 18:58:52 -0700951static bool checkInputManagerUnitialized(JNIEnv* env) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700952 if (gNativeInputManager == NULL) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700953 LOGE("Input manager not initialized.");
954 jniThrowRuntimeException(env, "Input manager not initialized.");
955 return true;
956 }
957 return false;
958}
959
960static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
Jeff Brown2352b972011-04-12 22:39:53 -0700961 jobject contextObj, jobject callbacksObj, jobject messageQueueObj) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700962 if (gNativeInputManager == NULL) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800963 sp<Looper> looper = android_os_MessageQueue_getLooper(env, messageQueueObj);
Jeff Brown2352b972011-04-12 22:39:53 -0700964 gNativeInputManager = new NativeInputManager(contextObj, callbacksObj, looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700965 } else {
966 LOGE("Input manager already initialized.");
967 jniThrowRuntimeException(env, "Input manager already initialized.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700968 }
969}
970
971static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
972 if (checkInputManagerUnitialized(env)) {
973 return;
974 }
975
Jeff Brown9c3cda02010-06-15 01:31:58 -0700976 status_t result = gNativeInputManager->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700977 if (result) {
978 jniThrowRuntimeException(env, "Input manager could not be started.");
979 }
980}
981
982static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Jeff Brownbc68a592011-07-25 12:58:12 -0700983 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700984 if (checkInputManagerUnitialized(env)) {
985 return;
986 }
987
988 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
989 // to be passed in like this, not sure which is better but leaving it like this
990 // keeps the window manager in direct control of when display transitions propagate down
991 // to the input dispatcher
Jeff Brownbc68a592011-07-25 12:58:12 -0700992 gNativeInputManager->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700993}
994
995static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
996 jint displayId, jint orientation) {
997 if (checkInputManagerUnitialized(env)) {
998 return;
999 }
1000
Jeff Brown9c3cda02010-06-15 01:31:58 -07001001 gNativeInputManager->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001002}
1003
1004static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001005 jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001006 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001007 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001008 }
1009
Jeff Brownb88102f2010-09-08 11:49:43 -07001010 return gNativeInputManager->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001011 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001012}
1013
1014static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001015 jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001016 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001017 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001018 }
1019
Jeff Brownb88102f2010-09-08 11:49:43 -07001020 return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001021 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001022}
1023
1024static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001025 jint deviceId, jint sourceMask, jint sw) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001026 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001027 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001028 }
1029
Jeff Brownb88102f2010-09-08 11:49:43 -07001030 return gNativeInputManager->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001031 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001032}
1033
1034static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001035 jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001036 if (checkInputManagerUnitialized(env)) {
1037 return JNI_FALSE;
1038 }
1039
1040 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1041 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1042 jsize numCodes = env->GetArrayLength(keyCodes);
1043 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001044 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brownb88102f2010-09-08 11:49:43 -07001045 result = gNativeInputManager->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001046 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001047 } else {
1048 result = JNI_FALSE;
1049 }
1050
1051 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1052 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1053 return result;
1054}
1055
1056static void throwInputChannelNotInitialized(JNIEnv* env) {
1057 jniThrowException(env, "java/lang/IllegalStateException",
1058 "inputChannel is not initialized");
1059}
1060
1061static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env,
1062 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
1063 LOGW("Input channel object '%s' was disposed without first being unregistered with "
1064 "the input manager!", inputChannel->getName().string());
1065
Jeff Brown9c3cda02010-06-15 01:31:58 -07001066 if (gNativeInputManager != NULL) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07001067 gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown9c3cda02010-06-15 01:31:58 -07001068 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001069}
1070
1071static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001072 jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001073 if (checkInputManagerUnitialized(env)) {
1074 return;
1075 }
1076
1077 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1078 inputChannelObj);
1079 if (inputChannel == NULL) {
1080 throwInputChannelNotInitialized(env);
1081 return;
1082 }
1083
Jeff Brown928e0542011-01-10 11:17:36 -08001084 sp<InputWindowHandle> inputWindowHandle =
1085 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001086
1087 status_t status = gNativeInputManager->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001088 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001089 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001090 String8 message;
1091 message.appendFormat("Failed to register input channel. status=%d", status);
1092 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001093 return;
1094 }
1095
Jeff Browna41ca772010-08-11 14:46:32 -07001096 if (! monitor) {
1097 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
1098 android_server_InputManager_handleInputChannelDisposed, NULL);
1099 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001100}
1101
1102static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1103 jobject inputChannelObj) {
1104 if (checkInputManagerUnitialized(env)) {
1105 return;
1106 }
1107
1108 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1109 inputChannelObj);
1110 if (inputChannel == NULL) {
1111 throwInputChannelNotInitialized(env);
1112 return;
1113 }
1114
1115 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1116
Jeff Brown7fbdc842010-06-17 20:52:56 -07001117 status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001118 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1119 String8 message;
1120 message.appendFormat("Failed to unregister input channel. status=%d", status);
1121 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001122 }
1123}
1124
Jeff Brown0029c662011-03-30 02:25:18 -07001125static void android_server_InputManager_nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1126 jboolean enabled) {
1127 if (checkInputManagerUnitialized(env)) {
1128 return;
1129 }
1130
1131 gNativeInputManager->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
1132}
1133
Jeff Brown6ec402b2010-07-28 15:48:59 -07001134static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1135 jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001136 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07001137 if (checkInputManagerUnitialized(env)) {
1138 return INPUT_EVENT_INJECTION_FAILED;
1139 }
1140
Jeff Brown6ec402b2010-07-28 15:48:59 -07001141 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1142 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001143 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1144 if (status) {
1145 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1146 return INPUT_EVENT_INJECTION_FAILED;
1147 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001148
Jeff Brownb88102f2010-09-08 11:49:43 -07001149 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001150 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1151 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001152 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001153 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1154 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001155 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1156 return INPUT_EVENT_INJECTION_FAILED;
1157 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001158
Jeff Brownb88102f2010-09-08 11:49:43 -07001159 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001160 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1161 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001162 } else {
1163 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001164 return INPUT_EVENT_INJECTION_FAILED;
1165 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001166}
1167
Jeff Brown349703e2010-06-22 01:27:15 -07001168static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz,
Jeff Brown9302c872011-07-13 22:51:29 -07001169 jobjectArray windowHandleObjArray) {
Jeff Brown349703e2010-06-22 01:27:15 -07001170 if (checkInputManagerUnitialized(env)) {
1171 return;
1172 }
1173
Jeff Brown9302c872011-07-13 22:51:29 -07001174 gNativeInputManager->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001175}
1176
1177static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
Jeff Brown9302c872011-07-13 22:51:29 -07001178 jobject applicationHandleObj) {
Jeff Brown349703e2010-06-22 01:27:15 -07001179 if (checkInputManagerUnitialized(env)) {
1180 return;
1181 }
1182
Jeff Brown9302c872011-07-13 22:51:29 -07001183 gNativeInputManager->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001184}
1185
1186static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env,
1187 jclass clazz, jboolean enabled, jboolean frozen) {
1188 if (checkInputManagerUnitialized(env)) {
1189 return;
1190 }
1191
1192 gNativeInputManager->setInputDispatchMode(enabled, frozen);
1193}
1194
Jeff Brown05dc66a2011-03-02 14:41:58 -08001195static void android_server_InputManager_nativeSetSystemUiVisibility(JNIEnv* env,
1196 jclass clazz, jint visibility) {
1197 if (checkInputManagerUnitialized(env)) {
1198 return;
1199 }
1200
1201 gNativeInputManager->setSystemUiVisibility(visibility);
1202}
1203
Jeff Brown8d608662010-08-30 03:02:23 -07001204static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env,
1205 jclass clazz, jint deviceId) {
1206 if (checkInputManagerUnitialized(env)) {
1207 return NULL;
1208 }
1209
1210 InputDeviceInfo deviceInfo;
Jeff Brownb88102f2010-09-08 11:49:43 -07001211 status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -07001212 deviceId, & deviceInfo);
1213 if (status) {
1214 return NULL;
1215 }
1216
1217 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
1218 if (! deviceObj) {
1219 return NULL;
1220 }
1221
1222 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
1223 if (! deviceNameObj) {
1224 return NULL;
1225 }
1226
1227 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
1228 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
1229 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
1230 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
1231
Jeff Brownefd32662011-03-08 15:13:06 -08001232 const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
Jeff Brown8d608662010-08-30 03:02:23 -07001233 for (size_t i = 0; i < ranges.size(); i++) {
Jeff Brownefd32662011-03-08 15:13:06 -08001234 const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
Jeff Brown8d608662010-08-30 03:02:23 -07001235 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
Jeff Brownefd32662011-03-08 15:13:06 -08001236 range.axis, range.source, range.min, range.max, range.flat, range.fuzz);
Jeff Brown8d608662010-08-30 03:02:23 -07001237 if (env->ExceptionCheck()) {
1238 return NULL;
1239 }
1240 }
1241
1242 return deviceObj;
1243}
1244
1245static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env,
1246 jclass clazz) {
1247 if (checkInputManagerUnitialized(env)) {
1248 return NULL;
1249 }
1250
1251 Vector<int> deviceIds;
Jeff Brownb88102f2010-09-08 11:49:43 -07001252 gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001253
1254 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1255 if (! deviceIdsObj) {
1256 return NULL;
1257 }
1258
1259 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1260 return deviceIdsObj;
1261}
1262
Jeff Brown57c59372010-09-21 18:22:55 -07001263static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env,
1264 jclass clazz, jobject configObj) {
1265 if (checkInputManagerUnitialized(env)) {
1266 return;
1267 }
1268
1269 InputConfiguration config;
1270 gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config);
1271
1272 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1273 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1274 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1275}
1276
Jeff Browne6504122010-09-27 14:52:15 -07001277static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env,
1278 jclass clazz, jobject fromChannelObj, jobject toChannelObj) {
1279 if (checkInputManagerUnitialized(env)) {
1280 return false;
1281 }
1282
1283 sp<InputChannel> fromChannel =
1284 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1285 sp<InputChannel> toChannel =
1286 android_view_InputChannel_getInputChannel(env, toChannelObj);
1287
1288 if (fromChannel == NULL || toChannel == NULL) {
1289 return false;
1290 }
1291
1292 return gNativeInputManager->getInputManager()->getDispatcher()->
1293 transferTouchFocus(fromChannel, toChannel);
1294}
1295
Jeff Brown1a84fd12011-06-02 01:26:32 -07001296static void android_server_InputManager_nativeSetPointerSpeed(JNIEnv* env,
1297 jclass clazz, jint speed) {
1298 if (checkInputManagerUnitialized(env)) {
1299 return;
1300 }
1301
1302 gNativeInputManager->setPointerSpeed(speed);
1303}
1304
Jeff Browndaf4a122011-08-26 17:14:14 -07001305static void android_server_InputManager_nativeSetShowTouches(JNIEnv* env,
1306 jclass clazz, jboolean enabled) {
1307 if (checkInputManagerUnitialized(env)) {
1308 return;
1309 }
1310
1311 gNativeInputManager->setShowTouches(enabled);
1312}
1313
Jeff Browne33348b2010-07-15 23:54:05 -07001314static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
1315 if (checkInputManagerUnitialized(env)) {
1316 return NULL;
1317 }
1318
Jeff Brownb88102f2010-09-08 11:49:43 -07001319 String8 dump;
1320 gNativeInputManager->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001321 return env->NewStringUTF(dump.string());
1322}
1323
Jeff Brown89ef0722011-08-10 16:25:21 -07001324static void android_server_InputManager_nativeMonitor(JNIEnv* env, jclass clazz) {
1325 if (checkInputManagerUnitialized(env)) {
1326 return;
1327 }
1328
1329 gNativeInputManager->getInputManager()->getReader()->monitor();
1330 gNativeInputManager->getInputManager()->getDispatcher()->monitor();
1331}
1332
Jeff Brown9c3cda02010-06-15 01:31:58 -07001333// ----------------------------------------------------------------------------
1334
Jeff Brown46b9ac02010-04-22 18:58:52 -07001335static JNINativeMethod gInputManagerMethods[] = {
1336 /* name, signature, funcPtr */
Jeff Brown2352b972011-04-12 22:39:53 -07001337 { "nativeInit", "(Landroid/content/Context;"
1338 "Lcom/android/server/wm/InputManager$Callbacks;Landroid/os/MessageQueue;)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001339 (void*) android_server_InputManager_nativeInit },
1340 { "nativeStart", "()V",
1341 (void*) android_server_InputManager_nativeStart },
Jeff Brownbc68a592011-07-25 12:58:12 -07001342 { "nativeSetDisplaySize", "(IIIII)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001343 (void*) android_server_InputManager_nativeSetDisplaySize },
1344 { "nativeSetDisplayOrientation", "(II)V",
1345 (void*) android_server_InputManager_nativeSetDisplayOrientation },
1346 { "nativeGetScanCodeState", "(III)I",
1347 (void*) android_server_InputManager_nativeGetScanCodeState },
1348 { "nativeGetKeyCodeState", "(III)I",
1349 (void*) android_server_InputManager_nativeGetKeyCodeState },
1350 { "nativeGetSwitchState", "(III)I",
1351 (void*) android_server_InputManager_nativeGetSwitchState },
Jeff Brown6d0fec22010-07-23 21:28:06 -07001352 { "nativeHasKeys", "(II[I[Z)Z",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001353 (void*) android_server_InputManager_nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001354 { "nativeRegisterInputChannel",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001355 "(Landroid/view/InputChannel;Lcom/android/server/wm/InputWindowHandle;Z)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001356 (void*) android_server_InputManager_nativeRegisterInputChannel },
1357 { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V",
Jeff Brown7fbdc842010-06-17 20:52:56 -07001358 (void*) android_server_InputManager_nativeUnregisterInputChannel },
Jeff Brown0029c662011-03-30 02:25:18 -07001359 { "nativeSetInputFilterEnabled", "(Z)V",
1360 (void*) android_server_InputManager_nativeSetInputFilterEnabled },
1361 { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIIII)I",
Jeff Brown6ec402b2010-07-28 15:48:59 -07001362 (void*) android_server_InputManager_nativeInjectInputEvent },
Jeff Brown9302c872011-07-13 22:51:29 -07001363 { "nativeSetInputWindows", "([Lcom/android/server/wm/InputWindowHandle;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001364 (void*) android_server_InputManager_nativeSetInputWindows },
Jeff Brown9302c872011-07-13 22:51:29 -07001365 { "nativeSetFocusedApplication", "(Lcom/android/server/wm/InputApplicationHandle;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001366 (void*) android_server_InputManager_nativeSetFocusedApplication },
1367 { "nativeSetInputDispatchMode", "(ZZ)V",
1368 (void*) android_server_InputManager_nativeSetInputDispatchMode },
Jeff Brown05dc66a2011-03-02 14:41:58 -08001369 { "nativeSetSystemUiVisibility", "(I)V",
1370 (void*) android_server_InputManager_nativeSetSystemUiVisibility },
Jeff Brown8d608662010-08-30 03:02:23 -07001371 { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;",
1372 (void*) android_server_InputManager_nativeGetInputDevice },
1373 { "nativeGetInputDeviceIds", "()[I",
1374 (void*) android_server_InputManager_nativeGetInputDeviceIds },
Jeff Brown57c59372010-09-21 18:22:55 -07001375 { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V",
1376 (void*) android_server_InputManager_nativeGetInputConfiguration },
Jeff Browne6504122010-09-27 14:52:15 -07001377 { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1378 (void*) android_server_InputManager_nativeTransferTouchFocus },
Jeff Brown1a84fd12011-06-02 01:26:32 -07001379 { "nativeSetPointerSpeed", "(I)V",
1380 (void*) android_server_InputManager_nativeSetPointerSpeed },
Jeff Browndaf4a122011-08-26 17:14:14 -07001381 { "nativeSetShowTouches", "(Z)V",
1382 (void*) android_server_InputManager_nativeSetShowTouches },
Jeff Browne33348b2010-07-15 23:54:05 -07001383 { "nativeDump", "()Ljava/lang/String;",
1384 (void*) android_server_InputManager_nativeDump },
Jeff Brown89ef0722011-08-10 16:25:21 -07001385 { "nativeMonitor", "()V",
1386 (void*) android_server_InputManager_nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001387};
1388
1389#define FIND_CLASS(var, className) \
1390 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001391 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001392
1393#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1394 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1395 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1396
1397#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1398 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1399 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1400
1401int register_android_server_InputManager(JNIEnv* env) {
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001402 int res = jniRegisterNativeMethods(env, "com/android/server/wm/InputManager",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001403 gInputManagerMethods, NELEM(gInputManagerMethods));
1404 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1405
Jeff Brown9c3cda02010-06-15 01:31:58 -07001406 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001407
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001408 jclass clazz;
1409 FIND_CLASS(clazz, "com/android/server/wm/InputManager$Callbacks");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001410
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001411 GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001412 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001413
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001414 GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001415 "notifyLidSwitchChanged", "(JZ)V");
1416
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001417 GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001418 "notifyInputChannelBroken", "(Lcom/android/server/wm/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001419
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001420 GET_METHOD_ID(gCallbacksClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001421 "notifyANR",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001422 "(Lcom/android/server/wm/InputApplicationHandle;Lcom/android/server/wm/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001423
Jeff Brown0029c662011-03-30 02:25:18 -07001424 GET_METHOD_ID(gCallbacksClassInfo.filterInputEvent, clazz,
1425 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1426
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001427 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001428 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001429
Jeff Brown56194eb2011-03-02 19:23:13 -08001430 GET_METHOD_ID(gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001431 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001432 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1433
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001434 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001435 "interceptKeyBeforeDispatching",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001436 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Z");
Jeff Brown349703e2010-06-22 01:27:15 -07001437
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001438 GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001439 "dispatchUnhandledKey",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001440 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001441
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001442 GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001443 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001444
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001445 GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001446 "getVirtualKeyQuietTimeMillis", "()I");
1447
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001448 GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001449 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1450
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001451 GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001452 "getKeyRepeatTimeout", "()I");
1453
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001454 GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001455 "getKeyRepeatDelay", "()I");
1456
Jeff Brown774ed9d2011-06-07 17:48:39 -07001457 GET_METHOD_ID(gCallbacksClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001458 "getHoverTapTimeout", "()I");
1459
Jeff Brown774ed9d2011-06-07 17:48:39 -07001460 GET_METHOD_ID(gCallbacksClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001461 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001462
Dianne Hackbornf3b57de2011-06-03 12:13:24 -07001463 GET_METHOD_ID(gCallbacksClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001464 "getDoubleTapTimeout", "()I");
1465
Dianne Hackbornf3b57de2011-06-03 12:13:24 -07001466 GET_METHOD_ID(gCallbacksClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001467 "getLongPressTimeout", "()I");
1468
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001469 GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, clazz,
Jeff Brownae9fc032010-08-18 15:51:08 -07001470 "getMaxEventsPerSecond", "()I");
1471
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001472 GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001473 "getPointerLayer", "()I");
1474
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001475 GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001476 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001477
Jeff Brown6ec402b2010-07-28 15:48:59 -07001478 // KeyEvent
1479
1480 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001481 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1482
Jeff Brown6ec402b2010-07-28 15:48:59 -07001483
Jeff Brown8d608662010-08-30 03:02:23 -07001484 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001485
1486 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001487 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001488
Jeff Brown8d608662010-08-30 03:02:23 -07001489 // InputDevice
1490
1491 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001492 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
Jeff Brown8d608662010-08-30 03:02:23 -07001493
1494 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1495 "<init>", "()V");
1496
1497 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
Jeff Brownefd32662011-03-08 15:13:06 -08001498 "addMotionRange", "(IIFFFF)V");
Jeff Brown8d608662010-08-30 03:02:23 -07001499
1500 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1501 "mId", "I");
1502
1503 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1504 "mName", "Ljava/lang/String;");
1505
1506 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1507 "mSources", "I");
1508
1509 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1510 "mKeyboardType", "I");
1511
Jeff Brown57c59372010-09-21 18:22:55 -07001512 // Configuration
1513
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001514 FIND_CLASS(clazz, "android/content/res/Configuration");
Jeff Brown57c59372010-09-21 18:22:55 -07001515
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001516 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001517 "touchscreen", "I");
1518
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001519 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001520 "keyboard", "I");
1521
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001522 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001523 "navigation", "I");
1524
Jeff Brown46b9ac02010-04-22 18:58:52 -07001525 return 0;
1526}
1527
Jeff Brown46b9ac02010-04-22 18:58:52 -07001528} /* namespace android */