blob: 37950745d9f2413828379eafc1bf866331000a0f [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 Brown9f25b7f2012-04-10 14:30:49 -070042#include <android_view_InputDevice.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080043#include <android_view_KeyEvent.h>
44#include <android_view_MotionEvent.h>
45#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070046#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080047#include <android/graphics/GraphicsJNI.h>
48
Jeff Brown00fa7bd2010-07-02 15:37:36 -070049#include "com_android_server_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070050#include "com_android_server_input_InputApplicationHandle.h"
51#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070052
53namespace android {
54
Jeff Brown1a84fd12011-06-02 01:26:32 -070055// The exponent used to calculate the pointer speed scaling factor.
56// The scaling factor is calculated as 2 ^ (speed * exponent),
57// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070058static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070059
Jeff Brown46b9ac02010-04-22 18:58:52 -070060static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070061 jmethodID notifyConfigurationChanged;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070062 jmethodID notifyInputDevicesChanged;
Jeff Brown46b9ac02010-04-22 18:58:52 -070063 jmethodID notifyLidSwitchChanged;
Jeff Brown7fbdc842010-06-17 20:52:56 -070064 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070065 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070066 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070067 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080068 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070069 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070070 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070071 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080072 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070073 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080074 jmethodID getKeyRepeatTimeout;
75 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070076 jmethodID getHoverTapTimeout;
77 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070078 jmethodID getDoubleTapTimeout;
79 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080080 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080081 jmethodID getPointerIcon;
Jeff Brown4532e612012-04-05 14:27:12 -070082} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070083
84static struct {
85 jclass clazz;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070086} gInputDeviceClassInfo;
87
88static struct {
89 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070090} gKeyEventClassInfo;
91
92static struct {
93 jclass clazz;
94} gMotionEventClassInfo;
95
Jeff Brown8d608662010-08-30 03:02:23 -070096static struct {
Jeff Brown57c59372010-09-21 18:22:55 -070097 jfieldID touchscreen;
98 jfieldID keyboard;
99 jfieldID navigation;
100} gConfigurationClassInfo;
101
Jeff Brown928e0542011-01-10 11:17:36 -0800102
103// --- Global functions ---
104
Jeff Brown214eaf42011-05-26 19:17:02 -0700105template<typename T>
106inline static T min(const T& a, const T& b) {
107 return a < b ? a : b;
108}
109
110template<typename T>
111inline static T max(const T& a, const T& b) {
112 return a > b ? a : b;
113}
114
Jeff Brown928e0542011-01-10 11:17:36 -0800115static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
116 const sp<InputApplicationHandle>& inputApplicationHandle) {
117 if (inputApplicationHandle == NULL) {
118 return NULL;
119 }
120 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
121 getInputApplicationHandleObjLocalRef(env);
122}
123
124static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
125 const sp<InputWindowHandle>& inputWindowHandle) {
126 if (inputWindowHandle == NULL) {
127 return NULL;
128 }
129 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
130 getInputWindowHandleObjLocalRef(env);
131}
132
Jeff Brown2352b972011-04-12 22:39:53 -0700133static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
134 SpriteIcon* outSpriteIcon) {
135 PointerIcon pointerIcon;
136 status_t status = android_view_PointerIcon_loadSystemIcon(env,
137 contextObj, style, &pointerIcon);
138 if (!status) {
139 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
140 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
141 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
142 }
143}
144
Jeff Brown905805a2011-10-12 13:57:59 -0700145enum {
146 WM_ACTION_PASS_TO_USER = 1,
147 WM_ACTION_POKE_USER_ACTIVITY = 2,
148 WM_ACTION_GO_TO_SLEEP = 4,
149};
150
Jeff Brown928e0542011-01-10 11:17:36 -0800151
152// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800153
Jeff Brown9c3cda02010-06-15 01:31:58 -0700154class NativeInputManager : public virtual RefBase,
155 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700156 public virtual InputDispatcherPolicyInterface,
157 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700158protected:
159 virtual ~NativeInputManager();
160
161public:
Jeff Brown4532e612012-04-05 14:27:12 -0700162 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700163
164 inline sp<InputManager> getInputManager() const { return mInputManager; }
165
Jeff Brownb88102f2010-09-08 11:49:43 -0700166 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700167
Jeff Brownbc68a592011-07-25 12:58:12 -0700168 void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
169 int32_t externalWidth, int32_t externalHeight);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700170 void setDisplayOrientation(int32_t displayId, int32_t orientation);
171
Jeff Brown7fbdc842010-06-17 20:52:56 -0700172 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800173 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700174 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
175
Jeff Brown9302c872011-07-13 22:51:29 -0700176 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
177 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700178 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800179 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700180 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700181 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700182
Jeff Brown9c3cda02010-06-15 01:31:58 -0700183 /* --- InputReaderPolicyInterface implementation --- */
184
Jeff Brown214eaf42011-05-26 19:17:02 -0700185 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800186 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700187 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
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 Brown905805a2011-10-12 13:57:59 -0700202 virtual nsecs_t interceptKeyBeforeDispatching(
203 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700204 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800205 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800206 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700207 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700208 virtual bool checkInjectEventsPermissionNonReentrant(
209 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700210
Jeff Brown2352b972011-04-12 22:39:53 -0700211 /* --- PointerControllerPolicyInterface implementation --- */
212
213 virtual void loadPointerResources(PointerResources* outResources);
214
Jeff Brown9c3cda02010-06-15 01:31:58 -0700215private:
216 sp<InputManager> mInputManager;
217
Jeff Brown2352b972011-04-12 22:39:53 -0700218 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700219 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800220 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700221
Jeff Brown83c09682010-12-23 17:50:18 -0800222 Mutex mLock;
223 struct Locked {
224 // Display size information.
Jeff Brownbc68a592011-07-25 12:58:12 -0700225 int32_t displayWidth, displayHeight; // -1 when not initialized
226 int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
Jeff Brown83c09682010-12-23 17:50:18 -0800227 int32_t displayOrientation;
228
Jeff Brown05dc66a2011-03-02 14:41:58 -0800229 // System UI visibility.
230 int32_t systemUiVisibility;
231
Jeff Brown1a84fd12011-06-02 01:26:32 -0700232 // Pointer speed.
233 int32_t pointerSpeed;
234
Jeff Brown474dcb52011-06-14 20:22:50 -0700235 // True if pointer gestures are enabled.
236 bool pointerGesturesEnabled;
237
Jeff Browndaf4a122011-08-26 17:14:14 -0700238 // Show touches feature enable/disable.
239 bool showTouches;
240
Jeff Brown5541de92011-04-11 11:54:25 -0700241 // Sprite controller singleton, created on first use.
242 sp<SpriteController> spriteController;
243
Jeff Brown83c09682010-12-23 17:50:18 -0800244 // Pointer controller singleton, created and destroyed as needed.
245 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800246 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700247
Jeff Brown2352b972011-04-12 22:39:53 -0700248 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800249 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700250 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800251
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700252 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700253 bool isScreenOn();
254 bool isScreenBright();
255
Jeff Brownb88102f2010-09-08 11:49:43 -0700256 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700257
Jeff Brown9c3cda02010-06-15 01:31:58 -0700258 static inline JNIEnv* jniEnv() {
259 return AndroidRuntime::getJNIEnv();
260 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700261};
262
Jeff Brown928e0542011-01-10 11:17:36 -0800263
Jeff Brown9c3cda02010-06-15 01:31:58 -0700264
Jeff Brown2352b972011-04-12 22:39:53 -0700265NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700266 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700267 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700268 JNIEnv* env = jniEnv();
269
Jeff Brown2352b972011-04-12 22:39:53 -0700270 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700271 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700272
Jeff Brown83c09682010-12-23 17:50:18 -0800273 {
274 AutoMutex _l(mLock);
275 mLocked.displayWidth = -1;
276 mLocked.displayHeight = -1;
Jeff Brownbc68a592011-07-25 12:58:12 -0700277 mLocked.displayExternalWidth = -1;
278 mLocked.displayExternalHeight = -1;
Jeff Brown65fd2512011-08-18 11:20:58 -0700279 mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800280
281 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700282 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700283 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700284 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800285 }
286
Jeff Brown9c3cda02010-06-15 01:31:58 -0700287 sp<EventHub> eventHub = new EventHub();
288 mInputManager = new InputManager(eventHub, this, this);
289}
290
291NativeInputManager::~NativeInputManager() {
292 JNIEnv* env = jniEnv();
293
Jeff Brown2352b972011-04-12 22:39:53 -0700294 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700295 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700296}
297
Jeff Brownb88102f2010-09-08 11:49:43 -0700298void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700299 mInputManager->getReader()->dump(dump);
300 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700301
Jeff Brownb88102f2010-09-08 11:49:43 -0700302 mInputManager->getDispatcher()->dump(dump);
303 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700304}
305
Jeff Brown7fbdc842010-06-17 20:52:56 -0700306bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700307 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000308 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700309 LOGE_EX(env);
310 env->ExceptionClear();
311 return true;
312 }
313 return false;
314}
315
Jeff Brownbc68a592011-07-25 12:58:12 -0700316void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
317 int32_t externalWidth, int32_t externalHeight) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700318 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700319 if (displayId == 0) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700320 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700321
Jeff Brown65fd2512011-08-18 11:20:58 -0700322 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
323 changed = true;
324 mLocked.displayWidth = width;
325 mLocked.displayHeight = height;
Jeff Brownbc68a592011-07-25 12:58:12 -0700326
Jeff Brown65fd2512011-08-18 11:20:58 -0700327 sp<PointerController> controller = mLocked.pointerController.promote();
328 if (controller != NULL) {
329 controller->setDisplaySize(width, height);
Jeff Brown2352b972011-04-12 22:39:53 -0700330 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700331 }
Jeff Brown2352b972011-04-12 22:39:53 -0700332
Jeff Brown65fd2512011-08-18 11:20:58 -0700333 if (mLocked.displayExternalWidth != externalWidth
334 || mLocked.displayExternalHeight != externalHeight) {
335 changed = true;
Jeff Brownbc68a592011-07-25 12:58:12 -0700336 mLocked.displayExternalWidth = externalWidth;
337 mLocked.displayExternalHeight = externalHeight;
Jeff Brown65fd2512011-08-18 11:20:58 -0700338 }
339 }
340
341 if (changed) {
342 mInputManager->getReader()->requestRefreshConfiguration(
343 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700344 }
345}
346
347void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700348 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700349 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800350 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700351
Jeff Brown83c09682010-12-23 17:50:18 -0800352 if (mLocked.displayOrientation != orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700353 changed = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800354 mLocked.displayOrientation = orientation;
355
356 sp<PointerController> controller = mLocked.pointerController.promote();
357 if (controller != NULL) {
358 controller->setDisplayOrientation(orientation);
359 }
360 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700361 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700362
363 if (changed) {
364 mInputManager->getReader()->requestRefreshConfiguration(
365 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
366 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700367}
368
Jeff Brown7fbdc842010-06-17 20:52:56 -0700369status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800370 const sp<InputChannel>& inputChannel,
371 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
372 return mInputManager->getDispatcher()->registerInputChannel(
373 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700374}
375
376status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
377 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700378 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700379}
380
Jeff Brown214eaf42011-05-26 19:17:02 -0700381void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700382 JNIEnv* env = jniEnv();
383
Jeff Brown4532e612012-04-05 14:27:12 -0700384 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
385 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700386 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
387 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
388 }
389
390 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700391 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
392 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700393 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
394 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700395 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700396 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700397 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700398 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700399 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700400 env->DeleteLocalRef(item);
401 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700402 env->DeleteLocalRef(excludedDeviceNames);
403 }
404
Jeff Brown4532e612012-04-05 14:27:12 -0700405 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
406 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700407 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700408 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
409 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700410 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700411 jint longPressTimeout = env->CallIntMethod(mServiceObj,
412 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700413 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700414 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700415
416 // We must ensure that the tap-drag interval is significantly shorter than
417 // the long-press timeout because the tap is held down for the entire duration
418 // of the double-tap timeout.
419 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700420 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700421 outConfig->pointerGestureTapDragInterval =
422 milliseconds_to_nanoseconds(tapDragInterval);
423 }
424 }
425 }
426
Jeff Brown4532e612012-04-05 14:27:12 -0700427 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
428 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700429 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
430 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700431 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700432
433 { // acquire lock
434 AutoMutex _l(mLock);
435
436 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
437 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700438 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700439
Jeff Browndaf4a122011-08-26 17:14:14 -0700440 outConfig->showTouches = mLocked.showTouches;
441
Jeff Brown65fd2512011-08-18 11:20:58 -0700442 outConfig->setDisplayInfo(0, false /*external*/,
443 mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
444 outConfig->setDisplayInfo(0, true /*external*/,
445 mLocked.displayExternalWidth, mLocked.displayExternalHeight,
446 mLocked.displayOrientation);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700447 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700448}
449
Jeff Brown83c09682010-12-23 17:50:18 -0800450sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
451 AutoMutex _l(mLock);
452
453 sp<PointerController> controller = mLocked.pointerController.promote();
454 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700455 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800456
Jeff Brown2352b972011-04-12 22:39:53 -0700457 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800458 mLocked.pointerController = controller;
459
460 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
461 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800462
Jeff Brown5541de92011-04-11 11:54:25 -0700463 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700464 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
465 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700466 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
467 PointerIcon pointerIcon;
468 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
469 mContextObj, &pointerIcon);
470 if (!status && !pointerIcon.isNullIcon()) {
471 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
472 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
473 } else {
474 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800475 }
Jeff Brown2352b972011-04-12 22:39:53 -0700476 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800477 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800478
Jeff Brown2352b972011-04-12 22:39:53 -0700479 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800480 }
481 return controller;
482}
483
Jeff Brown5541de92011-04-11 11:54:25 -0700484void NativeInputManager::ensureSpriteControllerLocked() {
485 if (mLocked.spriteController == NULL) {
486 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700487 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700488 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
489 layer = -1;
490 }
491 mLocked.spriteController = new SpriteController(mLooper, layer);
492 }
493}
494
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700495void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
496 JNIEnv* env = jniEnv();
497
498 size_t count = inputDevices.size();
499 jobjectArray inputDevicesObjArray = env->NewObjectArray(
500 count, gInputDeviceClassInfo.clazz, NULL);
501 if (inputDevicesObjArray) {
502 bool error = false;
503 for (size_t i = 0; i < count; i++) {
504 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
505 if (!inputDeviceObj) {
506 error = true;
507 break;
508 }
509
510 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
511 env->DeleteLocalRef(inputDeviceObj);
512 }
513
514 if (!error) {
515 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
516 inputDevicesObjArray);
517 }
518
519 env->DeleteLocalRef(inputDevicesObjArray);
520 }
521
522 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
523}
524
Jeff Browne20c9e02010-10-11 14:20:19 -0700525void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
526 int32_t switchValue, uint32_t policyFlags) {
527#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000528 ALOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
Jeff Browne20c9e02010-10-11 14:20:19 -0700529 when, switchCode, switchValue, policyFlags);
530#endif
531
532 JNIEnv* env = jniEnv();
533
534 switch (switchCode) {
535 case SW_LID:
Jeff Brown27fd3422012-04-09 11:05:16 -0700536 // When switch value is set indicates lid is closed.
Jeff Brown4532e612012-04-05 14:27:12 -0700537 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyLidSwitchChanged,
Jeff Brown27fd3422012-04-09 11:05:16 -0700538 when, switchValue == 0 /*lidOpen*/);
Jeff Browne20c9e02010-10-11 14:20:19 -0700539 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
540 break;
541 }
542}
543
Jeff Brown9c3cda02010-06-15 01:31:58 -0700544void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
545#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000546 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700547#endif
548
549 JNIEnv* env = jniEnv();
550
Jeff Brown4532e612012-04-05 14:27:12 -0700551 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700552 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700553}
554
Jeff Brown519e0242010-09-15 15:18:56 -0700555nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800556 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700557#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000558 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700559#endif
560
561 JNIEnv* env = jniEnv();
562
Jeff Brown928e0542011-01-10 11:17:36 -0800563 jobject inputApplicationHandleObj =
564 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
565 jobject inputWindowHandleObj =
566 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700567
Jeff Brown4532e612012-04-05 14:27:12 -0700568 jlong newTimeout = env->CallLongMethod(mServiceObj,
569 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700570 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
571 newTimeout = 0; // abort dispatch
572 } else {
573 assert(newTimeout >= 0);
574 }
575
Jeff Brown928e0542011-01-10 11:17:36 -0800576 env->DeleteLocalRef(inputWindowHandleObj);
577 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700578 return newTimeout;
579}
580
Jeff Brown928e0542011-01-10 11:17:36 -0800581void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700582#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000583 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700584#endif
585
Jeff Brown7fbdc842010-06-17 20:52:56 -0700586 JNIEnv* env = jniEnv();
587
Jeff Brown928e0542011-01-10 11:17:36 -0800588 jobject inputWindowHandleObj =
589 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
590 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700591 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800592 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700593 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
594
Jeff Brown928e0542011-01-10 11:17:36 -0800595 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700596 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700597}
598
Jeff Brown214eaf42011-05-26 19:17:02 -0700599void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
600 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800601
Jeff Brown4532e612012-04-05 14:27:12 -0700602 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
603 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700604 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
605 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
606 }
Jeff Browna4547672011-03-02 21:38:11 -0800607
Jeff Brown4532e612012-04-05 14:27:12 -0700608 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
609 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700610 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
611 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
612 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700613}
614
Jeff Brown214eaf42011-05-26 19:17:02 -0700615bool NativeInputManager::isKeyRepeatEnabled() {
616 // Only enable automatic key repeating when the screen is on.
617 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700618}
619
Jeff Brown9302c872011-07-13 22:51:29 -0700620void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
621 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700622
Jeff Brown9302c872011-07-13 22:51:29 -0700623 if (windowHandleObjArray) {
624 jsize length = env->GetArrayLength(windowHandleObjArray);
625 for (jsize i = 0; i < length; i++) {
626 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
627 if (! windowHandleObj) {
628 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700629 }
Jeff Brown9302c872011-07-13 22:51:29 -0700630
631 sp<InputWindowHandle> windowHandle =
632 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
633 if (windowHandle != NULL) {
634 windowHandles.push(windowHandle);
635 }
636 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700637 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700638 }
Jeff Brown349703e2010-06-22 01:27:15 -0700639
Jeff Brown9302c872011-07-13 22:51:29 -0700640 mInputManager->getDispatcher()->setInputWindows(windowHandles);
641
642 // Do this after the dispatcher has updated the window handle state.
643 bool newPointerGesturesEnabled = true;
644 size_t numWindows = windowHandles.size();
645 for (size_t i = 0; i < numWindows; i++) {
646 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700647 const InputWindowInfo* windowInfo = windowHandle->getInfo();
648 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
649 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700650 newPointerGesturesEnabled = false;
651 }
652 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700653
654 uint32_t changes = 0;
655 { // acquire lock
656 AutoMutex _l(mLock);
657
658 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
659 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
660 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
661 }
662 } // release lock
663
664 if (changes) {
665 mInputManager->getReader()->requestRefreshConfiguration(changes);
666 }
Jeff Brown349703e2010-06-22 01:27:15 -0700667}
668
Jeff Brown9302c872011-07-13 22:51:29 -0700669void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
670 sp<InputApplicationHandle> applicationHandle =
671 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
672 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700673}
674
675void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700676 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700677}
678
Jeff Brown05dc66a2011-03-02 14:41:58 -0800679void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
680 AutoMutex _l(mLock);
681
682 if (mLocked.systemUiVisibility != visibility) {
683 mLocked.systemUiVisibility = visibility;
684
685 sp<PointerController> controller = mLocked.pointerController.promote();
686 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700687 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800688 }
689 }
690}
691
Jeff Brown2352b972011-04-12 22:39:53 -0700692void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800693 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700694 controller->setInactivityTimeout(lightsOut
695 ? PointerController::INACTIVITY_TIMEOUT_SHORT
696 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800697}
698
Jeff Brown1a84fd12011-06-02 01:26:32 -0700699void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700700 { // acquire lock
701 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700702
Jeff Brown474dcb52011-06-14 20:22:50 -0700703 if (mLocked.pointerSpeed == speed) {
704 return;
705 }
706
Steve Block6215d3f2012-01-04 20:05:49 +0000707 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700708 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700709 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700710
Jeff Brown474dcb52011-06-14 20:22:50 -0700711 mInputManager->getReader()->requestRefreshConfiguration(
712 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700713}
714
Jeff Browndaf4a122011-08-26 17:14:14 -0700715void NativeInputManager::setShowTouches(bool enabled) {
716 { // acquire lock
717 AutoMutex _l(mLock);
718
719 if (mLocked.showTouches == enabled) {
720 return;
721 }
722
Steve Block6215d3f2012-01-04 20:05:49 +0000723 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700724 mLocked.showTouches = enabled;
725 } // release lock
726
727 mInputManager->getReader()->requestRefreshConfiguration(
728 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
729}
730
Jeff Browne20c9e02010-10-11 14:20:19 -0700731bool NativeInputManager::isScreenOn() {
732 return android_server_PowerManagerService_isScreenOn();
733}
734
735bool NativeInputManager::isScreenBright() {
736 return android_server_PowerManagerService_isScreenBright();
737}
738
Jeff Brown0029c662011-03-30 02:25:18 -0700739bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
740 jobject inputEventObj;
741
742 JNIEnv* env = jniEnv();
743 switch (inputEvent->getType()) {
744 case AINPUT_EVENT_TYPE_KEY:
745 inputEventObj = android_view_KeyEvent_fromNative(env,
746 static_cast<const KeyEvent*>(inputEvent));
747 break;
748 case AINPUT_EVENT_TYPE_MOTION:
749 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
750 static_cast<const MotionEvent*>(inputEvent));
751 break;
752 default:
753 return true; // dispatch the event normally
754 }
755
756 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000757 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700758 return true; // dispatch the event normally
759 }
760
761 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700762 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700763 inputEventObj, policyFlags);
764 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
765 pass = true;
766 }
767 env->DeleteLocalRef(inputEventObj);
768 return pass;
769}
770
Jeff Brown1f245102010-11-18 20:53:46 -0800771void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
772 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700773 // Policy:
774 // - Ignore untrusted events and pass them along.
775 // - Ask the window manager what to do with normal events and trusted injected events.
776 // - For normal events wake and brighten the screen if currently off or dim.
777 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800778 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700779 bool isScreenOn = this->isScreenOn();
780 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700781
Jeff Brown3122e442010-10-11 23:32:49 -0700782 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800783 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
784 jint wmActions;
785 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700786 wmActions = env->CallIntMethod(mServiceObj,
787 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800788 keyEventObj, policyFlags, isScreenOn);
789 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
790 wmActions = 0;
791 }
792 android_view_KeyEvent_recycle(env, keyEventObj);
793 env->DeleteLocalRef(keyEventObj);
794 } else {
Steve Block3762c312012-01-06 19:20:56 +0000795 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700796 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700797 }
798
Jeff Brown1f245102010-11-18 20:53:46 -0800799 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700800 if (!isScreenOn) {
801 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700802 }
803
804 if (!isScreenBright) {
805 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
806 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700807 }
808
Jeff Brown56194eb2011-03-02 19:23:13 -0800809 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700810 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700811 policyFlags |= POLICY_FLAG_PASS_TO_USER;
812 }
813}
814
Jeff Brown56194eb2011-03-02 19:23:13 -0800815void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700816 // Policy:
817 // - Ignore untrusted events and pass them along.
818 // - No special filtering for injected events required at this time.
819 // - Filter normal events based on screen state.
820 // - For normal events brighten (but do not wake) the screen if currently dim.
821 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
822 if (isScreenOn()) {
823 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700824
Jeff Brown3122e442010-10-11 23:32:49 -0700825 if (!isScreenBright()) {
826 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
827 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800828 } else {
829 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700830 jint wmActions = env->CallIntMethod(mServiceObj,
831 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800832 policyFlags);
833 if (checkAndClearExceptionFromCallback(env,
834 "interceptMotionBeforeQueueingWhenScreenOff")) {
835 wmActions = 0;
836 }
837
838 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
839 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700840 }
Jeff Brown3122e442010-10-11 23:32:49 -0700841 } else {
842 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700843 }
844}
845
Jeff Brown56194eb2011-03-02 19:23:13 -0800846void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
847 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800848 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800849#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000850 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800851#endif
852 android_server_PowerManagerService_goToSleep(when);
853 }
854
855 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800856#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000857 ALOGD("handleInterceptActions: Poking user activity.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800858#endif
859 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
860 }
861
862 if (wmActions & WM_ACTION_PASS_TO_USER) {
863 policyFlags |= POLICY_FLAG_PASS_TO_USER;
864 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800865#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000866 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800867#endif
868 }
869}
870
Jeff Brown905805a2011-10-12 13:57:59 -0700871nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800872 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700873 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700874 // Policy:
875 // - Ignore untrusted events and pass them along.
876 // - Filter normal events and trusted injected events through the window manager policy to
877 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700878 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700879 if (policyFlags & POLICY_FLAG_TRUSTED) {
880 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700881
Jeff Brown928e0542011-01-10 11:17:36 -0800882 // Note: inputWindowHandle may be null.
883 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800884 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
885 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700886 jlong delayMillis = env->CallLongMethod(mServiceObj,
887 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800888 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800889 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
890 android_view_KeyEvent_recycle(env, keyEventObj);
891 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700892 if (!error) {
893 if (delayMillis < 0) {
894 result = -1;
895 } else if (delayMillis > 0) {
896 result = milliseconds_to_nanoseconds(delayMillis);
897 }
898 }
Jeff Brown1f245102010-11-18 20:53:46 -0800899 } else {
Steve Block3762c312012-01-06 19:20:56 +0000900 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800901 }
Jeff Brown928e0542011-01-10 11:17:36 -0800902 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700903 }
Jeff Brown1f245102010-11-18 20:53:46 -0800904 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700905}
906
Jeff Brown928e0542011-01-10 11:17:36 -0800907bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800908 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700909 // Policy:
910 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800911 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700912 if (policyFlags & POLICY_FLAG_TRUSTED) {
913 JNIEnv* env = jniEnv();
914
Jeff Brown928e0542011-01-10 11:17:36 -0800915 // Note: inputWindowHandle may be null.
916 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800917 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
918 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700919 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
920 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800921 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700922 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
923 fallbackKeyEventObj = NULL;
924 }
Jeff Brown1f245102010-11-18 20:53:46 -0800925 android_view_KeyEvent_recycle(env, keyEventObj);
926 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800927
928 if (fallbackKeyEventObj) {
929 // Note: outFallbackKeyEvent may be the same object as keyEvent.
930 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
931 outFallbackKeyEvent)) {
932 result = true;
933 }
934 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
935 env->DeleteLocalRef(fallbackKeyEventObj);
936 }
Jeff Brown1f245102010-11-18 20:53:46 -0800937 } else {
Steve Block3762c312012-01-06 19:20:56 +0000938 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800939 }
Jeff Brown928e0542011-01-10 11:17:36 -0800940 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700941 }
Jeff Brown1f245102010-11-18 20:53:46 -0800942 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700943}
944
Jeff Brown01ce2e92010-09-26 22:20:12 -0700945void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
946 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700947}
948
Jeff Brown349703e2010-06-22 01:27:15 -0700949
Jeff Brownb88102f2010-09-08 11:49:43 -0700950bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
951 int32_t injectorPid, int32_t injectorUid) {
952 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700953 jboolean result = env->CallBooleanMethod(mServiceObj,
954 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700955 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
956 result = false;
957 }
Jeff Brown349703e2010-06-22 01:27:15 -0700958 return result;
959}
960
Jeff Brown2352b972011-04-12 22:39:53 -0700961void NativeInputManager::loadPointerResources(PointerResources* outResources) {
962 JNIEnv* env = jniEnv();
963
964 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
965 &outResources->spotHover);
966 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
967 &outResources->spotTouch);
968 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
969 &outResources->spotAnchor);
970}
971
Jeff Brown83c09682010-12-23 17:50:18 -0800972
Jeff Brown9c3cda02010-06-15 01:31:58 -0700973// ----------------------------------------------------------------------------
974
Jeff Brown4532e612012-04-05 14:27:12 -0700975static jint nativeInit(JNIEnv* env, jclass clazz,
976 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -0700977 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
978 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
979 messageQueue->getLooper());
Jeff Brown4532e612012-04-05 14:27:12 -0700980 im->incStrong(serviceObj);
981 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700982}
983
Jeff Brown4532e612012-04-05 14:27:12 -0700984static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
985 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700986
Jeff Brown4532e612012-04-05 14:27:12 -0700987 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700988 if (result) {
989 jniThrowRuntimeException(env, "Input manager could not be started.");
990 }
991}
992
Jeff Brown4532e612012-04-05 14:27:12 -0700993static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, jint ptr,
Jeff Brownbc68a592011-07-25 12:58:12 -0700994 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -0700995 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700996
997 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
998 // to be passed in like this, not sure which is better but leaving it like this
999 // keeps the window manager in direct control of when display transitions propagate down
1000 // to the input dispatcher
Jeff Brown4532e612012-04-05 14:27:12 -07001001 im->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001002}
1003
Jeff Brown4532e612012-04-05 14:27:12 -07001004static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
1005 jint ptr, jint displayId, jint orientation) {
1006 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001007
Jeff Brown4532e612012-04-05 14:27:12 -07001008 im->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001009}
1010
Jeff Brown4532e612012-04-05 14:27:12 -07001011static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
1012 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
1013 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001014
Jeff Brown4532e612012-04-05 14:27:12 -07001015 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001016 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001017}
1018
Jeff Brown4532e612012-04-05 14:27:12 -07001019static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
1020 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
1021 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001022
Jeff Brown4532e612012-04-05 14:27:12 -07001023 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001024 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001025}
1026
Jeff Brown4532e612012-04-05 14:27:12 -07001027static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1028 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1029 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001030
Jeff Brown4532e612012-04-05 14:27:12 -07001031 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001032 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001033}
1034
Jeff Brown4532e612012-04-05 14:27:12 -07001035static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1036 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1037 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001038
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 Brown4532e612012-04-05 14:27:12 -07001044 result = im->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
Jeff Brown4532e612012-04-05 14:27:12 -07001060static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001061 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001062 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1063
Steve Block8564c8d2012-01-05 23:22:43 +00001064 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001065 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001066 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001067}
1068
Jeff Brown4532e612012-04-05 14:27:12 -07001069static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1070 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1071 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001072
1073 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1074 inputChannelObj);
1075 if (inputChannel == NULL) {
1076 throwInputChannelNotInitialized(env);
1077 return;
1078 }
1079
Jeff Brown928e0542011-01-10 11:17:36 -08001080 sp<InputWindowHandle> inputWindowHandle =
1081 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001082
Jeff Brown4532e612012-04-05 14:27:12 -07001083 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001084 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001085 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001086 String8 message;
1087 message.appendFormat("Failed to register input channel. status=%d", status);
1088 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001089 return;
1090 }
1091
Jeff Browna41ca772010-08-11 14:46:32 -07001092 if (! monitor) {
1093 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001094 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001095 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001096}
1097
Jeff Brown4532e612012-04-05 14:27:12 -07001098static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1099 jint ptr, jobject inputChannelObj) {
1100 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001101
1102 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1103 inputChannelObj);
1104 if (inputChannel == NULL) {
1105 throwInputChannelNotInitialized(env);
1106 return;
1107 }
1108
1109 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1110
Jeff Brown4532e612012-04-05 14:27:12 -07001111 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001112 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1113 String8 message;
1114 message.appendFormat("Failed to unregister input channel. status=%d", status);
1115 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001116 }
1117}
1118
Jeff Brown4532e612012-04-05 14:27:12 -07001119static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1120 jint ptr, jboolean enabled) {
1121 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001122
Jeff Brown4532e612012-04-05 14:27:12 -07001123 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001124}
1125
Jeff Brown4532e612012-04-05 14:27:12 -07001126static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1127 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001128 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001129 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001130
Jeff Brown6ec402b2010-07-28 15:48:59 -07001131 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1132 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001133 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1134 if (status) {
1135 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1136 return INPUT_EVENT_INJECTION_FAILED;
1137 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001138
Jeff Brown4532e612012-04-05 14:27:12 -07001139 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001140 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1141 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001142 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001143 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1144 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001145 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1146 return INPUT_EVENT_INJECTION_FAILED;
1147 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001148
Jeff Brown4532e612012-04-05 14:27:12 -07001149 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001150 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1151 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001152 } else {
1153 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001154 return INPUT_EVENT_INJECTION_FAILED;
1155 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001156}
1157
Jeff Brown4532e612012-04-05 14:27:12 -07001158static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1159 jint ptr, jobjectArray windowHandleObjArray) {
1160 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001161
Jeff Brown4532e612012-04-05 14:27:12 -07001162 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001163}
1164
Jeff Brown4532e612012-04-05 14:27:12 -07001165static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1166 jint ptr, jobject applicationHandleObj) {
1167 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001168
Jeff Brown4532e612012-04-05 14:27:12 -07001169 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001170}
1171
Jeff Brown4532e612012-04-05 14:27:12 -07001172static void nativeSetInputDispatchMode(JNIEnv* env,
1173 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1174 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001175
Jeff Brown4532e612012-04-05 14:27:12 -07001176 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001177}
1178
Jeff Brown4532e612012-04-05 14:27:12 -07001179static void nativeSetSystemUiVisibility(JNIEnv* env,
1180 jclass clazz, jint ptr, jint visibility) {
1181 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001182
Jeff Brown4532e612012-04-05 14:27:12 -07001183 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001184}
1185
Jeff Brown4532e612012-04-05 14:27:12 -07001186static void nativeGetInputConfiguration(JNIEnv* env,
1187 jclass clazz, jint ptr, jobject configObj) {
1188 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown57c59372010-09-21 18:22:55 -07001189
1190 InputConfiguration config;
Jeff Brown4532e612012-04-05 14:27:12 -07001191 im->getInputManager()->getReader()->getInputConfiguration(& config);
Jeff Brown57c59372010-09-21 18:22:55 -07001192
1193 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1194 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1195 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1196}
1197
Jeff Brown4532e612012-04-05 14:27:12 -07001198static jboolean nativeTransferTouchFocus(JNIEnv* env,
1199 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1200 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001201
1202 sp<InputChannel> fromChannel =
1203 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1204 sp<InputChannel> toChannel =
1205 android_view_InputChannel_getInputChannel(env, toChannelObj);
1206
1207 if (fromChannel == NULL || toChannel == NULL) {
1208 return false;
1209 }
1210
Jeff Brown4532e612012-04-05 14:27:12 -07001211 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001212 transferTouchFocus(fromChannel, toChannel);
1213}
1214
Jeff Brown4532e612012-04-05 14:27:12 -07001215static void nativeSetPointerSpeed(JNIEnv* env,
1216 jclass clazz, jint ptr, jint speed) {
1217 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001218
Jeff Brown4532e612012-04-05 14:27:12 -07001219 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001220}
1221
Jeff Brown4532e612012-04-05 14:27:12 -07001222static void nativeSetShowTouches(JNIEnv* env,
1223 jclass clazz, jint ptr, jboolean enabled) {
1224 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001225
Jeff Brown4532e612012-04-05 14:27:12 -07001226 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001227}
1228
Jeff Browna47425a2012-04-13 04:09:27 -07001229static void nativeVibrate(JNIEnv* env,
1230 jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
1231 jint repeat, jint token) {
1232 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1233
1234 size_t patternSize = env->GetArrayLength(patternObj);
1235 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
1236 ALOGI("Skipped requested vibration because the pattern size is %d "
1237 "which is more than the maximum supported size of %d.",
1238 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1239 return; // limit to reasonable size
1240 }
1241
1242 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1243 patternObj, NULL));
1244 nsecs_t pattern[patternSize];
1245 for (size_t i = 0; i < patternSize; i++) {
1246 pattern[i] = max(jlong(0), min(patternMillis[i],
1247 MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
1248 }
1249 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1250
1251 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1252}
1253
1254static void nativeCancelVibrate(JNIEnv* env,
1255 jclass clazz, jint ptr, jint deviceId, jint token) {
1256 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1257
1258 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1259}
1260
Jeff Brown4532e612012-04-05 14:27:12 -07001261static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1262 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001263
Jeff Brownb88102f2010-09-08 11:49:43 -07001264 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001265 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001266 return env->NewStringUTF(dump.string());
1267}
1268
Jeff Brown4532e612012-04-05 14:27:12 -07001269static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1270 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001271
Jeff Brown4532e612012-04-05 14:27:12 -07001272 im->getInputManager()->getReader()->monitor();
1273 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001274}
1275
Jeff Brown9c3cda02010-06-15 01:31:58 -07001276// ----------------------------------------------------------------------------
1277
Jeff Brown46b9ac02010-04-22 18:58:52 -07001278static JNINativeMethod gInputManagerMethods[] = {
1279 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001280 { "nativeInit",
1281 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1282 (void*) nativeInit },
1283 { "nativeStart", "(I)V",
1284 (void*) nativeStart },
1285 { "nativeSetDisplaySize", "(IIIIII)V",
1286 (void*) nativeSetDisplaySize },
1287 { "nativeSetDisplayOrientation", "(III)V",
1288 (void*) nativeSetDisplayOrientation },
1289 { "nativeGetScanCodeState", "(IIII)I",
1290 (void*) nativeGetScanCodeState },
1291 { "nativeGetKeyCodeState", "(IIII)I",
1292 (void*) nativeGetKeyCodeState },
1293 { "nativeGetSwitchState", "(IIII)I",
1294 (void*) nativeGetSwitchState },
1295 { "nativeHasKeys", "(III[I[Z)Z",
1296 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001297 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001298 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1299 (void*) nativeRegisterInputChannel },
1300 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1301 (void*) nativeUnregisterInputChannel },
1302 { "nativeSetInputFilterEnabled", "(IZ)V",
1303 (void*) nativeSetInputFilterEnabled },
1304 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1305 (void*) nativeInjectInputEvent },
1306 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1307 (void*) nativeSetInputWindows },
1308 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1309 (void*) nativeSetFocusedApplication },
1310 { "nativeSetInputDispatchMode", "(IZZ)V",
1311 (void*) nativeSetInputDispatchMode },
1312 { "nativeSetSystemUiVisibility", "(II)V",
1313 (void*) nativeSetSystemUiVisibility },
Jeff Brown4532e612012-04-05 14:27:12 -07001314 { "nativeGetInputConfiguration", "(ILandroid/content/res/Configuration;)V",
1315 (void*) nativeGetInputConfiguration },
1316 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1317 (void*) nativeTransferTouchFocus },
1318 { "nativeSetPointerSpeed", "(II)V",
1319 (void*) nativeSetPointerSpeed },
1320 { "nativeSetShowTouches", "(IZ)V",
1321 (void*) nativeSetShowTouches },
Jeff Browna47425a2012-04-13 04:09:27 -07001322 { "nativeVibrate", "(II[JII)V",
1323 (void*) nativeVibrate },
1324 { "nativeCancelVibrate", "(III)V",
1325 (void*) nativeCancelVibrate },
Jeff Brown4532e612012-04-05 14:27:12 -07001326 { "nativeDump", "(I)Ljava/lang/String;",
1327 (void*) nativeDump },
1328 { "nativeMonitor", "(I)V",
1329 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001330};
1331
1332#define FIND_CLASS(var, className) \
1333 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001334 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001335
1336#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1337 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1338 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1339
1340#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1341 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1342 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1343
1344int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001345 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001346 gInputManagerMethods, NELEM(gInputManagerMethods));
1347 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1348
Jeff Brown9c3cda02010-06-15 01:31:58 -07001349 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001350
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001351 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001352 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001353
Jeff Brown4532e612012-04-05 14:27:12 -07001354 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001355 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001356
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001357 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1358 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1359
Jeff Brown4532e612012-04-05 14:27:12 -07001360 GET_METHOD_ID(gServiceClassInfo.notifyLidSwitchChanged, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001361 "notifyLidSwitchChanged", "(JZ)V");
1362
Jeff Brown4532e612012-04-05 14:27:12 -07001363 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1364 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001365
Jeff Brown4532e612012-04-05 14:27:12 -07001366 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001367 "notifyANR",
Jeff Brown4532e612012-04-05 14:27:12 -07001368 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001369
Jeff Brown4532e612012-04-05 14:27:12 -07001370 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001371 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1372
Jeff Brown4532e612012-04-05 14:27:12 -07001373 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001374 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001375
Jeff Brown4532e612012-04-05 14:27:12 -07001376 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001377 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001378 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1379
Jeff Brown4532e612012-04-05 14:27:12 -07001380 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001381 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001382 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001383
Jeff Brown4532e612012-04-05 14:27:12 -07001384 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001385 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001386 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001387
Jeff Brown4532e612012-04-05 14:27:12 -07001388 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001389 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001390
Jeff Brown4532e612012-04-05 14:27:12 -07001391 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001392 "getVirtualKeyQuietTimeMillis", "()I");
1393
Jeff Brown4532e612012-04-05 14:27:12 -07001394 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001395 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1396
Jeff Brown4532e612012-04-05 14:27:12 -07001397 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001398 "getKeyRepeatTimeout", "()I");
1399
Jeff Brown4532e612012-04-05 14:27:12 -07001400 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001401 "getKeyRepeatDelay", "()I");
1402
Jeff Brown4532e612012-04-05 14:27:12 -07001403 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001404 "getHoverTapTimeout", "()I");
1405
Jeff Brown4532e612012-04-05 14:27:12 -07001406 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001407 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001408
Jeff Brown4532e612012-04-05 14:27:12 -07001409 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001410 "getDoubleTapTimeout", "()I");
1411
Jeff Brown4532e612012-04-05 14:27:12 -07001412 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001413 "getLongPressTimeout", "()I");
1414
Jeff Brown4532e612012-04-05 14:27:12 -07001415 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001416 "getPointerLayer", "()I");
1417
Jeff Brown4532e612012-04-05 14:27:12 -07001418 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001419 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001420
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001421 // InputDevice
1422
1423 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1424 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1425
Jeff Brown6ec402b2010-07-28 15:48:59 -07001426 // KeyEvent
1427
1428 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001429 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1430
Jeff Brown8d608662010-08-30 03:02:23 -07001431 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001432
1433 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001434 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001435
Jeff Brown57c59372010-09-21 18:22:55 -07001436 // Configuration
1437
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001438 FIND_CLASS(clazz, "android/content/res/Configuration");
Jeff Brown57c59372010-09-21 18:22:55 -07001439
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001440 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001441 "touchscreen", "I");
1442
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001443 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001444 "keyboard", "I");
1445
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001446 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001447 "navigation", "I");
1448
Jeff Brown46b9ac02010-04-22 18:58:52 -07001449 return 0;
1450}
1451
Jeff Brown46b9ac02010-04-22 18:58:52 -07001452} /* namespace android */