blob: b6c2eb460e84e0b0ebcad9be24ff5a14373f769d [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>
Ruben Brunk87eac992013-09-09 17:44:59 -070032#include <android_runtime/Log.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080033
Jeff Brown46b9ac02010-04-22 18:58:52 -070034#include <utils/Log.h>
Jeff Brown05dc66a2011-03-02 14:41:58 -080035#include <utils/Looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070036#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080037
Jeff Brownb4ff35d2011-01-02 16:37:43 -080038#include <input/InputManager.h>
39#include <input/PointerController.h>
Jeff Brown5541de92011-04-11 11:54:25 -070040#include <input/SpriteController.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080041
Jeff Brown05dc66a2011-03-02 14:41:58 -080042#include <android_os_MessageQueue.h>
Jeff Brown9f25b7f2012-04-10 14:30:49 -070043#include <android_view_InputDevice.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080044#include <android_view_KeyEvent.h>
45#include <android_view_MotionEvent.h>
46#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070047#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080048#include <android/graphics/GraphicsJNI.h>
49
Jeff Brown6ec6f792012-04-17 16:52:41 -070050#include <ScopedLocalRef.h>
51#include <ScopedUtfChars.h>
52
Jeff Brown4f8ecd82012-06-18 18:29:13 -070053#include "com_android_server_power_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070054#include "com_android_server_input_InputApplicationHandle.h"
55#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070056
57namespace android {
58
Jeff Brown1a84fd12011-06-02 01:26:32 -070059// The exponent used to calculate the pointer speed scaling factor.
60// The scaling factor is calculated as 2 ^ (speed * exponent),
61// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070062static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070063
Jeff Brown46b9ac02010-04-22 18:58:52 -070064static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070065 jmethodID notifyConfigurationChanged;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070066 jmethodID notifyInputDevicesChanged;
Jeff Brown53384282012-08-20 20:16:01 -070067 jmethodID notifySwitch;
Jeff Brown7fbdc842010-06-17 20:52:56 -070068 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070069 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070070 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070071 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080072 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070073 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070074 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070075 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080076 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070077 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080078 jmethodID getKeyRepeatTimeout;
79 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070080 jmethodID getHoverTapTimeout;
81 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070082 jmethodID getDoubleTapTimeout;
83 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080084 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080085 jmethodID getPointerIcon;
Jeff Brown6ec6f792012-04-17 16:52:41 -070086 jmethodID getKeyboardLayoutOverlay;
Jeff Brown5bbd4b42012-04-20 19:28:00 -070087 jmethodID getDeviceAlias;
Jeff Brown4532e612012-04-05 14:27:12 -070088} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070089
90static struct {
91 jclass clazz;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070092} gInputDeviceClassInfo;
93
94static struct {
95 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070096} gKeyEventClassInfo;
97
98static struct {
99 jclass clazz;
100} gMotionEventClassInfo;
101
Jeff Brown928e0542011-01-10 11:17:36 -0800102
103// --- Global functions ---
104
Jeff Brown214eaf42011-05-26 19:17:02 -0700105template<typename T>
106inline static T min(const T& a, const T& b) {
107 return a < b ? a : b;
108}
109
110template<typename T>
111inline static T max(const T& a, const T& b) {
112 return a > b ? a : b;
113}
114
Jeff Brown928e0542011-01-10 11:17:36 -0800115static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
116 const sp<InputApplicationHandle>& inputApplicationHandle) {
117 if (inputApplicationHandle == NULL) {
118 return NULL;
119 }
120 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
121 getInputApplicationHandleObjLocalRef(env);
122}
123
124static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
125 const sp<InputWindowHandle>& inputWindowHandle) {
126 if (inputWindowHandle == NULL) {
127 return NULL;
128 }
129 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
130 getInputWindowHandleObjLocalRef(env);
131}
132
Jeff Brown2352b972011-04-12 22:39:53 -0700133static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
134 SpriteIcon* outSpriteIcon) {
135 PointerIcon pointerIcon;
136 status_t status = android_view_PointerIcon_loadSystemIcon(env,
137 contextObj, style, &pointerIcon);
138 if (!status) {
139 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
140 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
141 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
142 }
143}
144
Jeff Brown905805a2011-10-12 13:57:59 -0700145enum {
146 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown96307042012-07-27 15:51:34 -0700147 WM_ACTION_WAKE_UP = 2,
Jeff Brown905805a2011-10-12 13:57:59 -0700148 WM_ACTION_GO_TO_SLEEP = 4,
149};
150
Jeff Brown928e0542011-01-10 11:17:36 -0800151
152// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800153
Jeff Brown9c3cda02010-06-15 01:31:58 -0700154class NativeInputManager : public virtual RefBase,
155 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700156 public virtual InputDispatcherPolicyInterface,
157 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700158protected:
159 virtual ~NativeInputManager();
160
161public:
Jeff Brown4532e612012-04-05 14:27:12 -0700162 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700163
164 inline sp<InputManager> getInputManager() const { return mInputManager; }
165
Jeff Brownb88102f2010-09-08 11:49:43 -0700166 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700167
Jeff Brownd728bf52012-09-08 18:05:28 -0700168 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700169
Jeff Brown7fbdc842010-06-17 20:52:56 -0700170 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800171 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700172 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
173
Jeff Brown9302c872011-07-13 22:51:29 -0700174 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
175 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700176 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800177 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700178 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700179 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700180
Jeff Brown9c3cda02010-06-15 01:31:58 -0700181 /* --- InputReaderPolicyInterface implementation --- */
182
Jeff Brown214eaf42011-05-26 19:17:02 -0700183 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800184 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700185 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700186 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700187 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700188
189 /* --- InputDispatcherPolicyInterface implementation --- */
190
Jeff Brownbcc046a2012-09-27 20:46:43 -0700191 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700192 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700193 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700194 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800195 const sp<InputWindowHandle>& inputWindowHandle);
196 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700197 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700198 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
199 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800200 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800201 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700202 virtual nsecs_t interceptKeyBeforeDispatching(
203 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700204 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800205 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800206 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700207 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700208 virtual bool checkInjectEventsPermissionNonReentrant(
209 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700210
Jeff Brown2352b972011-04-12 22:39:53 -0700211 /* --- PointerControllerPolicyInterface implementation --- */
212
213 virtual void loadPointerResources(PointerResources* outResources);
214
Jeff Brown9c3cda02010-06-15 01:31:58 -0700215private:
216 sp<InputManager> mInputManager;
217
Jeff Brown2352b972011-04-12 22:39:53 -0700218 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700219 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800220 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700221
Jeff Brown83c09682010-12-23 17:50:18 -0800222 Mutex mLock;
223 struct Locked {
224 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700225 DisplayViewport internalViewport;
226 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800227
Jeff Brown05dc66a2011-03-02 14:41:58 -0800228 // System UI visibility.
229 int32_t systemUiVisibility;
230
Jeff Brown1a84fd12011-06-02 01:26:32 -0700231 // Pointer speed.
232 int32_t pointerSpeed;
233
Jeff Brown474dcb52011-06-14 20:22:50 -0700234 // True if pointer gestures are enabled.
235 bool pointerGesturesEnabled;
236
Jeff Browndaf4a122011-08-26 17:14:14 -0700237 // Show touches feature enable/disable.
238 bool showTouches;
239
Jeff Brown5541de92011-04-11 11:54:25 -0700240 // Sprite controller singleton, created on first use.
241 sp<SpriteController> spriteController;
242
Jeff Brown83c09682010-12-23 17:50:18 -0800243 // Pointer controller singleton, created and destroyed as needed.
244 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800245 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700246
Jeff Brown2352b972011-04-12 22:39:53 -0700247 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800248 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700249 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800250
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700251 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700252 bool isScreenOn();
253 bool isScreenBright();
254
Jeff Brownb88102f2010-09-08 11:49:43 -0700255 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700256
Jeff Brown9c3cda02010-06-15 01:31:58 -0700257 static inline JNIEnv* jniEnv() {
258 return AndroidRuntime::getJNIEnv();
259 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700260};
261
Jeff Brown928e0542011-01-10 11:17:36 -0800262
Jeff Brown9c3cda02010-06-15 01:31:58 -0700263
Jeff Brown2352b972011-04-12 22:39:53 -0700264NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700265 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700266 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700267 JNIEnv* env = jniEnv();
268
Jeff Brown2352b972011-04-12 22:39:53 -0700269 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700270 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700271
Jeff Brown83c09682010-12-23 17:50:18 -0800272 {
273 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800274 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700275 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700276 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700277 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800278 }
279
Jeff Brown9c3cda02010-06-15 01:31:58 -0700280 sp<EventHub> eventHub = new EventHub();
281 mInputManager = new InputManager(eventHub, this, this);
282}
283
284NativeInputManager::~NativeInputManager() {
285 JNIEnv* env = jniEnv();
286
Jeff Brown2352b972011-04-12 22:39:53 -0700287 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700288 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700289}
290
Jeff Brownb88102f2010-09-08 11:49:43 -0700291void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700292 mInputManager->getReader()->dump(dump);
293 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700294
Jeff Brownb88102f2010-09-08 11:49:43 -0700295 mInputManager->getDispatcher()->dump(dump);
296 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700297}
298
Jeff Brown7fbdc842010-06-17 20:52:56 -0700299bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700300 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000301 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700302 LOGE_EX(env);
303 env->ExceptionClear();
304 return true;
305 }
306 return false;
307}
308
Jeff Brownd728bf52012-09-08 18:05:28 -0700309void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700310 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700311 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700312 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700313
Jeff Brownd728bf52012-09-08 18:05:28 -0700314 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
315 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700316 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700317 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700318
Jeff Brownd728bf52012-09-08 18:05:28 -0700319 if (!external) {
320 sp<PointerController> controller = mLocked.pointerController.promote();
321 if (controller != NULL) {
322 controller->setDisplayViewport(
323 viewport.logicalRight - viewport.logicalLeft,
324 viewport.logicalBottom - viewport.logicalTop,
325 viewport.orientation);
326 }
Jeff Brown2352b972011-04-12 22:39:53 -0700327 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700328 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700329 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700330
331 if (changed) {
332 mInputManager->getReader()->requestRefreshConfiguration(
333 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
334 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700335}
336
Jeff Brown7fbdc842010-06-17 20:52:56 -0700337status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800338 const sp<InputChannel>& inputChannel,
339 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
340 return mInputManager->getDispatcher()->registerInputChannel(
341 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700342}
343
344status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
345 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700346 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700347}
348
Jeff Brown214eaf42011-05-26 19:17:02 -0700349void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700350 JNIEnv* env = jniEnv();
351
Jeff Brown4532e612012-04-05 14:27:12 -0700352 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
353 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700354 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
355 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
356 }
357
358 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700359 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
360 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700361 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
362 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700363 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700364 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700365 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700366 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700367 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700368 env->DeleteLocalRef(item);
369 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700370 env->DeleteLocalRef(excludedDeviceNames);
371 }
372
Jeff Brown4532e612012-04-05 14:27:12 -0700373 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
374 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700375 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700376 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
377 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700378 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700379 jint longPressTimeout = env->CallIntMethod(mServiceObj,
380 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700381 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700382 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700383
384 // We must ensure that the tap-drag interval is significantly shorter than
385 // the long-press timeout because the tap is held down for the entire duration
386 // of the double-tap timeout.
387 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700388 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700389 outConfig->pointerGestureTapDragInterval =
390 milliseconds_to_nanoseconds(tapDragInterval);
391 }
392 }
393 }
394
Jeff Brown4532e612012-04-05 14:27:12 -0700395 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
396 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700397 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
398 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700399 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700400
401 { // acquire lock
402 AutoMutex _l(mLock);
403
404 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
405 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700406 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700407
Jeff Browndaf4a122011-08-26 17:14:14 -0700408 outConfig->showTouches = mLocked.showTouches;
409
Jeff Brownd728bf52012-09-08 18:05:28 -0700410 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
411 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700412 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700413}
414
Jeff Brown83c09682010-12-23 17:50:18 -0800415sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
416 AutoMutex _l(mLock);
417
418 sp<PointerController> controller = mLocked.pointerController.promote();
419 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700420 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800421
Jeff Brown2352b972011-04-12 22:39:53 -0700422 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800423 mLocked.pointerController = controller;
424
Jeff Brownd728bf52012-09-08 18:05:28 -0700425 DisplayViewport& v = mLocked.internalViewport;
426 controller->setDisplayViewport(
427 v.logicalRight - v.logicalLeft,
428 v.logicalBottom - v.logicalTop,
429 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800430
Jeff Brown5541de92011-04-11 11:54:25 -0700431 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700432 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
433 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700434 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
435 PointerIcon pointerIcon;
436 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
437 mContextObj, &pointerIcon);
438 if (!status && !pointerIcon.isNullIcon()) {
439 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
440 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
441 } else {
442 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800443 }
Jeff Brown2352b972011-04-12 22:39:53 -0700444 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800445 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800446
Jeff Brown2352b972011-04-12 22:39:53 -0700447 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800448 }
449 return controller;
450}
451
Jeff Brown5541de92011-04-11 11:54:25 -0700452void NativeInputManager::ensureSpriteControllerLocked() {
453 if (mLocked.spriteController == NULL) {
454 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700455 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700456 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
457 layer = -1;
458 }
459 mLocked.spriteController = new SpriteController(mLooper, layer);
460 }
461}
462
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700463void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
464 JNIEnv* env = jniEnv();
465
466 size_t count = inputDevices.size();
467 jobjectArray inputDevicesObjArray = env->NewObjectArray(
468 count, gInputDeviceClassInfo.clazz, NULL);
469 if (inputDevicesObjArray) {
470 bool error = false;
471 for (size_t i = 0; i < count; i++) {
472 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
473 if (!inputDeviceObj) {
474 error = true;
475 break;
476 }
477
478 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
479 env->DeleteLocalRef(inputDeviceObj);
480 }
481
482 if (!error) {
483 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
484 inputDevicesObjArray);
485 }
486
487 env->DeleteLocalRef(inputDevicesObjArray);
488 }
489
490 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
491}
492
Jeff Brown6ec6f792012-04-17 16:52:41 -0700493sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
494 const String8& inputDeviceDescriptor) {
495 JNIEnv* env = jniEnv();
496
497 sp<KeyCharacterMap> result;
498 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
499 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
500 gServiceClassInfo.getKeyboardLayoutOverlay, descriptorObj.get())));
501 if (arrayObj.get()) {
502 ScopedLocalRef<jstring> filenameObj(env,
503 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
504 ScopedLocalRef<jstring> contentsObj(env,
505 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
506 ScopedUtfChars filenameChars(env, filenameObj.get());
507 ScopedUtfChars contentsChars(env, contentsObj.get());
508
509 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
510 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
511 }
512 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
513 return result;
514}
515
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700516String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
517 JNIEnv* env = jniEnv();
518
519 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
520 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
521 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
522 String8 result;
523 if (aliasObj.get()) {
524 ScopedUtfChars aliasChars(env, aliasObj.get());
525 result.setTo(aliasChars.c_str());
526 }
527 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
528 return result;
529}
530
Jeff Brownbcc046a2012-09-27 20:46:43 -0700531void NativeInputManager::notifySwitch(nsecs_t when,
532 uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700533#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700534 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
535 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700536#endif
537
538 JNIEnv* env = jniEnv();
539
Jeff Brown53384282012-08-20 20:16:01 -0700540 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700541 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700542 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700543}
544
Jeff Brown9c3cda02010-06-15 01:31:58 -0700545void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
546#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000547 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700548#endif
549
550 JNIEnv* env = jniEnv();
551
Jeff Brown4532e612012-04-05 14:27:12 -0700552 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700553 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700554}
555
Jeff Brown519e0242010-09-15 15:18:56 -0700556nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800557 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700558#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000559 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700560#endif
561
562 JNIEnv* env = jniEnv();
563
Jeff Brown928e0542011-01-10 11:17:36 -0800564 jobject inputApplicationHandleObj =
565 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
566 jobject inputWindowHandleObj =
567 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700568
Jeff Brown4532e612012-04-05 14:27:12 -0700569 jlong newTimeout = env->CallLongMethod(mServiceObj,
570 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700571 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
572 newTimeout = 0; // abort dispatch
573 } else {
574 assert(newTimeout >= 0);
575 }
576
Jeff Brown928e0542011-01-10 11:17:36 -0800577 env->DeleteLocalRef(inputWindowHandleObj);
578 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700579 return newTimeout;
580}
581
Jeff Brown928e0542011-01-10 11:17:36 -0800582void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700583#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000584 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700585#endif
586
Jeff Brown7fbdc842010-06-17 20:52:56 -0700587 JNIEnv* env = jniEnv();
588
Jeff Brown928e0542011-01-10 11:17:36 -0800589 jobject inputWindowHandleObj =
590 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
591 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700592 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800593 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700594 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
595
Jeff Brown928e0542011-01-10 11:17:36 -0800596 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700597 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700598}
599
Jeff Brown214eaf42011-05-26 19:17:02 -0700600void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
601 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800602
Jeff Brown4532e612012-04-05 14:27:12 -0700603 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
604 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700605 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
606 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
607 }
Jeff Browna4547672011-03-02 21:38:11 -0800608
Jeff Brown4532e612012-04-05 14:27:12 -0700609 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
610 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700611 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
612 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
613 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700614}
615
Jeff Brown214eaf42011-05-26 19:17:02 -0700616bool NativeInputManager::isKeyRepeatEnabled() {
617 // Only enable automatic key repeating when the screen is on.
618 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700619}
620
Jeff Brown9302c872011-07-13 22:51:29 -0700621void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
622 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700623
Jeff Brown9302c872011-07-13 22:51:29 -0700624 if (windowHandleObjArray) {
625 jsize length = env->GetArrayLength(windowHandleObjArray);
626 for (jsize i = 0; i < length; i++) {
627 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
628 if (! windowHandleObj) {
629 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700630 }
Jeff Brown9302c872011-07-13 22:51:29 -0700631
632 sp<InputWindowHandle> windowHandle =
633 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
634 if (windowHandle != NULL) {
635 windowHandles.push(windowHandle);
636 }
637 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700638 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700639 }
Jeff Brown349703e2010-06-22 01:27:15 -0700640
Jeff Brown9302c872011-07-13 22:51:29 -0700641 mInputManager->getDispatcher()->setInputWindows(windowHandles);
642
643 // Do this after the dispatcher has updated the window handle state.
644 bool newPointerGesturesEnabled = true;
645 size_t numWindows = windowHandles.size();
646 for (size_t i = 0; i < numWindows; i++) {
647 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700648 const InputWindowInfo* windowInfo = windowHandle->getInfo();
649 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
650 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700651 newPointerGesturesEnabled = false;
652 }
653 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700654
655 uint32_t changes = 0;
656 { // acquire lock
657 AutoMutex _l(mLock);
658
659 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
660 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
661 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
662 }
663 } // release lock
664
665 if (changes) {
666 mInputManager->getReader()->requestRefreshConfiguration(changes);
667 }
Jeff Brown349703e2010-06-22 01:27:15 -0700668}
669
Jeff Brown9302c872011-07-13 22:51:29 -0700670void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
671 sp<InputApplicationHandle> applicationHandle =
672 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
673 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700674}
675
676void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700677 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700678}
679
Jeff Brown05dc66a2011-03-02 14:41:58 -0800680void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
681 AutoMutex _l(mLock);
682
683 if (mLocked.systemUiVisibility != visibility) {
684 mLocked.systemUiVisibility = visibility;
685
686 sp<PointerController> controller = mLocked.pointerController.promote();
687 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700688 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800689 }
690 }
691}
692
Jeff Brown2352b972011-04-12 22:39:53 -0700693void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800694 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700695 controller->setInactivityTimeout(lightsOut
696 ? PointerController::INACTIVITY_TIMEOUT_SHORT
697 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800698}
699
Jeff Brown1a84fd12011-06-02 01:26:32 -0700700void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700701 { // acquire lock
702 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700703
Jeff Brown474dcb52011-06-14 20:22:50 -0700704 if (mLocked.pointerSpeed == speed) {
705 return;
706 }
707
Steve Block6215d3f2012-01-04 20:05:49 +0000708 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700709 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700710 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700711
Jeff Brown474dcb52011-06-14 20:22:50 -0700712 mInputManager->getReader()->requestRefreshConfiguration(
713 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700714}
715
Jeff Browndaf4a122011-08-26 17:14:14 -0700716void NativeInputManager::setShowTouches(bool enabled) {
717 { // acquire lock
718 AutoMutex _l(mLock);
719
720 if (mLocked.showTouches == enabled) {
721 return;
722 }
723
Steve Block6215d3f2012-01-04 20:05:49 +0000724 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700725 mLocked.showTouches = enabled;
726 } // release lock
727
728 mInputManager->getReader()->requestRefreshConfiguration(
729 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
730}
731
Jeff Browne20c9e02010-10-11 14:20:19 -0700732bool NativeInputManager::isScreenOn() {
733 return android_server_PowerManagerService_isScreenOn();
734}
735
736bool NativeInputManager::isScreenBright() {
737 return android_server_PowerManagerService_isScreenBright();
738}
739
Jeff Brown0029c662011-03-30 02:25:18 -0700740bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
741 jobject inputEventObj;
742
743 JNIEnv* env = jniEnv();
744 switch (inputEvent->getType()) {
745 case AINPUT_EVENT_TYPE_KEY:
746 inputEventObj = android_view_KeyEvent_fromNative(env,
747 static_cast<const KeyEvent*>(inputEvent));
748 break;
749 case AINPUT_EVENT_TYPE_MOTION:
750 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
751 static_cast<const MotionEvent*>(inputEvent));
752 break;
753 default:
754 return true; // dispatch the event normally
755 }
756
757 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000758 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700759 return true; // dispatch the event normally
760 }
761
762 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700763 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700764 inputEventObj, policyFlags);
765 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
766 pass = true;
767 }
768 env->DeleteLocalRef(inputEventObj);
769 return pass;
770}
771
Jeff Brown1f245102010-11-18 20:53:46 -0800772void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
773 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700774 // Policy:
775 // - Ignore untrusted events and pass them along.
776 // - Ask the window manager what to do with normal events and trusted injected events.
777 // - For normal events wake and brighten the screen if currently off or dim.
778 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800779 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700780 bool isScreenOn = this->isScreenOn();
781 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700782
Jeff Brown3122e442010-10-11 23:32:49 -0700783 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800784 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
785 jint wmActions;
786 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700787 wmActions = env->CallIntMethod(mServiceObj,
788 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800789 keyEventObj, policyFlags, isScreenOn);
790 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
791 wmActions = 0;
792 }
793 android_view_KeyEvent_recycle(env, keyEventObj);
794 env->DeleteLocalRef(keyEventObj);
795 } else {
Steve Block3762c312012-01-06 19:20:56 +0000796 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700797 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700798 }
799
Jeff Brown1f245102010-11-18 20:53:46 -0800800 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700801 if (!isScreenOn) {
802 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700803 }
804
805 if (!isScreenBright) {
806 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
807 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700808 }
809
Jeff Brown56194eb2011-03-02 19:23:13 -0800810 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700811 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700812 policyFlags |= POLICY_FLAG_PASS_TO_USER;
813 }
814}
815
Jeff Brown56194eb2011-03-02 19:23:13 -0800816void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700817 // Policy:
818 // - Ignore untrusted events and pass them along.
819 // - No special filtering for injected events required at this time.
820 // - Filter normal events based on screen state.
821 // - For normal events brighten (but do not wake) the screen if currently dim.
822 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
823 if (isScreenOn()) {
824 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700825
Jeff Brown3122e442010-10-11 23:32:49 -0700826 if (!isScreenBright()) {
827 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
828 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800829 } else {
830 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700831 jint wmActions = env->CallIntMethod(mServiceObj,
832 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800833 policyFlags);
834 if (checkAndClearExceptionFromCallback(env,
835 "interceptMotionBeforeQueueingWhenScreenOff")) {
836 wmActions = 0;
837 }
838
839 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
840 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700841 }
Jeff Brown3122e442010-10-11 23:32:49 -0700842 } else {
843 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700844 }
845}
846
Jeff Brown56194eb2011-03-02 19:23:13 -0800847void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
848 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800849 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800850#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000851 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800852#endif
853 android_server_PowerManagerService_goToSleep(when);
854 }
855
Jeff Brown96307042012-07-27 15:51:34 -0700856 if (wmActions & WM_ACTION_WAKE_UP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800857#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown96307042012-07-27 15:51:34 -0700858 ALOGD("handleInterceptActions: Waking up.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800859#endif
Jeff Brown96307042012-07-27 15:51:34 -0700860 android_server_PowerManagerService_wakeUp(when);
Jeff Brown56194eb2011-03-02 19:23:13 -0800861 }
862
863 if (wmActions & WM_ACTION_PASS_TO_USER) {
864 policyFlags |= POLICY_FLAG_PASS_TO_USER;
865 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800866#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000867 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800868#endif
869 }
870}
871
Jeff Brown905805a2011-10-12 13:57:59 -0700872nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800873 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700874 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700875 // Policy:
876 // - Ignore untrusted events and pass them along.
877 // - Filter normal events and trusted injected events through the window manager policy to
878 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700879 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700880 if (policyFlags & POLICY_FLAG_TRUSTED) {
881 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700882
Jeff Brown928e0542011-01-10 11:17:36 -0800883 // Note: inputWindowHandle may be null.
884 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800885 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
886 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700887 jlong delayMillis = env->CallLongMethod(mServiceObj,
888 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800889 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800890 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
891 android_view_KeyEvent_recycle(env, keyEventObj);
892 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700893 if (!error) {
894 if (delayMillis < 0) {
895 result = -1;
896 } else if (delayMillis > 0) {
897 result = milliseconds_to_nanoseconds(delayMillis);
898 }
899 }
Jeff Brown1f245102010-11-18 20:53:46 -0800900 } else {
Steve Block3762c312012-01-06 19:20:56 +0000901 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800902 }
Jeff Brown928e0542011-01-10 11:17:36 -0800903 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700904 }
Jeff Brown1f245102010-11-18 20:53:46 -0800905 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700906}
907
Jeff Brown928e0542011-01-10 11:17:36 -0800908bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800909 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700910 // Policy:
911 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800912 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700913 if (policyFlags & POLICY_FLAG_TRUSTED) {
914 JNIEnv* env = jniEnv();
915
Jeff Brown928e0542011-01-10 11:17:36 -0800916 // Note: inputWindowHandle may be null.
917 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800918 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
919 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700920 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
921 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800922 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700923 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
924 fallbackKeyEventObj = NULL;
925 }
Jeff Brown1f245102010-11-18 20:53:46 -0800926 android_view_KeyEvent_recycle(env, keyEventObj);
927 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800928
929 if (fallbackKeyEventObj) {
930 // Note: outFallbackKeyEvent may be the same object as keyEvent.
931 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
932 outFallbackKeyEvent)) {
933 result = true;
934 }
935 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
936 env->DeleteLocalRef(fallbackKeyEventObj);
937 }
Jeff Brown1f245102010-11-18 20:53:46 -0800938 } else {
Steve Block3762c312012-01-06 19:20:56 +0000939 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800940 }
Jeff Brown928e0542011-01-10 11:17:36 -0800941 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700942 }
Jeff Brown1f245102010-11-18 20:53:46 -0800943 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700944}
945
Jeff Brown01ce2e92010-09-26 22:20:12 -0700946void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
947 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700948}
949
Jeff Brown349703e2010-06-22 01:27:15 -0700950
Jeff Brownb88102f2010-09-08 11:49:43 -0700951bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
952 int32_t injectorPid, int32_t injectorUid) {
953 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700954 jboolean result = env->CallBooleanMethod(mServiceObj,
955 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700956 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
957 result = false;
958 }
Jeff Brown349703e2010-06-22 01:27:15 -0700959 return result;
960}
961
Jeff Brown2352b972011-04-12 22:39:53 -0700962void NativeInputManager::loadPointerResources(PointerResources* outResources) {
963 JNIEnv* env = jniEnv();
964
965 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
966 &outResources->spotHover);
967 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
968 &outResources->spotTouch);
969 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
970 &outResources->spotAnchor);
971}
972
Jeff Brown83c09682010-12-23 17:50:18 -0800973
Jeff Brown9c3cda02010-06-15 01:31:58 -0700974// ----------------------------------------------------------------------------
975
Jeff Brown4532e612012-04-05 14:27:12 -0700976static jint nativeInit(JNIEnv* env, jclass clazz,
977 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -0700978 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -0800979 if (messageQueue == NULL) {
980 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
981 return 0;
982 }
983
Jeff Brown603b4452012-04-06 17:39:41 -0700984 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
985 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800986 im->incStrong(0);
Jeff Brown4532e612012-04-05 14:27:12 -0700987 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700988}
989
Jeff Brown4532e612012-04-05 14:27:12 -0700990static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
991 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700992
Jeff Brown4532e612012-04-05 14:27:12 -0700993 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700994 if (result) {
995 jniThrowRuntimeException(env, "Input manager could not be started.");
996 }
997}
998
Jeff Brownd728bf52012-09-08 18:05:28 -0700999static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jint ptr, jboolean external,
1000 jint displayId, jint orientation,
1001 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001002 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1003 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001004 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001005
Jeff Brownd728bf52012-09-08 18:05:28 -07001006 DisplayViewport v;
1007 v.displayId = displayId;
1008 v.orientation = orientation;
1009 v.logicalLeft = logicalLeft;
1010 v.logicalTop = logicalTop;
1011 v.logicalRight = logicalRight;
1012 v.logicalBottom = logicalBottom;
1013 v.physicalLeft = physicalLeft;
1014 v.physicalTop = physicalTop;
1015 v.physicalRight = physicalRight;
1016 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001017 v.deviceWidth = deviceWidth;
1018 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001019 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001020}
1021
Jeff Brown4532e612012-04-05 14:27:12 -07001022static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
1023 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
1024 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001025
Jeff Brown4532e612012-04-05 14:27:12 -07001026 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001027 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001028}
1029
Jeff Brown4532e612012-04-05 14:27:12 -07001030static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
1031 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
1032 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001033
Jeff Brown4532e612012-04-05 14:27:12 -07001034 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001035 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001036}
1037
Jeff Brown4532e612012-04-05 14:27:12 -07001038static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1039 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1040 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001041
Jeff Brown4532e612012-04-05 14:27:12 -07001042 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001043 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001044}
1045
Jeff Brown4532e612012-04-05 14:27:12 -07001046static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1047 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1048 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001049
1050 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1051 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1052 jsize numCodes = env->GetArrayLength(keyCodes);
1053 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001054 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001055 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001056 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001057 } else {
1058 result = JNI_FALSE;
1059 }
1060
1061 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1062 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1063 return result;
1064}
1065
1066static void throwInputChannelNotInitialized(JNIEnv* env) {
1067 jniThrowException(env, "java/lang/IllegalStateException",
1068 "inputChannel is not initialized");
1069}
1070
Jeff Brown4532e612012-04-05 14:27:12 -07001071static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001072 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001073 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1074
Steve Block8564c8d2012-01-05 23:22:43 +00001075 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001076 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001077 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001078}
1079
Jeff Brown4532e612012-04-05 14:27:12 -07001080static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1081 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1082 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001083
1084 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1085 inputChannelObj);
1086 if (inputChannel == NULL) {
1087 throwInputChannelNotInitialized(env);
1088 return;
1089 }
1090
Jeff Brown928e0542011-01-10 11:17:36 -08001091 sp<InputWindowHandle> inputWindowHandle =
1092 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001093
Jeff Brown4532e612012-04-05 14:27:12 -07001094 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001095 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001096 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001097 String8 message;
1098 message.appendFormat("Failed to register input channel. status=%d", status);
1099 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001100 return;
1101 }
1102
Jeff Browna41ca772010-08-11 14:46:32 -07001103 if (! monitor) {
1104 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001105 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001106 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001107}
1108
Jeff Brown4532e612012-04-05 14:27:12 -07001109static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1110 jint ptr, jobject inputChannelObj) {
1111 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001112
1113 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1114 inputChannelObj);
1115 if (inputChannel == NULL) {
1116 throwInputChannelNotInitialized(env);
1117 return;
1118 }
1119
1120 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1121
Jeff Brown4532e612012-04-05 14:27:12 -07001122 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001123 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1124 String8 message;
1125 message.appendFormat("Failed to unregister input channel. status=%d", status);
1126 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001127 }
1128}
1129
Jeff Brown4532e612012-04-05 14:27:12 -07001130static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1131 jint ptr, jboolean enabled) {
1132 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001133
Jeff Brown4532e612012-04-05 14:27:12 -07001134 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001135}
1136
Jeff Brown4532e612012-04-05 14:27:12 -07001137static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1138 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001139 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001140 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001141
Jeff Brown6ec402b2010-07-28 15:48:59 -07001142 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1143 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001144 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1145 if (status) {
1146 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1147 return INPUT_EVENT_INJECTION_FAILED;
1148 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001149
Jeff Brown4532e612012-04-05 14:27:12 -07001150 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001151 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1152 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001153 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001154 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1155 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001156 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1157 return INPUT_EVENT_INJECTION_FAILED;
1158 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001159
Jeff Brown4532e612012-04-05 14:27:12 -07001160 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001161 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1162 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001163 } else {
1164 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001165 return INPUT_EVENT_INJECTION_FAILED;
1166 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001167}
1168
Jeff Brown4532e612012-04-05 14:27:12 -07001169static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1170 jint ptr, jobjectArray windowHandleObjArray) {
1171 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001172
Jeff Brown4532e612012-04-05 14:27:12 -07001173 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001174}
1175
Jeff Brown4532e612012-04-05 14:27:12 -07001176static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1177 jint ptr, jobject applicationHandleObj) {
1178 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001179
Jeff Brown4532e612012-04-05 14:27:12 -07001180 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001181}
1182
Jeff Brown4532e612012-04-05 14:27:12 -07001183static void nativeSetInputDispatchMode(JNIEnv* env,
1184 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1185 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001186
Jeff Brown4532e612012-04-05 14:27:12 -07001187 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001188}
1189
Jeff Brown4532e612012-04-05 14:27:12 -07001190static void nativeSetSystemUiVisibility(JNIEnv* env,
1191 jclass clazz, jint ptr, jint visibility) {
1192 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001193
Jeff Brown4532e612012-04-05 14:27:12 -07001194 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001195}
1196
Jeff Brown4532e612012-04-05 14:27:12 -07001197static jboolean nativeTransferTouchFocus(JNIEnv* env,
1198 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1199 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001200
1201 sp<InputChannel> fromChannel =
1202 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1203 sp<InputChannel> toChannel =
1204 android_view_InputChannel_getInputChannel(env, toChannelObj);
1205
1206 if (fromChannel == NULL || toChannel == NULL) {
1207 return false;
1208 }
1209
Jeff Brown4532e612012-04-05 14:27:12 -07001210 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001211 transferTouchFocus(fromChannel, toChannel);
1212}
1213
Jeff Brown4532e612012-04-05 14:27:12 -07001214static void nativeSetPointerSpeed(JNIEnv* env,
1215 jclass clazz, jint ptr, jint speed) {
1216 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001217
Jeff Brown4532e612012-04-05 14:27:12 -07001218 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001219}
1220
Jeff Brown4532e612012-04-05 14:27:12 -07001221static void nativeSetShowTouches(JNIEnv* env,
1222 jclass clazz, jint ptr, jboolean enabled) {
1223 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001224
Jeff Brown4532e612012-04-05 14:27:12 -07001225 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001226}
1227
Jeff Browna47425a2012-04-13 04:09:27 -07001228static void nativeVibrate(JNIEnv* env,
1229 jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
1230 jint repeat, jint token) {
1231 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1232
1233 size_t patternSize = env->GetArrayLength(patternObj);
1234 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
1235 ALOGI("Skipped requested vibration because the pattern size is %d "
1236 "which is more than the maximum supported size of %d.",
1237 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1238 return; // limit to reasonable size
1239 }
1240
1241 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1242 patternObj, NULL));
1243 nsecs_t pattern[patternSize];
1244 for (size_t i = 0; i < patternSize; i++) {
1245 pattern[i] = max(jlong(0), min(patternMillis[i],
1246 MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
1247 }
1248 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1249
1250 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1251}
1252
1253static void nativeCancelVibrate(JNIEnv* env,
1254 jclass clazz, jint ptr, jint deviceId, jint token) {
1255 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1256
1257 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1258}
1259
Jeff Brown6ec6f792012-04-17 16:52:41 -07001260static void nativeReloadKeyboardLayouts(JNIEnv* env,
1261 jclass clazz, jint ptr) {
1262 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1263
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001264 im->getInputManager()->getReader()->requestRefreshConfiguration(
1265 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1266}
1267
1268static void nativeReloadDeviceAliases(JNIEnv* env,
1269 jclass clazz, jint ptr) {
1270 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1271
1272 im->getInputManager()->getReader()->requestRefreshConfiguration(
1273 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001274}
1275
Jeff Brown4532e612012-04-05 14:27:12 -07001276static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1277 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001278
Jeff Brownb88102f2010-09-08 11:49:43 -07001279 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001280 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001281 return env->NewStringUTF(dump.string());
1282}
1283
Jeff Brown4532e612012-04-05 14:27:12 -07001284static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1285 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001286
Jeff Brown4532e612012-04-05 14:27:12 -07001287 im->getInputManager()->getReader()->monitor();
1288 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001289}
1290
Jeff Brown9c3cda02010-06-15 01:31:58 -07001291// ----------------------------------------------------------------------------
1292
Jeff Brown46b9ac02010-04-22 18:58:52 -07001293static JNINativeMethod gInputManagerMethods[] = {
1294 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001295 { "nativeInit",
1296 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1297 (void*) nativeInit },
1298 { "nativeStart", "(I)V",
1299 (void*) nativeStart },
Jeff Brown83d616a2012-09-09 20:33:43 -07001300 { "nativeSetDisplayViewport", "(IZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001301 (void*) nativeSetDisplayViewport },
Jeff Brown4532e612012-04-05 14:27:12 -07001302 { "nativeGetScanCodeState", "(IIII)I",
1303 (void*) nativeGetScanCodeState },
1304 { "nativeGetKeyCodeState", "(IIII)I",
1305 (void*) nativeGetKeyCodeState },
1306 { "nativeGetSwitchState", "(IIII)I",
1307 (void*) nativeGetSwitchState },
1308 { "nativeHasKeys", "(III[I[Z)Z",
1309 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001310 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001311 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1312 (void*) nativeRegisterInputChannel },
1313 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1314 (void*) nativeUnregisterInputChannel },
1315 { "nativeSetInputFilterEnabled", "(IZ)V",
1316 (void*) nativeSetInputFilterEnabled },
1317 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1318 (void*) nativeInjectInputEvent },
1319 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1320 (void*) nativeSetInputWindows },
1321 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1322 (void*) nativeSetFocusedApplication },
1323 { "nativeSetInputDispatchMode", "(IZZ)V",
1324 (void*) nativeSetInputDispatchMode },
1325 { "nativeSetSystemUiVisibility", "(II)V",
1326 (void*) nativeSetSystemUiVisibility },
Jeff Brown4532e612012-04-05 14:27:12 -07001327 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1328 (void*) nativeTransferTouchFocus },
1329 { "nativeSetPointerSpeed", "(II)V",
1330 (void*) nativeSetPointerSpeed },
1331 { "nativeSetShowTouches", "(IZ)V",
1332 (void*) nativeSetShowTouches },
Jeff Browna47425a2012-04-13 04:09:27 -07001333 { "nativeVibrate", "(II[JII)V",
1334 (void*) nativeVibrate },
1335 { "nativeCancelVibrate", "(III)V",
1336 (void*) nativeCancelVibrate },
Jeff Brown6ec6f792012-04-17 16:52:41 -07001337 { "nativeReloadKeyboardLayouts", "(I)V",
1338 (void*) nativeReloadKeyboardLayouts },
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001339 { "nativeReloadDeviceAliases", "(I)V",
1340 (void*) nativeReloadDeviceAliases },
Jeff Brown4532e612012-04-05 14:27:12 -07001341 { "nativeDump", "(I)Ljava/lang/String;",
1342 (void*) nativeDump },
1343 { "nativeMonitor", "(I)V",
1344 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001345};
1346
1347#define FIND_CLASS(var, className) \
1348 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001349 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001350
1351#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1352 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1353 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1354
1355#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1356 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1357 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1358
1359int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001360 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001361 gInputManagerMethods, NELEM(gInputManagerMethods));
1362 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1363
Jeff Brown9c3cda02010-06-15 01:31:58 -07001364 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001365
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001366 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001367 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001368
Jeff Brown4532e612012-04-05 14:27:12 -07001369 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001370 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001371
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001372 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1373 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1374
Jeff Brown53384282012-08-20 20:16:01 -07001375 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1376 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001377
Jeff Brown4532e612012-04-05 14:27:12 -07001378 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1379 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001380
Jeff Brown4532e612012-04-05 14:27:12 -07001381 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001382 "notifyANR",
Jeff Brown4532e612012-04-05 14:27:12 -07001383 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001384
Jeff Brown4532e612012-04-05 14:27:12 -07001385 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001386 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1387
Jeff Brown4532e612012-04-05 14:27:12 -07001388 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001389 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001390
Jeff Brown4532e612012-04-05 14:27:12 -07001391 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001392 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001393 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1394
Jeff Brown4532e612012-04-05 14:27:12 -07001395 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001396 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001397 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001398
Jeff Brown4532e612012-04-05 14:27:12 -07001399 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001400 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001401 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001402
Jeff Brown4532e612012-04-05 14:27:12 -07001403 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001404 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001405
Jeff Brown4532e612012-04-05 14:27:12 -07001406 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001407 "getVirtualKeyQuietTimeMillis", "()I");
1408
Jeff Brown4532e612012-04-05 14:27:12 -07001409 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001410 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1411
Jeff Brown4532e612012-04-05 14:27:12 -07001412 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001413 "getKeyRepeatTimeout", "()I");
1414
Jeff Brown4532e612012-04-05 14:27:12 -07001415 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001416 "getKeyRepeatDelay", "()I");
1417
Jeff Brown4532e612012-04-05 14:27:12 -07001418 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001419 "getHoverTapTimeout", "()I");
1420
Jeff Brown4532e612012-04-05 14:27:12 -07001421 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001422 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001423
Jeff Brown4532e612012-04-05 14:27:12 -07001424 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001425 "getDoubleTapTimeout", "()I");
1426
Jeff Brown4532e612012-04-05 14:27:12 -07001427 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001428 "getLongPressTimeout", "()I");
1429
Jeff Brown4532e612012-04-05 14:27:12 -07001430 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001431 "getPointerLayer", "()I");
1432
Jeff Brown4532e612012-04-05 14:27:12 -07001433 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001434 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001435
Jeff Brown6ec6f792012-04-17 16:52:41 -07001436 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
1437 "getKeyboardLayoutOverlay", "(Ljava/lang/String;)[Ljava/lang/String;");
1438
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001439 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1440 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1441
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001442 // InputDevice
1443
1444 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1445 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1446
Jeff Brown6ec402b2010-07-28 15:48:59 -07001447 // KeyEvent
1448
1449 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001450 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1451
Jeff Brown8d608662010-08-30 03:02:23 -07001452 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001453
1454 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001455 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001456
Jeff Brown46b9ac02010-04-22 18:58:52 -07001457 return 0;
1458}
1459
Jeff Brown46b9ac02010-04-22 18:58:52 -07001460} /* namespace android */