blob: 22795bf6dc519d15fbf63756d163ef838dc3b48c [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "InputManager-JNI"
18
Jeff Brown9c3cda02010-06-15 01:31:58 -070019//#define LOG_NDEBUG 0
20
21// Log debug messages about InputReaderPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070022#define DEBUG_INPUT_READER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070023
24// Log debug messages about InputDispatcherPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070025#define DEBUG_INPUT_DISPATCHER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070026
Jeff Brown83c09682010-12-23 17:50:18 -080027
Jeff Brown46b9ac02010-04-22 18:58:52 -070028#include "JNIHelp.h"
29#include "jni.h"
Jeff Brown349703e2010-06-22 01:27:15 -070030#include <limits.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070031#include <android_runtime/AndroidRuntime.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080032
Jeff Brown46b9ac02010-04-22 18:58:52 -070033#include <utils/Log.h>
Jeff Brown05dc66a2011-03-02 14:41:58 -080034#include <utils/Looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070035#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080036
Jeff Brownb4ff35d2011-01-02 16:37:43 -080037#include <input/InputManager.h>
38#include <input/PointerController.h>
Jeff Brown5541de92011-04-11 11:54:25 -070039#include <input/SpriteController.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040
Jeff Brown05dc66a2011-03-02 14:41:58 -080041#include <android_os_MessageQueue.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080042#include <android_view_KeyEvent.h>
43#include <android_view_MotionEvent.h>
44#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070045#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080046#include <android/graphics/GraphicsJNI.h>
47
Jeff Brown00fa7bd2010-07-02 15:37:36 -070048#include "com_android_server_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070049#include "com_android_server_input_InputApplicationHandle.h"
50#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070051
52namespace android {
53
Jeff Brown1a84fd12011-06-02 01:26:32 -070054// The exponent used to calculate the pointer speed scaling factor.
55// The scaling factor is calculated as 2 ^ (speed * exponent),
56// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070057static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070058
Jeff Brown46b9ac02010-04-22 18:58:52 -070059static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070060 jmethodID notifyConfigurationChanged;
61 jmethodID notifyLidSwitchChanged;
Jeff Brown7fbdc842010-06-17 20:52:56 -070062 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070063 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070064 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070065 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080066 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070067 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070068 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070069 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080070 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070071 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080072 jmethodID getKeyRepeatTimeout;
73 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070074 jmethodID getHoverTapTimeout;
75 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070076 jmethodID getDoubleTapTimeout;
77 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080078 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080079 jmethodID getPointerIcon;
Jeff Brown4532e612012-04-05 14:27:12 -070080} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070081
82static struct {
83 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070084} gKeyEventClassInfo;
85
86static struct {
87 jclass clazz;
88} gMotionEventClassInfo;
89
Jeff Brown8d608662010-08-30 03:02:23 -070090static struct {
91 jclass clazz;
92
93 jmethodID ctor;
94 jmethodID addMotionRange;
95
96 jfieldID mId;
97 jfieldID mName;
98 jfieldID mSources;
99 jfieldID mKeyboardType;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800100 jfieldID mKeyCharacterMapFile;
Jeff Brown8d608662010-08-30 03:02:23 -0700101} gInputDeviceClassInfo;
102
Jeff Brown57c59372010-09-21 18:22:55 -0700103static struct {
Jeff Brown57c59372010-09-21 18:22:55 -0700104 jfieldID touchscreen;
105 jfieldID keyboard;
106 jfieldID navigation;
107} gConfigurationClassInfo;
108
Jeff Brown928e0542011-01-10 11:17:36 -0800109
110// --- Global functions ---
111
Jeff Brown214eaf42011-05-26 19:17:02 -0700112template<typename T>
113inline static T min(const T& a, const T& b) {
114 return a < b ? a : b;
115}
116
117template<typename T>
118inline static T max(const T& a, const T& b) {
119 return a > b ? a : b;
120}
121
Jeff Brown928e0542011-01-10 11:17:36 -0800122static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
123 const sp<InputApplicationHandle>& inputApplicationHandle) {
124 if (inputApplicationHandle == NULL) {
125 return NULL;
126 }
127 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
128 getInputApplicationHandleObjLocalRef(env);
129}
130
131static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
132 const sp<InputWindowHandle>& inputWindowHandle) {
133 if (inputWindowHandle == NULL) {
134 return NULL;
135 }
136 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
137 getInputWindowHandleObjLocalRef(env);
138}
139
Jeff Brown2352b972011-04-12 22:39:53 -0700140static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
141 SpriteIcon* outSpriteIcon) {
142 PointerIcon pointerIcon;
143 status_t status = android_view_PointerIcon_loadSystemIcon(env,
144 contextObj, style, &pointerIcon);
145 if (!status) {
146 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
147 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
148 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
149 }
150}
151
Jeff Brown905805a2011-10-12 13:57:59 -0700152enum {
153 WM_ACTION_PASS_TO_USER = 1,
154 WM_ACTION_POKE_USER_ACTIVITY = 2,
155 WM_ACTION_GO_TO_SLEEP = 4,
156};
157
Jeff Brown928e0542011-01-10 11:17:36 -0800158
159// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800160
Jeff Brown9c3cda02010-06-15 01:31:58 -0700161class NativeInputManager : public virtual RefBase,
162 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700163 public virtual InputDispatcherPolicyInterface,
164 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700165protected:
166 virtual ~NativeInputManager();
167
168public:
Jeff Brown4532e612012-04-05 14:27:12 -0700169 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700170
171 inline sp<InputManager> getInputManager() const { return mInputManager; }
172
Jeff Brownb88102f2010-09-08 11:49:43 -0700173 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700174
Jeff Brownbc68a592011-07-25 12:58:12 -0700175 void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
176 int32_t externalWidth, int32_t externalHeight);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700177 void setDisplayOrientation(int32_t displayId, int32_t orientation);
178
Jeff Brown7fbdc842010-06-17 20:52:56 -0700179 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800180 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700181 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
182
Jeff Brown9302c872011-07-13 22:51:29 -0700183 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
184 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700185 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800186 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700187 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700188 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700189
Jeff Brown9c3cda02010-06-15 01:31:58 -0700190 /* --- InputReaderPolicyInterface implementation --- */
191
Jeff Brown214eaf42011-05-26 19:17:02 -0700192 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800193 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194
195 /* --- InputDispatcherPolicyInterface implementation --- */
196
Jeff Browne20c9e02010-10-11 14:20:19 -0700197 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
198 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700199 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700200 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800201 const sp<InputWindowHandle>& inputWindowHandle);
202 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700203 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700204 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
205 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800206 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800207 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700208 virtual nsecs_t interceptKeyBeforeDispatching(
209 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700210 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800211 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800212 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700213 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700214 virtual bool checkInjectEventsPermissionNonReentrant(
215 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700216
Jeff Brown2352b972011-04-12 22:39:53 -0700217 /* --- PointerControllerPolicyInterface implementation --- */
218
219 virtual void loadPointerResources(PointerResources* outResources);
220
Jeff Brown9c3cda02010-06-15 01:31:58 -0700221private:
222 sp<InputManager> mInputManager;
223
Jeff Brown2352b972011-04-12 22:39:53 -0700224 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700225 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800226 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700227
Jeff Brown83c09682010-12-23 17:50:18 -0800228 Mutex mLock;
229 struct Locked {
230 // Display size information.
Jeff Brownbc68a592011-07-25 12:58:12 -0700231 int32_t displayWidth, displayHeight; // -1 when not initialized
232 int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
Jeff Brown83c09682010-12-23 17:50:18 -0800233 int32_t displayOrientation;
234
Jeff Brown05dc66a2011-03-02 14:41:58 -0800235 // System UI visibility.
236 int32_t systemUiVisibility;
237
Jeff Brown1a84fd12011-06-02 01:26:32 -0700238 // Pointer speed.
239 int32_t pointerSpeed;
240
Jeff Brown474dcb52011-06-14 20:22:50 -0700241 // True if pointer gestures are enabled.
242 bool pointerGesturesEnabled;
243
Jeff Browndaf4a122011-08-26 17:14:14 -0700244 // Show touches feature enable/disable.
245 bool showTouches;
246
Jeff Brown5541de92011-04-11 11:54:25 -0700247 // Sprite controller singleton, created on first use.
248 sp<SpriteController> spriteController;
249
Jeff Brown83c09682010-12-23 17:50:18 -0800250 // Pointer controller singleton, created and destroyed as needed.
251 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800252 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700253
Jeff Brown2352b972011-04-12 22:39:53 -0700254 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800255 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700256 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800257
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700258 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700259 bool isScreenOn();
260 bool isScreenBright();
261
Jeff Brownb88102f2010-09-08 11:49:43 -0700262 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700263
Jeff Brown9c3cda02010-06-15 01:31:58 -0700264 static inline JNIEnv* jniEnv() {
265 return AndroidRuntime::getJNIEnv();
266 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700267};
268
Jeff Brown928e0542011-01-10 11:17:36 -0800269
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270
Jeff Brown2352b972011-04-12 22:39:53 -0700271NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700272 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700273 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700274 JNIEnv* env = jniEnv();
275
Jeff Brown2352b972011-04-12 22:39:53 -0700276 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700277 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700278
Jeff Brown83c09682010-12-23 17:50:18 -0800279 {
280 AutoMutex _l(mLock);
281 mLocked.displayWidth = -1;
282 mLocked.displayHeight = -1;
Jeff Brownbc68a592011-07-25 12:58:12 -0700283 mLocked.displayExternalWidth = -1;
284 mLocked.displayExternalHeight = -1;
Jeff Brown65fd2512011-08-18 11:20:58 -0700285 mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800286
287 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700288 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700289 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700290 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800291 }
292
Jeff Brown9c3cda02010-06-15 01:31:58 -0700293 sp<EventHub> eventHub = new EventHub();
294 mInputManager = new InputManager(eventHub, this, this);
295}
296
297NativeInputManager::~NativeInputManager() {
298 JNIEnv* env = jniEnv();
299
Jeff Brown2352b972011-04-12 22:39:53 -0700300 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700301 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700302}
303
Jeff Brownb88102f2010-09-08 11:49:43 -0700304void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700305 mInputManager->getReader()->dump(dump);
306 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700307
Jeff Brownb88102f2010-09-08 11:49:43 -0700308 mInputManager->getDispatcher()->dump(dump);
309 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700310}
311
Jeff Brown7fbdc842010-06-17 20:52:56 -0700312bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700313 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000314 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700315 LOGE_EX(env);
316 env->ExceptionClear();
317 return true;
318 }
319 return false;
320}
321
Jeff Brownbc68a592011-07-25 12:58:12 -0700322void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
323 int32_t externalWidth, int32_t externalHeight) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700324 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700325 if (displayId == 0) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700326 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700327
Jeff Brown65fd2512011-08-18 11:20:58 -0700328 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
329 changed = true;
330 mLocked.displayWidth = width;
331 mLocked.displayHeight = height;
Jeff Brownbc68a592011-07-25 12:58:12 -0700332
Jeff Brown65fd2512011-08-18 11:20:58 -0700333 sp<PointerController> controller = mLocked.pointerController.promote();
334 if (controller != NULL) {
335 controller->setDisplaySize(width, height);
Jeff Brown2352b972011-04-12 22:39:53 -0700336 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700337 }
Jeff Brown2352b972011-04-12 22:39:53 -0700338
Jeff Brown65fd2512011-08-18 11:20:58 -0700339 if (mLocked.displayExternalWidth != externalWidth
340 || mLocked.displayExternalHeight != externalHeight) {
341 changed = true;
Jeff Brownbc68a592011-07-25 12:58:12 -0700342 mLocked.displayExternalWidth = externalWidth;
343 mLocked.displayExternalHeight = externalHeight;
Jeff Brown65fd2512011-08-18 11:20:58 -0700344 }
345 }
346
347 if (changed) {
348 mInputManager->getReader()->requestRefreshConfiguration(
349 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700350 }
351}
352
353void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700354 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700355 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800356 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700357
Jeff Brown83c09682010-12-23 17:50:18 -0800358 if (mLocked.displayOrientation != orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700359 changed = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800360 mLocked.displayOrientation = orientation;
361
362 sp<PointerController> controller = mLocked.pointerController.promote();
363 if (controller != NULL) {
364 controller->setDisplayOrientation(orientation);
365 }
366 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700367 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700368
369 if (changed) {
370 mInputManager->getReader()->requestRefreshConfiguration(
371 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
372 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700373}
374
Jeff Brown7fbdc842010-06-17 20:52:56 -0700375status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800376 const sp<InputChannel>& inputChannel,
377 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
378 return mInputManager->getDispatcher()->registerInputChannel(
379 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700380}
381
382status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
383 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700384 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700385}
386
Jeff Brown214eaf42011-05-26 19:17:02 -0700387void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700388 JNIEnv* env = jniEnv();
389
Jeff Brown4532e612012-04-05 14:27:12 -0700390 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
391 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700392 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
393 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
394 }
395
396 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700397 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
398 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700399 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
400 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700401 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700402 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700403 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700404 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700405 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700406 env->DeleteLocalRef(item);
407 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700408 env->DeleteLocalRef(excludedDeviceNames);
409 }
410
Jeff Brown4532e612012-04-05 14:27:12 -0700411 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
412 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700413 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700414 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
415 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700416 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700417 jint longPressTimeout = env->CallIntMethod(mServiceObj,
418 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700419 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700420 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700421
422 // We must ensure that the tap-drag interval is significantly shorter than
423 // the long-press timeout because the tap is held down for the entire duration
424 // of the double-tap timeout.
425 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700426 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700427 outConfig->pointerGestureTapDragInterval =
428 milliseconds_to_nanoseconds(tapDragInterval);
429 }
430 }
431 }
432
Jeff Brown4532e612012-04-05 14:27:12 -0700433 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
434 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700435 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
436 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700437 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700438
439 { // acquire lock
440 AutoMutex _l(mLock);
441
442 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
443 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700444 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700445
Jeff Browndaf4a122011-08-26 17:14:14 -0700446 outConfig->showTouches = mLocked.showTouches;
447
Jeff Brown65fd2512011-08-18 11:20:58 -0700448 outConfig->setDisplayInfo(0, false /*external*/,
449 mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
450 outConfig->setDisplayInfo(0, true /*external*/,
451 mLocked.displayExternalWidth, mLocked.displayExternalHeight,
452 mLocked.displayOrientation);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700453 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700454}
455
Jeff Brown83c09682010-12-23 17:50:18 -0800456sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
457 AutoMutex _l(mLock);
458
459 sp<PointerController> controller = mLocked.pointerController.promote();
460 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700461 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800462
Jeff Brown2352b972011-04-12 22:39:53 -0700463 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800464 mLocked.pointerController = controller;
465
466 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
467 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800468
Jeff Brown5541de92011-04-11 11:54:25 -0700469 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700470 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
471 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700472 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
473 PointerIcon pointerIcon;
474 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
475 mContextObj, &pointerIcon);
476 if (!status && !pointerIcon.isNullIcon()) {
477 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
478 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
479 } else {
480 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800481 }
Jeff Brown2352b972011-04-12 22:39:53 -0700482 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800483 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800484
Jeff Brown2352b972011-04-12 22:39:53 -0700485 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800486 }
487 return controller;
488}
489
Jeff Brown5541de92011-04-11 11:54:25 -0700490void NativeInputManager::ensureSpriteControllerLocked() {
491 if (mLocked.spriteController == NULL) {
492 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700493 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700494 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
495 layer = -1;
496 }
497 mLocked.spriteController = new SpriteController(mLooper, layer);
498 }
499}
500
Jeff Browne20c9e02010-10-11 14:20:19 -0700501void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
502 int32_t switchValue, uint32_t policyFlags) {
503#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000504 ALOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
Jeff Browne20c9e02010-10-11 14:20:19 -0700505 when, switchCode, switchValue, policyFlags);
506#endif
507
508 JNIEnv* env = jniEnv();
509
510 switch (switchCode) {
511 case SW_LID:
Jeff Brown4532e612012-04-05 14:27:12 -0700512 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyLidSwitchChanged,
Jeff Browne20c9e02010-10-11 14:20:19 -0700513 when, switchValue == 0);
514 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
515 break;
516 }
517}
518
Jeff Brown9c3cda02010-06-15 01:31:58 -0700519void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
520#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000521 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700522#endif
523
524 JNIEnv* env = jniEnv();
525
Jeff Brown4532e612012-04-05 14:27:12 -0700526 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700527 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700528}
529
Jeff Brown519e0242010-09-15 15:18:56 -0700530nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800531 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700532#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000533 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700534#endif
535
536 JNIEnv* env = jniEnv();
537
Jeff Brown928e0542011-01-10 11:17:36 -0800538 jobject inputApplicationHandleObj =
539 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
540 jobject inputWindowHandleObj =
541 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700542
Jeff Brown4532e612012-04-05 14:27:12 -0700543 jlong newTimeout = env->CallLongMethod(mServiceObj,
544 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700545 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
546 newTimeout = 0; // abort dispatch
547 } else {
548 assert(newTimeout >= 0);
549 }
550
Jeff Brown928e0542011-01-10 11:17:36 -0800551 env->DeleteLocalRef(inputWindowHandleObj);
552 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700553 return newTimeout;
554}
555
Jeff Brown928e0542011-01-10 11:17:36 -0800556void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700557#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000558 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700559#endif
560
Jeff Brown7fbdc842010-06-17 20:52:56 -0700561 JNIEnv* env = jniEnv();
562
Jeff Brown928e0542011-01-10 11:17:36 -0800563 jobject inputWindowHandleObj =
564 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
565 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700566 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800567 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700568 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
569
Jeff Brown928e0542011-01-10 11:17:36 -0800570 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700571 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700572}
573
Jeff Brown214eaf42011-05-26 19:17:02 -0700574void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
575 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800576
Jeff Brown4532e612012-04-05 14:27:12 -0700577 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
578 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700579 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
580 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
581 }
Jeff Browna4547672011-03-02 21:38:11 -0800582
Jeff Brown4532e612012-04-05 14:27:12 -0700583 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
584 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700585 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
586 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
587 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700588}
589
Jeff Brown214eaf42011-05-26 19:17:02 -0700590bool NativeInputManager::isKeyRepeatEnabled() {
591 // Only enable automatic key repeating when the screen is on.
592 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700593}
594
Jeff Brown9302c872011-07-13 22:51:29 -0700595void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
596 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700597
Jeff Brown9302c872011-07-13 22:51:29 -0700598 if (windowHandleObjArray) {
599 jsize length = env->GetArrayLength(windowHandleObjArray);
600 for (jsize i = 0; i < length; i++) {
601 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
602 if (! windowHandleObj) {
603 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700604 }
Jeff Brown9302c872011-07-13 22:51:29 -0700605
606 sp<InputWindowHandle> windowHandle =
607 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
608 if (windowHandle != NULL) {
609 windowHandles.push(windowHandle);
610 }
611 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700612 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700613 }
Jeff Brown349703e2010-06-22 01:27:15 -0700614
Jeff Brown9302c872011-07-13 22:51:29 -0700615 mInputManager->getDispatcher()->setInputWindows(windowHandles);
616
617 // Do this after the dispatcher has updated the window handle state.
618 bool newPointerGesturesEnabled = true;
619 size_t numWindows = windowHandles.size();
620 for (size_t i = 0; i < numWindows; i++) {
621 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700622 const InputWindowInfo* windowInfo = windowHandle->getInfo();
623 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
624 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700625 newPointerGesturesEnabled = false;
626 }
627 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700628
629 uint32_t changes = 0;
630 { // acquire lock
631 AutoMutex _l(mLock);
632
633 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
634 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
635 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
636 }
637 } // release lock
638
639 if (changes) {
640 mInputManager->getReader()->requestRefreshConfiguration(changes);
641 }
Jeff Brown349703e2010-06-22 01:27:15 -0700642}
643
Jeff Brown9302c872011-07-13 22:51:29 -0700644void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
645 sp<InputApplicationHandle> applicationHandle =
646 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
647 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700648}
649
650void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700651 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700652}
653
Jeff Brown05dc66a2011-03-02 14:41:58 -0800654void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
655 AutoMutex _l(mLock);
656
657 if (mLocked.systemUiVisibility != visibility) {
658 mLocked.systemUiVisibility = visibility;
659
660 sp<PointerController> controller = mLocked.pointerController.promote();
661 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700662 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800663 }
664 }
665}
666
Jeff Brown2352b972011-04-12 22:39:53 -0700667void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800668 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700669 controller->setInactivityTimeout(lightsOut
670 ? PointerController::INACTIVITY_TIMEOUT_SHORT
671 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800672}
673
Jeff Brown1a84fd12011-06-02 01:26:32 -0700674void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700675 { // acquire lock
676 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700677
Jeff Brown474dcb52011-06-14 20:22:50 -0700678 if (mLocked.pointerSpeed == speed) {
679 return;
680 }
681
Steve Block6215d3f2012-01-04 20:05:49 +0000682 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700683 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700684 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700685
Jeff Brown474dcb52011-06-14 20:22:50 -0700686 mInputManager->getReader()->requestRefreshConfiguration(
687 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700688}
689
Jeff Browndaf4a122011-08-26 17:14:14 -0700690void NativeInputManager::setShowTouches(bool enabled) {
691 { // acquire lock
692 AutoMutex _l(mLock);
693
694 if (mLocked.showTouches == enabled) {
695 return;
696 }
697
Steve Block6215d3f2012-01-04 20:05:49 +0000698 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700699 mLocked.showTouches = enabled;
700 } // release lock
701
702 mInputManager->getReader()->requestRefreshConfiguration(
703 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
704}
705
Jeff Browne20c9e02010-10-11 14:20:19 -0700706bool NativeInputManager::isScreenOn() {
707 return android_server_PowerManagerService_isScreenOn();
708}
709
710bool NativeInputManager::isScreenBright() {
711 return android_server_PowerManagerService_isScreenBright();
712}
713
Jeff Brown0029c662011-03-30 02:25:18 -0700714bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
715 jobject inputEventObj;
716
717 JNIEnv* env = jniEnv();
718 switch (inputEvent->getType()) {
719 case AINPUT_EVENT_TYPE_KEY:
720 inputEventObj = android_view_KeyEvent_fromNative(env,
721 static_cast<const KeyEvent*>(inputEvent));
722 break;
723 case AINPUT_EVENT_TYPE_MOTION:
724 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
725 static_cast<const MotionEvent*>(inputEvent));
726 break;
727 default:
728 return true; // dispatch the event normally
729 }
730
731 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000732 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700733 return true; // dispatch the event normally
734 }
735
736 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700737 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700738 inputEventObj, policyFlags);
739 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
740 pass = true;
741 }
742 env->DeleteLocalRef(inputEventObj);
743 return pass;
744}
745
Jeff Brown1f245102010-11-18 20:53:46 -0800746void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
747 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700748 // Policy:
749 // - Ignore untrusted events and pass them along.
750 // - Ask the window manager what to do with normal events and trusted injected events.
751 // - For normal events wake and brighten the screen if currently off or dim.
752 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800753 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700754 bool isScreenOn = this->isScreenOn();
755 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700756
Jeff Brown3122e442010-10-11 23:32:49 -0700757 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800758 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
759 jint wmActions;
760 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700761 wmActions = env->CallIntMethod(mServiceObj,
762 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800763 keyEventObj, policyFlags, isScreenOn);
764 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
765 wmActions = 0;
766 }
767 android_view_KeyEvent_recycle(env, keyEventObj);
768 env->DeleteLocalRef(keyEventObj);
769 } else {
Steve Block3762c312012-01-06 19:20:56 +0000770 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700771 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700772 }
773
Jeff Brown1f245102010-11-18 20:53:46 -0800774 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700775 if (!isScreenOn) {
776 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700777 }
778
779 if (!isScreenBright) {
780 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
781 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700782 }
783
Jeff Brown56194eb2011-03-02 19:23:13 -0800784 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700785 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700786 policyFlags |= POLICY_FLAG_PASS_TO_USER;
787 }
788}
789
Jeff Brown56194eb2011-03-02 19:23:13 -0800790void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700791 // Policy:
792 // - Ignore untrusted events and pass them along.
793 // - No special filtering for injected events required at this time.
794 // - Filter normal events based on screen state.
795 // - For normal events brighten (but do not wake) the screen if currently dim.
796 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
797 if (isScreenOn()) {
798 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700799
Jeff Brown3122e442010-10-11 23:32:49 -0700800 if (!isScreenBright()) {
801 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
802 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800803 } else {
804 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700805 jint wmActions = env->CallIntMethod(mServiceObj,
806 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800807 policyFlags);
808 if (checkAndClearExceptionFromCallback(env,
809 "interceptMotionBeforeQueueingWhenScreenOff")) {
810 wmActions = 0;
811 }
812
813 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
814 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700815 }
Jeff Brown3122e442010-10-11 23:32:49 -0700816 } else {
817 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700818 }
819}
820
Jeff Brown56194eb2011-03-02 19:23:13 -0800821void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
822 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800823 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800824#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000825 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800826#endif
827 android_server_PowerManagerService_goToSleep(when);
828 }
829
830 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800831#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000832 ALOGD("handleInterceptActions: Poking user activity.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800833#endif
834 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
835 }
836
837 if (wmActions & WM_ACTION_PASS_TO_USER) {
838 policyFlags |= POLICY_FLAG_PASS_TO_USER;
839 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800840#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000841 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800842#endif
843 }
844}
845
Jeff Brown905805a2011-10-12 13:57:59 -0700846nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800847 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700848 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700849 // Policy:
850 // - Ignore untrusted events and pass them along.
851 // - Filter normal events and trusted injected events through the window manager policy to
852 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700853 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700854 if (policyFlags & POLICY_FLAG_TRUSTED) {
855 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700856
Jeff Brown928e0542011-01-10 11:17:36 -0800857 // Note: inputWindowHandle may be null.
858 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800859 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
860 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700861 jlong delayMillis = env->CallLongMethod(mServiceObj,
862 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800863 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800864 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
865 android_view_KeyEvent_recycle(env, keyEventObj);
866 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700867 if (!error) {
868 if (delayMillis < 0) {
869 result = -1;
870 } else if (delayMillis > 0) {
871 result = milliseconds_to_nanoseconds(delayMillis);
872 }
873 }
Jeff Brown1f245102010-11-18 20:53:46 -0800874 } else {
Steve Block3762c312012-01-06 19:20:56 +0000875 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800876 }
Jeff Brown928e0542011-01-10 11:17:36 -0800877 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700878 }
Jeff Brown1f245102010-11-18 20:53:46 -0800879 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700880}
881
Jeff Brown928e0542011-01-10 11:17:36 -0800882bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800883 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700884 // Policy:
885 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800886 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700887 if (policyFlags & POLICY_FLAG_TRUSTED) {
888 JNIEnv* env = jniEnv();
889
Jeff Brown928e0542011-01-10 11:17:36 -0800890 // Note: inputWindowHandle may be null.
891 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800892 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
893 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700894 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
895 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800896 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700897 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
898 fallbackKeyEventObj = NULL;
899 }
Jeff Brown1f245102010-11-18 20:53:46 -0800900 android_view_KeyEvent_recycle(env, keyEventObj);
901 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800902
903 if (fallbackKeyEventObj) {
904 // Note: outFallbackKeyEvent may be the same object as keyEvent.
905 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
906 outFallbackKeyEvent)) {
907 result = true;
908 }
909 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
910 env->DeleteLocalRef(fallbackKeyEventObj);
911 }
Jeff Brown1f245102010-11-18 20:53:46 -0800912 } else {
Steve Block3762c312012-01-06 19:20:56 +0000913 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800914 }
Jeff Brown928e0542011-01-10 11:17:36 -0800915 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700916 }
Jeff Brown1f245102010-11-18 20:53:46 -0800917 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700918}
919
Jeff Brown01ce2e92010-09-26 22:20:12 -0700920void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
921 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700922}
923
Jeff Brown349703e2010-06-22 01:27:15 -0700924
Jeff Brownb88102f2010-09-08 11:49:43 -0700925bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
926 int32_t injectorPid, int32_t injectorUid) {
927 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700928 jboolean result = env->CallBooleanMethod(mServiceObj,
929 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700930 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
931 result = false;
932 }
Jeff Brown349703e2010-06-22 01:27:15 -0700933 return result;
934}
935
Jeff Brown2352b972011-04-12 22:39:53 -0700936void NativeInputManager::loadPointerResources(PointerResources* outResources) {
937 JNIEnv* env = jniEnv();
938
939 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
940 &outResources->spotHover);
941 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
942 &outResources->spotTouch);
943 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
944 &outResources->spotAnchor);
945}
946
Jeff Brown83c09682010-12-23 17:50:18 -0800947
Jeff Brown9c3cda02010-06-15 01:31:58 -0700948// ----------------------------------------------------------------------------
949
Jeff Brown4532e612012-04-05 14:27:12 -0700950static jint nativeInit(JNIEnv* env, jclass clazz,
951 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
952 sp<Looper> looper = android_os_MessageQueue_getLooper(env, messageQueueObj);
953 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj, looper);
954 im->incStrong(serviceObj);
955 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700956}
957
Jeff Brown4532e612012-04-05 14:27:12 -0700958static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
959 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700960
Jeff Brown4532e612012-04-05 14:27:12 -0700961 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700962 if (result) {
963 jniThrowRuntimeException(env, "Input manager could not be started.");
964 }
965}
966
Jeff Brown4532e612012-04-05 14:27:12 -0700967static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, jint ptr,
Jeff Brownbc68a592011-07-25 12:58:12 -0700968 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -0700969 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700970
971 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
972 // to be passed in like this, not sure which is better but leaving it like this
973 // keeps the window manager in direct control of when display transitions propagate down
974 // to the input dispatcher
Jeff Brown4532e612012-04-05 14:27:12 -0700975 im->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700976}
977
Jeff Brown4532e612012-04-05 14:27:12 -0700978static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
979 jint ptr, jint displayId, jint orientation) {
980 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700981
Jeff Brown4532e612012-04-05 14:27:12 -0700982 im->setDisplayOrientation(displayId, orientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700983}
984
Jeff Brown4532e612012-04-05 14:27:12 -0700985static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
986 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
987 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700988
Jeff Brown4532e612012-04-05 14:27:12 -0700989 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700990 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700991}
992
Jeff Brown4532e612012-04-05 14:27:12 -0700993static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
994 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
995 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700996
Jeff Brown4532e612012-04-05 14:27:12 -0700997 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -0700998 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700999}
1000
Jeff Brown4532e612012-04-05 14:27:12 -07001001static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1002 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1003 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001004
Jeff Brown4532e612012-04-05 14:27:12 -07001005 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001006 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001007}
1008
Jeff Brown4532e612012-04-05 14:27:12 -07001009static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1010 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1011 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001012
1013 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1014 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1015 jsize numCodes = env->GetArrayLength(keyCodes);
1016 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001017 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001018 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001019 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001020 } else {
1021 result = JNI_FALSE;
1022 }
1023
1024 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1025 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1026 return result;
1027}
1028
1029static void throwInputChannelNotInitialized(JNIEnv* env) {
1030 jniThrowException(env, "java/lang/IllegalStateException",
1031 "inputChannel is not initialized");
1032}
1033
Jeff Brown4532e612012-04-05 14:27:12 -07001034static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001035 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001036 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1037
Steve Block8564c8d2012-01-05 23:22:43 +00001038 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001039 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001040 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001041}
1042
Jeff Brown4532e612012-04-05 14:27:12 -07001043static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1044 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1045 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001046
1047 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1048 inputChannelObj);
1049 if (inputChannel == NULL) {
1050 throwInputChannelNotInitialized(env);
1051 return;
1052 }
1053
Jeff Brown928e0542011-01-10 11:17:36 -08001054 sp<InputWindowHandle> inputWindowHandle =
1055 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001056
Jeff Brown4532e612012-04-05 14:27:12 -07001057 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001058 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001059 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001060 String8 message;
1061 message.appendFormat("Failed to register input channel. status=%d", status);
1062 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001063 return;
1064 }
1065
Jeff Browna41ca772010-08-11 14:46:32 -07001066 if (! monitor) {
1067 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001068 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001069 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001070}
1071
Jeff Brown4532e612012-04-05 14:27:12 -07001072static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1073 jint ptr, jobject inputChannelObj) {
1074 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001075
1076 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1077 inputChannelObj);
1078 if (inputChannel == NULL) {
1079 throwInputChannelNotInitialized(env);
1080 return;
1081 }
1082
1083 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1084
Jeff Brown4532e612012-04-05 14:27:12 -07001085 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001086 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1087 String8 message;
1088 message.appendFormat("Failed to unregister input channel. status=%d", status);
1089 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001090 }
1091}
1092
Jeff Brown4532e612012-04-05 14:27:12 -07001093static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1094 jint ptr, jboolean enabled) {
1095 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001096
Jeff Brown4532e612012-04-05 14:27:12 -07001097 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001098}
1099
Jeff Brown4532e612012-04-05 14:27:12 -07001100static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1101 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001102 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001103 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001104
Jeff Brown6ec402b2010-07-28 15:48:59 -07001105 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1106 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001107 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1108 if (status) {
1109 jniThrowRuntimeException(env, "Could not read contents of KeyEvent 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 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1115 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001116 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001117 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1118 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001119 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1120 return INPUT_EVENT_INJECTION_FAILED;
1121 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001122
Jeff Brown4532e612012-04-05 14:27:12 -07001123 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001124 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1125 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001126 } else {
1127 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001128 return INPUT_EVENT_INJECTION_FAILED;
1129 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001130}
1131
Jeff Brown4532e612012-04-05 14:27:12 -07001132static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1133 jint ptr, jobjectArray windowHandleObjArray) {
1134 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001135
Jeff Brown4532e612012-04-05 14:27:12 -07001136 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001137}
1138
Jeff Brown4532e612012-04-05 14:27:12 -07001139static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1140 jint ptr, jobject applicationHandleObj) {
1141 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001142
Jeff Brown4532e612012-04-05 14:27:12 -07001143 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001144}
1145
Jeff Brown4532e612012-04-05 14:27:12 -07001146static void nativeSetInputDispatchMode(JNIEnv* env,
1147 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1148 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001149
Jeff Brown4532e612012-04-05 14:27:12 -07001150 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001151}
1152
Jeff Brown4532e612012-04-05 14:27:12 -07001153static void nativeSetSystemUiVisibility(JNIEnv* env,
1154 jclass clazz, jint ptr, jint visibility) {
1155 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001156
Jeff Brown4532e612012-04-05 14:27:12 -07001157 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001158}
1159
Jeff Brown4532e612012-04-05 14:27:12 -07001160static jobject nativeGetInputDevice(JNIEnv* env,
1161 jclass clazz, jint ptr, jint deviceId) {
1162 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown8d608662010-08-30 03:02:23 -07001163
1164 InputDeviceInfo deviceInfo;
Jeff Brown4532e612012-04-05 14:27:12 -07001165 status_t status = im->getInputManager()->getReader()->getInputDeviceInfo(
Jeff Brown8d608662010-08-30 03:02:23 -07001166 deviceId, & deviceInfo);
1167 if (status) {
1168 return NULL;
1169 }
1170
1171 jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor);
1172 if (! deviceObj) {
1173 return NULL;
1174 }
1175
1176 jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string());
1177 if (! deviceNameObj) {
1178 return NULL;
1179 }
1180
Jeff Brown1e08fe92011-11-15 17:48:10 -08001181 jstring fileStr = env->NewStringUTF(deviceInfo.getKeyCharacterMapFile());
1182 if (!fileStr) {
1183 return NULL;
1184 }
1185
Jeff Brown8d608662010-08-30 03:02:23 -07001186 env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId());
1187 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj);
1188 env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources());
1189 env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType());
Jeff Brown1e08fe92011-11-15 17:48:10 -08001190 env->SetObjectField(deviceObj, gInputDeviceClassInfo.mKeyCharacterMapFile, fileStr);
Jeff Brown8d608662010-08-30 03:02:23 -07001191
Jeff Brownefd32662011-03-08 15:13:06 -08001192 const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
Jeff Brown8d608662010-08-30 03:02:23 -07001193 for (size_t i = 0; i < ranges.size(); i++) {
Jeff Brownefd32662011-03-08 15:13:06 -08001194 const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
Jeff Brown8d608662010-08-30 03:02:23 -07001195 env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange,
Jeff Brownefd32662011-03-08 15:13:06 -08001196 range.axis, range.source, range.min, range.max, range.flat, range.fuzz);
Jeff Brown8d608662010-08-30 03:02:23 -07001197 if (env->ExceptionCheck()) {
1198 return NULL;
1199 }
1200 }
1201
1202 return deviceObj;
1203}
1204
Jeff Brown4532e612012-04-05 14:27:12 -07001205static jintArray nativeGetInputDeviceIds(JNIEnv* env,
1206 jclass clazz, jint ptr) {
1207 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown8d608662010-08-30 03:02:23 -07001208
1209 Vector<int> deviceIds;
Jeff Brown4532e612012-04-05 14:27:12 -07001210 im->getInputManager()->getReader()->getInputDeviceIds(deviceIds);
Jeff Brown8d608662010-08-30 03:02:23 -07001211
1212 jintArray deviceIdsObj = env->NewIntArray(deviceIds.size());
1213 if (! deviceIdsObj) {
1214 return NULL;
1215 }
1216
1217 env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array());
1218 return deviceIdsObj;
1219}
1220
Jeff Brown4532e612012-04-05 14:27:12 -07001221static void nativeGetInputConfiguration(JNIEnv* env,
1222 jclass clazz, jint ptr, jobject configObj) {
1223 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown57c59372010-09-21 18:22:55 -07001224
1225 InputConfiguration config;
Jeff Brown4532e612012-04-05 14:27:12 -07001226 im->getInputManager()->getReader()->getInputConfiguration(& config);
Jeff Brown57c59372010-09-21 18:22:55 -07001227
1228 env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen);
1229 env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard);
1230 env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation);
1231}
1232
Jeff Brown4532e612012-04-05 14:27:12 -07001233static jboolean nativeTransferTouchFocus(JNIEnv* env,
1234 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1235 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001236
1237 sp<InputChannel> fromChannel =
1238 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1239 sp<InputChannel> toChannel =
1240 android_view_InputChannel_getInputChannel(env, toChannelObj);
1241
1242 if (fromChannel == NULL || toChannel == NULL) {
1243 return false;
1244 }
1245
Jeff Brown4532e612012-04-05 14:27:12 -07001246 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001247 transferTouchFocus(fromChannel, toChannel);
1248}
1249
Jeff Brown4532e612012-04-05 14:27:12 -07001250static void nativeSetPointerSpeed(JNIEnv* env,
1251 jclass clazz, jint ptr, jint speed) {
1252 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001253
Jeff Brown4532e612012-04-05 14:27:12 -07001254 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001255}
1256
Jeff Brown4532e612012-04-05 14:27:12 -07001257static void nativeSetShowTouches(JNIEnv* env,
1258 jclass clazz, jint ptr, jboolean enabled) {
1259 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001260
Jeff Brown4532e612012-04-05 14:27:12 -07001261 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001262}
1263
Jeff Brown4532e612012-04-05 14:27:12 -07001264static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1265 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001266
Jeff Brownb88102f2010-09-08 11:49:43 -07001267 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001268 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001269 return env->NewStringUTF(dump.string());
1270}
1271
Jeff Brown4532e612012-04-05 14:27:12 -07001272static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1273 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001274
Jeff Brown4532e612012-04-05 14:27:12 -07001275 im->getInputManager()->getReader()->monitor();
1276 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001277}
1278
Jeff Brown9c3cda02010-06-15 01:31:58 -07001279// ----------------------------------------------------------------------------
1280
Jeff Brown46b9ac02010-04-22 18:58:52 -07001281static JNINativeMethod gInputManagerMethods[] = {
1282 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001283 { "nativeInit",
1284 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1285 (void*) nativeInit },
1286 { "nativeStart", "(I)V",
1287 (void*) nativeStart },
1288 { "nativeSetDisplaySize", "(IIIIII)V",
1289 (void*) nativeSetDisplaySize },
1290 { "nativeSetDisplayOrientation", "(III)V",
1291 (void*) nativeSetDisplayOrientation },
1292 { "nativeGetScanCodeState", "(IIII)I",
1293 (void*) nativeGetScanCodeState },
1294 { "nativeGetKeyCodeState", "(IIII)I",
1295 (void*) nativeGetKeyCodeState },
1296 { "nativeGetSwitchState", "(IIII)I",
1297 (void*) nativeGetSwitchState },
1298 { "nativeHasKeys", "(III[I[Z)Z",
1299 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001300 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001301 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1302 (void*) nativeRegisterInputChannel },
1303 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1304 (void*) nativeUnregisterInputChannel },
1305 { "nativeSetInputFilterEnabled", "(IZ)V",
1306 (void*) nativeSetInputFilterEnabled },
1307 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1308 (void*) nativeInjectInputEvent },
1309 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1310 (void*) nativeSetInputWindows },
1311 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1312 (void*) nativeSetFocusedApplication },
1313 { "nativeSetInputDispatchMode", "(IZZ)V",
1314 (void*) nativeSetInputDispatchMode },
1315 { "nativeSetSystemUiVisibility", "(II)V",
1316 (void*) nativeSetSystemUiVisibility },
1317 { "nativeGetInputDevice", "(II)Landroid/view/InputDevice;",
1318 (void*) nativeGetInputDevice },
1319 { "nativeGetInputDeviceIds", "(I)[I",
1320 (void*) nativeGetInputDeviceIds },
1321 { "nativeGetInputConfiguration", "(ILandroid/content/res/Configuration;)V",
1322 (void*) nativeGetInputConfiguration },
1323 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1324 (void*) nativeTransferTouchFocus },
1325 { "nativeSetPointerSpeed", "(II)V",
1326 (void*) nativeSetPointerSpeed },
1327 { "nativeSetShowTouches", "(IZ)V",
1328 (void*) nativeSetShowTouches },
1329 { "nativeDump", "(I)Ljava/lang/String;",
1330 (void*) nativeDump },
1331 { "nativeMonitor", "(I)V",
1332 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001333};
1334
1335#define FIND_CLASS(var, className) \
1336 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001337 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001338
1339#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1340 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1341 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1342
1343#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1344 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1345 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1346
1347int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001348 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001349 gInputManagerMethods, NELEM(gInputManagerMethods));
1350 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1351
Jeff Brown9c3cda02010-06-15 01:31:58 -07001352 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001353
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001354 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001355 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001356
Jeff Brown4532e612012-04-05 14:27:12 -07001357 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001358 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001359
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 Brown6ec402b2010-07-28 15:48:59 -07001421 // KeyEvent
1422
1423 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001424 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1425
Jeff Brown8d608662010-08-30 03:02:23 -07001426 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001427
1428 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001429 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001430
Jeff Brown8d608662010-08-30 03:02:23 -07001431 // InputDevice
1432
1433 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001434 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
Jeff Brown8d608662010-08-30 03:02:23 -07001435
1436 GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz,
1437 "<init>", "()V");
1438
1439 GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz,
Jeff Brownefd32662011-03-08 15:13:06 -08001440 "addMotionRange", "(IIFFFF)V");
Jeff Brown8d608662010-08-30 03:02:23 -07001441
1442 GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz,
1443 "mId", "I");
1444
1445 GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz,
1446 "mName", "Ljava/lang/String;");
1447
1448 GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz,
1449 "mSources", "I");
1450
1451 GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz,
1452 "mKeyboardType", "I");
1453
Jeff Brown1e08fe92011-11-15 17:48:10 -08001454 GET_FIELD_ID(gInputDeviceClassInfo.mKeyCharacterMapFile, gInputDeviceClassInfo.clazz,
1455 "mKeyCharacterMapFile", "Ljava/lang/String;");
1456
Jeff Brown57c59372010-09-21 18:22:55 -07001457 // Configuration
1458
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001459 FIND_CLASS(clazz, "android/content/res/Configuration");
Jeff Brown57c59372010-09-21 18:22:55 -07001460
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001461 GET_FIELD_ID(gConfigurationClassInfo.touchscreen, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001462 "touchscreen", "I");
1463
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001464 GET_FIELD_ID(gConfigurationClassInfo.keyboard, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001465 "keyboard", "I");
1466
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001467 GET_FIELD_ID(gConfigurationClassInfo.navigation, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001468 "navigation", "I");
1469
Jeff Brown46b9ac02010-04-22 18:58:52 -07001470 return 0;
1471}
1472
Jeff Brown46b9ac02010-04-22 18:58:52 -07001473} /* namespace android */