blob: 09e5be40bb995f00b71b5503551edeb6338e1c08 [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 Brown6ec6f792012-04-17 16:52:41 -070049#include <ScopedLocalRef.h>
50#include <ScopedUtfChars.h>
51
Jeff Brown4f8ecd82012-06-18 18:29:13 -070052#include "com_android_server_power_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070053#include "com_android_server_input_InputApplicationHandle.h"
54#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070055
56namespace android {
57
Jeff Brown1a84fd12011-06-02 01:26:32 -070058// The exponent used to calculate the pointer speed scaling factor.
59// The scaling factor is calculated as 2 ^ (speed * exponent),
60// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070061static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070062
Jeff Brown46b9ac02010-04-22 18:58:52 -070063static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070064 jmethodID notifyConfigurationChanged;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070065 jmethodID notifyInputDevicesChanged;
Jeff Brown53384282012-08-20 20:16:01 -070066 jmethodID notifySwitch;
Jeff Brown7fbdc842010-06-17 20:52:56 -070067 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070068 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070069 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070070 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080071 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070072 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070073 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070074 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080075 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070076 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080077 jmethodID getKeyRepeatTimeout;
78 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070079 jmethodID getHoverTapTimeout;
80 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070081 jmethodID getDoubleTapTimeout;
82 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080083 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080084 jmethodID getPointerIcon;
Jeff Brown6ec6f792012-04-17 16:52:41 -070085 jmethodID getKeyboardLayoutOverlay;
Jeff Brown5bbd4b42012-04-20 19:28:00 -070086 jmethodID getDeviceAlias;
Jeff Brown4532e612012-04-05 14:27:12 -070087} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070088
89static struct {
90 jclass clazz;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070091} gInputDeviceClassInfo;
92
93static struct {
94 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070095} gKeyEventClassInfo;
96
97static struct {
98 jclass clazz;
99} gMotionEventClassInfo;
100
Jeff Brown928e0542011-01-10 11:17:36 -0800101
102// --- Global functions ---
103
Jeff Brown214eaf42011-05-26 19:17:02 -0700104template<typename T>
105inline static T min(const T& a, const T& b) {
106 return a < b ? a : b;
107}
108
109template<typename T>
110inline static T max(const T& a, const T& b) {
111 return a > b ? a : b;
112}
113
Jeff Brown928e0542011-01-10 11:17:36 -0800114static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
115 const sp<InputApplicationHandle>& inputApplicationHandle) {
116 if (inputApplicationHandle == NULL) {
117 return NULL;
118 }
119 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
120 getInputApplicationHandleObjLocalRef(env);
121}
122
123static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
124 const sp<InputWindowHandle>& inputWindowHandle) {
125 if (inputWindowHandle == NULL) {
126 return NULL;
127 }
128 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
129 getInputWindowHandleObjLocalRef(env);
130}
131
Jeff Brown2352b972011-04-12 22:39:53 -0700132static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
133 SpriteIcon* outSpriteIcon) {
134 PointerIcon pointerIcon;
135 status_t status = android_view_PointerIcon_loadSystemIcon(env,
136 contextObj, style, &pointerIcon);
137 if (!status) {
138 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
139 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
140 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
141 }
142}
143
Jeff Brown905805a2011-10-12 13:57:59 -0700144enum {
145 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown96307042012-07-27 15:51:34 -0700146 WM_ACTION_WAKE_UP = 2,
Jeff Brown905805a2011-10-12 13:57:59 -0700147 WM_ACTION_GO_TO_SLEEP = 4,
148};
149
Jeff Brown928e0542011-01-10 11:17:36 -0800150
151// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800152
Jeff Brown9c3cda02010-06-15 01:31:58 -0700153class NativeInputManager : public virtual RefBase,
154 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700155 public virtual InputDispatcherPolicyInterface,
156 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700157protected:
158 virtual ~NativeInputManager();
159
160public:
Jeff Brown4532e612012-04-05 14:27:12 -0700161 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700162
163 inline sp<InputManager> getInputManager() const { return mInputManager; }
164
Jeff Brownb88102f2010-09-08 11:49:43 -0700165 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700166
Jeff Brownd728bf52012-09-08 18:05:28 -0700167 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700168
Jeff Brown7fbdc842010-06-17 20:52:56 -0700169 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800170 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700171 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
172
Jeff Brown9302c872011-07-13 22:51:29 -0700173 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
174 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700175 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800176 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700177 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700178 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700179
Jeff Brown9c3cda02010-06-15 01:31:58 -0700180 /* --- InputReaderPolicyInterface implementation --- */
181
Jeff Brown214eaf42011-05-26 19:17:02 -0700182 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800183 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700184 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700185 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700186 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700187
188 /* --- InputDispatcherPolicyInterface implementation --- */
189
Jeff Brownbcc046a2012-09-27 20:46:43 -0700190 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700191 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700192 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700193 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800194 const sp<InputWindowHandle>& inputWindowHandle);
195 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700196 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700197 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
198 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800199 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800200 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700201 virtual nsecs_t interceptKeyBeforeDispatching(
202 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700203 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800204 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800205 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700206 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700207 virtual bool checkInjectEventsPermissionNonReentrant(
208 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700209
Jeff Brown2352b972011-04-12 22:39:53 -0700210 /* --- PointerControllerPolicyInterface implementation --- */
211
212 virtual void loadPointerResources(PointerResources* outResources);
213
Jeff Brown9c3cda02010-06-15 01:31:58 -0700214private:
215 sp<InputManager> mInputManager;
216
Jeff Brown2352b972011-04-12 22:39:53 -0700217 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700218 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800219 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700220
Jeff Brown83c09682010-12-23 17:50:18 -0800221 Mutex mLock;
222 struct Locked {
223 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700224 DisplayViewport internalViewport;
225 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800226
Jeff Brown05dc66a2011-03-02 14:41:58 -0800227 // System UI visibility.
228 int32_t systemUiVisibility;
229
Jeff Brown1a84fd12011-06-02 01:26:32 -0700230 // Pointer speed.
231 int32_t pointerSpeed;
232
Jeff Brown474dcb52011-06-14 20:22:50 -0700233 // True if pointer gestures are enabled.
234 bool pointerGesturesEnabled;
235
Jeff Browndaf4a122011-08-26 17:14:14 -0700236 // Show touches feature enable/disable.
237 bool showTouches;
238
Jeff Brown5541de92011-04-11 11:54:25 -0700239 // Sprite controller singleton, created on first use.
240 sp<SpriteController> spriteController;
241
Jeff Brown83c09682010-12-23 17:50:18 -0800242 // Pointer controller singleton, created and destroyed as needed.
243 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800244 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700245
Jeff Brown2352b972011-04-12 22:39:53 -0700246 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800247 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700248 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800249
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700250 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700251 bool isScreenOn();
252 bool isScreenBright();
253
Jeff Brownb88102f2010-09-08 11:49:43 -0700254 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700255
Jeff Brown9c3cda02010-06-15 01:31:58 -0700256 static inline JNIEnv* jniEnv() {
257 return AndroidRuntime::getJNIEnv();
258 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700259};
260
Jeff Brown928e0542011-01-10 11:17:36 -0800261
Jeff Brown9c3cda02010-06-15 01:31:58 -0700262
Jeff Brown2352b972011-04-12 22:39:53 -0700263NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700264 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700265 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700266 JNIEnv* env = jniEnv();
267
Jeff Brown2352b972011-04-12 22:39:53 -0700268 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700269 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270
Jeff Brown83c09682010-12-23 17:50:18 -0800271 {
272 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800273 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700274 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700275 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700276 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800277 }
278
Jeff Brown9c3cda02010-06-15 01:31:58 -0700279 sp<EventHub> eventHub = new EventHub();
280 mInputManager = new InputManager(eventHub, this, this);
281}
282
283NativeInputManager::~NativeInputManager() {
284 JNIEnv* env = jniEnv();
285
Jeff Brown2352b972011-04-12 22:39:53 -0700286 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700287 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700288}
289
Jeff Brownb88102f2010-09-08 11:49:43 -0700290void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700291 mInputManager->getReader()->dump(dump);
292 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700293
Jeff Brownb88102f2010-09-08 11:49:43 -0700294 mInputManager->getDispatcher()->dump(dump);
295 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700296}
297
Jeff Brown7fbdc842010-06-17 20:52:56 -0700298bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700299 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000300 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700301 LOGE_EX(env);
302 env->ExceptionClear();
303 return true;
304 }
305 return false;
306}
307
Jeff Brownd728bf52012-09-08 18:05:28 -0700308void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700309 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700310 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700311 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700312
Jeff Brownd728bf52012-09-08 18:05:28 -0700313 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
314 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700315 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700316 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700317
Jeff Brownd728bf52012-09-08 18:05:28 -0700318 if (!external) {
319 sp<PointerController> controller = mLocked.pointerController.promote();
320 if (controller != NULL) {
321 controller->setDisplayViewport(
322 viewport.logicalRight - viewport.logicalLeft,
323 viewport.logicalBottom - viewport.logicalTop,
324 viewport.orientation);
325 }
Jeff Brown2352b972011-04-12 22:39:53 -0700326 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700327 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700328 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700329
330 if (changed) {
331 mInputManager->getReader()->requestRefreshConfiguration(
332 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
333 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700334}
335
Jeff Brown7fbdc842010-06-17 20:52:56 -0700336status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800337 const sp<InputChannel>& inputChannel,
338 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
339 return mInputManager->getDispatcher()->registerInputChannel(
340 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700341}
342
343status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
344 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700345 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700346}
347
Jeff Brown214eaf42011-05-26 19:17:02 -0700348void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700349 JNIEnv* env = jniEnv();
350
Jeff Brown4532e612012-04-05 14:27:12 -0700351 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
352 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700353 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
354 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
355 }
356
357 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700358 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
359 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700360 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
361 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700362 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700363 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700364 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700365 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700366 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700367 env->DeleteLocalRef(item);
368 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700369 env->DeleteLocalRef(excludedDeviceNames);
370 }
371
Jeff Brown4532e612012-04-05 14:27:12 -0700372 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
373 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700374 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700375 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
376 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700377 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700378 jint longPressTimeout = env->CallIntMethod(mServiceObj,
379 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700380 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700381 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700382
383 // We must ensure that the tap-drag interval is significantly shorter than
384 // the long-press timeout because the tap is held down for the entire duration
385 // of the double-tap timeout.
386 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700387 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700388 outConfig->pointerGestureTapDragInterval =
389 milliseconds_to_nanoseconds(tapDragInterval);
390 }
391 }
392 }
393
Jeff Brown4532e612012-04-05 14:27:12 -0700394 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
395 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700396 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
397 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700398 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700399
400 { // acquire lock
401 AutoMutex _l(mLock);
402
403 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
404 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700405 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700406
Jeff Browndaf4a122011-08-26 17:14:14 -0700407 outConfig->showTouches = mLocked.showTouches;
408
Jeff Brownd728bf52012-09-08 18:05:28 -0700409 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
410 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700411 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700412}
413
Jeff Brown83c09682010-12-23 17:50:18 -0800414sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
415 AutoMutex _l(mLock);
416
417 sp<PointerController> controller = mLocked.pointerController.promote();
418 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700419 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800420
Jeff Brown2352b972011-04-12 22:39:53 -0700421 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800422 mLocked.pointerController = controller;
423
Jeff Brownd728bf52012-09-08 18:05:28 -0700424 DisplayViewport& v = mLocked.internalViewport;
425 controller->setDisplayViewport(
426 v.logicalRight - v.logicalLeft,
427 v.logicalBottom - v.logicalTop,
428 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800429
Jeff Brown5541de92011-04-11 11:54:25 -0700430 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700431 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
432 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700433 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
434 PointerIcon pointerIcon;
435 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
436 mContextObj, &pointerIcon);
437 if (!status && !pointerIcon.isNullIcon()) {
438 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
439 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
440 } else {
441 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800442 }
Jeff Brown2352b972011-04-12 22:39:53 -0700443 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800444 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800445
Jeff Brown2352b972011-04-12 22:39:53 -0700446 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800447 }
448 return controller;
449}
450
Jeff Brown5541de92011-04-11 11:54:25 -0700451void NativeInputManager::ensureSpriteControllerLocked() {
452 if (mLocked.spriteController == NULL) {
453 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700454 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700455 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
456 layer = -1;
457 }
458 mLocked.spriteController = new SpriteController(mLooper, layer);
459 }
460}
461
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700462void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
463 JNIEnv* env = jniEnv();
464
465 size_t count = inputDevices.size();
466 jobjectArray inputDevicesObjArray = env->NewObjectArray(
467 count, gInputDeviceClassInfo.clazz, NULL);
468 if (inputDevicesObjArray) {
469 bool error = false;
470 for (size_t i = 0; i < count; i++) {
471 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
472 if (!inputDeviceObj) {
473 error = true;
474 break;
475 }
476
477 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
478 env->DeleteLocalRef(inputDeviceObj);
479 }
480
481 if (!error) {
482 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
483 inputDevicesObjArray);
484 }
485
486 env->DeleteLocalRef(inputDevicesObjArray);
487 }
488
489 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
490}
491
Jeff Brown6ec6f792012-04-17 16:52:41 -0700492sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
493 const String8& inputDeviceDescriptor) {
494 JNIEnv* env = jniEnv();
495
496 sp<KeyCharacterMap> result;
497 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
498 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
499 gServiceClassInfo.getKeyboardLayoutOverlay, descriptorObj.get())));
500 if (arrayObj.get()) {
501 ScopedLocalRef<jstring> filenameObj(env,
502 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
503 ScopedLocalRef<jstring> contentsObj(env,
504 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
505 ScopedUtfChars filenameChars(env, filenameObj.get());
506 ScopedUtfChars contentsChars(env, contentsObj.get());
507
508 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
509 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
510 }
511 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
512 return result;
513}
514
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700515String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
516 JNIEnv* env = jniEnv();
517
518 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
519 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
520 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
521 String8 result;
522 if (aliasObj.get()) {
523 ScopedUtfChars aliasChars(env, aliasObj.get());
524 result.setTo(aliasChars.c_str());
525 }
526 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
527 return result;
528}
529
Jeff Brownbcc046a2012-09-27 20:46:43 -0700530void NativeInputManager::notifySwitch(nsecs_t when,
531 uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700532#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700533 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
534 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700535#endif
536
537 JNIEnv* env = jniEnv();
538
Jeff Brown53384282012-08-20 20:16:01 -0700539 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700540 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700541 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700542}
543
Jeff Brown9c3cda02010-06-15 01:31:58 -0700544void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
545#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000546 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700547#endif
548
549 JNIEnv* env = jniEnv();
550
Jeff Brown4532e612012-04-05 14:27:12 -0700551 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700552 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700553}
554
Jeff Brown519e0242010-09-15 15:18:56 -0700555nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800556 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700557#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000558 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700559#endif
560
561 JNIEnv* env = jniEnv();
562
Jeff Brown928e0542011-01-10 11:17:36 -0800563 jobject inputApplicationHandleObj =
564 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
565 jobject inputWindowHandleObj =
566 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700567
Jeff Brown4532e612012-04-05 14:27:12 -0700568 jlong newTimeout = env->CallLongMethod(mServiceObj,
569 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700570 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
571 newTimeout = 0; // abort dispatch
572 } else {
573 assert(newTimeout >= 0);
574 }
575
Jeff Brown928e0542011-01-10 11:17:36 -0800576 env->DeleteLocalRef(inputWindowHandleObj);
577 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700578 return newTimeout;
579}
580
Jeff Brown928e0542011-01-10 11:17:36 -0800581void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700582#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000583 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700584#endif
585
Jeff Brown7fbdc842010-06-17 20:52:56 -0700586 JNIEnv* env = jniEnv();
587
Jeff Brown928e0542011-01-10 11:17:36 -0800588 jobject inputWindowHandleObj =
589 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
590 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700591 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800592 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700593 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
594
Jeff Brown928e0542011-01-10 11:17:36 -0800595 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700596 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700597}
598
Jeff Brown214eaf42011-05-26 19:17:02 -0700599void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
600 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800601
Jeff Brown4532e612012-04-05 14:27:12 -0700602 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
603 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700604 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
605 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
606 }
Jeff Browna4547672011-03-02 21:38:11 -0800607
Jeff Brown4532e612012-04-05 14:27:12 -0700608 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
609 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700610 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
611 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
612 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700613}
614
Jeff Brown214eaf42011-05-26 19:17:02 -0700615bool NativeInputManager::isKeyRepeatEnabled() {
616 // Only enable automatic key repeating when the screen is on.
617 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700618}
619
Jeff Brown9302c872011-07-13 22:51:29 -0700620void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
621 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700622
Jeff Brown9302c872011-07-13 22:51:29 -0700623 if (windowHandleObjArray) {
624 jsize length = env->GetArrayLength(windowHandleObjArray);
625 for (jsize i = 0; i < length; i++) {
626 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
627 if (! windowHandleObj) {
628 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700629 }
Jeff Brown9302c872011-07-13 22:51:29 -0700630
631 sp<InputWindowHandle> windowHandle =
632 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
633 if (windowHandle != NULL) {
634 windowHandles.push(windowHandle);
635 }
636 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700637 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700638 }
Jeff Brown349703e2010-06-22 01:27:15 -0700639
Jeff Brown9302c872011-07-13 22:51:29 -0700640 mInputManager->getDispatcher()->setInputWindows(windowHandles);
641
642 // Do this after the dispatcher has updated the window handle state.
643 bool newPointerGesturesEnabled = true;
644 size_t numWindows = windowHandles.size();
645 for (size_t i = 0; i < numWindows; i++) {
646 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700647 const InputWindowInfo* windowInfo = windowHandle->getInfo();
648 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
649 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700650 newPointerGesturesEnabled = false;
651 }
652 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700653
654 uint32_t changes = 0;
655 { // acquire lock
656 AutoMutex _l(mLock);
657
658 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
659 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
660 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
661 }
662 } // release lock
663
664 if (changes) {
665 mInputManager->getReader()->requestRefreshConfiguration(changes);
666 }
Jeff Brown349703e2010-06-22 01:27:15 -0700667}
668
Jeff Brown9302c872011-07-13 22:51:29 -0700669void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
670 sp<InputApplicationHandle> applicationHandle =
671 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
672 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700673}
674
675void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700676 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700677}
678
Jeff Brown05dc66a2011-03-02 14:41:58 -0800679void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
680 AutoMutex _l(mLock);
681
682 if (mLocked.systemUiVisibility != visibility) {
683 mLocked.systemUiVisibility = visibility;
684
685 sp<PointerController> controller = mLocked.pointerController.promote();
686 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700687 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800688 }
689 }
690}
691
Jeff Brown2352b972011-04-12 22:39:53 -0700692void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800693 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700694 controller->setInactivityTimeout(lightsOut
695 ? PointerController::INACTIVITY_TIMEOUT_SHORT
696 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800697}
698
Jeff Brown1a84fd12011-06-02 01:26:32 -0700699void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700700 { // acquire lock
701 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700702
Jeff Brown474dcb52011-06-14 20:22:50 -0700703 if (mLocked.pointerSpeed == speed) {
704 return;
705 }
706
Steve Block6215d3f2012-01-04 20:05:49 +0000707 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700708 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700709 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700710
Jeff Brown474dcb52011-06-14 20:22:50 -0700711 mInputManager->getReader()->requestRefreshConfiguration(
712 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700713}
714
Jeff Browndaf4a122011-08-26 17:14:14 -0700715void NativeInputManager::setShowTouches(bool enabled) {
716 { // acquire lock
717 AutoMutex _l(mLock);
718
719 if (mLocked.showTouches == enabled) {
720 return;
721 }
722
Steve Block6215d3f2012-01-04 20:05:49 +0000723 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700724 mLocked.showTouches = enabled;
725 } // release lock
726
727 mInputManager->getReader()->requestRefreshConfiguration(
728 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
729}
730
Jeff Browne20c9e02010-10-11 14:20:19 -0700731bool NativeInputManager::isScreenOn() {
732 return android_server_PowerManagerService_isScreenOn();
733}
734
735bool NativeInputManager::isScreenBright() {
736 return android_server_PowerManagerService_isScreenBright();
737}
738
Jeff Brown0029c662011-03-30 02:25:18 -0700739bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
740 jobject inputEventObj;
741
742 JNIEnv* env = jniEnv();
743 switch (inputEvent->getType()) {
744 case AINPUT_EVENT_TYPE_KEY:
745 inputEventObj = android_view_KeyEvent_fromNative(env,
746 static_cast<const KeyEvent*>(inputEvent));
747 break;
748 case AINPUT_EVENT_TYPE_MOTION:
749 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
750 static_cast<const MotionEvent*>(inputEvent));
751 break;
752 default:
753 return true; // dispatch the event normally
754 }
755
756 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000757 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700758 return true; // dispatch the event normally
759 }
760
761 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700762 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700763 inputEventObj, policyFlags);
764 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
765 pass = true;
766 }
767 env->DeleteLocalRef(inputEventObj);
768 return pass;
769}
770
Jeff Brown1f245102010-11-18 20:53:46 -0800771void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
772 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700773 // Policy:
774 // - Ignore untrusted events and pass them along.
775 // - Ask the window manager what to do with normal events and trusted injected events.
776 // - For normal events wake and brighten the screen if currently off or dim.
777 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800778 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700779 bool isScreenOn = this->isScreenOn();
780 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700781
Jeff Brown3122e442010-10-11 23:32:49 -0700782 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800783 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
784 jint wmActions;
785 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700786 wmActions = env->CallIntMethod(mServiceObj,
787 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800788 keyEventObj, policyFlags, isScreenOn);
789 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
790 wmActions = 0;
791 }
792 android_view_KeyEvent_recycle(env, keyEventObj);
793 env->DeleteLocalRef(keyEventObj);
794 } else {
Steve Block3762c312012-01-06 19:20:56 +0000795 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700796 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700797 }
798
Jeff Brown1f245102010-11-18 20:53:46 -0800799 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700800 if (!isScreenOn) {
801 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700802 }
803
804 if (!isScreenBright) {
805 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
806 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700807 }
808
Jeff Brown56194eb2011-03-02 19:23:13 -0800809 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700810 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700811 policyFlags |= POLICY_FLAG_PASS_TO_USER;
812 }
813}
814
Jeff Brown56194eb2011-03-02 19:23:13 -0800815void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700816 // Policy:
817 // - Ignore untrusted events and pass them along.
818 // - No special filtering for injected events required at this time.
819 // - Filter normal events based on screen state.
820 // - For normal events brighten (but do not wake) the screen if currently dim.
821 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
822 if (isScreenOn()) {
823 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700824
Jeff Brown3122e442010-10-11 23:32:49 -0700825 if (!isScreenBright()) {
826 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
827 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800828 } else {
829 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700830 jint wmActions = env->CallIntMethod(mServiceObj,
831 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800832 policyFlags);
833 if (checkAndClearExceptionFromCallback(env,
834 "interceptMotionBeforeQueueingWhenScreenOff")) {
835 wmActions = 0;
836 }
837
838 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
839 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700840 }
Jeff Brown3122e442010-10-11 23:32:49 -0700841 } else {
842 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700843 }
844}
845
Jeff Brown56194eb2011-03-02 19:23:13 -0800846void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
847 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800848 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800849#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000850 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800851#endif
852 android_server_PowerManagerService_goToSleep(when);
853 }
854
Jeff Brown96307042012-07-27 15:51:34 -0700855 if (wmActions & WM_ACTION_WAKE_UP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800856#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown96307042012-07-27 15:51:34 -0700857 ALOGD("handleInterceptActions: Waking up.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800858#endif
Jeff Brown96307042012-07-27 15:51:34 -0700859 android_server_PowerManagerService_wakeUp(when);
Jeff Brown56194eb2011-03-02 19:23:13 -0800860 }
861
862 if (wmActions & WM_ACTION_PASS_TO_USER) {
863 policyFlags |= POLICY_FLAG_PASS_TO_USER;
864 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800865#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000866 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800867#endif
868 }
869}
870
Jeff Brown905805a2011-10-12 13:57:59 -0700871nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800872 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700873 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700874 // Policy:
875 // - Ignore untrusted events and pass them along.
876 // - Filter normal events and trusted injected events through the window manager policy to
877 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700878 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700879 if (policyFlags & POLICY_FLAG_TRUSTED) {
880 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700881
Jeff Brown928e0542011-01-10 11:17:36 -0800882 // Note: inputWindowHandle may be null.
883 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800884 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
885 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700886 jlong delayMillis = env->CallLongMethod(mServiceObj,
887 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800888 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800889 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
890 android_view_KeyEvent_recycle(env, keyEventObj);
891 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700892 if (!error) {
893 if (delayMillis < 0) {
894 result = -1;
895 } else if (delayMillis > 0) {
896 result = milliseconds_to_nanoseconds(delayMillis);
897 }
898 }
Jeff Brown1f245102010-11-18 20:53:46 -0800899 } else {
Steve Block3762c312012-01-06 19:20:56 +0000900 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800901 }
Jeff Brown928e0542011-01-10 11:17:36 -0800902 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700903 }
Jeff Brown1f245102010-11-18 20:53:46 -0800904 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700905}
906
Jeff Brown928e0542011-01-10 11:17:36 -0800907bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800908 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700909 // Policy:
910 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800911 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700912 if (policyFlags & POLICY_FLAG_TRUSTED) {
913 JNIEnv* env = jniEnv();
914
Jeff Brown928e0542011-01-10 11:17:36 -0800915 // Note: inputWindowHandle may be null.
916 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800917 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
918 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700919 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
920 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800921 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700922 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
923 fallbackKeyEventObj = NULL;
924 }
Jeff Brown1f245102010-11-18 20:53:46 -0800925 android_view_KeyEvent_recycle(env, keyEventObj);
926 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800927
928 if (fallbackKeyEventObj) {
929 // Note: outFallbackKeyEvent may be the same object as keyEvent.
930 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
931 outFallbackKeyEvent)) {
932 result = true;
933 }
934 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
935 env->DeleteLocalRef(fallbackKeyEventObj);
936 }
Jeff Brown1f245102010-11-18 20:53:46 -0800937 } else {
Steve Block3762c312012-01-06 19:20:56 +0000938 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800939 }
Jeff Brown928e0542011-01-10 11:17:36 -0800940 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700941 }
Jeff Brown1f245102010-11-18 20:53:46 -0800942 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700943}
944
Jeff Brown01ce2e92010-09-26 22:20:12 -0700945void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
946 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700947}
948
Jeff Brown349703e2010-06-22 01:27:15 -0700949
Jeff Brownb88102f2010-09-08 11:49:43 -0700950bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
951 int32_t injectorPid, int32_t injectorUid) {
952 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700953 jboolean result = env->CallBooleanMethod(mServiceObj,
954 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700955 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
956 result = false;
957 }
Jeff Brown349703e2010-06-22 01:27:15 -0700958 return result;
959}
960
Jeff Brown2352b972011-04-12 22:39:53 -0700961void NativeInputManager::loadPointerResources(PointerResources* outResources) {
962 JNIEnv* env = jniEnv();
963
964 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
965 &outResources->spotHover);
966 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
967 &outResources->spotTouch);
968 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
969 &outResources->spotAnchor);
970}
971
Jeff Brown83c09682010-12-23 17:50:18 -0800972
Jeff Brown9c3cda02010-06-15 01:31:58 -0700973// ----------------------------------------------------------------------------
974
Jeff Brown4532e612012-04-05 14:27:12 -0700975static jint nativeInit(JNIEnv* env, jclass clazz,
976 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -0700977 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -0800978 if (messageQueue == NULL) {
979 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
980 return 0;
981 }
982
Jeff Brown603b4452012-04-06 17:39:41 -0700983 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
984 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800985 im->incStrong(0);
Jeff Brown4532e612012-04-05 14:27:12 -0700986 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700987}
988
Jeff Brown4532e612012-04-05 14:27:12 -0700989static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
990 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700991
Jeff Brown4532e612012-04-05 14:27:12 -0700992 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700993 if (result) {
994 jniThrowRuntimeException(env, "Input manager could not be started.");
995 }
996}
997
Jeff Brownd728bf52012-09-08 18:05:28 -0700998static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jint ptr, jboolean external,
999 jint displayId, jint orientation,
1000 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001001 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1002 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001003 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001004
Jeff Brownd728bf52012-09-08 18:05:28 -07001005 DisplayViewport v;
1006 v.displayId = displayId;
1007 v.orientation = orientation;
1008 v.logicalLeft = logicalLeft;
1009 v.logicalTop = logicalTop;
1010 v.logicalRight = logicalRight;
1011 v.logicalBottom = logicalBottom;
1012 v.physicalLeft = physicalLeft;
1013 v.physicalTop = physicalTop;
1014 v.physicalRight = physicalRight;
1015 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001016 v.deviceWidth = deviceWidth;
1017 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001018 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001019}
1020
Jeff Brown4532e612012-04-05 14:27:12 -07001021static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
1022 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
1023 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001024
Jeff Brown4532e612012-04-05 14:27:12 -07001025 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001026 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001027}
1028
Jeff Brown4532e612012-04-05 14:27:12 -07001029static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
1030 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
1031 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001032
Jeff Brown4532e612012-04-05 14:27:12 -07001033 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001034 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001035}
1036
Jeff Brown4532e612012-04-05 14:27:12 -07001037static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1038 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1039 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001040
Jeff Brown4532e612012-04-05 14:27:12 -07001041 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001042 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001043}
1044
Jeff Brown4532e612012-04-05 14:27:12 -07001045static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1046 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1047 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001048
1049 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1050 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1051 jsize numCodes = env->GetArrayLength(keyCodes);
1052 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001053 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001054 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001055 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001056 } else {
1057 result = JNI_FALSE;
1058 }
1059
1060 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1061 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1062 return result;
1063}
1064
1065static void throwInputChannelNotInitialized(JNIEnv* env) {
1066 jniThrowException(env, "java/lang/IllegalStateException",
1067 "inputChannel is not initialized");
1068}
1069
Jeff Brown4532e612012-04-05 14:27:12 -07001070static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001071 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001072 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1073
Steve Block8564c8d2012-01-05 23:22:43 +00001074 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001075 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001076 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001077}
1078
Jeff Brown4532e612012-04-05 14:27:12 -07001079static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1080 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1081 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001082
1083 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1084 inputChannelObj);
1085 if (inputChannel == NULL) {
1086 throwInputChannelNotInitialized(env);
1087 return;
1088 }
1089
Jeff Brown928e0542011-01-10 11:17:36 -08001090 sp<InputWindowHandle> inputWindowHandle =
1091 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001092
Jeff Brown4532e612012-04-05 14:27:12 -07001093 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001094 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001095 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001096 String8 message;
1097 message.appendFormat("Failed to register input channel. status=%d", status);
1098 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001099 return;
1100 }
1101
Jeff Browna41ca772010-08-11 14:46:32 -07001102 if (! monitor) {
1103 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001104 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001105 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001106}
1107
Jeff Brown4532e612012-04-05 14:27:12 -07001108static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1109 jint ptr, jobject inputChannelObj) {
1110 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001111
1112 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1113 inputChannelObj);
1114 if (inputChannel == NULL) {
1115 throwInputChannelNotInitialized(env);
1116 return;
1117 }
1118
1119 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1120
Jeff Brown4532e612012-04-05 14:27:12 -07001121 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001122 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1123 String8 message;
1124 message.appendFormat("Failed to unregister input channel. status=%d", status);
1125 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001126 }
1127}
1128
Jeff Brown4532e612012-04-05 14:27:12 -07001129static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1130 jint ptr, jboolean enabled) {
1131 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001132
Jeff Brown4532e612012-04-05 14:27:12 -07001133 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001134}
1135
Jeff Brown4532e612012-04-05 14:27:12 -07001136static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1137 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001138 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001139 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001140
Jeff Brown6ec402b2010-07-28 15:48:59 -07001141 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1142 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001143 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1144 if (status) {
1145 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1146 return INPUT_EVENT_INJECTION_FAILED;
1147 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001148
Jeff Brown4532e612012-04-05 14:27:12 -07001149 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001150 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1151 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001152 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001153 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1154 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001155 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1156 return INPUT_EVENT_INJECTION_FAILED;
1157 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001158
Jeff Brown4532e612012-04-05 14:27:12 -07001159 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001160 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1161 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001162 } else {
1163 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001164 return INPUT_EVENT_INJECTION_FAILED;
1165 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001166}
1167
Jeff Brown4532e612012-04-05 14:27:12 -07001168static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1169 jint ptr, jobjectArray windowHandleObjArray) {
1170 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001171
Jeff Brown4532e612012-04-05 14:27:12 -07001172 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001173}
1174
Jeff Brown4532e612012-04-05 14:27:12 -07001175static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1176 jint ptr, jobject applicationHandleObj) {
1177 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001178
Jeff Brown4532e612012-04-05 14:27:12 -07001179 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001180}
1181
Jeff Brown4532e612012-04-05 14:27:12 -07001182static void nativeSetInputDispatchMode(JNIEnv* env,
1183 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1184 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001185
Jeff Brown4532e612012-04-05 14:27:12 -07001186 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001187}
1188
Jeff Brown4532e612012-04-05 14:27:12 -07001189static void nativeSetSystemUiVisibility(JNIEnv* env,
1190 jclass clazz, jint ptr, jint visibility) {
1191 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001192
Jeff Brown4532e612012-04-05 14:27:12 -07001193 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001194}
1195
Jeff Brown4532e612012-04-05 14:27:12 -07001196static jboolean nativeTransferTouchFocus(JNIEnv* env,
1197 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1198 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001199
1200 sp<InputChannel> fromChannel =
1201 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1202 sp<InputChannel> toChannel =
1203 android_view_InputChannel_getInputChannel(env, toChannelObj);
1204
1205 if (fromChannel == NULL || toChannel == NULL) {
1206 return false;
1207 }
1208
Jeff Brown4532e612012-04-05 14:27:12 -07001209 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001210 transferTouchFocus(fromChannel, toChannel);
1211}
1212
Jeff Brown4532e612012-04-05 14:27:12 -07001213static void nativeSetPointerSpeed(JNIEnv* env,
1214 jclass clazz, jint ptr, jint speed) {
1215 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001216
Jeff Brown4532e612012-04-05 14:27:12 -07001217 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001218}
1219
Jeff Brown4532e612012-04-05 14:27:12 -07001220static void nativeSetShowTouches(JNIEnv* env,
1221 jclass clazz, jint ptr, jboolean enabled) {
1222 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001223
Jeff Brown4532e612012-04-05 14:27:12 -07001224 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001225}
1226
Jeff Browna47425a2012-04-13 04:09:27 -07001227static void nativeVibrate(JNIEnv* env,
1228 jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
1229 jint repeat, jint token) {
1230 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1231
1232 size_t patternSize = env->GetArrayLength(patternObj);
1233 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
1234 ALOGI("Skipped requested vibration because the pattern size is %d "
1235 "which is more than the maximum supported size of %d.",
1236 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1237 return; // limit to reasonable size
1238 }
1239
1240 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1241 patternObj, NULL));
1242 nsecs_t pattern[patternSize];
1243 for (size_t i = 0; i < patternSize; i++) {
1244 pattern[i] = max(jlong(0), min(patternMillis[i],
1245 MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
1246 }
1247 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1248
1249 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1250}
1251
1252static void nativeCancelVibrate(JNIEnv* env,
1253 jclass clazz, jint ptr, jint deviceId, jint token) {
1254 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1255
1256 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1257}
1258
Jeff Brown6ec6f792012-04-17 16:52:41 -07001259static void nativeReloadKeyboardLayouts(JNIEnv* env,
1260 jclass clazz, jint ptr) {
1261 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1262
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001263 im->getInputManager()->getReader()->requestRefreshConfiguration(
1264 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1265}
1266
1267static void nativeReloadDeviceAliases(JNIEnv* env,
1268 jclass clazz, jint ptr) {
1269 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1270
1271 im->getInputManager()->getReader()->requestRefreshConfiguration(
1272 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001273}
1274
Jeff Brown4532e612012-04-05 14:27:12 -07001275static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1276 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001277
Jeff Brownb88102f2010-09-08 11:49:43 -07001278 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001279 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001280 return env->NewStringUTF(dump.string());
1281}
1282
Jeff Brown4532e612012-04-05 14:27:12 -07001283static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1284 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001285
Jeff Brown4532e612012-04-05 14:27:12 -07001286 im->getInputManager()->getReader()->monitor();
1287 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001288}
1289
Jeff Brown9c3cda02010-06-15 01:31:58 -07001290// ----------------------------------------------------------------------------
1291
Jeff Brown46b9ac02010-04-22 18:58:52 -07001292static JNINativeMethod gInputManagerMethods[] = {
1293 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001294 { "nativeInit",
1295 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1296 (void*) nativeInit },
1297 { "nativeStart", "(I)V",
1298 (void*) nativeStart },
Jeff Brown83d616a2012-09-09 20:33:43 -07001299 { "nativeSetDisplayViewport", "(IZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001300 (void*) nativeSetDisplayViewport },
Jeff Brown4532e612012-04-05 14:27:12 -07001301 { "nativeGetScanCodeState", "(IIII)I",
1302 (void*) nativeGetScanCodeState },
1303 { "nativeGetKeyCodeState", "(IIII)I",
1304 (void*) nativeGetKeyCodeState },
1305 { "nativeGetSwitchState", "(IIII)I",
1306 (void*) nativeGetSwitchState },
1307 { "nativeHasKeys", "(III[I[Z)Z",
1308 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001309 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001310 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1311 (void*) nativeRegisterInputChannel },
1312 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1313 (void*) nativeUnregisterInputChannel },
1314 { "nativeSetInputFilterEnabled", "(IZ)V",
1315 (void*) nativeSetInputFilterEnabled },
1316 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1317 (void*) nativeInjectInputEvent },
1318 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1319 (void*) nativeSetInputWindows },
1320 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1321 (void*) nativeSetFocusedApplication },
1322 { "nativeSetInputDispatchMode", "(IZZ)V",
1323 (void*) nativeSetInputDispatchMode },
1324 { "nativeSetSystemUiVisibility", "(II)V",
1325 (void*) nativeSetSystemUiVisibility },
Jeff Brown4532e612012-04-05 14:27:12 -07001326 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1327 (void*) nativeTransferTouchFocus },
1328 { "nativeSetPointerSpeed", "(II)V",
1329 (void*) nativeSetPointerSpeed },
1330 { "nativeSetShowTouches", "(IZ)V",
1331 (void*) nativeSetShowTouches },
Jeff Browna47425a2012-04-13 04:09:27 -07001332 { "nativeVibrate", "(II[JII)V",
1333 (void*) nativeVibrate },
1334 { "nativeCancelVibrate", "(III)V",
1335 (void*) nativeCancelVibrate },
Jeff Brown6ec6f792012-04-17 16:52:41 -07001336 { "nativeReloadKeyboardLayouts", "(I)V",
1337 (void*) nativeReloadKeyboardLayouts },
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001338 { "nativeReloadDeviceAliases", "(I)V",
1339 (void*) nativeReloadDeviceAliases },
Jeff Brown4532e612012-04-05 14:27:12 -07001340 { "nativeDump", "(I)Ljava/lang/String;",
1341 (void*) nativeDump },
1342 { "nativeMonitor", "(I)V",
1343 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001344};
1345
1346#define FIND_CLASS(var, className) \
1347 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001348 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001349
1350#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1351 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1352 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1353
1354#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1355 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1356 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1357
1358int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001359 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001360 gInputManagerMethods, NELEM(gInputManagerMethods));
1361 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1362
Jeff Brown9c3cda02010-06-15 01:31:58 -07001363 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001364
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001365 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001366 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001367
Jeff Brown4532e612012-04-05 14:27:12 -07001368 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001369 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001370
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001371 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1372 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1373
Jeff Brown53384282012-08-20 20:16:01 -07001374 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1375 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001376
Jeff Brown4532e612012-04-05 14:27:12 -07001377 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1378 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001379
Jeff Brown4532e612012-04-05 14:27:12 -07001380 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001381 "notifyANR",
Jeff Brown4532e612012-04-05 14:27:12 -07001382 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001383
Jeff Brown4532e612012-04-05 14:27:12 -07001384 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001385 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1386
Jeff Brown4532e612012-04-05 14:27:12 -07001387 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001388 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001389
Jeff Brown4532e612012-04-05 14:27:12 -07001390 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001391 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001392 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1393
Jeff Brown4532e612012-04-05 14:27:12 -07001394 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001395 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001396 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001397
Jeff Brown4532e612012-04-05 14:27:12 -07001398 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001399 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001400 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001401
Jeff Brown4532e612012-04-05 14:27:12 -07001402 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001403 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001404
Jeff Brown4532e612012-04-05 14:27:12 -07001405 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001406 "getVirtualKeyQuietTimeMillis", "()I");
1407
Jeff Brown4532e612012-04-05 14:27:12 -07001408 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001409 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1410
Jeff Brown4532e612012-04-05 14:27:12 -07001411 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001412 "getKeyRepeatTimeout", "()I");
1413
Jeff Brown4532e612012-04-05 14:27:12 -07001414 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001415 "getKeyRepeatDelay", "()I");
1416
Jeff Brown4532e612012-04-05 14:27:12 -07001417 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001418 "getHoverTapTimeout", "()I");
1419
Jeff Brown4532e612012-04-05 14:27:12 -07001420 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001421 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001422
Jeff Brown4532e612012-04-05 14:27:12 -07001423 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001424 "getDoubleTapTimeout", "()I");
1425
Jeff Brown4532e612012-04-05 14:27:12 -07001426 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001427 "getLongPressTimeout", "()I");
1428
Jeff Brown4532e612012-04-05 14:27:12 -07001429 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001430 "getPointerLayer", "()I");
1431
Jeff Brown4532e612012-04-05 14:27:12 -07001432 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001433 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001434
Jeff Brown6ec6f792012-04-17 16:52:41 -07001435 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
1436 "getKeyboardLayoutOverlay", "(Ljava/lang/String;)[Ljava/lang/String;");
1437
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001438 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1439 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1440
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001441 // InputDevice
1442
1443 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1444 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1445
Jeff Brown6ec402b2010-07-28 15:48:59 -07001446 // KeyEvent
1447
1448 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001449 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1450
Jeff Brown8d608662010-08-30 03:02:23 -07001451 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001452
1453 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001454 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001455
Jeff Brown46b9ac02010-04-22 18:58:52 -07001456 return 0;
1457}
1458
Jeff Brown46b9ac02010-04-22 18:58:52 -07001459} /* namespace android */