blob: 85d6e1104b7df746fe56312c70d4bca6ed9db8bb [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;
62 jmethodID notifyLidSwitchChanged;
Jeff Brown7fbdc842010-06-17 20:52:56 -070063 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070064 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070065 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070066 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080067 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070068 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070069 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070070 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080071 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070072 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080073 jmethodID getKeyRepeatTimeout;
74 jmethodID getKeyRepeatDelay;
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 Brown4532e612012-04-05 14:27:12 -070081} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070082
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 {
Jeff Brown57c59372010-09-21 18:22:55 -070092 jfieldID touchscreen;
93 jfieldID keyboard;
94 jfieldID navigation;
95} gConfigurationClassInfo;
96
Jeff Brown928e0542011-01-10 11:17:36 -080097
98// --- Global functions ---
99
Jeff Brown214eaf42011-05-26 19:17:02 -0700100template<typename T>
101inline static T min(const T& a, const T& b) {
102 return a < b ? a : b;
103}
104
105template<typename T>
106inline static T max(const T& a, const T& b) {
107 return a > b ? a : b;
108}
109
Jeff Brown928e0542011-01-10 11:17:36 -0800110static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
111 const sp<InputApplicationHandle>& inputApplicationHandle) {
112 if (inputApplicationHandle == NULL) {
113 return NULL;
114 }
115 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
116 getInputApplicationHandleObjLocalRef(env);
117}
118
119static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
120 const sp<InputWindowHandle>& inputWindowHandle) {
121 if (inputWindowHandle == NULL) {
122 return NULL;
123 }
124 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
125 getInputWindowHandleObjLocalRef(env);
126}
127
Jeff Brown2352b972011-04-12 22:39:53 -0700128static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
129 SpriteIcon* outSpriteIcon) {
130 PointerIcon pointerIcon;
131 status_t status = android_view_PointerIcon_loadSystemIcon(env,
132 contextObj, style, &pointerIcon);
133 if (!status) {
134 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
135 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
136 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
137 }
138}
139
Jeff Brown905805a2011-10-12 13:57:59 -0700140enum {
141 WM_ACTION_PASS_TO_USER = 1,
142 WM_ACTION_POKE_USER_ACTIVITY = 2,
143 WM_ACTION_GO_TO_SLEEP = 4,
144};
145
Jeff Brown928e0542011-01-10 11:17:36 -0800146
147// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800148
Jeff Brown9c3cda02010-06-15 01:31:58 -0700149class NativeInputManager : public virtual RefBase,
150 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700151 public virtual InputDispatcherPolicyInterface,
152 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700153protected:
154 virtual ~NativeInputManager();
155
156public:
Jeff Brown4532e612012-04-05 14:27:12 -0700157 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700158
159 inline sp<InputManager> getInputManager() const { return mInputManager; }
160
Jeff Brownb88102f2010-09-08 11:49:43 -0700161 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700162
Jeff Brownbc68a592011-07-25 12:58:12 -0700163 void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
164 int32_t externalWidth, int32_t externalHeight);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700165 void setDisplayOrientation(int32_t displayId, int32_t orientation);
166
Jeff Brown7fbdc842010-06-17 20:52:56 -0700167 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800168 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700169 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
170
Jeff Brown9302c872011-07-13 22:51:29 -0700171 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
172 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700173 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800174 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700175 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700176 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700177
Jeff Brown9c3cda02010-06-15 01:31:58 -0700178 /* --- InputReaderPolicyInterface implementation --- */
179
Jeff Brown214eaf42011-05-26 19:17:02 -0700180 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800181 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700182
183 /* --- InputDispatcherPolicyInterface implementation --- */
184
Jeff Browne20c9e02010-10-11 14:20:19 -0700185 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
186 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700187 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700188 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800189 const sp<InputWindowHandle>& inputWindowHandle);
190 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700191 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700192 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
193 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800194 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800195 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700196 virtual nsecs_t interceptKeyBeforeDispatching(
197 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700198 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800199 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800200 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700201 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700202 virtual bool checkInjectEventsPermissionNonReentrant(
203 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700204
Jeff Brown2352b972011-04-12 22:39:53 -0700205 /* --- PointerControllerPolicyInterface implementation --- */
206
207 virtual void loadPointerResources(PointerResources* outResources);
208
Jeff Brown9c3cda02010-06-15 01:31:58 -0700209private:
210 sp<InputManager> mInputManager;
211
Jeff Brown2352b972011-04-12 22:39:53 -0700212 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700213 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800214 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700215
Jeff Brown83c09682010-12-23 17:50:18 -0800216 Mutex mLock;
217 struct Locked {
218 // Display size information.
Jeff Brownbc68a592011-07-25 12:58:12 -0700219 int32_t displayWidth, displayHeight; // -1 when not initialized
220 int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
Jeff Brown83c09682010-12-23 17:50:18 -0800221 int32_t displayOrientation;
222
Jeff Brown05dc66a2011-03-02 14:41:58 -0800223 // System UI visibility.
224 int32_t systemUiVisibility;
225
Jeff Brown1a84fd12011-06-02 01:26:32 -0700226 // Pointer speed.
227 int32_t pointerSpeed;
228
Jeff Brown474dcb52011-06-14 20:22:50 -0700229 // True if pointer gestures are enabled.
230 bool pointerGesturesEnabled;
231
Jeff Browndaf4a122011-08-26 17:14:14 -0700232 // Show touches feature enable/disable.
233 bool showTouches;
234
Jeff Brown5541de92011-04-11 11:54:25 -0700235 // Sprite controller singleton, created on first use.
236 sp<SpriteController> spriteController;
237
Jeff Brown83c09682010-12-23 17:50:18 -0800238 // Pointer controller singleton, created and destroyed as needed.
239 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800240 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700241
Jeff Brown2352b972011-04-12 22:39:53 -0700242 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800243 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700244 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800245
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700246 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700247 bool isScreenOn();
248 bool isScreenBright();
249
Jeff Brownb88102f2010-09-08 11:49:43 -0700250 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700251
Jeff Brown9c3cda02010-06-15 01:31:58 -0700252 static inline JNIEnv* jniEnv() {
253 return AndroidRuntime::getJNIEnv();
254 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700255};
256
Jeff Brown928e0542011-01-10 11:17:36 -0800257
Jeff Brown9c3cda02010-06-15 01:31:58 -0700258
Jeff Brown2352b972011-04-12 22:39:53 -0700259NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700260 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700261 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700262 JNIEnv* env = jniEnv();
263
Jeff Brown2352b972011-04-12 22:39:53 -0700264 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700265 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700266
Jeff Brown83c09682010-12-23 17:50:18 -0800267 {
268 AutoMutex _l(mLock);
269 mLocked.displayWidth = -1;
270 mLocked.displayHeight = -1;
Jeff Brownbc68a592011-07-25 12:58:12 -0700271 mLocked.displayExternalWidth = -1;
272 mLocked.displayExternalHeight = -1;
Jeff Brown65fd2512011-08-18 11:20:58 -0700273 mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800274
275 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700276 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700277 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700278 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800279 }
280
Jeff Brown9c3cda02010-06-15 01:31:58 -0700281 sp<EventHub> eventHub = new EventHub();
282 mInputManager = new InputManager(eventHub, this, this);
283}
284
285NativeInputManager::~NativeInputManager() {
286 JNIEnv* env = jniEnv();
287
Jeff Brown2352b972011-04-12 22:39:53 -0700288 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700289 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700290}
291
Jeff Brownb88102f2010-09-08 11:49:43 -0700292void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700293 mInputManager->getReader()->dump(dump);
294 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700295
Jeff Brownb88102f2010-09-08 11:49:43 -0700296 mInputManager->getDispatcher()->dump(dump);
297 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700298}
299
Jeff Brown7fbdc842010-06-17 20:52:56 -0700300bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700301 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000302 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700303 LOGE_EX(env);
304 env->ExceptionClear();
305 return true;
306 }
307 return false;
308}
309
Jeff Brownbc68a592011-07-25 12:58:12 -0700310void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
311 int32_t externalWidth, int32_t externalHeight) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700312 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700313 if (displayId == 0) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700314 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700315
Jeff Brown65fd2512011-08-18 11:20:58 -0700316 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
317 changed = true;
318 mLocked.displayWidth = width;
319 mLocked.displayHeight = height;
Jeff Brownbc68a592011-07-25 12:58:12 -0700320
Jeff Brown65fd2512011-08-18 11:20:58 -0700321 sp<PointerController> controller = mLocked.pointerController.promote();
322 if (controller != NULL) {
323 controller->setDisplaySize(width, height);
Jeff Brown2352b972011-04-12 22:39:53 -0700324 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700325 }
Jeff Brown2352b972011-04-12 22:39:53 -0700326
Jeff Brown65fd2512011-08-18 11:20:58 -0700327 if (mLocked.displayExternalWidth != externalWidth
328 || mLocked.displayExternalHeight != externalHeight) {
329 changed = true;
Jeff Brownbc68a592011-07-25 12:58:12 -0700330 mLocked.displayExternalWidth = externalWidth;
331 mLocked.displayExternalHeight = externalHeight;
Jeff Brown65fd2512011-08-18 11:20:58 -0700332 }
333 }
334
335 if (changed) {
336 mInputManager->getReader()->requestRefreshConfiguration(
337 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700338 }
339}
340
341void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700342 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700343 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800344 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700345
Jeff Brown83c09682010-12-23 17:50:18 -0800346 if (mLocked.displayOrientation != orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700347 changed = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800348 mLocked.displayOrientation = orientation;
349
350 sp<PointerController> controller = mLocked.pointerController.promote();
351 if (controller != NULL) {
352 controller->setDisplayOrientation(orientation);
353 }
354 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700355 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700356
357 if (changed) {
358 mInputManager->getReader()->requestRefreshConfiguration(
359 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
360 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700361}
362
Jeff Brown7fbdc842010-06-17 20:52:56 -0700363status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800364 const sp<InputChannel>& inputChannel,
365 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
366 return mInputManager->getDispatcher()->registerInputChannel(
367 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700368}
369
370status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
371 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700372 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700373}
374
Jeff Brown214eaf42011-05-26 19:17:02 -0700375void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700376 JNIEnv* env = jniEnv();
377
Jeff Brown4532e612012-04-05 14:27:12 -0700378 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
379 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700380 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
381 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
382 }
383
384 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700385 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
386 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700387 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
388 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700389 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700390 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700391 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700392 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700393 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700394 env->DeleteLocalRef(item);
395 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700396 env->DeleteLocalRef(excludedDeviceNames);
397 }
398
Jeff Brown4532e612012-04-05 14:27:12 -0700399 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
400 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700401 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700402 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
403 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700404 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700405 jint longPressTimeout = env->CallIntMethod(mServiceObj,
406 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700407 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700408 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700409
410 // We must ensure that the tap-drag interval is significantly shorter than
411 // the long-press timeout because the tap is held down for the entire duration
412 // of the double-tap timeout.
413 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700414 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700415 outConfig->pointerGestureTapDragInterval =
416 milliseconds_to_nanoseconds(tapDragInterval);
417 }
418 }
419 }
420
Jeff Brown4532e612012-04-05 14:27:12 -0700421 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
422 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700423 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
424 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700425 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700426
427 { // acquire lock
428 AutoMutex _l(mLock);
429
430 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
431 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700432 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700433
Jeff Browndaf4a122011-08-26 17:14:14 -0700434 outConfig->showTouches = mLocked.showTouches;
435
Jeff Brown65fd2512011-08-18 11:20:58 -0700436 outConfig->setDisplayInfo(0, false /*external*/,
437 mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
438 outConfig->setDisplayInfo(0, true /*external*/,
439 mLocked.displayExternalWidth, mLocked.displayExternalHeight,
440 mLocked.displayOrientation);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700441 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700442}
443
Jeff Brown83c09682010-12-23 17:50:18 -0800444sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
445 AutoMutex _l(mLock);
446
447 sp<PointerController> controller = mLocked.pointerController.promote();
448 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700449 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800450
Jeff Brown2352b972011-04-12 22:39:53 -0700451 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800452 mLocked.pointerController = controller;
453
454 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
455 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800456
Jeff Brown5541de92011-04-11 11:54:25 -0700457 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700458 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
459 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700460 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
461 PointerIcon pointerIcon;
462 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
463 mContextObj, &pointerIcon);
464 if (!status && !pointerIcon.isNullIcon()) {
465 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
466 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
467 } else {
468 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800469 }
Jeff Brown2352b972011-04-12 22:39:53 -0700470 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800471 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800472
Jeff Brown2352b972011-04-12 22:39:53 -0700473 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800474 }
475 return controller;
476}
477
Jeff Brown5541de92011-04-11 11:54:25 -0700478void NativeInputManager::ensureSpriteControllerLocked() {
479 if (mLocked.spriteController == NULL) {
480 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700481 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700482 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
483 layer = -1;
484 }
485 mLocked.spriteController = new SpriteController(mLooper, layer);
486 }
487}
488
Jeff Browne20c9e02010-10-11 14:20:19 -0700489void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
490 int32_t switchValue, uint32_t policyFlags) {
491#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000492 ALOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
Jeff Browne20c9e02010-10-11 14:20:19 -0700493 when, switchCode, switchValue, policyFlags);
494#endif
495
496 JNIEnv* env = jniEnv();
497
498 switch (switchCode) {
499 case SW_LID:
Jeff Brown27fd3422012-04-09 11:05:16 -0700500 // When switch value is set indicates lid is closed.
Jeff Brown4532e612012-04-05 14:27:12 -0700501 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyLidSwitchChanged,
Jeff Brown27fd3422012-04-09 11:05:16 -0700502 when, switchValue == 0 /*lidOpen*/);
Jeff Browne20c9e02010-10-11 14:20:19 -0700503 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
504 break;
505 }
506}
507
Jeff Brown9c3cda02010-06-15 01:31:58 -0700508void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
509#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000510 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700511#endif
512
513 JNIEnv* env = jniEnv();
514
Jeff Brown4532e612012-04-05 14:27:12 -0700515 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700516 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700517}
518
Jeff Brown519e0242010-09-15 15:18:56 -0700519nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800520 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700521#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000522 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700523#endif
524
525 JNIEnv* env = jniEnv();
526
Jeff Brown928e0542011-01-10 11:17:36 -0800527 jobject inputApplicationHandleObj =
528 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
529 jobject inputWindowHandleObj =
530 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700531
Jeff Brown4532e612012-04-05 14:27:12 -0700532 jlong newTimeout = env->CallLongMethod(mServiceObj,
533 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700534 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
535 newTimeout = 0; // abort dispatch
536 } else {
537 assert(newTimeout >= 0);
538 }
539
Jeff Brown928e0542011-01-10 11:17:36 -0800540 env->DeleteLocalRef(inputWindowHandleObj);
541 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700542 return newTimeout;
543}
544
Jeff Brown928e0542011-01-10 11:17:36 -0800545void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700546#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000547 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700548#endif
549
Jeff Brown7fbdc842010-06-17 20:52:56 -0700550 JNIEnv* env = jniEnv();
551
Jeff Brown928e0542011-01-10 11:17:36 -0800552 jobject inputWindowHandleObj =
553 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
554 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700555 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800556 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700557 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
558
Jeff Brown928e0542011-01-10 11:17:36 -0800559 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700560 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700561}
562
Jeff Brown214eaf42011-05-26 19:17:02 -0700563void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
564 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800565
Jeff Brown4532e612012-04-05 14:27:12 -0700566 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
567 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700568 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
569 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
570 }
Jeff Browna4547672011-03-02 21:38:11 -0800571
Jeff Brown4532e612012-04-05 14:27:12 -0700572 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
573 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700574 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
575 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
576 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700577}
578
Jeff Brown214eaf42011-05-26 19:17:02 -0700579bool NativeInputManager::isKeyRepeatEnabled() {
580 // Only enable automatic key repeating when the screen is on.
581 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700582}
583
Jeff Brown9302c872011-07-13 22:51:29 -0700584void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
585 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700586
Jeff Brown9302c872011-07-13 22:51:29 -0700587 if (windowHandleObjArray) {
588 jsize length = env->GetArrayLength(windowHandleObjArray);
589 for (jsize i = 0; i < length; i++) {
590 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
591 if (! windowHandleObj) {
592 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700593 }
Jeff Brown9302c872011-07-13 22:51:29 -0700594
595 sp<InputWindowHandle> windowHandle =
596 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
597 if (windowHandle != NULL) {
598 windowHandles.push(windowHandle);
599 }
600 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700601 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700602 }
Jeff Brown349703e2010-06-22 01:27:15 -0700603
Jeff Brown9302c872011-07-13 22:51:29 -0700604 mInputManager->getDispatcher()->setInputWindows(windowHandles);
605
606 // Do this after the dispatcher has updated the window handle state.
607 bool newPointerGesturesEnabled = true;
608 size_t numWindows = windowHandles.size();
609 for (size_t i = 0; i < numWindows; i++) {
610 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700611 const InputWindowInfo* windowInfo = windowHandle->getInfo();
612 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
613 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700614 newPointerGesturesEnabled = false;
615 }
616 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700617
618 uint32_t changes = 0;
619 { // acquire lock
620 AutoMutex _l(mLock);
621
622 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
623 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
624 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
625 }
626 } // release lock
627
628 if (changes) {
629 mInputManager->getReader()->requestRefreshConfiguration(changes);
630 }
Jeff Brown349703e2010-06-22 01:27:15 -0700631}
632
Jeff Brown9302c872011-07-13 22:51:29 -0700633void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
634 sp<InputApplicationHandle> applicationHandle =
635 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
636 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700637}
638
639void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700640 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700641}
642
Jeff Brown05dc66a2011-03-02 14:41:58 -0800643void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
644 AutoMutex _l(mLock);
645
646 if (mLocked.systemUiVisibility != visibility) {
647 mLocked.systemUiVisibility = visibility;
648
649 sp<PointerController> controller = mLocked.pointerController.promote();
650 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700651 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800652 }
653 }
654}
655
Jeff Brown2352b972011-04-12 22:39:53 -0700656void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800657 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700658 controller->setInactivityTimeout(lightsOut
659 ? PointerController::INACTIVITY_TIMEOUT_SHORT
660 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800661}
662
Jeff Brown1a84fd12011-06-02 01:26:32 -0700663void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700664 { // acquire lock
665 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700666
Jeff Brown474dcb52011-06-14 20:22:50 -0700667 if (mLocked.pointerSpeed == speed) {
668 return;
669 }
670
Steve Block6215d3f2012-01-04 20:05:49 +0000671 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700672 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700673 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700674
Jeff Brown474dcb52011-06-14 20:22:50 -0700675 mInputManager->getReader()->requestRefreshConfiguration(
676 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700677}
678
Jeff Browndaf4a122011-08-26 17:14:14 -0700679void NativeInputManager::setShowTouches(bool enabled) {
680 { // acquire lock
681 AutoMutex _l(mLock);
682
683 if (mLocked.showTouches == enabled) {
684 return;
685 }
686
Steve Block6215d3f2012-01-04 20:05:49 +0000687 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700688 mLocked.showTouches = enabled;
689 } // release lock
690
691 mInputManager->getReader()->requestRefreshConfiguration(
692 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
693}
694
Jeff Browne20c9e02010-10-11 14:20:19 -0700695bool NativeInputManager::isScreenOn() {
696 return android_server_PowerManagerService_isScreenOn();
697}
698
699bool NativeInputManager::isScreenBright() {
700 return android_server_PowerManagerService_isScreenBright();
701}
702
Jeff Brown0029c662011-03-30 02:25:18 -0700703bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
704 jobject inputEventObj;
705
706 JNIEnv* env = jniEnv();
707 switch (inputEvent->getType()) {
708 case AINPUT_EVENT_TYPE_KEY:
709 inputEventObj = android_view_KeyEvent_fromNative(env,
710 static_cast<const KeyEvent*>(inputEvent));
711 break;
712 case AINPUT_EVENT_TYPE_MOTION:
713 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
714 static_cast<const MotionEvent*>(inputEvent));
715 break;
716 default:
717 return true; // dispatch the event normally
718 }
719
720 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000721 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700722 return true; // dispatch the event normally
723 }
724
725 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700726 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700727 inputEventObj, policyFlags);
728 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
729 pass = true;
730 }
731 env->DeleteLocalRef(inputEventObj);
732 return pass;
733}
734
Jeff Brown1f245102010-11-18 20:53:46 -0800735void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
736 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700737 // Policy:
738 // - Ignore untrusted events and pass them along.
739 // - Ask the window manager what to do with normal events and trusted injected events.
740 // - For normal events wake and brighten the screen if currently off or dim.
741 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800742 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700743 bool isScreenOn = this->isScreenOn();
744 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700745
Jeff Brown3122e442010-10-11 23:32:49 -0700746 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800747 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
748 jint wmActions;
749 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700750 wmActions = env->CallIntMethod(mServiceObj,
751 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800752 keyEventObj, policyFlags, isScreenOn);
753 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
754 wmActions = 0;
755 }
756 android_view_KeyEvent_recycle(env, keyEventObj);
757 env->DeleteLocalRef(keyEventObj);
758 } else {
Steve Block3762c312012-01-06 19:20:56 +0000759 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700760 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700761 }
762
Jeff Brown1f245102010-11-18 20:53:46 -0800763 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700764 if (!isScreenOn) {
765 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700766 }
767
768 if (!isScreenBright) {
769 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
770 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700771 }
772
Jeff Brown56194eb2011-03-02 19:23:13 -0800773 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700774 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700775 policyFlags |= POLICY_FLAG_PASS_TO_USER;
776 }
777}
778
Jeff Brown56194eb2011-03-02 19:23:13 -0800779void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700780 // Policy:
781 // - Ignore untrusted events and pass them along.
782 // - No special filtering for injected events required at this time.
783 // - Filter normal events based on screen state.
784 // - For normal events brighten (but do not wake) the screen if currently dim.
785 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
786 if (isScreenOn()) {
787 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700788
Jeff Brown3122e442010-10-11 23:32:49 -0700789 if (!isScreenBright()) {
790 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
791 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800792 } else {
793 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700794 jint wmActions = env->CallIntMethod(mServiceObj,
795 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800796 policyFlags);
797 if (checkAndClearExceptionFromCallback(env,
798 "interceptMotionBeforeQueueingWhenScreenOff")) {
799 wmActions = 0;
800 }
801
802 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
803 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700804 }
Jeff Brown3122e442010-10-11 23:32:49 -0700805 } else {
806 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700807 }
808}
809
Jeff Brown56194eb2011-03-02 19:23:13 -0800810void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
811 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800812 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800813#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000814 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800815#endif
816 android_server_PowerManagerService_goToSleep(when);
817 }
818
819 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800820#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000821 ALOGD("handleInterceptActions: Poking user activity.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800822#endif
823 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
824 }
825
826 if (wmActions & WM_ACTION_PASS_TO_USER) {
827 policyFlags |= POLICY_FLAG_PASS_TO_USER;
828 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800829#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000830 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800831#endif
832 }
833}
834
Jeff Brown905805a2011-10-12 13:57:59 -0700835nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800836 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700837 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700838 // Policy:
839 // - Ignore untrusted events and pass them along.
840 // - Filter normal events and trusted injected events through the window manager policy to
841 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700842 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700843 if (policyFlags & POLICY_FLAG_TRUSTED) {
844 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700845
Jeff Brown928e0542011-01-10 11:17:36 -0800846 // Note: inputWindowHandle may be null.
847 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800848 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
849 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700850 jlong delayMillis = env->CallLongMethod(mServiceObj,
851 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800852 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800853 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
854 android_view_KeyEvent_recycle(env, keyEventObj);
855 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700856 if (!error) {
857 if (delayMillis < 0) {
858 result = -1;
859 } else if (delayMillis > 0) {
860 result = milliseconds_to_nanoseconds(delayMillis);
861 }
862 }
Jeff Brown1f245102010-11-18 20:53:46 -0800863 } else {
Steve Block3762c312012-01-06 19:20:56 +0000864 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800865 }
Jeff Brown928e0542011-01-10 11:17:36 -0800866 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700867 }
Jeff Brown1f245102010-11-18 20:53:46 -0800868 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700869}
870
Jeff Brown928e0542011-01-10 11:17:36 -0800871bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800872 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700873 // Policy:
874 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800875 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700876 if (policyFlags & POLICY_FLAG_TRUSTED) {
877 JNIEnv* env = jniEnv();
878
Jeff Brown928e0542011-01-10 11:17:36 -0800879 // Note: inputWindowHandle may be null.
880 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800881 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
882 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700883 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
884 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800885 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700886 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
887 fallbackKeyEventObj = NULL;
888 }
Jeff Brown1f245102010-11-18 20:53:46 -0800889 android_view_KeyEvent_recycle(env, keyEventObj);
890 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800891
892 if (fallbackKeyEventObj) {
893 // Note: outFallbackKeyEvent may be the same object as keyEvent.
894 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
895 outFallbackKeyEvent)) {
896 result = true;
897 }
898 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
899 env->DeleteLocalRef(fallbackKeyEventObj);
900 }
Jeff Brown1f245102010-11-18 20:53:46 -0800901 } else {
Steve Block3762c312012-01-06 19:20:56 +0000902 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800903 }
Jeff Brown928e0542011-01-10 11:17:36 -0800904 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700905 }
Jeff Brown1f245102010-11-18 20:53:46 -0800906 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700907}
908
Jeff Brown01ce2e92010-09-26 22:20:12 -0700909void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
910 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700911}
912
Jeff Brown349703e2010-06-22 01:27:15 -0700913
Jeff Brownb88102f2010-09-08 11:49:43 -0700914bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
915 int32_t injectorPid, int32_t injectorUid) {
916 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700917 jboolean result = env->CallBooleanMethod(mServiceObj,
918 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700919 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
920 result = false;
921 }
Jeff Brown349703e2010-06-22 01:27:15 -0700922 return result;
923}
924
Jeff Brown2352b972011-04-12 22:39:53 -0700925void NativeInputManager::loadPointerResources(PointerResources* outResources) {
926 JNIEnv* env = jniEnv();
927
928 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
929 &outResources->spotHover);
930 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
931 &outResources->spotTouch);
932 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
933 &outResources->spotAnchor);
934}
935
Jeff Brown83c09682010-12-23 17:50:18 -0800936
Jeff Brown9c3cda02010-06-15 01:31:58 -0700937// ----------------------------------------------------------------------------
938
Jeff Brown4532e612012-04-05 14:27:12 -0700939static jint nativeInit(JNIEnv* env, jclass clazz,
940 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -0700941 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
942 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
943 messageQueue->getLooper());
Jeff Brown4532e612012-04-05 14:27:12 -0700944 im->incStrong(serviceObj);
945 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700946}
947
Jeff Brown4532e612012-04-05 14:27:12 -0700948static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
949 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700950
Jeff Brown4532e612012-04-05 14:27:12 -0700951 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700952 if (result) {
953 jniThrowRuntimeException(env, "Input manager could not be started.");
954 }
955}
956
Jeff Brown4532e612012-04-05 14:27:12 -0700957static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, jint ptr,
Jeff Brownbc68a592011-07-25 12:58:12 -0700958 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -0700959 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700960
961 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
962 // to be passed in like this, not sure which is better but leaving it like this
963 // keeps the window manager in direct control of when display transitions propagate down
964 // to the input dispatcher
Jeff Brown4532e612012-04-05 14:27:12 -0700965 im->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700966}
967
Jeff Brown4532e612012-04-05 14:27:12 -0700968static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
969 jint ptr, jint displayId, jint orientation) {
970 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700971
Jeff Brown4532e612012-04-05 14:27:12 -0700972 im->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700973}
974
Jeff Brown4532e612012-04-05 14:27:12 -0700975static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
976 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
977 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700978
Jeff Brown4532e612012-04-05 14:27:12 -0700979 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700980 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700981}
982
Jeff Brown4532e612012-04-05 14:27:12 -0700983static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
984 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
985 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700986
Jeff Brown4532e612012-04-05 14:27:12 -0700987 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700988 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700989}
990
Jeff Brown4532e612012-04-05 14:27:12 -0700991static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
992 jint ptr, jint deviceId, jint sourceMask, jint sw) {
993 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700994
Jeff Brown4532e612012-04-05 14:27:12 -0700995 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700996 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700997}
998
Jeff Brown4532e612012-04-05 14:27:12 -0700999static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1000 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1001 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001002
1003 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1004 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1005 jsize numCodes = env->GetArrayLength(keyCodes);
1006 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001007 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001008 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001009 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001010 } else {
1011 result = JNI_FALSE;
1012 }
1013
1014 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1015 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1016 return result;
1017}
1018
1019static void throwInputChannelNotInitialized(JNIEnv* env) {
1020 jniThrowException(env, "java/lang/IllegalStateException",
1021 "inputChannel is not initialized");
1022}
1023
Jeff Brown4532e612012-04-05 14:27:12 -07001024static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001025 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001026 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1027
Steve Block8564c8d2012-01-05 23:22:43 +00001028 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001029 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001030 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001031}
1032
Jeff Brown4532e612012-04-05 14:27:12 -07001033static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1034 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1035 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001036
1037 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1038 inputChannelObj);
1039 if (inputChannel == NULL) {
1040 throwInputChannelNotInitialized(env);
1041 return;
1042 }
1043
Jeff Brown928e0542011-01-10 11:17:36 -08001044 sp<InputWindowHandle> inputWindowHandle =
1045 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001046
Jeff Brown4532e612012-04-05 14:27:12 -07001047 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001048 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001049 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001050 String8 message;
1051 message.appendFormat("Failed to register input channel. status=%d", status);
1052 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001053 return;
1054 }
1055
Jeff Browna41ca772010-08-11 14:46:32 -07001056 if (! monitor) {
1057 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001058 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001059 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001060}
1061
Jeff Brown4532e612012-04-05 14:27:12 -07001062static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1063 jint ptr, jobject inputChannelObj) {
1064 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001065
1066 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1067 inputChannelObj);
1068 if (inputChannel == NULL) {
1069 throwInputChannelNotInitialized(env);
1070 return;
1071 }
1072
1073 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1074
Jeff Brown4532e612012-04-05 14:27:12 -07001075 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001076 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1077 String8 message;
1078 message.appendFormat("Failed to unregister input channel. status=%d", status);
1079 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001080 }
1081}
1082
Jeff Brown4532e612012-04-05 14:27:12 -07001083static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1084 jint ptr, jboolean enabled) {
1085 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001086
Jeff Brown4532e612012-04-05 14:27:12 -07001087 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001088}
1089
Jeff Brown4532e612012-04-05 14:27:12 -07001090static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1091 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001092 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001093 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001094
Jeff Brown6ec402b2010-07-28 15:48:59 -07001095 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1096 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001097 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1098 if (status) {
1099 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1100 return INPUT_EVENT_INJECTION_FAILED;
1101 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001102
Jeff Brown4532e612012-04-05 14:27:12 -07001103 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001104 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1105 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001106 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001107 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1108 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001109 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1110 return INPUT_EVENT_INJECTION_FAILED;
1111 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001112
Jeff Brown4532e612012-04-05 14:27:12 -07001113 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001114 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1115 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001116 } else {
1117 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001118 return INPUT_EVENT_INJECTION_FAILED;
1119 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001120}
1121
Jeff Brown4532e612012-04-05 14:27:12 -07001122static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1123 jint ptr, jobjectArray windowHandleObjArray) {
1124 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001125
Jeff Brown4532e612012-04-05 14:27:12 -07001126 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001127}
1128
Jeff Brown4532e612012-04-05 14:27:12 -07001129static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1130 jint ptr, jobject applicationHandleObj) {
1131 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001132
Jeff Brown4532e612012-04-05 14:27:12 -07001133 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001134}
1135
Jeff Brown4532e612012-04-05 14:27:12 -07001136static void nativeSetInputDispatchMode(JNIEnv* env,
1137 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1138 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001139
Jeff Brown4532e612012-04-05 14:27:12 -07001140 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001141}
1142
Jeff Brown4532e612012-04-05 14:27:12 -07001143static void nativeSetSystemUiVisibility(JNIEnv* env,
1144 jclass clazz, jint ptr, jint visibility) {
1145 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001146
Jeff Brown4532e612012-04-05 14:27:12 -07001147 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001148}
1149
Jeff Brown4532e612012-04-05 14:27:12 -07001150static jobject nativeGetInputDevice(JNIEnv* env,
1151 jclass clazz, jint ptr, jint deviceId) {
1152 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown8d608662010-08-30 03:02:23 -07001153
1154 InputDeviceInfo deviceInfo;
Jeff Brown4532e612012-04-05 14:27:12 -07001155 status_t status = im->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -07001156 deviceId, & deviceInfo);
1157 if (status) {
1158 return NULL;
1159 }
1160
Jeff Brown9f25b7f2012-04-10 14:30:49 -07001161 return android_view_InputDevice_create(env, deviceInfo);
Jeff Brown8d608662010-08-30 03:02:23 -07001162}
1163
Jeff Brown4532e612012-04-05 14:27:12 -07001164static jintArray nativeGetInputDeviceIds(JNIEnv* env,
1165 jclass clazz, jint ptr) {
1166 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown8d608662010-08-30 03:02:23 -07001167
1168 Vector<int> deviceIds;
Jeff Brown4532e612012-04-05 14:27:12 -07001169 im->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001170
1171 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1172 if (! deviceIdsObj) {
1173 return NULL;
1174 }
1175
1176 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1177 return deviceIdsObj;
1178}
1179
Jeff Brown4532e612012-04-05 14:27:12 -07001180static void nativeGetInputConfiguration(JNIEnv* env,
1181 jclass clazz, jint ptr, jobject configObj) {
1182 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown57c59372010-09-21 18:22:55 -07001183
1184 InputConfiguration config;
Jeff Brown4532e612012-04-05 14:27:12 -07001185 im->getInputManager()->getReader()->getInputConfiguration(& config);
Jeff Brown57c59372010-09-21 18:22:55 -07001186
1187 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1188 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1189 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1190}
1191
Jeff Brown4532e612012-04-05 14:27:12 -07001192static jboolean nativeTransferTouchFocus(JNIEnv* env,
1193 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1194 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001195
1196 sp<InputChannel> fromChannel =
1197 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1198 sp<InputChannel> toChannel =
1199 android_view_InputChannel_getInputChannel(env, toChannelObj);
1200
1201 if (fromChannel == NULL || toChannel == NULL) {
1202 return false;
1203 }
1204
Jeff Brown4532e612012-04-05 14:27:12 -07001205 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001206 transferTouchFocus(fromChannel, toChannel);
1207}
1208
Jeff Brown4532e612012-04-05 14:27:12 -07001209static void nativeSetPointerSpeed(JNIEnv* env,
1210 jclass clazz, jint ptr, jint speed) {
1211 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001212
Jeff Brown4532e612012-04-05 14:27:12 -07001213 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001214}
1215
Jeff Brown4532e612012-04-05 14:27:12 -07001216static void nativeSetShowTouches(JNIEnv* env,
1217 jclass clazz, jint ptr, jboolean enabled) {
1218 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001219
Jeff Brown4532e612012-04-05 14:27:12 -07001220 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001221}
1222
Jeff Brown4532e612012-04-05 14:27:12 -07001223static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1224 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001225
Jeff Brownb88102f2010-09-08 11:49:43 -07001226 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001227 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001228 return env->NewStringUTF(dump.string());
1229}
1230
Jeff Brown4532e612012-04-05 14:27:12 -07001231static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1232 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001233
Jeff Brown4532e612012-04-05 14:27:12 -07001234 im->getInputManager()->getReader()->monitor();
1235 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001236}
1237
Jeff Brown9c3cda02010-06-15 01:31:58 -07001238// ----------------------------------------------------------------------------
1239
Jeff Brown46b9ac02010-04-22 18:58:52 -07001240static JNINativeMethod gInputManagerMethods[] = {
1241 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001242 { "nativeInit",
1243 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1244 (void*) nativeInit },
1245 { "nativeStart", "(I)V",
1246 (void*) nativeStart },
1247 { "nativeSetDisplaySize", "(IIIIII)V",
1248 (void*) nativeSetDisplaySize },
1249 { "nativeSetDisplayOrientation", "(III)V",
1250 (void*) nativeSetDisplayOrientation },
1251 { "nativeGetScanCodeState", "(IIII)I",
1252 (void*) nativeGetScanCodeState },
1253 { "nativeGetKeyCodeState", "(IIII)I",
1254 (void*) nativeGetKeyCodeState },
1255 { "nativeGetSwitchState", "(IIII)I",
1256 (void*) nativeGetSwitchState },
1257 { "nativeHasKeys", "(III[I[Z)Z",
1258 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001259 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001260 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1261 (void*) nativeRegisterInputChannel },
1262 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1263 (void*) nativeUnregisterInputChannel },
1264 { "nativeSetInputFilterEnabled", "(IZ)V",
1265 (void*) nativeSetInputFilterEnabled },
1266 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1267 (void*) nativeInjectInputEvent },
1268 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1269 (void*) nativeSetInputWindows },
1270 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1271 (void*) nativeSetFocusedApplication },
1272 { "nativeSetInputDispatchMode", "(IZZ)V",
1273 (void*) nativeSetInputDispatchMode },
1274 { "nativeSetSystemUiVisibility", "(II)V",
1275 (void*) nativeSetSystemUiVisibility },
1276 { "nativeGetInputDevice", "(II)Landroid/view/InputDevice;",
1277 (void*) nativeGetInputDevice },
1278 { "nativeGetInputDeviceIds", "(I)[I",
1279 (void*) nativeGetInputDeviceIds },
1280 { "nativeGetInputConfiguration", "(ILandroid/content/res/Configuration;)V",
1281 (void*) nativeGetInputConfiguration },
1282 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1283 (void*) nativeTransferTouchFocus },
1284 { "nativeSetPointerSpeed", "(II)V",
1285 (void*) nativeSetPointerSpeed },
1286 { "nativeSetShowTouches", "(IZ)V",
1287 (void*) nativeSetShowTouches },
1288 { "nativeDump", "(I)Ljava/lang/String;",
1289 (void*) nativeDump },
1290 { "nativeMonitor", "(I)V",
1291 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001292};
1293
1294#define FIND_CLASS(var, className) \
1295 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001296 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001297
1298#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1299 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1300 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1301
1302#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1303 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1304 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1305
1306int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001307 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001308 gInputManagerMethods, NELEM(gInputManagerMethods));
1309 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1310
Jeff Brown9c3cda02010-06-15 01:31:58 -07001311 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001312
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001313 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001314 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001315
Jeff Brown4532e612012-04-05 14:27:12 -07001316 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001317 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001318
Jeff Brown4532e612012-04-05 14:27:12 -07001319 GET_METHOD_ID(gServiceClassInfo.notifyLidSwitchChanged, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001320 "notifyLidSwitchChanged", "(JZ)V");
1321
Jeff Brown4532e612012-04-05 14:27:12 -07001322 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1323 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001324
Jeff Brown4532e612012-04-05 14:27:12 -07001325 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001326 "notifyANR",
Jeff Brown4532e612012-04-05 14:27:12 -07001327 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001328
Jeff Brown4532e612012-04-05 14:27:12 -07001329 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001330 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1331
Jeff Brown4532e612012-04-05 14:27:12 -07001332 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001333 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001334
Jeff Brown4532e612012-04-05 14:27:12 -07001335 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001336 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001337 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1338
Jeff Brown4532e612012-04-05 14:27:12 -07001339 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001340 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001341 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001342
Jeff Brown4532e612012-04-05 14:27:12 -07001343 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001344 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001345 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001346
Jeff Brown4532e612012-04-05 14:27:12 -07001347 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001348 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001349
Jeff Brown4532e612012-04-05 14:27:12 -07001350 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001351 "getVirtualKeyQuietTimeMillis", "()I");
1352
Jeff Brown4532e612012-04-05 14:27:12 -07001353 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001354 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1355
Jeff Brown4532e612012-04-05 14:27:12 -07001356 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001357 "getKeyRepeatTimeout", "()I");
1358
Jeff Brown4532e612012-04-05 14:27:12 -07001359 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001360 "getKeyRepeatDelay", "()I");
1361
Jeff Brown4532e612012-04-05 14:27:12 -07001362 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001363 "getHoverTapTimeout", "()I");
1364
Jeff Brown4532e612012-04-05 14:27:12 -07001365 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001366 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001367
Jeff Brown4532e612012-04-05 14:27:12 -07001368 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001369 "getDoubleTapTimeout", "()I");
1370
Jeff Brown4532e612012-04-05 14:27:12 -07001371 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001372 "getLongPressTimeout", "()I");
1373
Jeff Brown4532e612012-04-05 14:27:12 -07001374 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001375 "getPointerLayer", "()I");
1376
Jeff Brown4532e612012-04-05 14:27:12 -07001377 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001378 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001379
Jeff Brown6ec402b2010-07-28 15:48:59 -07001380 // KeyEvent
1381
1382 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001383 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1384
Jeff Brown8d608662010-08-30 03:02:23 -07001385 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001386
1387 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001388 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001389
Jeff Brown57c59372010-09-21 18:22:55 -07001390 // Configuration
1391
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001392 FIND_CLASS(clazz, "android/content/res/Configuration");
Jeff Brown57c59372010-09-21 18:22:55 -07001393
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001394 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001395 "touchscreen", "I");
1396
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001397 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001398 "keyboard", "I");
1399
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001400 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001401 "navigation", "I");
1402
Jeff Brown46b9ac02010-04-22 18:58:52 -07001403 return 0;
1404}
1405
Jeff Brown46b9ac02010-04-22 18:58:52 -07001406} /* namespace android */