blob: 0a723e84bf588a134c06e05c610dc0850a1f8611 [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);
621 if (windowHandle->hasFocus && (windowHandle->inputFeatures
622 & InputWindowHandle::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
623 newPointerGesturesEnabled = false;
624 }
625 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700626
627 uint32_t changes = 0;
628 { // acquire lock
629 AutoMutex _l(mLock);
630
631 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
632 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
633 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
634 }
635 } // release lock
636
637 if (changes) {
638 mInputManager->getReader()->requestRefreshConfiguration(changes);
639 }
Jeff Brown349703e2010-06-22 01:27:15 -0700640}
641
Jeff Brown9302c872011-07-13 22:51:29 -0700642void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
643 sp<InputApplicationHandle> applicationHandle =
644 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
645 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700646}
647
648void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700649 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700650}
651
Jeff Brown05dc66a2011-03-02 14:41:58 -0800652void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
653 AutoMutex _l(mLock);
654
655 if (mLocked.systemUiVisibility != visibility) {
656 mLocked.systemUiVisibility = visibility;
657
658 sp<PointerController> controller = mLocked.pointerController.promote();
659 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700660 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800661 }
662 }
663}
664
Jeff Brown2352b972011-04-12 22:39:53 -0700665void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800666 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700667 controller->setInactivityTimeout(lightsOut
668 ? PointerController::INACTIVITY_TIMEOUT_SHORT
669 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800670}
671
Jeff Brown1a84fd12011-06-02 01:26:32 -0700672void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700673 { // acquire lock
674 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700675
Jeff Brown474dcb52011-06-14 20:22:50 -0700676 if (mLocked.pointerSpeed == speed) {
677 return;
678 }
679
Jeff Brown1a84fd12011-06-02 01:26:32 -0700680 LOGI("Setting pointer speed to %d.", speed);
681 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700682 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700683
Jeff Brown474dcb52011-06-14 20:22:50 -0700684 mInputManager->getReader()->requestRefreshConfiguration(
685 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700686}
687
Jeff Browndaf4a122011-08-26 17:14:14 -0700688void NativeInputManager::setShowTouches(bool enabled) {
689 { // acquire lock
690 AutoMutex _l(mLock);
691
692 if (mLocked.showTouches == enabled) {
693 return;
694 }
695
696 LOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
697 mLocked.showTouches = enabled;
698 } // release lock
699
700 mInputManager->getReader()->requestRefreshConfiguration(
701 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
702}
703
Jeff Browne20c9e02010-10-11 14:20:19 -0700704bool NativeInputManager::isScreenOn() {
705 return android_server_PowerManagerService_isScreenOn();
706}
707
708bool NativeInputManager::isScreenBright() {
709 return android_server_PowerManagerService_isScreenBright();
710}
711
Jeff Brown0029c662011-03-30 02:25:18 -0700712bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
713 jobject inputEventObj;
714
715 JNIEnv* env = jniEnv();
716 switch (inputEvent->getType()) {
717 case AINPUT_EVENT_TYPE_KEY:
718 inputEventObj = android_view_KeyEvent_fromNative(env,
719 static_cast<const KeyEvent*>(inputEvent));
720 break;
721 case AINPUT_EVENT_TYPE_MOTION:
722 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
723 static_cast<const MotionEvent*>(inputEvent));
724 break;
725 default:
726 return true; // dispatch the event normally
727 }
728
729 if (!inputEventObj) {
730 LOGE("Failed to obtain input event object for filterInputEvent.");
731 return true; // dispatch the event normally
732 }
733
734 // The callee is responsible for recycling the event.
735 jboolean pass = env->CallBooleanMethod(mCallbacksObj, gCallbacksClassInfo.filterInputEvent,
736 inputEventObj, policyFlags);
737 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
738 pass = true;
739 }
740 env->DeleteLocalRef(inputEventObj);
741 return pass;
742}
743
Jeff Brown1f245102010-11-18 20:53:46 -0800744void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
745 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700746 // Policy:
747 // - Ignore untrusted events and pass them along.
748 // - Ask the window manager what to do with normal events and trusted injected events.
749 // - For normal events wake and brighten the screen if currently off or dim.
750 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800751 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700752 bool isScreenOn = this->isScreenOn();
753 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700754
Jeff Brown3122e442010-10-11 23:32:49 -0700755 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800756 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
757 jint wmActions;
758 if (keyEventObj) {
759 wmActions = env->CallIntMethod(mCallbacksObj,
760 gCallbacksClassInfo.interceptKeyBeforeQueueing,
761 keyEventObj, policyFlags, isScreenOn);
762 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
763 wmActions = 0;
764 }
765 android_view_KeyEvent_recycle(env, keyEventObj);
766 env->DeleteLocalRef(keyEventObj);
767 } else {
768 LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700769 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700770 }
771
Jeff Brown1f245102010-11-18 20:53:46 -0800772 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700773 if (!isScreenOn) {
774 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700775 }
776
777 if (!isScreenBright) {
778 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
779 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700780 }
781
Jeff Brown56194eb2011-03-02 19:23:13 -0800782 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700783 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700784 policyFlags |= POLICY_FLAG_PASS_TO_USER;
785 }
786}
787
Jeff Brown56194eb2011-03-02 19:23:13 -0800788void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700789 // Policy:
790 // - Ignore untrusted events and pass them along.
791 // - No special filtering for injected events required at this time.
792 // - Filter normal events based on screen state.
793 // - For normal events brighten (but do not wake) the screen if currently dim.
794 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
795 if (isScreenOn()) {
796 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700797
Jeff Brown3122e442010-10-11 23:32:49 -0700798 if (!isScreenBright()) {
799 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
800 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800801 } else {
802 JNIEnv* env = jniEnv();
803 jint wmActions = env->CallIntMethod(mCallbacksObj,
804 gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
805 policyFlags);
806 if (checkAndClearExceptionFromCallback(env,
807 "interceptMotionBeforeQueueingWhenScreenOff")) {
808 wmActions = 0;
809 }
810
811 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
812 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700813 }
Jeff Brown3122e442010-10-11 23:32:49 -0700814 } else {
815 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700816 }
817}
818
Jeff Brown56194eb2011-03-02 19:23:13 -0800819void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
820 uint32_t& policyFlags) {
821 enum {
822 WM_ACTION_PASS_TO_USER = 1,
823 WM_ACTION_POKE_USER_ACTIVITY = 2,
824 WM_ACTION_GO_TO_SLEEP = 4,
825 };
826
827 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800828#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800829 LOGD("handleInterceptActions: Going to sleep.");
830#endif
831 android_server_PowerManagerService_goToSleep(when);
832 }
833
834 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800835#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800836 LOGD("handleInterceptActions: Poking user activity.");
837#endif
838 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
839 }
840
841 if (wmActions & WM_ACTION_PASS_TO_USER) {
842 policyFlags |= POLICY_FLAG_PASS_TO_USER;
843 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800844#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800845 LOGD("handleInterceptActions: Not passing key to user.");
846#endif
847 }
848}
849
Jeff Brown928e0542011-01-10 11:17:36 -0800850bool NativeInputManager::interceptKeyBeforeDispatching(
851 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700852 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700853 // Policy:
854 // - Ignore untrusted events and pass them along.
855 // - Filter normal events and trusted injected events through the window manager policy to
856 // handle the HOME key and the like.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800857 bool result = false;
Jeff Brown3122e442010-10-11 23:32:49 -0700858 if (policyFlags & POLICY_FLAG_TRUSTED) {
859 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700860
Jeff Brown928e0542011-01-10 11:17:36 -0800861 // Note: inputWindowHandle may be null.
862 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800863 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
864 if (keyEventObj) {
865 jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
866 gCallbacksClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800867 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800868 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
869 android_view_KeyEvent_recycle(env, keyEventObj);
870 env->DeleteLocalRef(keyEventObj);
871 result = consumed && !error;
872 } else {
873 LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800874 }
Jeff Brown928e0542011-01-10 11:17:36 -0800875 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700876 }
Jeff Brown1f245102010-11-18 20:53:46 -0800877 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700878}
879
Jeff Brown928e0542011-01-10 11:17:36 -0800880bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800881 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700882 // Policy:
883 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800884 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700885 if (policyFlags & POLICY_FLAG_TRUSTED) {
886 JNIEnv* env = jniEnv();
887
Jeff Brown928e0542011-01-10 11:17:36 -0800888 // Note: inputWindowHandle may be null.
889 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800890 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
891 if (keyEventObj) {
Jeff Brown49ed71d2010-12-06 17:13:33 -0800892 jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800893 gCallbacksClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800894 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700895 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
896 fallbackKeyEventObj = NULL;
897 }
Jeff Brown1f245102010-11-18 20:53:46 -0800898 android_view_KeyEvent_recycle(env, keyEventObj);
899 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800900
901 if (fallbackKeyEventObj) {
902 // Note: outFallbackKeyEvent may be the same object as keyEvent.
903 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
904 outFallbackKeyEvent)) {
905 result = true;
906 }
907 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
908 env->DeleteLocalRef(fallbackKeyEventObj);
909 }
Jeff Brown1f245102010-11-18 20:53:46 -0800910 } else {
911 LOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800912 }
Jeff Brown928e0542011-01-10 11:17:36 -0800913 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700914 }
Jeff Brown1f245102010-11-18 20:53:46 -0800915 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700916}
917
Jeff Brown01ce2e92010-09-26 22:20:12 -0700918void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
919 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700920}
921
Jeff Brown349703e2010-06-22 01:27:15 -0700922
Jeff Brownb88102f2010-09-08 11:49:43 -0700923bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
924 int32_t injectorPid, int32_t injectorUid) {
925 JNIEnv* env = jniEnv();
926 jboolean result = env->CallBooleanMethod(mCallbacksObj,
927 gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700928 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
929 result = false;
930 }
Jeff Brown349703e2010-06-22 01:27:15 -0700931 return result;
932}
933
Jeff Brown2352b972011-04-12 22:39:53 -0700934void NativeInputManager::loadPointerResources(PointerResources* outResources) {
935 JNIEnv* env = jniEnv();
936
937 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
938 &outResources->spotHover);
939 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
940 &outResources->spotTouch);
941 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
942 &outResources->spotAnchor);
943}
944
Jeff Brown83c09682010-12-23 17:50:18 -0800945
Jeff Brown9c3cda02010-06-15 01:31:58 -0700946// ----------------------------------------------------------------------------
947
948static sp<NativeInputManager> gNativeInputManager;
949
Jeff Brown46b9ac02010-04-22 18:58:52 -0700950static bool checkInputManagerUnitialized(JNIEnv* env) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700951 if (gNativeInputManager == NULL) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700952 LOGE("Input manager not initialized.");
953 jniThrowRuntimeException(env, "Input manager not initialized.");
954 return true;
955 }
956 return false;
957}
958
959static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
Jeff Brown2352b972011-04-12 22:39:53 -0700960 jobject contextObj, jobject callbacksObj, jobject messageQueueObj) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700961 if (gNativeInputManager == NULL) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800962 sp<Looper> looper = android_os_MessageQueue_getLooper(env, messageQueueObj);
Jeff Brown2352b972011-04-12 22:39:53 -0700963 gNativeInputManager = new NativeInputManager(contextObj, callbacksObj, looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700964 } else {
965 LOGE("Input manager already initialized.");
966 jniThrowRuntimeException(env, "Input manager already initialized.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700967 }
968}
969
970static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
971 if (checkInputManagerUnitialized(env)) {
972 return;
973 }
974
Jeff Brown9c3cda02010-06-15 01:31:58 -0700975 status_t result = gNativeInputManager->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700976 if (result) {
977 jniThrowRuntimeException(env, "Input manager could not be started.");
978 }
979}
980
981static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Jeff Brownbc68a592011-07-25 12:58:12 -0700982 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700983 if (checkInputManagerUnitialized(env)) {
984 return;
985 }
986
987 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
988 // to be passed in like this, not sure which is better but leaving it like this
989 // keeps the window manager in direct control of when display transitions propagate down
990 // to the input dispatcher
Jeff Brownbc68a592011-07-25 12:58:12 -0700991 gNativeInputManager->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700992}
993
994static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
995 jint displayId, jint orientation) {
996 if (checkInputManagerUnitialized(env)) {
997 return;
998 }
999
Jeff Brown9c3cda02010-06-15 01:31:58 -07001000 gNativeInputManager->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001001}
1002
1003static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001004 jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001005 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001006 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001007 }
1008
Jeff Brownb88102f2010-09-08 11:49:43 -07001009 return gNativeInputManager->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001010 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001011}
1012
1013static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001014 jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001015 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001016 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001017 }
1018
Jeff Brownb88102f2010-09-08 11:49:43 -07001019 return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001020 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001021}
1022
1023static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001024 jint deviceId, jint sourceMask, jint sw) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001025 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001026 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001027 }
1028
Jeff Brownb88102f2010-09-08 11:49:43 -07001029 return gNativeInputManager->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001030 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001031}
1032
1033static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001034 jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001035 if (checkInputManagerUnitialized(env)) {
1036 return JNI_FALSE;
1037 }
1038
1039 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1040 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1041 jsize numCodes = env->GetArrayLength(keyCodes);
1042 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001043 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brownb88102f2010-09-08 11:49:43 -07001044 result = gNativeInputManager->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001045 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001046 } else {
1047 result = JNI_FALSE;
1048 }
1049
1050 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1051 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1052 return result;
1053}
1054
1055static void throwInputChannelNotInitialized(JNIEnv* env) {
1056 jniThrowException(env, "java/lang/IllegalStateException",
1057 "inputChannel is not initialized");
1058}
1059
1060static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env,
1061 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
1062 LOGW("Input channel object '%s' was disposed without first being unregistered with "
1063 "the input manager!", inputChannel->getName().string());
1064
Jeff Brown9c3cda02010-06-15 01:31:58 -07001065 if (gNativeInputManager != NULL) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07001066 gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown9c3cda02010-06-15 01:31:58 -07001067 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001068}
1069
1070static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001071 jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001072 if (checkInputManagerUnitialized(env)) {
1073 return;
1074 }
1075
1076 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1077 inputChannelObj);
1078 if (inputChannel == NULL) {
1079 throwInputChannelNotInitialized(env);
1080 return;
1081 }
1082
Jeff Brown928e0542011-01-10 11:17:36 -08001083 sp<InputWindowHandle> inputWindowHandle =
1084 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001085
1086 status_t status = gNativeInputManager->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001087 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001088 if (status) {
1089 jniThrowRuntimeException(env, "Failed to register input channel. "
1090 "Check logs for details.");
1091 return;
1092 }
1093
Jeff Browna41ca772010-08-11 14:46:32 -07001094 if (! monitor) {
1095 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
1096 android_server_InputManager_handleInputChannelDisposed, NULL);
1097 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001098}
1099
1100static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1101 jobject inputChannelObj) {
1102 if (checkInputManagerUnitialized(env)) {
1103 return;
1104 }
1105
1106 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1107 inputChannelObj);
1108 if (inputChannel == NULL) {
1109 throwInputChannelNotInitialized(env);
1110 return;
1111 }
1112
1113 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1114
Jeff Brown7fbdc842010-06-17 20:52:56 -07001115 status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001116 if (status) {
1117 jniThrowRuntimeException(env, "Failed to unregister input channel. "
1118 "Check logs for details.");
1119 }
1120}
1121
Jeff Brown0029c662011-03-30 02:25:18 -07001122static void android_server_InputManager_nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1123 jboolean enabled) {
1124 if (checkInputManagerUnitialized(env)) {
1125 return;
1126 }
1127
1128 gNativeInputManager->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
1129}
1130
Jeff Brown6ec402b2010-07-28 15:48:59 -07001131static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1132 jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001133 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07001134 if (checkInputManagerUnitialized(env)) {
1135 return INPUT_EVENT_INJECTION_FAILED;
1136 }
1137
Jeff Brown6ec402b2010-07-28 15:48:59 -07001138 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1139 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001140 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1141 if (status) {
1142 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1143 return INPUT_EVENT_INJECTION_FAILED;
1144 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001145
Jeff Brownb88102f2010-09-08 11:49:43 -07001146 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001147 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1148 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001149 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001150 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1151 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001152 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1153 return INPUT_EVENT_INJECTION_FAILED;
1154 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001155
Jeff Brownb88102f2010-09-08 11:49:43 -07001156 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001157 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1158 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001159 } else {
1160 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001161 return INPUT_EVENT_INJECTION_FAILED;
1162 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001163}
1164
Jeff Brown349703e2010-06-22 01:27:15 -07001165static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz,
Jeff Brown9302c872011-07-13 22:51:29 -07001166 jobjectArray windowHandleObjArray) {
Jeff Brown349703e2010-06-22 01:27:15 -07001167 if (checkInputManagerUnitialized(env)) {
1168 return;
1169 }
1170
Jeff Brown9302c872011-07-13 22:51:29 -07001171 gNativeInputManager->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001172}
1173
1174static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
Jeff Brown9302c872011-07-13 22:51:29 -07001175 jobject applicationHandleObj) {
Jeff Brown349703e2010-06-22 01:27:15 -07001176 if (checkInputManagerUnitialized(env)) {
1177 return;
1178 }
1179
Jeff Brown9302c872011-07-13 22:51:29 -07001180 gNativeInputManager->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001181}
1182
1183static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env,
1184 jclass clazz, jboolean enabled, jboolean frozen) {
1185 if (checkInputManagerUnitialized(env)) {
1186 return;
1187 }
1188
1189 gNativeInputManager->setInputDispatchMode(enabled, frozen);
1190}
1191
Jeff Brown05dc66a2011-03-02 14:41:58 -08001192static void android_server_InputManager_nativeSetSystemUiVisibility(JNIEnv* env,
1193 jclass clazz, jint visibility) {
1194 if (checkInputManagerUnitialized(env)) {
1195 return;
1196 }
1197
1198 gNativeInputManager->setSystemUiVisibility(visibility);
1199}
1200
Jeff Brown8d608662010-08-30 03:02:23 -07001201static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env,
1202 jclass clazz, jint deviceId) {
1203 if (checkInputManagerUnitialized(env)) {
1204 return NULL;
1205 }
1206
1207 InputDeviceInfo deviceInfo;
Jeff Brownb88102f2010-09-08 11:49:43 -07001208 status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -07001209 deviceId, & deviceInfo);
1210 if (status) {
1211 return NULL;
1212 }
1213
1214 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
1215 if (! deviceObj) {
1216 return NULL;
1217 }
1218
1219 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
1220 if (! deviceNameObj) {
1221 return NULL;
1222 }
1223
1224 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
1225 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
1226 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
1227 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
1228
Jeff Brownefd32662011-03-08 15:13:06 -08001229 const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
Jeff Brown8d608662010-08-30 03:02:23 -07001230 for (size_t i = 0; i < ranges.size(); i++) {
Jeff Brownefd32662011-03-08 15:13:06 -08001231 const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
Jeff Brown8d608662010-08-30 03:02:23 -07001232 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
Jeff Brownefd32662011-03-08 15:13:06 -08001233 range.axis, range.source, range.min, range.max, range.flat, range.fuzz);
Jeff Brown8d608662010-08-30 03:02:23 -07001234 if (env->ExceptionCheck()) {
1235 return NULL;
1236 }
1237 }
1238
1239 return deviceObj;
1240}
1241
1242static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env,
1243 jclass clazz) {
1244 if (checkInputManagerUnitialized(env)) {
1245 return NULL;
1246 }
1247
1248 Vector<int> deviceIds;
Jeff Brownb88102f2010-09-08 11:49:43 -07001249 gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001250
1251 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1252 if (! deviceIdsObj) {
1253 return NULL;
1254 }
1255
1256 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1257 return deviceIdsObj;
1258}
1259
Jeff Brown57c59372010-09-21 18:22:55 -07001260static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env,
1261 jclass clazz, jobject configObj) {
1262 if (checkInputManagerUnitialized(env)) {
1263 return;
1264 }
1265
1266 InputConfiguration config;
1267 gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config);
1268
1269 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1270 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1271 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1272}
1273
Jeff Browne6504122010-09-27 14:52:15 -07001274static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env,
1275 jclass clazz, jobject fromChannelObj, jobject toChannelObj) {
1276 if (checkInputManagerUnitialized(env)) {
1277 return false;
1278 }
1279
1280 sp<InputChannel> fromChannel =
1281 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1282 sp<InputChannel> toChannel =
1283 android_view_InputChannel_getInputChannel(env, toChannelObj);
1284
1285 if (fromChannel == NULL || toChannel == NULL) {
1286 return false;
1287 }
1288
1289 return gNativeInputManager->getInputManager()->getDispatcher()->
1290 transferTouchFocus(fromChannel, toChannel);
1291}
1292
Jeff Brown1a84fd12011-06-02 01:26:32 -07001293static void android_server_InputManager_nativeSetPointerSpeed(JNIEnv* env,
1294 jclass clazz, jint speed) {
1295 if (checkInputManagerUnitialized(env)) {
1296 return;
1297 }
1298
1299 gNativeInputManager->setPointerSpeed(speed);
1300}
1301
Jeff Browndaf4a122011-08-26 17:14:14 -07001302static void android_server_InputManager_nativeSetShowTouches(JNIEnv* env,
1303 jclass clazz, jboolean enabled) {
1304 if (checkInputManagerUnitialized(env)) {
1305 return;
1306 }
1307
1308 gNativeInputManager->setShowTouches(enabled);
1309}
1310
Jeff Browne33348b2010-07-15 23:54:05 -07001311static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
1312 if (checkInputManagerUnitialized(env)) {
1313 return NULL;
1314 }
1315
Jeff Brownb88102f2010-09-08 11:49:43 -07001316 String8 dump;
1317 gNativeInputManager->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001318 return env->NewStringUTF(dump.string());
1319}
1320
Jeff Brown89ef0722011-08-10 16:25:21 -07001321static void android_server_InputManager_nativeMonitor(JNIEnv* env, jclass clazz) {
1322 if (checkInputManagerUnitialized(env)) {
1323 return;
1324 }
1325
1326 gNativeInputManager->getInputManager()->getReader()->monitor();
1327 gNativeInputManager->getInputManager()->getDispatcher()->monitor();
1328}
1329
Jeff Brown9c3cda02010-06-15 01:31:58 -07001330// ----------------------------------------------------------------------------
1331
Jeff Brown46b9ac02010-04-22 18:58:52 -07001332static JNINativeMethod gInputManagerMethods[] = {
1333 /* name, signature, funcPtr */
Jeff Brown2352b972011-04-12 22:39:53 -07001334 { "nativeInit", "(Landroid/content/Context;"
1335 "Lcom/android/server/wm/InputManager$Callbacks;Landroid/os/MessageQueue;)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001336 (void*) android_server_InputManager_nativeInit },
1337 { "nativeStart", "()V",
1338 (void*) android_server_InputManager_nativeStart },
Jeff Brownbc68a592011-07-25 12:58:12 -07001339 { "nativeSetDisplaySize", "(IIIII)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001340 (void*) android_server_InputManager_nativeSetDisplaySize },
1341 { "nativeSetDisplayOrientation", "(II)V",
1342 (void*) android_server_InputManager_nativeSetDisplayOrientation },
1343 { "nativeGetScanCodeState", "(III)I",
1344 (void*) android_server_InputManager_nativeGetScanCodeState },
1345 { "nativeGetKeyCodeState", "(III)I",
1346 (void*) android_server_InputManager_nativeGetKeyCodeState },
1347 { "nativeGetSwitchState", "(III)I",
1348 (void*) android_server_InputManager_nativeGetSwitchState },
Jeff Brown6d0fec22010-07-23 21:28:06 -07001349 { "nativeHasKeys", "(II[I[Z)Z",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001350 (void*) android_server_InputManager_nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001351 { "nativeRegisterInputChannel",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001352 "(Landroid/view/InputChannel;Lcom/android/server/wm/InputWindowHandle;Z)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001353 (void*) android_server_InputManager_nativeRegisterInputChannel },
1354 { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V",
Jeff Brown7fbdc842010-06-17 20:52:56 -07001355 (void*) android_server_InputManager_nativeUnregisterInputChannel },
Jeff Brown0029c662011-03-30 02:25:18 -07001356 { "nativeSetInputFilterEnabled", "(Z)V",
1357 (void*) android_server_InputManager_nativeSetInputFilterEnabled },
1358 { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIIII)I",
Jeff Brown6ec402b2010-07-28 15:48:59 -07001359 (void*) android_server_InputManager_nativeInjectInputEvent },
Jeff Brown9302c872011-07-13 22:51:29 -07001360 { "nativeSetInputWindows", "([Lcom/android/server/wm/InputWindowHandle;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001361 (void*) android_server_InputManager_nativeSetInputWindows },
Jeff Brown9302c872011-07-13 22:51:29 -07001362 { "nativeSetFocusedApplication", "(Lcom/android/server/wm/InputApplicationHandle;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001363 (void*) android_server_InputManager_nativeSetFocusedApplication },
1364 { "nativeSetInputDispatchMode", "(ZZ)V",
1365 (void*) android_server_InputManager_nativeSetInputDispatchMode },
Jeff Brown05dc66a2011-03-02 14:41:58 -08001366 { "nativeSetSystemUiVisibility", "(I)V",
1367 (void*) android_server_InputManager_nativeSetSystemUiVisibility },
Jeff Brown8d608662010-08-30 03:02:23 -07001368 { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;",
1369 (void*) android_server_InputManager_nativeGetInputDevice },
1370 { "nativeGetInputDeviceIds", "()[I",
1371 (void*) android_server_InputManager_nativeGetInputDeviceIds },
Jeff Brown57c59372010-09-21 18:22:55 -07001372 { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V",
1373 (void*) android_server_InputManager_nativeGetInputConfiguration },
Jeff Browne6504122010-09-27 14:52:15 -07001374 { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1375 (void*) android_server_InputManager_nativeTransferTouchFocus },
Jeff Brown1a84fd12011-06-02 01:26:32 -07001376 { "nativeSetPointerSpeed", "(I)V",
1377 (void*) android_server_InputManager_nativeSetPointerSpeed },
Jeff Browndaf4a122011-08-26 17:14:14 -07001378 { "nativeSetShowTouches", "(Z)V",
1379 (void*) android_server_InputManager_nativeSetShowTouches },
Jeff Browne33348b2010-07-15 23:54:05 -07001380 { "nativeDump", "()Ljava/lang/String;",
1381 (void*) android_server_InputManager_nativeDump },
Jeff Brown89ef0722011-08-10 16:25:21 -07001382 { "nativeMonitor", "()V",
1383 (void*) android_server_InputManager_nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001384};
1385
1386#define FIND_CLASS(var, className) \
1387 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001388 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001389
1390#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1391 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1392 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1393
1394#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1395 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1396 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1397
1398int register_android_server_InputManager(JNIEnv* env) {
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001399 int res = jniRegisterNativeMethods(env, "com/android/server/wm/InputManager",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001400 gInputManagerMethods, NELEM(gInputManagerMethods));
1401 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1402
Jeff Brown9c3cda02010-06-15 01:31:58 -07001403 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001404
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001405 jclass clazz;
1406 FIND_CLASS(clazz, "com/android/server/wm/InputManager$Callbacks");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001407
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001408 GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001409 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001410
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001411 GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001412 "notifyLidSwitchChanged", "(JZ)V");
1413
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001414 GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001415 "notifyInputChannelBroken", "(Lcom/android/server/wm/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001416
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001417 GET_METHOD_ID(gCallbacksClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001418 "notifyANR",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001419 "(Lcom/android/server/wm/InputApplicationHandle;Lcom/android/server/wm/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001420
Jeff Brown0029c662011-03-30 02:25:18 -07001421 GET_METHOD_ID(gCallbacksClassInfo.filterInputEvent, clazz,
1422 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1423
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001424 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001425 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001426
Jeff Brown56194eb2011-03-02 19:23:13 -08001427 GET_METHOD_ID(gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001428 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001429 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1430
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001431 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001432 "interceptKeyBeforeDispatching",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001433 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Z");
Jeff Brown349703e2010-06-22 01:27:15 -07001434
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001435 GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001436 "dispatchUnhandledKey",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001437 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001438
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001439 GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001440 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001441
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001442 GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001443 "getVirtualKeyQuietTimeMillis", "()I");
1444
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001445 GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001446 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1447
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001448 GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001449 "getKeyRepeatTimeout", "()I");
1450
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001451 GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001452 "getKeyRepeatDelay", "()I");
1453
Jeff Brown774ed9d2011-06-07 17:48:39 -07001454 GET_METHOD_ID(gCallbacksClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001455 "getHoverTapTimeout", "()I");
1456
Jeff Brown774ed9d2011-06-07 17:48:39 -07001457 GET_METHOD_ID(gCallbacksClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001458 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001459
Dianne Hackbornf3b57de2011-06-03 12:13:24 -07001460 GET_METHOD_ID(gCallbacksClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001461 "getDoubleTapTimeout", "()I");
1462
Dianne Hackbornf3b57de2011-06-03 12:13:24 -07001463 GET_METHOD_ID(gCallbacksClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001464 "getLongPressTimeout", "()I");
1465
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001466 GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, clazz,
Jeff Brownae9fc032010-08-18 15:51:08 -07001467 "getMaxEventsPerSecond", "()I");
1468
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001469 GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001470 "getPointerLayer", "()I");
1471
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001472 GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001473 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001474
Jeff Brown6ec402b2010-07-28 15:48:59 -07001475 // KeyEvent
1476
1477 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001478 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1479
Jeff Brown6ec402b2010-07-28 15:48:59 -07001480
Jeff Brown8d608662010-08-30 03:02:23 -07001481 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001482
1483 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001484 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001485
Jeff Brown8d608662010-08-30 03:02:23 -07001486 // InputDevice
1487
1488 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001489 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
Jeff Brown8d608662010-08-30 03:02:23 -07001490
1491 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1492 "<init>", "()V");
1493
1494 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
Jeff Brownefd32662011-03-08 15:13:06 -08001495 "addMotionRange", "(IIFFFF)V");
Jeff Brown8d608662010-08-30 03:02:23 -07001496
1497 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1498 "mId", "I");
1499
1500 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1501 "mName", "Ljava/lang/String;");
1502
1503 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1504 "mSources", "I");
1505
1506 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1507 "mKeyboardType", "I");
1508
Jeff Brown57c59372010-09-21 18:22:55 -07001509 // Configuration
1510
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001511 FIND_CLASS(clazz, "android/content/res/Configuration");
Jeff Brown57c59372010-09-21 18:22:55 -07001512
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001513 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001514 "touchscreen", "I");
1515
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001516 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001517 "keyboard", "I");
1518
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001519 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001520 "navigation", "I");
1521
Jeff Brown46b9ac02010-04-22 18:58:52 -07001522 return 0;
1523}
1524
Jeff Brown46b9ac02010-04-22 18:58:52 -07001525} /* namespace android */