blob: 12a1c7a0bdac9c9e3b020ca447164076b459a126 [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
RoboErikfb290df2013-12-16 11:27:55 -0800102static struct {
103 jclass clazz;
104 jmethodID constructor;
105} gInputDeviceIdentifierInfo;
106
107
Jeff Brown928e0542011-01-10 11:17:36 -0800108
109// --- Global functions ---
110
Jeff Brown214eaf42011-05-26 19:17:02 -0700111template<typename T>
112inline static T min(const T& a, const T& b) {
113 return a < b ? a : b;
114}
115
116template<typename T>
117inline static T max(const T& a, const T& b) {
118 return a > b ? a : b;
119}
120
Jeff Brown928e0542011-01-10 11:17:36 -0800121static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
122 const sp<InputApplicationHandle>& inputApplicationHandle) {
123 if (inputApplicationHandle == NULL) {
124 return NULL;
125 }
126 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
127 getInputApplicationHandleObjLocalRef(env);
128}
129
130static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
131 const sp<InputWindowHandle>& inputWindowHandle) {
132 if (inputWindowHandle == NULL) {
133 return NULL;
134 }
135 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
136 getInputWindowHandleObjLocalRef(env);
137}
138
Jeff Brown2352b972011-04-12 22:39:53 -0700139static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
140 SpriteIcon* outSpriteIcon) {
141 PointerIcon pointerIcon;
142 status_t status = android_view_PointerIcon_loadSystemIcon(env,
143 contextObj, style, &pointerIcon);
144 if (!status) {
145 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
146 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
147 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
148 }
149}
150
Jeff Brown905805a2011-10-12 13:57:59 -0700151enum {
152 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown96307042012-07-27 15:51:34 -0700153 WM_ACTION_WAKE_UP = 2,
Jeff Brown905805a2011-10-12 13:57:59 -0700154 WM_ACTION_GO_TO_SLEEP = 4,
155};
156
Jeff Brown928e0542011-01-10 11:17:36 -0800157
158// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800159
Jeff Brown9c3cda02010-06-15 01:31:58 -0700160class NativeInputManager : public virtual RefBase,
161 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700162 public virtual InputDispatcherPolicyInterface,
163 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700164protected:
165 virtual ~NativeInputManager();
166
167public:
Jeff Brown4532e612012-04-05 14:27:12 -0700168 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700169
170 inline sp<InputManager> getInputManager() const { return mInputManager; }
171
Jeff Brownb88102f2010-09-08 11:49:43 -0700172 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700173
Jeff Brownd728bf52012-09-08 18:05:28 -0700174 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700175
Jeff Brown7fbdc842010-06-17 20:52:56 -0700176 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800177 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700178 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
179
Jeff Brown9302c872011-07-13 22:51:29 -0700180 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
181 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700182 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800183 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700184 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700185 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700186
Jeff Brown9c3cda02010-06-15 01:31:58 -0700187 /* --- InputReaderPolicyInterface implementation --- */
188
Jeff Brown214eaf42011-05-26 19:17:02 -0700189 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800190 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700191 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
RoboErikfb290df2013-12-16 11:27:55 -0800192 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700193 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194
195 /* --- InputDispatcherPolicyInterface implementation --- */
196
Jeff Brownbcc046a2012-09-27 20:46:43 -0700197 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700198 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700199 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700200 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700201 const sp<InputWindowHandle>& inputWindowHandle,
202 const String8& reason);
Jeff Brown928e0542011-01-10 11:17:36 -0800203 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700204 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700205 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
206 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800207 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800208 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700209 virtual nsecs_t interceptKeyBeforeDispatching(
210 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700211 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800212 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800213 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700214 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700215 virtual bool checkInjectEventsPermissionNonReentrant(
216 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700217
Jeff Brown2352b972011-04-12 22:39:53 -0700218 /* --- PointerControllerPolicyInterface implementation --- */
219
220 virtual void loadPointerResources(PointerResources* outResources);
221
Jeff Brown9c3cda02010-06-15 01:31:58 -0700222private:
223 sp<InputManager> mInputManager;
224
Jeff Brown2352b972011-04-12 22:39:53 -0700225 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700226 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800227 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700228
Jeff Brown83c09682010-12-23 17:50:18 -0800229 Mutex mLock;
230 struct Locked {
231 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700232 DisplayViewport internalViewport;
233 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800234
Jeff Brown05dc66a2011-03-02 14:41:58 -0800235 // System UI visibility.
236 int32_t systemUiVisibility;
237
Jeff Brown1a84fd12011-06-02 01:26:32 -0700238 // Pointer speed.
239 int32_t pointerSpeed;
240
Jeff Brown474dcb52011-06-14 20:22:50 -0700241 // True if pointer gestures are enabled.
242 bool pointerGesturesEnabled;
243
Jeff Browndaf4a122011-08-26 17:14:14 -0700244 // Show touches feature enable/disable.
245 bool showTouches;
246
Jeff Brown5541de92011-04-11 11:54:25 -0700247 // Sprite controller singleton, created on first use.
248 sp<SpriteController> spriteController;
249
Jeff Brown83c09682010-12-23 17:50:18 -0800250 // Pointer controller singleton, created and destroyed as needed.
251 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800252 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700253
Jeff Brown2352b972011-04-12 22:39:53 -0700254 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800255 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700256 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800257
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700258 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700259 bool isScreenOn();
260 bool isScreenBright();
261
Jeff Brownb88102f2010-09-08 11:49:43 -0700262 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700263
Jeff Brown9c3cda02010-06-15 01:31:58 -0700264 static inline JNIEnv* jniEnv() {
265 return AndroidRuntime::getJNIEnv();
266 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700267};
268
Jeff Brown928e0542011-01-10 11:17:36 -0800269
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270
Jeff Brown2352b972011-04-12 22:39:53 -0700271NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700272 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700273 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700274 JNIEnv* env = jniEnv();
275
Jeff Brown2352b972011-04-12 22:39:53 -0700276 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700277 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700278
Jeff Brown83c09682010-12-23 17:50:18 -0800279 {
280 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800281 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700282 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700283 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700284 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800285 }
286
Jeff Brown9c3cda02010-06-15 01:31:58 -0700287 sp<EventHub> eventHub = new EventHub();
288 mInputManager = new InputManager(eventHub, this, this);
289}
290
291NativeInputManager::~NativeInputManager() {
292 JNIEnv* env = jniEnv();
293
Jeff Brown2352b972011-04-12 22:39:53 -0700294 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700295 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700296}
297
Jeff Brownb88102f2010-09-08 11:49:43 -0700298void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700299 mInputManager->getReader()->dump(dump);
300 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700301
Jeff Brownb88102f2010-09-08 11:49:43 -0700302 mInputManager->getDispatcher()->dump(dump);
303 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700304}
305
Jeff Brown7fbdc842010-06-17 20:52:56 -0700306bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700307 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000308 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700309 LOGE_EX(env);
310 env->ExceptionClear();
311 return true;
312 }
313 return false;
314}
315
Jeff Brownd728bf52012-09-08 18:05:28 -0700316void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700317 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700318 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700319 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700320
Jeff Brownd728bf52012-09-08 18:05:28 -0700321 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
322 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700323 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700324 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700325
Jeff Brownd728bf52012-09-08 18:05:28 -0700326 if (!external) {
327 sp<PointerController> controller = mLocked.pointerController.promote();
328 if (controller != NULL) {
329 controller->setDisplayViewport(
330 viewport.logicalRight - viewport.logicalLeft,
331 viewport.logicalBottom - viewport.logicalTop,
332 viewport.orientation);
333 }
Jeff Brown2352b972011-04-12 22:39:53 -0700334 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700335 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700336 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700337
338 if (changed) {
339 mInputManager->getReader()->requestRefreshConfiguration(
340 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
341 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700342}
343
Jeff Brown7fbdc842010-06-17 20:52:56 -0700344status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800345 const sp<InputChannel>& inputChannel,
346 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
347 return mInputManager->getDispatcher()->registerInputChannel(
348 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700349}
350
351status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
352 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700353 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700354}
355
Jeff Brown214eaf42011-05-26 19:17:02 -0700356void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700357 JNIEnv* env = jniEnv();
358
Jeff Brown4532e612012-04-05 14:27:12 -0700359 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
360 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700361 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
362 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
363 }
364
365 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700366 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
367 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700368 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
369 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700370 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700371 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700372 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700373 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700374 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700375 env->DeleteLocalRef(item);
376 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700377 env->DeleteLocalRef(excludedDeviceNames);
378 }
379
Jeff Brown4532e612012-04-05 14:27:12 -0700380 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
381 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700382 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700383 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
384 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700385 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700386 jint longPressTimeout = env->CallIntMethod(mServiceObj,
387 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700388 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700389 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700390
391 // We must ensure that the tap-drag interval is significantly shorter than
392 // the long-press timeout because the tap is held down for the entire duration
393 // of the double-tap timeout.
394 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700395 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700396 outConfig->pointerGestureTapDragInterval =
397 milliseconds_to_nanoseconds(tapDragInterval);
398 }
399 }
400 }
401
Jeff Brown4532e612012-04-05 14:27:12 -0700402 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
403 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700404 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
405 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700406 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700407
408 { // acquire lock
409 AutoMutex _l(mLock);
410
411 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
412 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700413 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700414
Jeff Browndaf4a122011-08-26 17:14:14 -0700415 outConfig->showTouches = mLocked.showTouches;
416
Jeff Brownd728bf52012-09-08 18:05:28 -0700417 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
418 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700419 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700420}
421
Jeff Brown83c09682010-12-23 17:50:18 -0800422sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
423 AutoMutex _l(mLock);
424
425 sp<PointerController> controller = mLocked.pointerController.promote();
426 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700427 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800428
Jeff Brown2352b972011-04-12 22:39:53 -0700429 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800430 mLocked.pointerController = controller;
431
Jeff Brownd728bf52012-09-08 18:05:28 -0700432 DisplayViewport& v = mLocked.internalViewport;
433 controller->setDisplayViewport(
434 v.logicalRight - v.logicalLeft,
435 v.logicalBottom - v.logicalTop,
436 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800437
Jeff Brown5541de92011-04-11 11:54:25 -0700438 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700439 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
440 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700441 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
442 PointerIcon pointerIcon;
443 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
444 mContextObj, &pointerIcon);
445 if (!status && !pointerIcon.isNullIcon()) {
446 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
447 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
448 } else {
449 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800450 }
Jeff Brown2352b972011-04-12 22:39:53 -0700451 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800452 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800453
Jeff Brown2352b972011-04-12 22:39:53 -0700454 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800455 }
456 return controller;
457}
458
Jeff Brown5541de92011-04-11 11:54:25 -0700459void NativeInputManager::ensureSpriteControllerLocked() {
460 if (mLocked.spriteController == NULL) {
461 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700462 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700463 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
464 layer = -1;
465 }
466 mLocked.spriteController = new SpriteController(mLooper, layer);
467 }
468}
469
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700470void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
471 JNIEnv* env = jniEnv();
472
473 size_t count = inputDevices.size();
474 jobjectArray inputDevicesObjArray = env->NewObjectArray(
475 count, gInputDeviceClassInfo.clazz, NULL);
476 if (inputDevicesObjArray) {
477 bool error = false;
478 for (size_t i = 0; i < count; i++) {
479 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
480 if (!inputDeviceObj) {
481 error = true;
482 break;
483 }
484
485 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
486 env->DeleteLocalRef(inputDeviceObj);
487 }
488
489 if (!error) {
490 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
491 inputDevicesObjArray);
492 }
493
494 env->DeleteLocalRef(inputDevicesObjArray);
495 }
496
497 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
498}
499
Jeff Brown6ec6f792012-04-17 16:52:41 -0700500sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
RoboErikfb290df2013-12-16 11:27:55 -0800501 const InputDeviceIdentifier& identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700502 JNIEnv* env = jniEnv();
503
504 sp<KeyCharacterMap> result;
RoboErikfb290df2013-12-16 11:27:55 -0800505 ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
506 ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
507 gInputDeviceIdentifierInfo.constructor, descriptor.get(),
508 identifier.vendor, identifier.product));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700509 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
RoboErikfb290df2013-12-16 11:27:55 -0800510 gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700511 if (arrayObj.get()) {
512 ScopedLocalRef<jstring> filenameObj(env,
513 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
514 ScopedLocalRef<jstring> contentsObj(env,
515 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
516 ScopedUtfChars filenameChars(env, filenameObj.get());
517 ScopedUtfChars contentsChars(env, contentsObj.get());
518
519 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
520 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
521 }
522 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
523 return result;
524}
525
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700526String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
527 JNIEnv* env = jniEnv();
528
529 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
530 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
531 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
532 String8 result;
533 if (aliasObj.get()) {
534 ScopedUtfChars aliasChars(env, aliasObj.get());
535 result.setTo(aliasChars.c_str());
536 }
537 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
538 return result;
539}
540
Jeff Brownbcc046a2012-09-27 20:46:43 -0700541void NativeInputManager::notifySwitch(nsecs_t when,
542 uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700543#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700544 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
545 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700546#endif
547
548 JNIEnv* env = jniEnv();
549
Jeff Brown53384282012-08-20 20:16:01 -0700550 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700551 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700552 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700553}
554
Jeff Brown9c3cda02010-06-15 01:31:58 -0700555void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
556#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000557 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700558#endif
559
560 JNIEnv* env = jniEnv();
561
Jeff Brown4532e612012-04-05 14:27:12 -0700562 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700563 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700564}
565
Jeff Brown519e0242010-09-15 15:18:56 -0700566nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700567 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700568#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000569 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700570#endif
571
572 JNIEnv* env = jniEnv();
573
Jeff Brown928e0542011-01-10 11:17:36 -0800574 jobject inputApplicationHandleObj =
575 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
576 jobject inputWindowHandleObj =
577 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownbd181bb2013-09-10 16:44:24 -0700578 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700579
Jeff Brown4532e612012-04-05 14:27:12 -0700580 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700581 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
582 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700583 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
584 newTimeout = 0; // abort dispatch
585 } else {
586 assert(newTimeout >= 0);
587 }
588
Jeff Brownbd181bb2013-09-10 16:44:24 -0700589 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800590 env->DeleteLocalRef(inputWindowHandleObj);
591 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700592 return newTimeout;
593}
594
Jeff Brown928e0542011-01-10 11:17:36 -0800595void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700596#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000597 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700598#endif
599
Jeff Brown7fbdc842010-06-17 20:52:56 -0700600 JNIEnv* env = jniEnv();
601
Jeff Brown928e0542011-01-10 11:17:36 -0800602 jobject inputWindowHandleObj =
603 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
604 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700605 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800606 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700607 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
608
Jeff Brown928e0542011-01-10 11:17:36 -0800609 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700610 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700611}
612
Jeff Brown214eaf42011-05-26 19:17:02 -0700613void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
614 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800615
Jeff Brown4532e612012-04-05 14:27:12 -0700616 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
617 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700618 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
619 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
620 }
Jeff Browna4547672011-03-02 21:38:11 -0800621
Jeff Brown4532e612012-04-05 14:27:12 -0700622 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
623 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700624 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
625 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
626 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700627}
628
Jeff Brown214eaf42011-05-26 19:17:02 -0700629bool NativeInputManager::isKeyRepeatEnabled() {
630 // Only enable automatic key repeating when the screen is on.
631 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700632}
633
Jeff Brown9302c872011-07-13 22:51:29 -0700634void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
635 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700636
Jeff Brown9302c872011-07-13 22:51:29 -0700637 if (windowHandleObjArray) {
638 jsize length = env->GetArrayLength(windowHandleObjArray);
639 for (jsize i = 0; i < length; i++) {
640 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
641 if (! windowHandleObj) {
642 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700643 }
Jeff Brown9302c872011-07-13 22:51:29 -0700644
645 sp<InputWindowHandle> windowHandle =
646 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
647 if (windowHandle != NULL) {
648 windowHandles.push(windowHandle);
649 }
650 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700651 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700652 }
Jeff Brown349703e2010-06-22 01:27:15 -0700653
Jeff Brown9302c872011-07-13 22:51:29 -0700654 mInputManager->getDispatcher()->setInputWindows(windowHandles);
655
656 // Do this after the dispatcher has updated the window handle state.
657 bool newPointerGesturesEnabled = true;
658 size_t numWindows = windowHandles.size();
659 for (size_t i = 0; i < numWindows; i++) {
660 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700661 const InputWindowInfo* windowInfo = windowHandle->getInfo();
662 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
663 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700664 newPointerGesturesEnabled = false;
665 }
666 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700667
668 uint32_t changes = 0;
669 { // acquire lock
670 AutoMutex _l(mLock);
671
672 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
673 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
674 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
675 }
676 } // release lock
677
678 if (changes) {
679 mInputManager->getReader()->requestRefreshConfiguration(changes);
680 }
Jeff Brown349703e2010-06-22 01:27:15 -0700681}
682
Jeff Brown9302c872011-07-13 22:51:29 -0700683void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
684 sp<InputApplicationHandle> applicationHandle =
685 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
686 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700687}
688
689void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700690 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700691}
692
Jeff Brown05dc66a2011-03-02 14:41:58 -0800693void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
694 AutoMutex _l(mLock);
695
696 if (mLocked.systemUiVisibility != visibility) {
697 mLocked.systemUiVisibility = visibility;
698
699 sp<PointerController> controller = mLocked.pointerController.promote();
700 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700701 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800702 }
703 }
704}
705
Jeff Brown2352b972011-04-12 22:39:53 -0700706void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800707 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700708 controller->setInactivityTimeout(lightsOut
709 ? PointerController::INACTIVITY_TIMEOUT_SHORT
710 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800711}
712
Jeff Brown1a84fd12011-06-02 01:26:32 -0700713void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700714 { // acquire lock
715 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700716
Jeff Brown474dcb52011-06-14 20:22:50 -0700717 if (mLocked.pointerSpeed == speed) {
718 return;
719 }
720
Steve Block6215d3f2012-01-04 20:05:49 +0000721 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700722 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700723 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700724
Jeff Brown474dcb52011-06-14 20:22:50 -0700725 mInputManager->getReader()->requestRefreshConfiguration(
726 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700727}
728
Jeff Browndaf4a122011-08-26 17:14:14 -0700729void NativeInputManager::setShowTouches(bool enabled) {
730 { // acquire lock
731 AutoMutex _l(mLock);
732
733 if (mLocked.showTouches == enabled) {
734 return;
735 }
736
Steve Block6215d3f2012-01-04 20:05:49 +0000737 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700738 mLocked.showTouches = enabled;
739 } // release lock
740
741 mInputManager->getReader()->requestRefreshConfiguration(
742 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
743}
744
Jeff Browne20c9e02010-10-11 14:20:19 -0700745bool NativeInputManager::isScreenOn() {
746 return android_server_PowerManagerService_isScreenOn();
747}
748
749bool NativeInputManager::isScreenBright() {
750 return android_server_PowerManagerService_isScreenBright();
751}
752
Jeff Brown0029c662011-03-30 02:25:18 -0700753bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
754 jobject inputEventObj;
755
756 JNIEnv* env = jniEnv();
757 switch (inputEvent->getType()) {
758 case AINPUT_EVENT_TYPE_KEY:
759 inputEventObj = android_view_KeyEvent_fromNative(env,
760 static_cast<const KeyEvent*>(inputEvent));
761 break;
762 case AINPUT_EVENT_TYPE_MOTION:
763 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
764 static_cast<const MotionEvent*>(inputEvent));
765 break;
766 default:
767 return true; // dispatch the event normally
768 }
769
770 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000771 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700772 return true; // dispatch the event normally
773 }
774
775 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700776 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700777 inputEventObj, policyFlags);
778 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
779 pass = true;
780 }
781 env->DeleteLocalRef(inputEventObj);
782 return pass;
783}
784
Jeff Brown1f245102010-11-18 20:53:46 -0800785void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
786 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700787 // Policy:
788 // - Ignore untrusted events and pass them along.
789 // - Ask the window manager what to do with normal events and trusted injected events.
790 // - For normal events wake and brighten the screen if currently off or dim.
791 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800792 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700793 bool isScreenOn = this->isScreenOn();
794 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700795
Jeff Brown3122e442010-10-11 23:32:49 -0700796 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800797 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
798 jint wmActions;
799 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700800 wmActions = env->CallIntMethod(mServiceObj,
801 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800802 keyEventObj, policyFlags, isScreenOn);
803 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
804 wmActions = 0;
805 }
806 android_view_KeyEvent_recycle(env, keyEventObj);
807 env->DeleteLocalRef(keyEventObj);
808 } else {
Steve Block3762c312012-01-06 19:20:56 +0000809 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700810 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700811 }
812
Jeff Brown1f245102010-11-18 20:53:46 -0800813 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700814 if (!isScreenOn) {
815 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700816 }
817
818 if (!isScreenBright) {
819 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
820 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700821 }
822
Jeff Brown56194eb2011-03-02 19:23:13 -0800823 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700824 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700825 policyFlags |= POLICY_FLAG_PASS_TO_USER;
826 }
827}
828
Jeff Brown56194eb2011-03-02 19:23:13 -0800829void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700830 // Policy:
831 // - Ignore untrusted events and pass them along.
832 // - No special filtering for injected events required at this time.
833 // - Filter normal events based on screen state.
834 // - For normal events brighten (but do not wake) the screen if currently dim.
835 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
836 if (isScreenOn()) {
837 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700838
Jeff Brown3122e442010-10-11 23:32:49 -0700839 if (!isScreenBright()) {
840 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
841 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800842 } else {
843 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700844 jint wmActions = env->CallIntMethod(mServiceObj,
845 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800846 policyFlags);
847 if (checkAndClearExceptionFromCallback(env,
848 "interceptMotionBeforeQueueingWhenScreenOff")) {
849 wmActions = 0;
850 }
851
852 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
853 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700854 }
Jeff Brown3122e442010-10-11 23:32:49 -0700855 } else {
856 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700857 }
858}
859
Jeff Brown56194eb2011-03-02 19:23:13 -0800860void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
861 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800862 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800863#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000864 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800865#endif
866 android_server_PowerManagerService_goToSleep(when);
867 }
868
Jeff Brown96307042012-07-27 15:51:34 -0700869 if (wmActions & WM_ACTION_WAKE_UP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800870#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown96307042012-07-27 15:51:34 -0700871 ALOGD("handleInterceptActions: Waking up.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800872#endif
Jeff Brown96307042012-07-27 15:51:34 -0700873 android_server_PowerManagerService_wakeUp(when);
Jeff Brown56194eb2011-03-02 19:23:13 -0800874 }
875
876 if (wmActions & WM_ACTION_PASS_TO_USER) {
877 policyFlags |= POLICY_FLAG_PASS_TO_USER;
878 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800879#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000880 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800881#endif
882 }
883}
884
Jeff Brown905805a2011-10-12 13:57:59 -0700885nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800886 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700887 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700888 // Policy:
889 // - Ignore untrusted events and pass them along.
890 // - Filter normal events and trusted injected events through the window manager policy to
891 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700892 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700893 if (policyFlags & POLICY_FLAG_TRUSTED) {
894 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700895
Jeff Brown928e0542011-01-10 11:17:36 -0800896 // Note: inputWindowHandle may be null.
897 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800898 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
899 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700900 jlong delayMillis = env->CallLongMethod(mServiceObj,
901 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800902 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800903 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
904 android_view_KeyEvent_recycle(env, keyEventObj);
905 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700906 if (!error) {
907 if (delayMillis < 0) {
908 result = -1;
909 } else if (delayMillis > 0) {
910 result = milliseconds_to_nanoseconds(delayMillis);
911 }
912 }
Jeff Brown1f245102010-11-18 20:53:46 -0800913 } else {
Steve Block3762c312012-01-06 19:20:56 +0000914 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800915 }
Jeff Brown928e0542011-01-10 11:17:36 -0800916 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700917 }
Jeff Brown1f245102010-11-18 20:53:46 -0800918 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700919}
920
Jeff Brown928e0542011-01-10 11:17:36 -0800921bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800922 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700923 // Policy:
924 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800925 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700926 if (policyFlags & POLICY_FLAG_TRUSTED) {
927 JNIEnv* env = jniEnv();
928
Jeff Brown928e0542011-01-10 11:17:36 -0800929 // Note: inputWindowHandle may be null.
930 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800931 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
932 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700933 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
934 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800935 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700936 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
937 fallbackKeyEventObj = NULL;
938 }
Jeff Brown1f245102010-11-18 20:53:46 -0800939 android_view_KeyEvent_recycle(env, keyEventObj);
940 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800941
942 if (fallbackKeyEventObj) {
943 // Note: outFallbackKeyEvent may be the same object as keyEvent.
944 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
945 outFallbackKeyEvent)) {
946 result = true;
947 }
948 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
949 env->DeleteLocalRef(fallbackKeyEventObj);
950 }
Jeff Brown1f245102010-11-18 20:53:46 -0800951 } else {
Steve Block3762c312012-01-06 19:20:56 +0000952 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800953 }
Jeff Brown928e0542011-01-10 11:17:36 -0800954 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700955 }
Jeff Brown1f245102010-11-18 20:53:46 -0800956 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700957}
958
Jeff Brown01ce2e92010-09-26 22:20:12 -0700959void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
960 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700961}
962
Jeff Brown349703e2010-06-22 01:27:15 -0700963
Jeff Brownb88102f2010-09-08 11:49:43 -0700964bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
965 int32_t injectorPid, int32_t injectorUid) {
966 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700967 jboolean result = env->CallBooleanMethod(mServiceObj,
968 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700969 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
970 result = false;
971 }
Jeff Brown349703e2010-06-22 01:27:15 -0700972 return result;
973}
974
Jeff Brown2352b972011-04-12 22:39:53 -0700975void NativeInputManager::loadPointerResources(PointerResources* outResources) {
976 JNIEnv* env = jniEnv();
977
978 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
979 &outResources->spotHover);
980 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
981 &outResources->spotTouch);
982 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
983 &outResources->spotAnchor);
984}
985
Jeff Brown83c09682010-12-23 17:50:18 -0800986
Jeff Brown9c3cda02010-06-15 01:31:58 -0700987// ----------------------------------------------------------------------------
988
Jeff Brown4532e612012-04-05 14:27:12 -0700989static jint nativeInit(JNIEnv* env, jclass clazz,
990 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -0700991 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -0800992 if (messageQueue == NULL) {
993 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
994 return 0;
995 }
996
Jeff Brown603b4452012-04-06 17:39:41 -0700997 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
998 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800999 im->incStrong(0);
Jeff Brown4532e612012-04-05 14:27:12 -07001000 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001001}
1002
Jeff Brown4532e612012-04-05 14:27:12 -07001003static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
1004 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001005
Jeff Brown4532e612012-04-05 14:27:12 -07001006 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001007 if (result) {
1008 jniThrowRuntimeException(env, "Input manager could not be started.");
1009 }
1010}
1011
Jeff Brownd728bf52012-09-08 18:05:28 -07001012static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jint ptr, jboolean external,
1013 jint displayId, jint orientation,
1014 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001015 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1016 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001017 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001018
Jeff Brownd728bf52012-09-08 18:05:28 -07001019 DisplayViewport v;
1020 v.displayId = displayId;
1021 v.orientation = orientation;
1022 v.logicalLeft = logicalLeft;
1023 v.logicalTop = logicalTop;
1024 v.logicalRight = logicalRight;
1025 v.logicalBottom = logicalBottom;
1026 v.physicalLeft = physicalLeft;
1027 v.physicalTop = physicalTop;
1028 v.physicalRight = physicalRight;
1029 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001030 v.deviceWidth = deviceWidth;
1031 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001032 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001033}
1034
Jeff Brown4532e612012-04-05 14:27:12 -07001035static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
1036 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
1037 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001038
Jeff Brown4532e612012-04-05 14:27:12 -07001039 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001040 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001041}
1042
Jeff Brown4532e612012-04-05 14:27:12 -07001043static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
1044 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
1045 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001046
Jeff Brown4532e612012-04-05 14:27:12 -07001047 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001048 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001049}
1050
Jeff Brown4532e612012-04-05 14:27:12 -07001051static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1052 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1053 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001054
Jeff Brown4532e612012-04-05 14:27:12 -07001055 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001056 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001057}
1058
Jeff Brown4532e612012-04-05 14:27:12 -07001059static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1060 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1061 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001062
1063 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1064 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1065 jsize numCodes = env->GetArrayLength(keyCodes);
1066 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001067 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001068 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001069 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001070 } else {
1071 result = JNI_FALSE;
1072 }
1073
1074 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1075 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1076 return result;
1077}
1078
1079static void throwInputChannelNotInitialized(JNIEnv* env) {
1080 jniThrowException(env, "java/lang/IllegalStateException",
1081 "inputChannel is not initialized");
1082}
1083
Jeff Brown4532e612012-04-05 14:27:12 -07001084static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001085 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001086 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1087
Steve Block8564c8d2012-01-05 23:22:43 +00001088 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001089 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001090 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001091}
1092
Jeff Brown4532e612012-04-05 14:27:12 -07001093static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1094 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1095 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001096
1097 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1098 inputChannelObj);
1099 if (inputChannel == NULL) {
1100 throwInputChannelNotInitialized(env);
1101 return;
1102 }
1103
Jeff Brown928e0542011-01-10 11:17:36 -08001104 sp<InputWindowHandle> inputWindowHandle =
1105 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001106
Jeff Brown4532e612012-04-05 14:27:12 -07001107 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001108 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001109 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001110 String8 message;
1111 message.appendFormat("Failed to register input channel. status=%d", status);
1112 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001113 return;
1114 }
1115
Jeff Browna41ca772010-08-11 14:46:32 -07001116 if (! monitor) {
1117 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001118 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001119 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001120}
1121
Jeff Brown4532e612012-04-05 14:27:12 -07001122static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1123 jint ptr, jobject inputChannelObj) {
1124 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001125
1126 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1127 inputChannelObj);
1128 if (inputChannel == NULL) {
1129 throwInputChannelNotInitialized(env);
1130 return;
1131 }
1132
1133 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1134
Jeff Brown4532e612012-04-05 14:27:12 -07001135 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001136 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1137 String8 message;
1138 message.appendFormat("Failed to unregister input channel. status=%d", status);
1139 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001140 }
1141}
1142
Jeff Brown4532e612012-04-05 14:27:12 -07001143static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1144 jint ptr, jboolean enabled) {
1145 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001146
Jeff Brown4532e612012-04-05 14:27:12 -07001147 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001148}
1149
Jeff Brown4532e612012-04-05 14:27:12 -07001150static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1151 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001152 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001153 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001154
Jeff Brown6ec402b2010-07-28 15:48:59 -07001155 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1156 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001157 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1158 if (status) {
1159 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1160 return INPUT_EVENT_INJECTION_FAILED;
1161 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001162
Jeff Brown4532e612012-04-05 14:27:12 -07001163 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001164 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1165 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001166 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001167 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1168 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001169 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1170 return INPUT_EVENT_INJECTION_FAILED;
1171 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001172
Jeff Brown4532e612012-04-05 14:27:12 -07001173 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001174 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1175 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001176 } else {
1177 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001178 return INPUT_EVENT_INJECTION_FAILED;
1179 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001180}
1181
Jeff Brown4532e612012-04-05 14:27:12 -07001182static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1183 jint ptr, jobjectArray windowHandleObjArray) {
1184 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001185
Jeff Brown4532e612012-04-05 14:27:12 -07001186 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001187}
1188
Jeff Brown4532e612012-04-05 14:27:12 -07001189static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1190 jint ptr, jobject applicationHandleObj) {
1191 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001192
Jeff Brown4532e612012-04-05 14:27:12 -07001193 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001194}
1195
Jeff Brown4532e612012-04-05 14:27:12 -07001196static void nativeSetInputDispatchMode(JNIEnv* env,
1197 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1198 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001199
Jeff Brown4532e612012-04-05 14:27:12 -07001200 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001201}
1202
Jeff Brown4532e612012-04-05 14:27:12 -07001203static void nativeSetSystemUiVisibility(JNIEnv* env,
1204 jclass clazz, jint ptr, jint visibility) {
1205 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001206
Jeff Brown4532e612012-04-05 14:27:12 -07001207 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001208}
1209
Jeff Brown4532e612012-04-05 14:27:12 -07001210static jboolean nativeTransferTouchFocus(JNIEnv* env,
1211 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1212 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001213
1214 sp<InputChannel> fromChannel =
1215 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1216 sp<InputChannel> toChannel =
1217 android_view_InputChannel_getInputChannel(env, toChannelObj);
1218
1219 if (fromChannel == NULL || toChannel == NULL) {
1220 return false;
1221 }
1222
Jeff Brown4532e612012-04-05 14:27:12 -07001223 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001224 transferTouchFocus(fromChannel, toChannel);
1225}
1226
Jeff Brown4532e612012-04-05 14:27:12 -07001227static void nativeSetPointerSpeed(JNIEnv* env,
1228 jclass clazz, jint ptr, jint speed) {
1229 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001230
Jeff Brown4532e612012-04-05 14:27:12 -07001231 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001232}
1233
Jeff Brown4532e612012-04-05 14:27:12 -07001234static void nativeSetShowTouches(JNIEnv* env,
1235 jclass clazz, jint ptr, jboolean enabled) {
1236 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001237
Jeff Brown4532e612012-04-05 14:27:12 -07001238 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001239}
1240
Jeff Browna47425a2012-04-13 04:09:27 -07001241static void nativeVibrate(JNIEnv* env,
1242 jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
1243 jint repeat, jint token) {
1244 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1245
1246 size_t patternSize = env->GetArrayLength(patternObj);
1247 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
1248 ALOGI("Skipped requested vibration because the pattern size is %d "
1249 "which is more than the maximum supported size of %d.",
1250 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1251 return; // limit to reasonable size
1252 }
1253
1254 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1255 patternObj, NULL));
1256 nsecs_t pattern[patternSize];
1257 for (size_t i = 0; i < patternSize; i++) {
1258 pattern[i] = max(jlong(0), min(patternMillis[i],
1259 MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
1260 }
1261 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1262
1263 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1264}
1265
1266static void nativeCancelVibrate(JNIEnv* env,
1267 jclass clazz, jint ptr, jint deviceId, jint token) {
1268 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1269
1270 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1271}
1272
Jeff Brown6ec6f792012-04-17 16:52:41 -07001273static void nativeReloadKeyboardLayouts(JNIEnv* env,
1274 jclass clazz, jint ptr) {
1275 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1276
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001277 im->getInputManager()->getReader()->requestRefreshConfiguration(
1278 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1279}
1280
1281static void nativeReloadDeviceAliases(JNIEnv* env,
1282 jclass clazz, jint ptr) {
1283 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1284
1285 im->getInputManager()->getReader()->requestRefreshConfiguration(
1286 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001287}
1288
Jeff Brown4532e612012-04-05 14:27:12 -07001289static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1290 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001291
Jeff Brownb88102f2010-09-08 11:49:43 -07001292 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001293 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001294 return env->NewStringUTF(dump.string());
1295}
1296
Jeff Brown4532e612012-04-05 14:27:12 -07001297static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1298 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001299
Jeff Brown4532e612012-04-05 14:27:12 -07001300 im->getInputManager()->getReader()->monitor();
1301 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001302}
1303
Jeff Brown9c3cda02010-06-15 01:31:58 -07001304// ----------------------------------------------------------------------------
1305
Jeff Brown46b9ac02010-04-22 18:58:52 -07001306static JNINativeMethod gInputManagerMethods[] = {
1307 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001308 { "nativeInit",
1309 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1310 (void*) nativeInit },
1311 { "nativeStart", "(I)V",
1312 (void*) nativeStart },
Jeff Brown83d616a2012-09-09 20:33:43 -07001313 { "nativeSetDisplayViewport", "(IZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001314 (void*) nativeSetDisplayViewport },
Jeff Brown4532e612012-04-05 14:27:12 -07001315 { "nativeGetScanCodeState", "(IIII)I",
1316 (void*) nativeGetScanCodeState },
1317 { "nativeGetKeyCodeState", "(IIII)I",
1318 (void*) nativeGetKeyCodeState },
1319 { "nativeGetSwitchState", "(IIII)I",
1320 (void*) nativeGetSwitchState },
1321 { "nativeHasKeys", "(III[I[Z)Z",
1322 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001323 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001324 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1325 (void*) nativeRegisterInputChannel },
1326 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1327 (void*) nativeUnregisterInputChannel },
1328 { "nativeSetInputFilterEnabled", "(IZ)V",
1329 (void*) nativeSetInputFilterEnabled },
1330 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1331 (void*) nativeInjectInputEvent },
1332 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1333 (void*) nativeSetInputWindows },
1334 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1335 (void*) nativeSetFocusedApplication },
1336 { "nativeSetInputDispatchMode", "(IZZ)V",
1337 (void*) nativeSetInputDispatchMode },
1338 { "nativeSetSystemUiVisibility", "(II)V",
1339 (void*) nativeSetSystemUiVisibility },
Jeff Brown4532e612012-04-05 14:27:12 -07001340 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1341 (void*) nativeTransferTouchFocus },
1342 { "nativeSetPointerSpeed", "(II)V",
1343 (void*) nativeSetPointerSpeed },
1344 { "nativeSetShowTouches", "(IZ)V",
1345 (void*) nativeSetShowTouches },
Jeff Browna47425a2012-04-13 04:09:27 -07001346 { "nativeVibrate", "(II[JII)V",
1347 (void*) nativeVibrate },
1348 { "nativeCancelVibrate", "(III)V",
1349 (void*) nativeCancelVibrate },
Jeff Brown6ec6f792012-04-17 16:52:41 -07001350 { "nativeReloadKeyboardLayouts", "(I)V",
1351 (void*) nativeReloadKeyboardLayouts },
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001352 { "nativeReloadDeviceAliases", "(I)V",
1353 (void*) nativeReloadDeviceAliases },
Jeff Brown4532e612012-04-05 14:27:12 -07001354 { "nativeDump", "(I)Ljava/lang/String;",
1355 (void*) nativeDump },
1356 { "nativeMonitor", "(I)V",
1357 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001358};
1359
1360#define FIND_CLASS(var, className) \
1361 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001362 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001363
1364#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1365 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1366 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1367
1368#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1369 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1370 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1371
1372int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001373 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001374 gInputManagerMethods, NELEM(gInputManagerMethods));
1375 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1376
Jeff Brown9c3cda02010-06-15 01:31:58 -07001377 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001378
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001379 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001380 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001381
Jeff Brown4532e612012-04-05 14:27:12 -07001382 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001383 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001384
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001385 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1386 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1387
Jeff Brown53384282012-08-20 20:16:01 -07001388 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1389 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001390
Jeff Brown4532e612012-04-05 14:27:12 -07001391 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1392 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001393
Jeff Brown4532e612012-04-05 14:27:12 -07001394 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001395 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001396 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001397
Jeff Brown4532e612012-04-05 14:27:12 -07001398 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001399 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1400
Jeff Brown4532e612012-04-05 14:27:12 -07001401 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001402 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001403
Jeff Brown4532e612012-04-05 14:27:12 -07001404 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001405 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001406 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1407
Jeff Brown4532e612012-04-05 14:27:12 -07001408 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001409 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001410 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001411
Jeff Brown4532e612012-04-05 14:27:12 -07001412 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001413 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001414 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001415
Jeff Brown4532e612012-04-05 14:27:12 -07001416 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001417 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001418
Jeff Brown4532e612012-04-05 14:27:12 -07001419 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001420 "getVirtualKeyQuietTimeMillis", "()I");
1421
Jeff Brown4532e612012-04-05 14:27:12 -07001422 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001423 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1424
Jeff Brown4532e612012-04-05 14:27:12 -07001425 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001426 "getKeyRepeatTimeout", "()I");
1427
Jeff Brown4532e612012-04-05 14:27:12 -07001428 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001429 "getKeyRepeatDelay", "()I");
1430
Jeff Brown4532e612012-04-05 14:27:12 -07001431 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001432 "getHoverTapTimeout", "()I");
1433
Jeff Brown4532e612012-04-05 14:27:12 -07001434 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001435 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001436
Jeff Brown4532e612012-04-05 14:27:12 -07001437 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001438 "getDoubleTapTimeout", "()I");
1439
Jeff Brown4532e612012-04-05 14:27:12 -07001440 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001441 "getLongPressTimeout", "()I");
1442
Jeff Brown4532e612012-04-05 14:27:12 -07001443 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001444 "getPointerLayer", "()I");
1445
Jeff Brown4532e612012-04-05 14:27:12 -07001446 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001447 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001448
Jeff Brown6ec6f792012-04-17 16:52:41 -07001449 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
RoboErikfb290df2013-12-16 11:27:55 -08001450 "getKeyboardLayoutOverlay",
1451 "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
Jeff Brown6ec6f792012-04-17 16:52:41 -07001452
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001453 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1454 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1455
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001456 // InputDevice
1457
1458 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1459 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1460
Jeff Brown6ec402b2010-07-28 15:48:59 -07001461 // KeyEvent
1462
1463 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001464 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1465
Jeff Brown8d608662010-08-30 03:02:23 -07001466 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001467
1468 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001469 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001470
RoboErikfb290df2013-12-16 11:27:55 -08001471 // InputDeviceIdentifier
1472
1473 FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
1474 gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
1475 GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
1476 "<init>", "(Ljava/lang/String;II)V");
1477
Jeff Brown46b9ac02010-04-22 18:58:52 -07001478 return 0;
1479}
1480
Jeff Brown46b9ac02010-04-22 18:58:52 -07001481} /* namespace android */