blob: 7e9fba891946854773a9a6676b9cebb99f29104d [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 Brown905805a2011-10-12 13:57:59 -0700152enum {
153 WM_ACTION_PASS_TO_USER = 1,
154 WM_ACTION_POKE_USER_ACTIVITY = 2,
155 WM_ACTION_GO_TO_SLEEP = 4,
156};
157
Jeff Brown928e0542011-01-10 11:17:36 -0800158
159// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800160
Jeff Brown9c3cda02010-06-15 01:31:58 -0700161class NativeInputManager : public virtual RefBase,
162 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700163 public virtual InputDispatcherPolicyInterface,
164 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700165protected:
166 virtual ~NativeInputManager();
167
168public:
Jeff Brown2352b972011-04-12 22:39:53 -0700169 NativeInputManager(jobject contextObj, jobject callbacksObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700170
171 inline sp<InputManager> getInputManager() const { return mInputManager; }
172
Jeff Brownb88102f2010-09-08 11:49:43 -0700173 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700174
Jeff Brownbc68a592011-07-25 12:58:12 -0700175 void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
176 int32_t externalWidth, int32_t externalHeight);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700177 void setDisplayOrientation(int32_t displayId, int32_t orientation);
178
Jeff Brown7fbdc842010-06-17 20:52:56 -0700179 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800180 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700181 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
182
Jeff Brown9302c872011-07-13 22:51:29 -0700183 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
184 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700185 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800186 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700187 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700188 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700189
Jeff Brown9c3cda02010-06-15 01:31:58 -0700190 /* --- InputReaderPolicyInterface implementation --- */
191
Jeff Brown214eaf42011-05-26 19:17:02 -0700192 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800193 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194
195 /* --- InputDispatcherPolicyInterface implementation --- */
196
Jeff Browne20c9e02010-10-11 14:20:19 -0700197 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
198 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700199 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700200 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800201 const sp<InputWindowHandle>& inputWindowHandle);
202 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700203 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700204 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
205 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800206 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800207 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700208 virtual nsecs_t interceptKeyBeforeDispatching(
209 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700210 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800211 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800212 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700213 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700214 virtual bool checkInjectEventsPermissionNonReentrant(
215 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700216
Jeff Brown2352b972011-04-12 22:39:53 -0700217 /* --- PointerControllerPolicyInterface implementation --- */
218
219 virtual void loadPointerResources(PointerResources* outResources);
220
Jeff Brown9c3cda02010-06-15 01:31:58 -0700221private:
222 sp<InputManager> mInputManager;
223
Jeff Brown2352b972011-04-12 22:39:53 -0700224 jobject mContextObj;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700225 jobject mCallbacksObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800226 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700227
Jeff Brown83c09682010-12-23 17:50:18 -0800228 Mutex mLock;
229 struct Locked {
230 // Display size information.
Jeff Brownbc68a592011-07-25 12:58:12 -0700231 int32_t displayWidth, displayHeight; // -1 when not initialized
232 int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
Jeff Brown83c09682010-12-23 17:50:18 -0800233 int32_t displayOrientation;
234
Jeff Brown05dc66a2011-03-02 14:41:58 -0800235 // System UI visibility.
236 int32_t systemUiVisibility;
237
Jeff Brown1a84fd12011-06-02 01:26:32 -0700238 // Pointer speed.
239 int32_t pointerSpeed;
240
Jeff Brown474dcb52011-06-14 20:22:50 -0700241 // True if pointer gestures are enabled.
242 bool pointerGesturesEnabled;
243
Jeff Browndaf4a122011-08-26 17:14:14 -0700244 // Show touches feature enable/disable.
245 bool showTouches;
246
Jeff Brown5541de92011-04-11 11:54:25 -0700247 // Sprite controller singleton, created on first use.
248 sp<SpriteController> spriteController;
249
Jeff Brown83c09682010-12-23 17:50:18 -0800250 // Pointer controller singleton, created and destroyed as needed.
251 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800252 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700253
Jeff Brown2352b972011-04-12 22:39:53 -0700254 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800255 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700256 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800257
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700258 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700259 bool isScreenOn();
260 bool isScreenBright();
261
Jeff Brownb88102f2010-09-08 11:49:43 -0700262 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700263
Jeff Brown9c3cda02010-06-15 01:31:58 -0700264 static inline JNIEnv* jniEnv() {
265 return AndroidRuntime::getJNIEnv();
266 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700267};
268
Jeff Brown928e0542011-01-10 11:17:36 -0800269
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270
Jeff Brown2352b972011-04-12 22:39:53 -0700271NativeInputManager::NativeInputManager(jobject contextObj,
272 jobject callbacksObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700273 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700274 JNIEnv* env = jniEnv();
275
Jeff Brown2352b972011-04-12 22:39:53 -0700276 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700277 mCallbacksObj = env->NewGlobalRef(callbacksObj);
278
Jeff Brown83c09682010-12-23 17:50:18 -0800279 {
280 AutoMutex _l(mLock);
281 mLocked.displayWidth = -1;
282 mLocked.displayHeight = -1;
Jeff Brownbc68a592011-07-25 12:58:12 -0700283 mLocked.displayExternalWidth = -1;
284 mLocked.displayExternalHeight = -1;
Jeff Brown65fd2512011-08-18 11:20:58 -0700285 mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800286
287 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700288 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700289 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700290 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800291 }
292
Jeff Brown9c3cda02010-06-15 01:31:58 -0700293 sp<EventHub> eventHub = new EventHub();
294 mInputManager = new InputManager(eventHub, this, this);
295}
296
297NativeInputManager::~NativeInputManager() {
298 JNIEnv* env = jniEnv();
299
Jeff Brown2352b972011-04-12 22:39:53 -0700300 env->DeleteGlobalRef(mContextObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700301 env->DeleteGlobalRef(mCallbacksObj);
302}
303
Jeff Brownb88102f2010-09-08 11:49:43 -0700304void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700305 mInputManager->getReader()->dump(dump);
306 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700307
Jeff Brownb88102f2010-09-08 11:49:43 -0700308 mInputManager->getDispatcher()->dump(dump);
309 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700310}
311
Jeff Brown7fbdc842010-06-17 20:52:56 -0700312bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700313 if (env->ExceptionCheck()) {
314 LOGE("An exception was thrown by callback '%s'.", methodName);
315 LOGE_EX(env);
316 env->ExceptionClear();
317 return true;
318 }
319 return false;
320}
321
Jeff Brownbc68a592011-07-25 12:58:12 -0700322void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
323 int32_t externalWidth, int32_t externalHeight) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700324 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700325 if (displayId == 0) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700326 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700327
Jeff Brown65fd2512011-08-18 11:20:58 -0700328 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
329 changed = true;
330 mLocked.displayWidth = width;
331 mLocked.displayHeight = height;
Jeff Brownbc68a592011-07-25 12:58:12 -0700332
Jeff Brown65fd2512011-08-18 11:20:58 -0700333 sp<PointerController> controller = mLocked.pointerController.promote();
334 if (controller != NULL) {
335 controller->setDisplaySize(width, height);
Jeff Brown2352b972011-04-12 22:39:53 -0700336 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700337 }
Jeff Brown2352b972011-04-12 22:39:53 -0700338
Jeff Brown65fd2512011-08-18 11:20:58 -0700339 if (mLocked.displayExternalWidth != externalWidth
340 || mLocked.displayExternalHeight != externalHeight) {
341 changed = true;
Jeff Brownbc68a592011-07-25 12:58:12 -0700342 mLocked.displayExternalWidth = externalWidth;
343 mLocked.displayExternalHeight = externalHeight;
Jeff Brown65fd2512011-08-18 11:20:58 -0700344 }
345 }
346
347 if (changed) {
348 mInputManager->getReader()->requestRefreshConfiguration(
349 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700350 }
351}
352
353void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700354 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700355 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800356 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700357
Jeff Brown83c09682010-12-23 17:50:18 -0800358 if (mLocked.displayOrientation != orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700359 changed = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800360 mLocked.displayOrientation = orientation;
361
362 sp<PointerController> controller = mLocked.pointerController.promote();
363 if (controller != NULL) {
364 controller->setDisplayOrientation(orientation);
365 }
366 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700367 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700368
369 if (changed) {
370 mInputManager->getReader()->requestRefreshConfiguration(
371 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
372 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700373}
374
Jeff Brown7fbdc842010-06-17 20:52:56 -0700375status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800376 const sp<InputChannel>& inputChannel,
377 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
378 return mInputManager->getDispatcher()->registerInputChannel(
379 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700380}
381
382status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
383 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700384 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700385}
386
Jeff Brown214eaf42011-05-26 19:17:02 -0700387void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700388 JNIEnv* env = jniEnv();
389
Jeff Brown214eaf42011-05-26 19:17:02 -0700390 jint virtualKeyQuietTime = env->CallIntMethod(mCallbacksObj,
391 gCallbacksClassInfo.getVirtualKeyQuietTimeMillis);
392 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
393 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
394 }
395
396 outConfig->excludedDeviceNames.clear();
397 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mCallbacksObj,
Jeff Brown9c3cda02010-06-15 01:31:58 -0700398 gCallbacksClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700399 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
400 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700401 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700402 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700403 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700404 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700405 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700406 env->DeleteLocalRef(item);
407 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700408 env->DeleteLocalRef(excludedDeviceNames);
409 }
410
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700411 jint hoverTapTimeout = env->CallIntMethod(mCallbacksObj,
412 gCallbacksClassInfo.getHoverTapTimeout);
413 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700414 jint doubleTapTimeout = env->CallIntMethod(mCallbacksObj,
415 gCallbacksClassInfo.getDoubleTapTimeout);
416 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
417 jint longPressTimeout = env->CallIntMethod(mCallbacksObj,
418 gCallbacksClassInfo.getLongPressTimeout);
419 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700420 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700421
422 // We must ensure that the tap-drag interval is significantly shorter than
423 // the long-press timeout because the tap is held down for the entire duration
424 // of the double-tap timeout.
425 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700426 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700427 outConfig->pointerGestureTapDragInterval =
428 milliseconds_to_nanoseconds(tapDragInterval);
429 }
430 }
431 }
432
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700433 jint hoverTapSlop = env->CallIntMethod(mCallbacksObj,
434 gCallbacksClassInfo.getHoverTapSlop);
435 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
436 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700437 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700438
439 { // acquire lock
440 AutoMutex _l(mLock);
441
442 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
443 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700444 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700445
Jeff Browndaf4a122011-08-26 17:14:14 -0700446 outConfig->showTouches = mLocked.showTouches;
447
Jeff Brown65fd2512011-08-18 11:20:58 -0700448 outConfig->setDisplayInfo(0, false /*external*/,
449 mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
450 outConfig->setDisplayInfo(0, true /*external*/,
451 mLocked.displayExternalWidth, mLocked.displayExternalHeight,
452 mLocked.displayOrientation);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700453 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700454}
455
Jeff Brown83c09682010-12-23 17:50:18 -0800456sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
457 AutoMutex _l(mLock);
458
459 sp<PointerController> controller = mLocked.pointerController.promote();
460 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700461 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800462
Jeff Brown2352b972011-04-12 22:39:53 -0700463 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800464 mLocked.pointerController = controller;
465
466 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
467 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800468
Jeff Brown5541de92011-04-11 11:54:25 -0700469 JNIEnv* env = jniEnv();
Jeff Brown2352b972011-04-12 22:39:53 -0700470 jobject pointerIconObj = env->CallObjectMethod(mCallbacksObj,
471 gCallbacksClassInfo.getPointerIcon);
472 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
473 PointerIcon pointerIcon;
474 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
475 mContextObj, &pointerIcon);
476 if (!status && !pointerIcon.isNullIcon()) {
477 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
478 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
479 } else {
480 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800481 }
Jeff Brown2352b972011-04-12 22:39:53 -0700482 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800483 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800484
Jeff Brown2352b972011-04-12 22:39:53 -0700485 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800486 }
487 return controller;
488}
489
Jeff Brown5541de92011-04-11 11:54:25 -0700490void NativeInputManager::ensureSpriteControllerLocked() {
491 if (mLocked.spriteController == NULL) {
492 JNIEnv* env = jniEnv();
493 jint layer = env->CallIntMethod(mCallbacksObj, gCallbacksClassInfo.getPointerLayer);
494 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
495 layer = -1;
496 }
497 mLocked.spriteController = new SpriteController(mLooper, layer);
498 }
499}
500
Jeff Browne20c9e02010-10-11 14:20:19 -0700501void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
502 int32_t switchValue, uint32_t policyFlags) {
503#if DEBUG_INPUT_DISPATCHER_POLICY
504 LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
505 when, switchCode, switchValue, policyFlags);
506#endif
507
508 JNIEnv* env = jniEnv();
509
510 switch (switchCode) {
511 case SW_LID:
512 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged,
513 when, switchValue == 0);
514 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
515 break;
516 }
517}
518
Jeff Brown9c3cda02010-06-15 01:31:58 -0700519void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
520#if DEBUG_INPUT_DISPATCHER_POLICY
521 LOGD("notifyConfigurationChanged - when=%lld", when);
522#endif
523
524 JNIEnv* env = jniEnv();
525
Jeff Brown57c59372010-09-21 18:22:55 -0700526 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700527 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700528}
529
Jeff Brown519e0242010-09-15 15:18:56 -0700530nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800531 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700532#if DEBUG_INPUT_DISPATCHER_POLICY
533 LOGD("notifyANR");
534#endif
535
536 JNIEnv* env = jniEnv();
537
Jeff Brown928e0542011-01-10 11:17:36 -0800538 jobject inputApplicationHandleObj =
539 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
540 jobject inputWindowHandleObj =
541 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700542
Jeff Brown519e0242010-09-15 15:18:56 -0700543 jlong newTimeout = env->CallLongMethod(mCallbacksObj,
Jeff Brown928e0542011-01-10 11:17:36 -0800544 gCallbacksClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700545 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
546 newTimeout = 0; // abort dispatch
547 } else {
548 assert(newTimeout >= 0);
549 }
550
Jeff Brown928e0542011-01-10 11:17:36 -0800551 env->DeleteLocalRef(inputWindowHandleObj);
552 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700553 return newTimeout;
554}
555
Jeff Brown928e0542011-01-10 11:17:36 -0800556void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700557#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown928e0542011-01-10 11:17:36 -0800558 LOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700559#endif
560
Jeff Brown7fbdc842010-06-17 20:52:56 -0700561 JNIEnv* env = jniEnv();
562
Jeff Brown928e0542011-01-10 11:17:36 -0800563 jobject inputWindowHandleObj =
564 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
565 if (inputWindowHandleObj) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700566 env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800567 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700568 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
569
Jeff Brown928e0542011-01-10 11:17:36 -0800570 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700571 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700572}
573
Jeff Brown214eaf42011-05-26 19:17:02 -0700574void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
575 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800576
Jeff Brown214eaf42011-05-26 19:17:02 -0700577 jint keyRepeatTimeout = env->CallIntMethod(mCallbacksObj,
578 gCallbacksClassInfo.getKeyRepeatTimeout);
579 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
580 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
581 }
Jeff Browna4547672011-03-02 21:38:11 -0800582
Jeff Brown214eaf42011-05-26 19:17:02 -0700583 jint keyRepeatDelay = env->CallIntMethod(mCallbacksObj,
584 gCallbacksClassInfo.getKeyRepeatDelay);
585 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
586 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
587 }
588
589 jint maxEventsPerSecond = env->CallIntMethod(mCallbacksObj,
590 gCallbacksClassInfo.getMaxEventsPerSecond);
591 if (!checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
592 outConfig->maxEventsPerSecond = maxEventsPerSecond;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700593 }
594}
595
Jeff Brown214eaf42011-05-26 19:17:02 -0700596bool NativeInputManager::isKeyRepeatEnabled() {
597 // Only enable automatic key repeating when the screen is on.
598 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700599}
600
Jeff Brown9302c872011-07-13 22:51:29 -0700601void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
602 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700603
Jeff Brown9302c872011-07-13 22:51:29 -0700604 if (windowHandleObjArray) {
605 jsize length = env->GetArrayLength(windowHandleObjArray);
606 for (jsize i = 0; i < length; i++) {
607 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
608 if (! windowHandleObj) {
609 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700610 }
Jeff Brown9302c872011-07-13 22:51:29 -0700611
612 sp<InputWindowHandle> windowHandle =
613 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
614 if (windowHandle != NULL) {
615 windowHandles.push(windowHandle);
616 }
617 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700618 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700619 }
Jeff Brown349703e2010-06-22 01:27:15 -0700620
Jeff Brown9302c872011-07-13 22:51:29 -0700621 mInputManager->getDispatcher()->setInputWindows(windowHandles);
622
623 // Do this after the dispatcher has updated the window handle state.
624 bool newPointerGesturesEnabled = true;
625 size_t numWindows = windowHandles.size();
626 for (size_t i = 0; i < numWindows; i++) {
627 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700628 const InputWindowInfo* windowInfo = windowHandle->getInfo();
629 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
630 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700631 newPointerGesturesEnabled = false;
632 }
633 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700634
635 uint32_t changes = 0;
636 { // acquire lock
637 AutoMutex _l(mLock);
638
639 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
640 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
641 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
642 }
643 } // release lock
644
645 if (changes) {
646 mInputManager->getReader()->requestRefreshConfiguration(changes);
647 }
Jeff Brown349703e2010-06-22 01:27:15 -0700648}
649
Jeff Brown9302c872011-07-13 22:51:29 -0700650void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
651 sp<InputApplicationHandle> applicationHandle =
652 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
653 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700654}
655
656void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700657 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700658}
659
Jeff Brown05dc66a2011-03-02 14:41:58 -0800660void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
661 AutoMutex _l(mLock);
662
663 if (mLocked.systemUiVisibility != visibility) {
664 mLocked.systemUiVisibility = visibility;
665
666 sp<PointerController> controller = mLocked.pointerController.promote();
667 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700668 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800669 }
670 }
671}
672
Jeff Brown2352b972011-04-12 22:39:53 -0700673void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800674 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700675 controller->setInactivityTimeout(lightsOut
676 ? PointerController::INACTIVITY_TIMEOUT_SHORT
677 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800678}
679
Jeff Brown1a84fd12011-06-02 01:26:32 -0700680void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700681 { // acquire lock
682 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700683
Jeff Brown474dcb52011-06-14 20:22:50 -0700684 if (mLocked.pointerSpeed == speed) {
685 return;
686 }
687
Jeff Brown1a84fd12011-06-02 01:26:32 -0700688 LOGI("Setting pointer speed to %d.", speed);
689 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700690 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700691
Jeff Brown474dcb52011-06-14 20:22:50 -0700692 mInputManager->getReader()->requestRefreshConfiguration(
693 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700694}
695
Jeff Browndaf4a122011-08-26 17:14:14 -0700696void NativeInputManager::setShowTouches(bool enabled) {
697 { // acquire lock
698 AutoMutex _l(mLock);
699
700 if (mLocked.showTouches == enabled) {
701 return;
702 }
703
704 LOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
705 mLocked.showTouches = enabled;
706 } // release lock
707
708 mInputManager->getReader()->requestRefreshConfiguration(
709 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
710}
711
Jeff Browne20c9e02010-10-11 14:20:19 -0700712bool NativeInputManager::isScreenOn() {
713 return android_server_PowerManagerService_isScreenOn();
714}
715
716bool NativeInputManager::isScreenBright() {
717 return android_server_PowerManagerService_isScreenBright();
718}
719
Jeff Brown0029c662011-03-30 02:25:18 -0700720bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
721 jobject inputEventObj;
722
723 JNIEnv* env = jniEnv();
724 switch (inputEvent->getType()) {
725 case AINPUT_EVENT_TYPE_KEY:
726 inputEventObj = android_view_KeyEvent_fromNative(env,
727 static_cast<const KeyEvent*>(inputEvent));
728 break;
729 case AINPUT_EVENT_TYPE_MOTION:
730 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
731 static_cast<const MotionEvent*>(inputEvent));
732 break;
733 default:
734 return true; // dispatch the event normally
735 }
736
737 if (!inputEventObj) {
738 LOGE("Failed to obtain input event object for filterInputEvent.");
739 return true; // dispatch the event normally
740 }
741
742 // The callee is responsible for recycling the event.
743 jboolean pass = env->CallBooleanMethod(mCallbacksObj, gCallbacksClassInfo.filterInputEvent,
744 inputEventObj, policyFlags);
745 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
746 pass = true;
747 }
748 env->DeleteLocalRef(inputEventObj);
749 return pass;
750}
751
Jeff Brown1f245102010-11-18 20:53:46 -0800752void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
753 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700754 // Policy:
755 // - Ignore untrusted events and pass them along.
756 // - Ask the window manager what to do with normal events and trusted injected events.
757 // - For normal events wake and brighten the screen if currently off or dim.
758 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800759 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700760 bool isScreenOn = this->isScreenOn();
761 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700762
Jeff Brown3122e442010-10-11 23:32:49 -0700763 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800764 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
765 jint wmActions;
766 if (keyEventObj) {
767 wmActions = env->CallIntMethod(mCallbacksObj,
768 gCallbacksClassInfo.interceptKeyBeforeQueueing,
769 keyEventObj, policyFlags, isScreenOn);
770 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
771 wmActions = 0;
772 }
773 android_view_KeyEvent_recycle(env, keyEventObj);
774 env->DeleteLocalRef(keyEventObj);
775 } else {
776 LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700777 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700778 }
779
Jeff Brown1f245102010-11-18 20:53:46 -0800780 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700781 if (!isScreenOn) {
782 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700783 }
784
785 if (!isScreenBright) {
786 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
787 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700788 }
789
Jeff Brown56194eb2011-03-02 19:23:13 -0800790 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700791 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700792 policyFlags |= POLICY_FLAG_PASS_TO_USER;
793 }
794}
795
Jeff Brown56194eb2011-03-02 19:23:13 -0800796void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700797 // Policy:
798 // - Ignore untrusted events and pass them along.
799 // - No special filtering for injected events required at this time.
800 // - Filter normal events based on screen state.
801 // - For normal events brighten (but do not wake) the screen if currently dim.
802 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
803 if (isScreenOn()) {
804 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700805
Jeff Brown3122e442010-10-11 23:32:49 -0700806 if (!isScreenBright()) {
807 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
808 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800809 } else {
810 JNIEnv* env = jniEnv();
811 jint wmActions = env->CallIntMethod(mCallbacksObj,
812 gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
813 policyFlags);
814 if (checkAndClearExceptionFromCallback(env,
815 "interceptMotionBeforeQueueingWhenScreenOff")) {
816 wmActions = 0;
817 }
818
819 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
820 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700821 }
Jeff Brown3122e442010-10-11 23:32:49 -0700822 } else {
823 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700824 }
825}
826
Jeff Brown56194eb2011-03-02 19:23:13 -0800827void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
828 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800829 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800830#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800831 LOGD("handleInterceptActions: Going to sleep.");
832#endif
833 android_server_PowerManagerService_goToSleep(when);
834 }
835
836 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800837#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800838 LOGD("handleInterceptActions: Poking user activity.");
839#endif
840 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
841 }
842
843 if (wmActions & WM_ACTION_PASS_TO_USER) {
844 policyFlags |= POLICY_FLAG_PASS_TO_USER;
845 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800846#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown56194eb2011-03-02 19:23:13 -0800847 LOGD("handleInterceptActions: Not passing key to user.");
848#endif
849 }
850}
851
Jeff Brown905805a2011-10-12 13:57:59 -0700852nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800853 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700854 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700855 // Policy:
856 // - Ignore untrusted events and pass them along.
857 // - Filter normal events and trusted injected events through the window manager policy to
858 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700859 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700860 if (policyFlags & POLICY_FLAG_TRUSTED) {
861 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700862
Jeff Brown928e0542011-01-10 11:17:36 -0800863 // Note: inputWindowHandle may be null.
864 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800865 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
866 if (keyEventObj) {
Jeff Brown905805a2011-10-12 13:57:59 -0700867 jlong delayMillis = env->CallLongMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800868 gCallbacksClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800869 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800870 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
871 android_view_KeyEvent_recycle(env, keyEventObj);
872 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700873 if (!error) {
874 if (delayMillis < 0) {
875 result = -1;
876 } else if (delayMillis > 0) {
877 result = milliseconds_to_nanoseconds(delayMillis);
878 }
879 }
Jeff Brown1f245102010-11-18 20:53:46 -0800880 } else {
881 LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800882 }
Jeff Brown928e0542011-01-10 11:17:36 -0800883 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700884 }
Jeff Brown1f245102010-11-18 20:53:46 -0800885 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700886}
887
Jeff Brown928e0542011-01-10 11:17:36 -0800888bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800889 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700890 // Policy:
891 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800892 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700893 if (policyFlags & POLICY_FLAG_TRUSTED) {
894 JNIEnv* env = jniEnv();
895
Jeff Brown928e0542011-01-10 11:17:36 -0800896 // Note: inputWindowHandle may be null.
897 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800898 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
899 if (keyEventObj) {
Jeff Brown49ed71d2010-12-06 17:13:33 -0800900 jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj,
Jeff Brown1f245102010-11-18 20:53:46 -0800901 gCallbacksClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800902 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700903 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
904 fallbackKeyEventObj = NULL;
905 }
Jeff Brown1f245102010-11-18 20:53:46 -0800906 android_view_KeyEvent_recycle(env, keyEventObj);
907 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800908
909 if (fallbackKeyEventObj) {
910 // Note: outFallbackKeyEvent may be the same object as keyEvent.
911 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
912 outFallbackKeyEvent)) {
913 result = true;
914 }
915 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
916 env->DeleteLocalRef(fallbackKeyEventObj);
917 }
Jeff Brown1f245102010-11-18 20:53:46 -0800918 } else {
919 LOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800920 }
Jeff Brown928e0542011-01-10 11:17:36 -0800921 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700922 }
Jeff Brown1f245102010-11-18 20:53:46 -0800923 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700924}
925
Jeff Brown01ce2e92010-09-26 22:20:12 -0700926void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
927 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700928}
929
Jeff Brown349703e2010-06-22 01:27:15 -0700930
Jeff Brownb88102f2010-09-08 11:49:43 -0700931bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
932 int32_t injectorPid, int32_t injectorUid) {
933 JNIEnv* env = jniEnv();
934 jboolean result = env->CallBooleanMethod(mCallbacksObj,
935 gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700936 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
937 result = false;
938 }
Jeff Brown349703e2010-06-22 01:27:15 -0700939 return result;
940}
941
Jeff Brown2352b972011-04-12 22:39:53 -0700942void NativeInputManager::loadPointerResources(PointerResources* outResources) {
943 JNIEnv* env = jniEnv();
944
945 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
946 &outResources->spotHover);
947 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
948 &outResources->spotTouch);
949 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
950 &outResources->spotAnchor);
951}
952
Jeff Brown83c09682010-12-23 17:50:18 -0800953
Jeff Brown9c3cda02010-06-15 01:31:58 -0700954// ----------------------------------------------------------------------------
955
956static sp<NativeInputManager> gNativeInputManager;
957
Jeff Brown46b9ac02010-04-22 18:58:52 -0700958static bool checkInputManagerUnitialized(JNIEnv* env) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700959 if (gNativeInputManager == NULL) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700960 LOGE("Input manager not initialized.");
961 jniThrowRuntimeException(env, "Input manager not initialized.");
962 return true;
963 }
964 return false;
965}
966
967static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
Jeff Brown2352b972011-04-12 22:39:53 -0700968 jobject contextObj, jobject callbacksObj, jobject messageQueueObj) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700969 if (gNativeInputManager == NULL) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800970 sp<Looper> looper = android_os_MessageQueue_getLooper(env, messageQueueObj);
Jeff Brown2352b972011-04-12 22:39:53 -0700971 gNativeInputManager = new NativeInputManager(contextObj, callbacksObj, looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700972 } else {
973 LOGE("Input manager already initialized.");
974 jniThrowRuntimeException(env, "Input manager already initialized.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700975 }
976}
977
978static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
979 if (checkInputManagerUnitialized(env)) {
980 return;
981 }
982
Jeff Brown9c3cda02010-06-15 01:31:58 -0700983 status_t result = gNativeInputManager->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700984 if (result) {
985 jniThrowRuntimeException(env, "Input manager could not be started.");
986 }
987}
988
989static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Jeff Brownbc68a592011-07-25 12:58:12 -0700990 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700991 if (checkInputManagerUnitialized(env)) {
992 return;
993 }
994
995 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
996 // to be passed in like this, not sure which is better but leaving it like this
997 // keeps the window manager in direct control of when display transitions propagate down
998 // to the input dispatcher
Jeff Brownbc68a592011-07-25 12:58:12 -0700999 gNativeInputManager->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001000}
1001
1002static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
1003 jint displayId, jint orientation) {
1004 if (checkInputManagerUnitialized(env)) {
1005 return;
1006 }
1007
Jeff Brown9c3cda02010-06-15 01:31:58 -07001008 gNativeInputManager->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001009}
1010
1011static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001012 jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001013 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001014 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001015 }
1016
Jeff Brownb88102f2010-09-08 11:49:43 -07001017 return gNativeInputManager->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001018 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001019}
1020
1021static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001022 jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001023 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001024 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001025 }
1026
Jeff Brownb88102f2010-09-08 11:49:43 -07001027 return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001028 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001029}
1030
1031static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001032 jint deviceId, jint sourceMask, jint sw) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001033 if (checkInputManagerUnitialized(env)) {
Jeff Brownc5ed5912010-07-14 18:48:53 -07001034 return AKEY_STATE_UNKNOWN;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001035 }
1036
Jeff Brownb88102f2010-09-08 11:49:43 -07001037 return gNativeInputManager->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001038 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001039}
1040
1041static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz,
Jeff Brown6d0fec22010-07-23 21:28:06 -07001042 jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001043 if (checkInputManagerUnitialized(env)) {
1044 return JNI_FALSE;
1045 }
1046
1047 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1048 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1049 jsize numCodes = env->GetArrayLength(keyCodes);
1050 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001051 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brownb88102f2010-09-08 11:49:43 -07001052 result = gNativeInputManager->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001053 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001054 } else {
1055 result = JNI_FALSE;
1056 }
1057
1058 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1059 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1060 return result;
1061}
1062
1063static void throwInputChannelNotInitialized(JNIEnv* env) {
1064 jniThrowException(env, "java/lang/IllegalStateException",
1065 "inputChannel is not initialized");
1066}
1067
1068static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env,
1069 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
1070 LOGW("Input channel object '%s' was disposed without first being unregistered with "
1071 "the input manager!", inputChannel->getName().string());
1072
Jeff Brown9c3cda02010-06-15 01:31:58 -07001073 if (gNativeInputManager != NULL) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07001074 gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Brown9c3cda02010-06-15 01:31:58 -07001075 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001076}
1077
1078static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001079 jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001080 if (checkInputManagerUnitialized(env)) {
1081 return;
1082 }
1083
1084 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1085 inputChannelObj);
1086 if (inputChannel == NULL) {
1087 throwInputChannelNotInitialized(env);
1088 return;
1089 }
1090
Jeff Brown928e0542011-01-10 11:17:36 -08001091 sp<InputWindowHandle> inputWindowHandle =
1092 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001093
1094 status_t status = gNativeInputManager->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001095 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001096 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001097 String8 message;
1098 message.appendFormat("Failed to register input channel. status=%d", status);
1099 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001100 return;
1101 }
1102
Jeff Browna41ca772010-08-11 14:46:32 -07001103 if (! monitor) {
1104 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
1105 android_server_InputManager_handleInputChannelDisposed, NULL);
1106 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001107}
1108
1109static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1110 jobject inputChannelObj) {
1111 if (checkInputManagerUnitialized(env)) {
1112 return;
1113 }
1114
1115 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1116 inputChannelObj);
1117 if (inputChannel == NULL) {
1118 throwInputChannelNotInitialized(env);
1119 return;
1120 }
1121
1122 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1123
Jeff Brown7fbdc842010-06-17 20:52:56 -07001124 status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001125 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1126 String8 message;
1127 message.appendFormat("Failed to unregister input channel. status=%d", status);
1128 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001129 }
1130}
1131
Jeff Brown0029c662011-03-30 02:25:18 -07001132static void android_server_InputManager_nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1133 jboolean enabled) {
1134 if (checkInputManagerUnitialized(env)) {
1135 return;
1136 }
1137
1138 gNativeInputManager->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
1139}
1140
Jeff Brown6ec402b2010-07-28 15:48:59 -07001141static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1142 jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001143 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown7fbdc842010-06-17 20:52:56 -07001144 if (checkInputManagerUnitialized(env)) {
1145 return INPUT_EVENT_INJECTION_FAILED;
1146 }
1147
Jeff Brown6ec402b2010-07-28 15:48:59 -07001148 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1149 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001150 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1151 if (status) {
1152 jniThrowRuntimeException(env, "Could not read contents of KeyEvent 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 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1158 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001159 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001160 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1161 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001162 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1163 return INPUT_EVENT_INJECTION_FAILED;
1164 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001165
Jeff Brownb88102f2010-09-08 11:49:43 -07001166 return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001167 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1168 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001169 } else {
1170 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001171 return INPUT_EVENT_INJECTION_FAILED;
1172 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001173}
1174
Jeff Brown349703e2010-06-22 01:27:15 -07001175static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz,
Jeff Brown9302c872011-07-13 22:51:29 -07001176 jobjectArray windowHandleObjArray) {
Jeff Brown349703e2010-06-22 01:27:15 -07001177 if (checkInputManagerUnitialized(env)) {
1178 return;
1179 }
1180
Jeff Brown9302c872011-07-13 22:51:29 -07001181 gNativeInputManager->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001182}
1183
1184static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
Jeff Brown9302c872011-07-13 22:51:29 -07001185 jobject applicationHandleObj) {
Jeff Brown349703e2010-06-22 01:27:15 -07001186 if (checkInputManagerUnitialized(env)) {
1187 return;
1188 }
1189
Jeff Brown9302c872011-07-13 22:51:29 -07001190 gNativeInputManager->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001191}
1192
1193static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env,
1194 jclass clazz, jboolean enabled, jboolean frozen) {
1195 if (checkInputManagerUnitialized(env)) {
1196 return;
1197 }
1198
1199 gNativeInputManager->setInputDispatchMode(enabled, frozen);
1200}
1201
Jeff Brown05dc66a2011-03-02 14:41:58 -08001202static void android_server_InputManager_nativeSetSystemUiVisibility(JNIEnv* env,
1203 jclass clazz, jint visibility) {
1204 if (checkInputManagerUnitialized(env)) {
1205 return;
1206 }
1207
1208 gNativeInputManager->setSystemUiVisibility(visibility);
1209}
1210
Jeff Brown8d608662010-08-30 03:02:23 -07001211static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env,
1212 jclass clazz, jint deviceId) {
1213 if (checkInputManagerUnitialized(env)) {
1214 return NULL;
1215 }
1216
1217 InputDeviceInfo deviceInfo;
Jeff Brownb88102f2010-09-08 11:49:43 -07001218 status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -07001219 deviceId, & deviceInfo);
1220 if (status) {
1221 return NULL;
1222 }
1223
1224 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
1225 if (! deviceObj) {
1226 return NULL;
1227 }
1228
1229 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
1230 if (! deviceNameObj) {
1231 return NULL;
1232 }
1233
1234 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
1235 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
1236 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
1237 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
1238
Jeff Brownefd32662011-03-08 15:13:06 -08001239 const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
Jeff Brown8d608662010-08-30 03:02:23 -07001240 for (size_t i = 0; i < ranges.size(); i++) {
Jeff Brownefd32662011-03-08 15:13:06 -08001241 const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
Jeff Brown8d608662010-08-30 03:02:23 -07001242 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
Jeff Brownefd32662011-03-08 15:13:06 -08001243 range.axis, range.source, range.min, range.max, range.flat, range.fuzz);
Jeff Brown8d608662010-08-30 03:02:23 -07001244 if (env->ExceptionCheck()) {
1245 return NULL;
1246 }
1247 }
1248
1249 return deviceObj;
1250}
1251
1252static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env,
1253 jclass clazz) {
1254 if (checkInputManagerUnitialized(env)) {
1255 return NULL;
1256 }
1257
1258 Vector<int> deviceIds;
Jeff Brownb88102f2010-09-08 11:49:43 -07001259 gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001260
1261 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1262 if (! deviceIdsObj) {
1263 return NULL;
1264 }
1265
1266 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1267 return deviceIdsObj;
1268}
1269
Jeff Brown57c59372010-09-21 18:22:55 -07001270static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env,
1271 jclass clazz, jobject configObj) {
1272 if (checkInputManagerUnitialized(env)) {
1273 return;
1274 }
1275
1276 InputConfiguration config;
1277 gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config);
1278
1279 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1280 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1281 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1282}
1283
Jeff Browne6504122010-09-27 14:52:15 -07001284static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env,
1285 jclass clazz, jobject fromChannelObj, jobject toChannelObj) {
1286 if (checkInputManagerUnitialized(env)) {
1287 return false;
1288 }
1289
1290 sp<InputChannel> fromChannel =
1291 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1292 sp<InputChannel> toChannel =
1293 android_view_InputChannel_getInputChannel(env, toChannelObj);
1294
1295 if (fromChannel == NULL || toChannel == NULL) {
1296 return false;
1297 }
1298
1299 return gNativeInputManager->getInputManager()->getDispatcher()->
1300 transferTouchFocus(fromChannel, toChannel);
1301}
1302
Jeff Brown1a84fd12011-06-02 01:26:32 -07001303static void android_server_InputManager_nativeSetPointerSpeed(JNIEnv* env,
1304 jclass clazz, jint speed) {
1305 if (checkInputManagerUnitialized(env)) {
1306 return;
1307 }
1308
1309 gNativeInputManager->setPointerSpeed(speed);
1310}
1311
Jeff Browndaf4a122011-08-26 17:14:14 -07001312static void android_server_InputManager_nativeSetShowTouches(JNIEnv* env,
1313 jclass clazz, jboolean enabled) {
1314 if (checkInputManagerUnitialized(env)) {
1315 return;
1316 }
1317
1318 gNativeInputManager->setShowTouches(enabled);
1319}
1320
Jeff Browne33348b2010-07-15 23:54:05 -07001321static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) {
1322 if (checkInputManagerUnitialized(env)) {
1323 return NULL;
1324 }
1325
Jeff Brownb88102f2010-09-08 11:49:43 -07001326 String8 dump;
1327 gNativeInputManager->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001328 return env->NewStringUTF(dump.string());
1329}
1330
Jeff Brown89ef0722011-08-10 16:25:21 -07001331static void android_server_InputManager_nativeMonitor(JNIEnv* env, jclass clazz) {
1332 if (checkInputManagerUnitialized(env)) {
1333 return;
1334 }
1335
1336 gNativeInputManager->getInputManager()->getReader()->monitor();
1337 gNativeInputManager->getInputManager()->getDispatcher()->monitor();
1338}
1339
Jeff Brown9c3cda02010-06-15 01:31:58 -07001340// ----------------------------------------------------------------------------
1341
Jeff Brown46b9ac02010-04-22 18:58:52 -07001342static JNINativeMethod gInputManagerMethods[] = {
1343 /* name, signature, funcPtr */
Jeff Brown2352b972011-04-12 22:39:53 -07001344 { "nativeInit", "(Landroid/content/Context;"
1345 "Lcom/android/server/wm/InputManager$Callbacks;Landroid/os/MessageQueue;)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001346 (void*) android_server_InputManager_nativeInit },
1347 { "nativeStart", "()V",
1348 (void*) android_server_InputManager_nativeStart },
Jeff Brownbc68a592011-07-25 12:58:12 -07001349 { "nativeSetDisplaySize", "(IIIII)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001350 (void*) android_server_InputManager_nativeSetDisplaySize },
1351 { "nativeSetDisplayOrientation", "(II)V",
1352 (void*) android_server_InputManager_nativeSetDisplayOrientation },
1353 { "nativeGetScanCodeState", "(III)I",
1354 (void*) android_server_InputManager_nativeGetScanCodeState },
1355 { "nativeGetKeyCodeState", "(III)I",
1356 (void*) android_server_InputManager_nativeGetKeyCodeState },
1357 { "nativeGetSwitchState", "(III)I",
1358 (void*) android_server_InputManager_nativeGetSwitchState },
Jeff Brown6d0fec22010-07-23 21:28:06 -07001359 { "nativeHasKeys", "(II[I[Z)Z",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001360 (void*) android_server_InputManager_nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001361 { "nativeRegisterInputChannel",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001362 "(Landroid/view/InputChannel;Lcom/android/server/wm/InputWindowHandle;Z)V",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001363 (void*) android_server_InputManager_nativeRegisterInputChannel },
1364 { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V",
Jeff Brown7fbdc842010-06-17 20:52:56 -07001365 (void*) android_server_InputManager_nativeUnregisterInputChannel },
Jeff Brown0029c662011-03-30 02:25:18 -07001366 { "nativeSetInputFilterEnabled", "(Z)V",
1367 (void*) android_server_InputManager_nativeSetInputFilterEnabled },
1368 { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIIII)I",
Jeff Brown6ec402b2010-07-28 15:48:59 -07001369 (void*) android_server_InputManager_nativeInjectInputEvent },
Jeff Brown9302c872011-07-13 22:51:29 -07001370 { "nativeSetInputWindows", "([Lcom/android/server/wm/InputWindowHandle;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001371 (void*) android_server_InputManager_nativeSetInputWindows },
Jeff Brown9302c872011-07-13 22:51:29 -07001372 { "nativeSetFocusedApplication", "(Lcom/android/server/wm/InputApplicationHandle;)V",
Jeff Brown349703e2010-06-22 01:27:15 -07001373 (void*) android_server_InputManager_nativeSetFocusedApplication },
1374 { "nativeSetInputDispatchMode", "(ZZ)V",
1375 (void*) android_server_InputManager_nativeSetInputDispatchMode },
Jeff Brown05dc66a2011-03-02 14:41:58 -08001376 { "nativeSetSystemUiVisibility", "(I)V",
1377 (void*) android_server_InputManager_nativeSetSystemUiVisibility },
Jeff Brown8d608662010-08-30 03:02:23 -07001378 { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;",
1379 (void*) android_server_InputManager_nativeGetInputDevice },
1380 { "nativeGetInputDeviceIds", "()[I",
1381 (void*) android_server_InputManager_nativeGetInputDeviceIds },
Jeff Brown57c59372010-09-21 18:22:55 -07001382 { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V",
1383 (void*) android_server_InputManager_nativeGetInputConfiguration },
Jeff Browne6504122010-09-27 14:52:15 -07001384 { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1385 (void*) android_server_InputManager_nativeTransferTouchFocus },
Jeff Brown1a84fd12011-06-02 01:26:32 -07001386 { "nativeSetPointerSpeed", "(I)V",
1387 (void*) android_server_InputManager_nativeSetPointerSpeed },
Jeff Browndaf4a122011-08-26 17:14:14 -07001388 { "nativeSetShowTouches", "(Z)V",
1389 (void*) android_server_InputManager_nativeSetShowTouches },
Jeff Browne33348b2010-07-15 23:54:05 -07001390 { "nativeDump", "()Ljava/lang/String;",
1391 (void*) android_server_InputManager_nativeDump },
Jeff Brown89ef0722011-08-10 16:25:21 -07001392 { "nativeMonitor", "()V",
1393 (void*) android_server_InputManager_nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001394};
1395
1396#define FIND_CLASS(var, className) \
1397 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001398 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001399
1400#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1401 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1402 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1403
1404#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1405 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1406 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1407
1408int register_android_server_InputManager(JNIEnv* env) {
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001409 int res = jniRegisterNativeMethods(env, "com/android/server/wm/InputManager",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001410 gInputManagerMethods, NELEM(gInputManagerMethods));
1411 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1412
Jeff Brown9c3cda02010-06-15 01:31:58 -07001413 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001414
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001415 jclass clazz;
1416 FIND_CLASS(clazz, "com/android/server/wm/InputManager$Callbacks");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001417
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001418 GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001419 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001420
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001421 GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001422 "notifyLidSwitchChanged", "(JZ)V");
1423
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001424 GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, clazz,
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001425 "notifyInputChannelBroken", "(Lcom/android/server/wm/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001426
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001427 GET_METHOD_ID(gCallbacksClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001428 "notifyANR",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001429 "(Lcom/android/server/wm/InputApplicationHandle;Lcom/android/server/wm/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001430
Jeff Brown0029c662011-03-30 02:25:18 -07001431 GET_METHOD_ID(gCallbacksClassInfo.filterInputEvent, clazz,
1432 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1433
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001434 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001435 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001436
Jeff Brown56194eb2011-03-02 19:23:13 -08001437 GET_METHOD_ID(gCallbacksClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001438 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001439 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1440
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001441 GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001442 "interceptKeyBeforeDispatching",
Jeff Brown905805a2011-10-12 13:57:59 -07001443 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001444
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001445 GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001446 "dispatchUnhandledKey",
Dianne Hackborna924dc0d2011-02-17 14:22:17 -08001447 "(Lcom/android/server/wm/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001448
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001449 GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001450 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001451
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001452 GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001453 "getVirtualKeyQuietTimeMillis", "()I");
1454
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001455 GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001456 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1457
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001458 GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001459 "getKeyRepeatTimeout", "()I");
1460
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001461 GET_METHOD_ID(gCallbacksClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001462 "getKeyRepeatDelay", "()I");
1463
Jeff Brown774ed9d2011-06-07 17:48:39 -07001464 GET_METHOD_ID(gCallbacksClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001465 "getHoverTapTimeout", "()I");
1466
Jeff Brown774ed9d2011-06-07 17:48:39 -07001467 GET_METHOD_ID(gCallbacksClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001468 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001469
Dianne Hackbornf3b57de2011-06-03 12:13:24 -07001470 GET_METHOD_ID(gCallbacksClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001471 "getDoubleTapTimeout", "()I");
1472
Dianne Hackbornf3b57de2011-06-03 12:13:24 -07001473 GET_METHOD_ID(gCallbacksClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001474 "getLongPressTimeout", "()I");
1475
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001476 GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, clazz,
Jeff Brownae9fc032010-08-18 15:51:08 -07001477 "getMaxEventsPerSecond", "()I");
1478
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001479 GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001480 "getPointerLayer", "()I");
1481
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001482 GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001483 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001484
Jeff Brown6ec402b2010-07-28 15:48:59 -07001485 // KeyEvent
1486
1487 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001488 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1489
Jeff Brown6ec402b2010-07-28 15:48:59 -07001490
Jeff Brown8d608662010-08-30 03:02:23 -07001491 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001492
1493 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001494 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001495
Jeff Brown8d608662010-08-30 03:02:23 -07001496 // InputDevice
1497
1498 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001499 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
Jeff Brown8d608662010-08-30 03:02:23 -07001500
1501 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1502 "<init>", "()V");
1503
1504 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
Jeff Brownefd32662011-03-08 15:13:06 -08001505 "addMotionRange", "(IIFFFF)V");
Jeff Brown8d608662010-08-30 03:02:23 -07001506
1507 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1508 "mId", "I");
1509
1510 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1511 "mName", "Ljava/lang/String;");
1512
1513 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1514 "mSources", "I");
1515
1516 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1517 "mKeyboardType", "I");
1518
Jeff Brown57c59372010-09-21 18:22:55 -07001519 // Configuration
1520
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001521 FIND_CLASS(clazz, "android/content/res/Configuration");
Jeff Brown57c59372010-09-21 18:22:55 -07001522
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001523 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001524 "touchscreen", "I");
1525
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001526 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001527 "keyboard", "I");
1528
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001529 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001530 "navigation", "I");
1531
Jeff Brown46b9ac02010-04-22 18:58:52 -07001532 return 0;
1533}
1534
Jeff Brown46b9ac02010-04-22 18:58:52 -07001535} /* namespace android */