blob: d8b8b94b9a08e8e730c9a50623cafef0cc138ee4 [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "InputManager-JNI"
18
Jeff Brown9c3cda02010-06-15 01:31:58 -070019//#define LOG_NDEBUG 0
20
21// Log debug messages about InputReaderPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070022#define DEBUG_INPUT_READER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070023
24// Log debug messages about InputDispatcherPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070025#define DEBUG_INPUT_DISPATCHER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070026
Jeff Brown83c09682010-12-23 17:50:18 -080027
Jeff Brown46b9ac02010-04-22 18:58:52 -070028#include "JNIHelp.h"
29#include "jni.h"
Jeff Brown349703e2010-06-22 01:27:15 -070030#include <limits.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070031#include <android_runtime/AndroidRuntime.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080032
Jeff Brown46b9ac02010-04-22 18:58:52 -070033#include <utils/Log.h>
Jeff Brown05dc66a2011-03-02 14:41:58 -080034#include <utils/Looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070035#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080036
Jeff Brownb4ff35d2011-01-02 16:37:43 -080037#include <input/InputManager.h>
38#include <input/PointerController.h>
Jeff Brown5541de92011-04-11 11:54:25 -070039#include <input/SpriteController.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040
Jeff Brown05dc66a2011-03-02 14:41:58 -080041#include <android_os_MessageQueue.h>
Jeff Brown9f25b7f2012-04-10 14:30:49 -070042#include <android_view_InputDevice.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080043#include <android_view_KeyEvent.h>
44#include <android_view_MotionEvent.h>
45#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070046#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080047#include <android/graphics/GraphicsJNI.h>
48
Jeff Brown6ec6f792012-04-17 16:52:41 -070049#include <ScopedLocalRef.h>
50#include <ScopedUtfChars.h>
51
Jeff Brown4f8ecd82012-06-18 18:29:13 -070052#include "com_android_server_power_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070053#include "com_android_server_input_InputApplicationHandle.h"
54#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070055
56namespace android {
57
Jeff Brown1a84fd12011-06-02 01:26:32 -070058// The exponent used to calculate the pointer speed scaling factor.
59// The scaling factor is calculated as 2 ^ (speed * exponent),
60// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070061static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070062
Jeff Brown46b9ac02010-04-22 18:58:52 -070063static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070064 jmethodID notifyConfigurationChanged;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070065 jmethodID notifyInputDevicesChanged;
Jeff Brown53384282012-08-20 20:16:01 -070066 jmethodID notifySwitch;
Jeff Brown7fbdc842010-06-17 20:52:56 -070067 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070068 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070069 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070070 jmethodID interceptKeyBeforeQueueing;
Jeff Brown56194eb2011-03-02 19:23:13 -080071 jmethodID interceptMotionBeforeQueueingWhenScreenOff;
Jeff Brown349703e2010-06-22 01:27:15 -070072 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070073 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070074 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080075 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070076 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080077 jmethodID getKeyRepeatTimeout;
78 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070079 jmethodID getHoverTapTimeout;
80 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070081 jmethodID getDoubleTapTimeout;
82 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080083 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080084 jmethodID getPointerIcon;
Jeff Brown6ec6f792012-04-17 16:52:41 -070085 jmethodID getKeyboardLayoutOverlay;
Jeff Brown5bbd4b42012-04-20 19:28:00 -070086 jmethodID getDeviceAlias;
Jeff Brown4532e612012-04-05 14:27:12 -070087} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070088
89static struct {
90 jclass clazz;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070091} gInputDeviceClassInfo;
92
93static struct {
94 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -070095} gKeyEventClassInfo;
96
97static struct {
98 jclass clazz;
99} gMotionEventClassInfo;
100
Jeff Brown928e0542011-01-10 11:17:36 -0800101
102// --- Global functions ---
103
Jeff Brown214eaf42011-05-26 19:17:02 -0700104template<typename T>
105inline static T min(const T& a, const T& b) {
106 return a < b ? a : b;
107}
108
109template<typename T>
110inline static T max(const T& a, const T& b) {
111 return a > b ? a : b;
112}
113
Jeff Brown928e0542011-01-10 11:17:36 -0800114static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
115 const sp<InputApplicationHandle>& inputApplicationHandle) {
116 if (inputApplicationHandle == NULL) {
117 return NULL;
118 }
119 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
120 getInputApplicationHandleObjLocalRef(env);
121}
122
123static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
124 const sp<InputWindowHandle>& inputWindowHandle) {
125 if (inputWindowHandle == NULL) {
126 return NULL;
127 }
128 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
129 getInputWindowHandleObjLocalRef(env);
130}
131
Jeff Brown2352b972011-04-12 22:39:53 -0700132static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
133 SpriteIcon* outSpriteIcon) {
134 PointerIcon pointerIcon;
135 status_t status = android_view_PointerIcon_loadSystemIcon(env,
136 contextObj, style, &pointerIcon);
137 if (!status) {
138 pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
139 outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
140 outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
141 }
142}
143
Jeff Brown905805a2011-10-12 13:57:59 -0700144enum {
145 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown96307042012-07-27 15:51:34 -0700146 WM_ACTION_WAKE_UP = 2,
Jeff Brown905805a2011-10-12 13:57:59 -0700147 WM_ACTION_GO_TO_SLEEP = 4,
148};
149
Jeff Brown928e0542011-01-10 11:17:36 -0800150
151// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800152
Jeff Brown9c3cda02010-06-15 01:31:58 -0700153class NativeInputManager : public virtual RefBase,
154 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700155 public virtual InputDispatcherPolicyInterface,
156 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700157protected:
158 virtual ~NativeInputManager();
159
160public:
Jeff Brown4532e612012-04-05 14:27:12 -0700161 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700162
163 inline sp<InputManager> getInputManager() const { return mInputManager; }
164
Jeff Brownb88102f2010-09-08 11:49:43 -0700165 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700166
Jeff Brownd728bf52012-09-08 18:05:28 -0700167 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700168
Jeff Brown7fbdc842010-06-17 20:52:56 -0700169 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800170 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700171 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
172
Jeff Brown9302c872011-07-13 22:51:29 -0700173 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
174 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700175 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800176 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700177 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700178 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700179
Jeff Brown9c3cda02010-06-15 01:31:58 -0700180 /* --- InputReaderPolicyInterface implementation --- */
181
Jeff Brown214eaf42011-05-26 19:17:02 -0700182 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800183 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700184 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700185 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700186 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700187
188 /* --- InputDispatcherPolicyInterface implementation --- */
189
Jeff Brownbcc046a2012-09-27 20:46:43 -0700190 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700191 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700192 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700193 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700194 const sp<InputWindowHandle>& inputWindowHandle,
195 const String8& reason);
Jeff Brown928e0542011-01-10 11:17:36 -0800196 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 Brownbd181bb2013-09-10 16:44:24 -0700557 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
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 Brownbd181bb2013-09-10 16:44:24 -0700568 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700569
Jeff Brown4532e612012-04-05 14:27:12 -0700570 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700571 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
572 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700573 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
574 newTimeout = 0; // abort dispatch
575 } else {
576 assert(newTimeout >= 0);
577 }
578
Jeff Brownbd181bb2013-09-10 16:44:24 -0700579 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800580 env->DeleteLocalRef(inputWindowHandleObj);
581 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700582 return newTimeout;
583}
584
Jeff Brown928e0542011-01-10 11:17:36 -0800585void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700586#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000587 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700588#endif
589
Jeff Brown7fbdc842010-06-17 20:52:56 -0700590 JNIEnv* env = jniEnv();
591
Jeff Brown928e0542011-01-10 11:17:36 -0800592 jobject inputWindowHandleObj =
593 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
594 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700595 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800596 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700597 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
598
Jeff Brown928e0542011-01-10 11:17:36 -0800599 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700600 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700601}
602
Jeff Brown214eaf42011-05-26 19:17:02 -0700603void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
604 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800605
Jeff Brown4532e612012-04-05 14:27:12 -0700606 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
607 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700608 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
609 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
610 }
Jeff Browna4547672011-03-02 21:38:11 -0800611
Jeff Brown4532e612012-04-05 14:27:12 -0700612 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
613 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700614 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
615 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
616 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700617}
618
Jeff Brown214eaf42011-05-26 19:17:02 -0700619bool NativeInputManager::isKeyRepeatEnabled() {
620 // Only enable automatic key repeating when the screen is on.
621 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700622}
623
Jeff Brown9302c872011-07-13 22:51:29 -0700624void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
625 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700626
Jeff Brown9302c872011-07-13 22:51:29 -0700627 if (windowHandleObjArray) {
628 jsize length = env->GetArrayLength(windowHandleObjArray);
629 for (jsize i = 0; i < length; i++) {
630 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
631 if (! windowHandleObj) {
632 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700633 }
Jeff Brown9302c872011-07-13 22:51:29 -0700634
635 sp<InputWindowHandle> windowHandle =
636 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
637 if (windowHandle != NULL) {
638 windowHandles.push(windowHandle);
639 }
640 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700641 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700642 }
Jeff Brown349703e2010-06-22 01:27:15 -0700643
Jeff Brown9302c872011-07-13 22:51:29 -0700644 mInputManager->getDispatcher()->setInputWindows(windowHandles);
645
646 // Do this after the dispatcher has updated the window handle state.
647 bool newPointerGesturesEnabled = true;
648 size_t numWindows = windowHandles.size();
649 for (size_t i = 0; i < numWindows; i++) {
650 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700651 const InputWindowInfo* windowInfo = windowHandle->getInfo();
652 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
653 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700654 newPointerGesturesEnabled = false;
655 }
656 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700657
658 uint32_t changes = 0;
659 { // acquire lock
660 AutoMutex _l(mLock);
661
662 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
663 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
664 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
665 }
666 } // release lock
667
668 if (changes) {
669 mInputManager->getReader()->requestRefreshConfiguration(changes);
670 }
Jeff Brown349703e2010-06-22 01:27:15 -0700671}
672
Jeff Brown9302c872011-07-13 22:51:29 -0700673void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
674 sp<InputApplicationHandle> applicationHandle =
675 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
676 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700677}
678
679void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700680 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700681}
682
Jeff Brown05dc66a2011-03-02 14:41:58 -0800683void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
684 AutoMutex _l(mLock);
685
686 if (mLocked.systemUiVisibility != visibility) {
687 mLocked.systemUiVisibility = visibility;
688
689 sp<PointerController> controller = mLocked.pointerController.promote();
690 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700691 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800692 }
693 }
694}
695
Jeff Brown2352b972011-04-12 22:39:53 -0700696void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800697 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700698 controller->setInactivityTimeout(lightsOut
699 ? PointerController::INACTIVITY_TIMEOUT_SHORT
700 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800701}
702
Jeff Brown1a84fd12011-06-02 01:26:32 -0700703void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700704 { // acquire lock
705 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700706
Jeff Brown474dcb52011-06-14 20:22:50 -0700707 if (mLocked.pointerSpeed == speed) {
708 return;
709 }
710
Steve Block6215d3f2012-01-04 20:05:49 +0000711 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700712 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700713 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700714
Jeff Brown474dcb52011-06-14 20:22:50 -0700715 mInputManager->getReader()->requestRefreshConfiguration(
716 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700717}
718
Jeff Browndaf4a122011-08-26 17:14:14 -0700719void NativeInputManager::setShowTouches(bool enabled) {
720 { // acquire lock
721 AutoMutex _l(mLock);
722
723 if (mLocked.showTouches == enabled) {
724 return;
725 }
726
Steve Block6215d3f2012-01-04 20:05:49 +0000727 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700728 mLocked.showTouches = enabled;
729 } // release lock
730
731 mInputManager->getReader()->requestRefreshConfiguration(
732 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
733}
734
Jeff Browne20c9e02010-10-11 14:20:19 -0700735bool NativeInputManager::isScreenOn() {
736 return android_server_PowerManagerService_isScreenOn();
737}
738
739bool NativeInputManager::isScreenBright() {
740 return android_server_PowerManagerService_isScreenBright();
741}
742
Jeff Brown0029c662011-03-30 02:25:18 -0700743bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
744 jobject inputEventObj;
745
746 JNIEnv* env = jniEnv();
747 switch (inputEvent->getType()) {
748 case AINPUT_EVENT_TYPE_KEY:
749 inputEventObj = android_view_KeyEvent_fromNative(env,
750 static_cast<const KeyEvent*>(inputEvent));
751 break;
752 case AINPUT_EVENT_TYPE_MOTION:
753 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
754 static_cast<const MotionEvent*>(inputEvent));
755 break;
756 default:
757 return true; // dispatch the event normally
758 }
759
760 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000761 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700762 return true; // dispatch the event normally
763 }
764
765 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700766 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700767 inputEventObj, policyFlags);
768 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
769 pass = true;
770 }
771 env->DeleteLocalRef(inputEventObj);
772 return pass;
773}
774
Jeff Brown1f245102010-11-18 20:53:46 -0800775void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
776 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700777 // Policy:
778 // - Ignore untrusted events and pass them along.
779 // - Ask the window manager what to do with normal events and trusted injected events.
780 // - For normal events wake and brighten the screen if currently off or dim.
781 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800782 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700783 bool isScreenOn = this->isScreenOn();
784 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700785
Jeff Brown3122e442010-10-11 23:32:49 -0700786 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800787 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
788 jint wmActions;
789 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700790 wmActions = env->CallIntMethod(mServiceObj,
791 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800792 keyEventObj, policyFlags, isScreenOn);
793 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
794 wmActions = 0;
795 }
796 android_view_KeyEvent_recycle(env, keyEventObj);
797 env->DeleteLocalRef(keyEventObj);
798 } else {
Steve Block3762c312012-01-06 19:20:56 +0000799 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700800 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700801 }
802
Jeff Brown1f245102010-11-18 20:53:46 -0800803 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700804 if (!isScreenOn) {
805 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700806 }
807
808 if (!isScreenBright) {
809 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
810 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700811 }
812
Jeff Brown56194eb2011-03-02 19:23:13 -0800813 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700814 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700815 policyFlags |= POLICY_FLAG_PASS_TO_USER;
816 }
817}
818
Jeff Brown56194eb2011-03-02 19:23:13 -0800819void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700820 // Policy:
821 // - Ignore untrusted events and pass them along.
822 // - No special filtering for injected events required at this time.
823 // - Filter normal events based on screen state.
824 // - For normal events brighten (but do not wake) the screen if currently dim.
825 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
826 if (isScreenOn()) {
827 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700828
Jeff Brown3122e442010-10-11 23:32:49 -0700829 if (!isScreenBright()) {
830 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
831 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800832 } else {
833 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700834 jint wmActions = env->CallIntMethod(mServiceObj,
835 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800836 policyFlags);
837 if (checkAndClearExceptionFromCallback(env,
838 "interceptMotionBeforeQueueingWhenScreenOff")) {
839 wmActions = 0;
840 }
841
842 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
843 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700844 }
Jeff Brown3122e442010-10-11 23:32:49 -0700845 } else {
846 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700847 }
848}
849
Jeff Brown56194eb2011-03-02 19:23:13 -0800850void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
851 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800852 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800853#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000854 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800855#endif
856 android_server_PowerManagerService_goToSleep(when);
857 }
858
Jeff Brown96307042012-07-27 15:51:34 -0700859 if (wmActions & WM_ACTION_WAKE_UP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800860#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brown96307042012-07-27 15:51:34 -0700861 ALOGD("handleInterceptActions: Waking up.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800862#endif
Jeff Brown96307042012-07-27 15:51:34 -0700863 android_server_PowerManagerService_wakeUp(when);
Jeff Brown56194eb2011-03-02 19:23:13 -0800864 }
865
866 if (wmActions & WM_ACTION_PASS_TO_USER) {
867 policyFlags |= POLICY_FLAG_PASS_TO_USER;
868 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800869#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000870 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800871#endif
872 }
873}
874
Jeff Brown905805a2011-10-12 13:57:59 -0700875nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800876 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700877 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700878 // Policy:
879 // - Ignore untrusted events and pass them along.
880 // - Filter normal events and trusted injected events through the window manager policy to
881 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700882 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700883 if (policyFlags & POLICY_FLAG_TRUSTED) {
884 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700885
Jeff Brown928e0542011-01-10 11:17:36 -0800886 // Note: inputWindowHandle may be null.
887 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800888 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
889 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700890 jlong delayMillis = env->CallLongMethod(mServiceObj,
891 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800892 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800893 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
894 android_view_KeyEvent_recycle(env, keyEventObj);
895 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700896 if (!error) {
897 if (delayMillis < 0) {
898 result = -1;
899 } else if (delayMillis > 0) {
900 result = milliseconds_to_nanoseconds(delayMillis);
901 }
902 }
Jeff Brown1f245102010-11-18 20:53:46 -0800903 } else {
Steve Block3762c312012-01-06 19:20:56 +0000904 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800905 }
Jeff Brown928e0542011-01-10 11:17:36 -0800906 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700907 }
Jeff Brown1f245102010-11-18 20:53:46 -0800908 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700909}
910
Jeff Brown928e0542011-01-10 11:17:36 -0800911bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800912 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700913 // Policy:
914 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800915 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700916 if (policyFlags & POLICY_FLAG_TRUSTED) {
917 JNIEnv* env = jniEnv();
918
Jeff Brown928e0542011-01-10 11:17:36 -0800919 // Note: inputWindowHandle may be null.
920 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800921 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
922 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700923 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
924 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800925 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700926 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
927 fallbackKeyEventObj = NULL;
928 }
Jeff Brown1f245102010-11-18 20:53:46 -0800929 android_view_KeyEvent_recycle(env, keyEventObj);
930 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800931
932 if (fallbackKeyEventObj) {
933 // Note: outFallbackKeyEvent may be the same object as keyEvent.
934 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
935 outFallbackKeyEvent)) {
936 result = true;
937 }
938 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
939 env->DeleteLocalRef(fallbackKeyEventObj);
940 }
Jeff Brown1f245102010-11-18 20:53:46 -0800941 } else {
Steve Block3762c312012-01-06 19:20:56 +0000942 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800943 }
Jeff Brown928e0542011-01-10 11:17:36 -0800944 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700945 }
Jeff Brown1f245102010-11-18 20:53:46 -0800946 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700947}
948
Jeff Brown01ce2e92010-09-26 22:20:12 -0700949void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
950 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700951}
952
Jeff Brown349703e2010-06-22 01:27:15 -0700953
Jeff Brownb88102f2010-09-08 11:49:43 -0700954bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
955 int32_t injectorPid, int32_t injectorUid) {
956 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700957 jboolean result = env->CallBooleanMethod(mServiceObj,
958 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700959 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
960 result = false;
961 }
Jeff Brown349703e2010-06-22 01:27:15 -0700962 return result;
963}
964
Jeff Brown2352b972011-04-12 22:39:53 -0700965void NativeInputManager::loadPointerResources(PointerResources* outResources) {
966 JNIEnv* env = jniEnv();
967
968 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
969 &outResources->spotHover);
970 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
971 &outResources->spotTouch);
972 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
973 &outResources->spotAnchor);
974}
975
Jeff Brown83c09682010-12-23 17:50:18 -0800976
Jeff Brown9c3cda02010-06-15 01:31:58 -0700977// ----------------------------------------------------------------------------
978
Jeff Brown4532e612012-04-05 14:27:12 -0700979static jint nativeInit(JNIEnv* env, jclass clazz,
980 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -0700981 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -0800982 if (messageQueue == NULL) {
983 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
984 return 0;
985 }
986
Jeff Brown603b4452012-04-06 17:39:41 -0700987 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
988 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800989 im->incStrong(0);
Jeff Brown4532e612012-04-05 14:27:12 -0700990 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700991}
992
Jeff Brown4532e612012-04-05 14:27:12 -0700993static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
994 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700995
Jeff Brown4532e612012-04-05 14:27:12 -0700996 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700997 if (result) {
998 jniThrowRuntimeException(env, "Input manager could not be started.");
999 }
1000}
1001
Jeff Brownd728bf52012-09-08 18:05:28 -07001002static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jint ptr, jboolean external,
1003 jint displayId, jint orientation,
1004 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001005 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1006 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001007 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001008
Jeff Brownd728bf52012-09-08 18:05:28 -07001009 DisplayViewport v;
1010 v.displayId = displayId;
1011 v.orientation = orientation;
1012 v.logicalLeft = logicalLeft;
1013 v.logicalTop = logicalTop;
1014 v.logicalRight = logicalRight;
1015 v.logicalBottom = logicalBottom;
1016 v.physicalLeft = physicalLeft;
1017 v.physicalTop = physicalTop;
1018 v.physicalRight = physicalRight;
1019 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001020 v.deviceWidth = deviceWidth;
1021 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001022 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001023}
1024
Jeff Brown4532e612012-04-05 14:27:12 -07001025static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
1026 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
1027 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001028
Jeff Brown4532e612012-04-05 14:27:12 -07001029 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001030 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001031}
1032
Jeff Brown4532e612012-04-05 14:27:12 -07001033static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
1034 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
1035 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001036
Jeff Brown4532e612012-04-05 14:27:12 -07001037 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001038 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001039}
1040
Jeff Brown4532e612012-04-05 14:27:12 -07001041static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1042 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1043 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001044
Jeff Brown4532e612012-04-05 14:27:12 -07001045 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001046 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001047}
1048
Jeff Brown4532e612012-04-05 14:27:12 -07001049static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1050 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1051 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001052
1053 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1054 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1055 jsize numCodes = env->GetArrayLength(keyCodes);
1056 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001057 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001058 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001059 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001060 } else {
1061 result = JNI_FALSE;
1062 }
1063
1064 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1065 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1066 return result;
1067}
1068
1069static void throwInputChannelNotInitialized(JNIEnv* env) {
1070 jniThrowException(env, "java/lang/IllegalStateException",
1071 "inputChannel is not initialized");
1072}
1073
Jeff Brown4532e612012-04-05 14:27:12 -07001074static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001075 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001076 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1077
Steve Block8564c8d2012-01-05 23:22:43 +00001078 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001079 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001080 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001081}
1082
Jeff Brown4532e612012-04-05 14:27:12 -07001083static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1084 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1085 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001086
1087 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1088 inputChannelObj);
1089 if (inputChannel == NULL) {
1090 throwInputChannelNotInitialized(env);
1091 return;
1092 }
1093
Jeff Brown928e0542011-01-10 11:17:36 -08001094 sp<InputWindowHandle> inputWindowHandle =
1095 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001096
Jeff Brown4532e612012-04-05 14:27:12 -07001097 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001098 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001099 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001100 String8 message;
1101 message.appendFormat("Failed to register input channel. status=%d", status);
1102 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001103 return;
1104 }
1105
Jeff Browna41ca772010-08-11 14:46:32 -07001106 if (! monitor) {
1107 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001108 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001109 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001110}
1111
Jeff Brown4532e612012-04-05 14:27:12 -07001112static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1113 jint ptr, jobject inputChannelObj) {
1114 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001115
1116 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1117 inputChannelObj);
1118 if (inputChannel == NULL) {
1119 throwInputChannelNotInitialized(env);
1120 return;
1121 }
1122
1123 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1124
Jeff Brown4532e612012-04-05 14:27:12 -07001125 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001126 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1127 String8 message;
1128 message.appendFormat("Failed to unregister input channel. status=%d", status);
1129 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001130 }
1131}
1132
Jeff Brown4532e612012-04-05 14:27:12 -07001133static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1134 jint ptr, jboolean enabled) {
1135 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001136
Jeff Brown4532e612012-04-05 14:27:12 -07001137 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001138}
1139
Jeff Brown4532e612012-04-05 14:27:12 -07001140static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1141 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001142 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001143 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001144
Jeff Brown6ec402b2010-07-28 15:48:59 -07001145 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1146 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001147 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1148 if (status) {
1149 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1150 return INPUT_EVENT_INJECTION_FAILED;
1151 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001152
Jeff Brown4532e612012-04-05 14:27:12 -07001153 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001154 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1155 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001156 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001157 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1158 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001159 jniThrowRuntimeException(env, "Could not read contents of MotionEvent 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 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1165 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001166 } else {
1167 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001168 return INPUT_EVENT_INJECTION_FAILED;
1169 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001170}
1171
Jeff Brown4532e612012-04-05 14:27:12 -07001172static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1173 jint ptr, jobjectArray windowHandleObjArray) {
1174 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001175
Jeff Brown4532e612012-04-05 14:27:12 -07001176 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001177}
1178
Jeff Brown4532e612012-04-05 14:27:12 -07001179static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1180 jint ptr, jobject applicationHandleObj) {
1181 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001182
Jeff Brown4532e612012-04-05 14:27:12 -07001183 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001184}
1185
Jeff Brown4532e612012-04-05 14:27:12 -07001186static void nativeSetInputDispatchMode(JNIEnv* env,
1187 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1188 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001189
Jeff Brown4532e612012-04-05 14:27:12 -07001190 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001191}
1192
Jeff Brown4532e612012-04-05 14:27:12 -07001193static void nativeSetSystemUiVisibility(JNIEnv* env,
1194 jclass clazz, jint ptr, jint visibility) {
1195 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001196
Jeff Brown4532e612012-04-05 14:27:12 -07001197 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001198}
1199
Jeff Brown4532e612012-04-05 14:27:12 -07001200static jboolean nativeTransferTouchFocus(JNIEnv* env,
1201 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1202 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001203
1204 sp<InputChannel> fromChannel =
1205 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1206 sp<InputChannel> toChannel =
1207 android_view_InputChannel_getInputChannel(env, toChannelObj);
1208
1209 if (fromChannel == NULL || toChannel == NULL) {
1210 return false;
1211 }
1212
Jeff Brown4532e612012-04-05 14:27:12 -07001213 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001214 transferTouchFocus(fromChannel, toChannel);
1215}
1216
Jeff Brown4532e612012-04-05 14:27:12 -07001217static void nativeSetPointerSpeed(JNIEnv* env,
1218 jclass clazz, jint ptr, jint speed) {
1219 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001220
Jeff Brown4532e612012-04-05 14:27:12 -07001221 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001222}
1223
Jeff Brown4532e612012-04-05 14:27:12 -07001224static void nativeSetShowTouches(JNIEnv* env,
1225 jclass clazz, jint ptr, jboolean enabled) {
1226 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001227
Jeff Brown4532e612012-04-05 14:27:12 -07001228 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001229}
1230
Jeff Browna47425a2012-04-13 04:09:27 -07001231static void nativeVibrate(JNIEnv* env,
1232 jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
1233 jint repeat, jint token) {
1234 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1235
1236 size_t patternSize = env->GetArrayLength(patternObj);
1237 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
1238 ALOGI("Skipped requested vibration because the pattern size is %d "
1239 "which is more than the maximum supported size of %d.",
1240 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1241 return; // limit to reasonable size
1242 }
1243
1244 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1245 patternObj, NULL));
1246 nsecs_t pattern[patternSize];
1247 for (size_t i = 0; i < patternSize; i++) {
1248 pattern[i] = max(jlong(0), min(patternMillis[i],
1249 MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
1250 }
1251 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1252
1253 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1254}
1255
1256static void nativeCancelVibrate(JNIEnv* env,
1257 jclass clazz, jint ptr, jint deviceId, jint token) {
1258 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1259
1260 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1261}
1262
Jeff Brown6ec6f792012-04-17 16:52:41 -07001263static void nativeReloadKeyboardLayouts(JNIEnv* env,
1264 jclass clazz, jint ptr) {
1265 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1266
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001267 im->getInputManager()->getReader()->requestRefreshConfiguration(
1268 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1269}
1270
1271static void nativeReloadDeviceAliases(JNIEnv* env,
1272 jclass clazz, jint ptr) {
1273 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1274
1275 im->getInputManager()->getReader()->requestRefreshConfiguration(
1276 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001277}
1278
Jeff Brown4532e612012-04-05 14:27:12 -07001279static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1280 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001281
Jeff Brownb88102f2010-09-08 11:49:43 -07001282 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001283 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001284 return env->NewStringUTF(dump.string());
1285}
1286
Jeff Brown4532e612012-04-05 14:27:12 -07001287static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1288 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001289
Jeff Brown4532e612012-04-05 14:27:12 -07001290 im->getInputManager()->getReader()->monitor();
1291 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001292}
1293
Jeff Brown9c3cda02010-06-15 01:31:58 -07001294// ----------------------------------------------------------------------------
1295
Jeff Brown46b9ac02010-04-22 18:58:52 -07001296static JNINativeMethod gInputManagerMethods[] = {
1297 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001298 { "nativeInit",
1299 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1300 (void*) nativeInit },
1301 { "nativeStart", "(I)V",
1302 (void*) nativeStart },
Jeff Brown83d616a2012-09-09 20:33:43 -07001303 { "nativeSetDisplayViewport", "(IZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001304 (void*) nativeSetDisplayViewport },
Jeff Brown4532e612012-04-05 14:27:12 -07001305 { "nativeGetScanCodeState", "(IIII)I",
1306 (void*) nativeGetScanCodeState },
1307 { "nativeGetKeyCodeState", "(IIII)I",
1308 (void*) nativeGetKeyCodeState },
1309 { "nativeGetSwitchState", "(IIII)I",
1310 (void*) nativeGetSwitchState },
1311 { "nativeHasKeys", "(III[I[Z)Z",
1312 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001313 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001314 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1315 (void*) nativeRegisterInputChannel },
1316 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1317 (void*) nativeUnregisterInputChannel },
1318 { "nativeSetInputFilterEnabled", "(IZ)V",
1319 (void*) nativeSetInputFilterEnabled },
1320 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1321 (void*) nativeInjectInputEvent },
1322 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1323 (void*) nativeSetInputWindows },
1324 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1325 (void*) nativeSetFocusedApplication },
1326 { "nativeSetInputDispatchMode", "(IZZ)V",
1327 (void*) nativeSetInputDispatchMode },
1328 { "nativeSetSystemUiVisibility", "(II)V",
1329 (void*) nativeSetSystemUiVisibility },
Jeff Brown4532e612012-04-05 14:27:12 -07001330 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1331 (void*) nativeTransferTouchFocus },
1332 { "nativeSetPointerSpeed", "(II)V",
1333 (void*) nativeSetPointerSpeed },
1334 { "nativeSetShowTouches", "(IZ)V",
1335 (void*) nativeSetShowTouches },
Jeff Browna47425a2012-04-13 04:09:27 -07001336 { "nativeVibrate", "(II[JII)V",
1337 (void*) nativeVibrate },
1338 { "nativeCancelVibrate", "(III)V",
1339 (void*) nativeCancelVibrate },
Jeff Brown6ec6f792012-04-17 16:52:41 -07001340 { "nativeReloadKeyboardLayouts", "(I)V",
1341 (void*) nativeReloadKeyboardLayouts },
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001342 { "nativeReloadDeviceAliases", "(I)V",
1343 (void*) nativeReloadDeviceAliases },
Jeff Brown4532e612012-04-05 14:27:12 -07001344 { "nativeDump", "(I)Ljava/lang/String;",
1345 (void*) nativeDump },
1346 { "nativeMonitor", "(I)V",
1347 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001348};
1349
1350#define FIND_CLASS(var, className) \
1351 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001352 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001353
1354#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1355 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1356 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1357
1358#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1359 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1360 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1361
1362int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001363 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001364 gInputManagerMethods, NELEM(gInputManagerMethods));
1365 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1366
Jeff Brown9c3cda02010-06-15 01:31:58 -07001367 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001368
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001369 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001370 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001371
Jeff Brown4532e612012-04-05 14:27:12 -07001372 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001373 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001374
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001375 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1376 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1377
Jeff Brown53384282012-08-20 20:16:01 -07001378 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1379 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001380
Jeff Brown4532e612012-04-05 14:27:12 -07001381 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1382 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001383
Jeff Brown4532e612012-04-05 14:27:12 -07001384 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001385 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001386 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001387
Jeff Brown4532e612012-04-05 14:27:12 -07001388 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001389 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1390
Jeff Brown4532e612012-04-05 14:27:12 -07001391 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001392 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001393
Jeff Brown4532e612012-04-05 14:27:12 -07001394 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001395 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001396 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1397
Jeff Brown4532e612012-04-05 14:27:12 -07001398 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001399 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001400 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001401
Jeff Brown4532e612012-04-05 14:27:12 -07001402 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001403 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001404 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001405
Jeff Brown4532e612012-04-05 14:27:12 -07001406 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001407 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001408
Jeff Brown4532e612012-04-05 14:27:12 -07001409 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001410 "getVirtualKeyQuietTimeMillis", "()I");
1411
Jeff Brown4532e612012-04-05 14:27:12 -07001412 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001413 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1414
Jeff Brown4532e612012-04-05 14:27:12 -07001415 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001416 "getKeyRepeatTimeout", "()I");
1417
Jeff Brown4532e612012-04-05 14:27:12 -07001418 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001419 "getKeyRepeatDelay", "()I");
1420
Jeff Brown4532e612012-04-05 14:27:12 -07001421 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001422 "getHoverTapTimeout", "()I");
1423
Jeff Brown4532e612012-04-05 14:27:12 -07001424 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001425 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001426
Jeff Brown4532e612012-04-05 14:27:12 -07001427 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001428 "getDoubleTapTimeout", "()I");
1429
Jeff Brown4532e612012-04-05 14:27:12 -07001430 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001431 "getLongPressTimeout", "()I");
1432
Jeff Brown4532e612012-04-05 14:27:12 -07001433 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001434 "getPointerLayer", "()I");
1435
Jeff Brown4532e612012-04-05 14:27:12 -07001436 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001437 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001438
Jeff Brown6ec6f792012-04-17 16:52:41 -07001439 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
1440 "getKeyboardLayoutOverlay", "(Ljava/lang/String;)[Ljava/lang/String;");
1441
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001442 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1443 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1444
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001445 // InputDevice
1446
1447 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1448 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1449
Jeff Brown6ec402b2010-07-28 15:48:59 -07001450 // KeyEvent
1451
1452 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001453 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1454
Jeff Brown8d608662010-08-30 03:02:23 -07001455 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001456
1457 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001458 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001459
Jeff Brown46b9ac02010-04-22 18:58:52 -07001460 return 0;
1461}
1462
Jeff Brown46b9ac02010-04-22 18:58:52 -07001463} /* namespace android */