blob: 57e1c28e4077e673c744025c68e625c53033f8be [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 Brown46b9ac02010-04-22 18:58:52 -070066 jmethodID notifyLidSwitchChanged;
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,
146 WM_ACTION_POKE_USER_ACTIVITY = 2,
147 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 Brownbc68a592011-07-25 12:58:12 -0700167 void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
168 int32_t externalWidth, int32_t externalHeight);
Jeff Brown93de7462012-05-02 16:29:42 -0700169 void setDisplayOrientation(int32_t displayId, int32_t orientation, int32_t externalOrientation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700170
Jeff Brown7fbdc842010-06-17 20:52:56 -0700171 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800172 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700173 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
174
Jeff Brown9302c872011-07-13 22:51:29 -0700175 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
176 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700177 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800178 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700179 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700180 void setShowTouches(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700181
Jeff Brown9c3cda02010-06-15 01:31:58 -0700182 /* --- InputReaderPolicyInterface implementation --- */
183
Jeff Brown214eaf42011-05-26 19:17:02 -0700184 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800185 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700186 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
Jeff Brown6ec6f792012-04-17 16:52:41 -0700187 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700188 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700189
190 /* --- InputDispatcherPolicyInterface implementation --- */
191
Jeff Browne20c9e02010-10-11 14:20:19 -0700192 virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue,
193 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700195 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800196 const sp<InputWindowHandle>& inputWindowHandle);
197 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700198 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700199 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
200 virtual bool isKeyRepeatEnabled();
Jeff Brown1f245102010-11-18 20:53:46 -0800201 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800202 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700203 virtual nsecs_t interceptKeyBeforeDispatching(
204 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700205 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800206 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800207 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700208 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700209 virtual bool checkInjectEventsPermissionNonReentrant(
210 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700211
Jeff Brown2352b972011-04-12 22:39:53 -0700212 /* --- PointerControllerPolicyInterface implementation --- */
213
214 virtual void loadPointerResources(PointerResources* outResources);
215
Jeff Brown9c3cda02010-06-15 01:31:58 -0700216private:
217 sp<InputManager> mInputManager;
218
Jeff Brown2352b972011-04-12 22:39:53 -0700219 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700220 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800221 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700222
Jeff Brown83c09682010-12-23 17:50:18 -0800223 Mutex mLock;
224 struct Locked {
225 // Display size information.
Jeff Brownbc68a592011-07-25 12:58:12 -0700226 int32_t displayWidth, displayHeight; // -1 when not initialized
Jeff Brown83c09682010-12-23 17:50:18 -0800227 int32_t displayOrientation;
Jeff Brown93de7462012-05-02 16:29:42 -0700228 int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
229 int32_t displayExternalOrientation;
Jeff Brown83c09682010-12-23 17:50:18 -0800230
Jeff Brown05dc66a2011-03-02 14:41:58 -0800231 // System UI visibility.
232 int32_t systemUiVisibility;
233
Jeff Brown1a84fd12011-06-02 01:26:32 -0700234 // Pointer speed.
235 int32_t pointerSpeed;
236
Jeff Brown474dcb52011-06-14 20:22:50 -0700237 // True if pointer gestures are enabled.
238 bool pointerGesturesEnabled;
239
Jeff Browndaf4a122011-08-26 17:14:14 -0700240 // Show touches feature enable/disable.
241 bool showTouches;
242
Jeff Brown5541de92011-04-11 11:54:25 -0700243 // Sprite controller singleton, created on first use.
244 sp<SpriteController> spriteController;
245
Jeff Brown83c09682010-12-23 17:50:18 -0800246 // Pointer controller singleton, created and destroyed as needed.
247 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800248 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700249
Jeff Brown2352b972011-04-12 22:39:53 -0700250 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800251 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700252 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800253
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700254 // Power manager interactions.
Jeff Brown9c3cda02010-06-15 01:31:58 -0700255 bool isScreenOn();
256 bool isScreenBright();
257
Jeff Brownb88102f2010-09-08 11:49:43 -0700258 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700259
Jeff Brown9c3cda02010-06-15 01:31:58 -0700260 static inline JNIEnv* jniEnv() {
261 return AndroidRuntime::getJNIEnv();
262 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700263};
264
Jeff Brown928e0542011-01-10 11:17:36 -0800265
Jeff Brown9c3cda02010-06-15 01:31:58 -0700266
Jeff Brown2352b972011-04-12 22:39:53 -0700267NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700268 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown214eaf42011-05-26 19:17:02 -0700269 mLooper(looper) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700270 JNIEnv* env = jniEnv();
271
Jeff Brown2352b972011-04-12 22:39:53 -0700272 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700273 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700274
Jeff Brown83c09682010-12-23 17:50:18 -0800275 {
276 AutoMutex _l(mLock);
277 mLocked.displayWidth = -1;
278 mLocked.displayHeight = -1;
Jeff Brown93de7462012-05-02 16:29:42 -0700279 mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
Jeff Brownbc68a592011-07-25 12:58:12 -0700280 mLocked.displayExternalWidth = -1;
281 mLocked.displayExternalHeight = -1;
Jeff Brown93de7462012-05-02 16:29:42 -0700282 mLocked.displayExternalOrientation = DISPLAY_ORIENTATION_0;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800283
284 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700285 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700286 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700287 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800288 }
289
Jeff Brown9c3cda02010-06-15 01:31:58 -0700290 sp<EventHub> eventHub = new EventHub();
291 mInputManager = new InputManager(eventHub, this, this);
292}
293
294NativeInputManager::~NativeInputManager() {
295 JNIEnv* env = jniEnv();
296
Jeff Brown2352b972011-04-12 22:39:53 -0700297 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700298 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700299}
300
Jeff Brownb88102f2010-09-08 11:49:43 -0700301void NativeInputManager::dump(String8& dump) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700302 mInputManager->getReader()->dump(dump);
303 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700304
Jeff Brownb88102f2010-09-08 11:49:43 -0700305 mInputManager->getDispatcher()->dump(dump);
306 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700307}
308
Jeff Brown7fbdc842010-06-17 20:52:56 -0700309bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700310 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000311 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700312 LOGE_EX(env);
313 env->ExceptionClear();
314 return true;
315 }
316 return false;
317}
318
Jeff Brownbc68a592011-07-25 12:58:12 -0700319void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height,
320 int32_t externalWidth, int32_t externalHeight) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700321 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700322 if (displayId == 0) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700323 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700324
Jeff Brown65fd2512011-08-18 11:20:58 -0700325 if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
326 changed = true;
327 mLocked.displayWidth = width;
328 mLocked.displayHeight = height;
Jeff Brownbc68a592011-07-25 12:58:12 -0700329
Jeff Brown65fd2512011-08-18 11:20:58 -0700330 sp<PointerController> controller = mLocked.pointerController.promote();
331 if (controller != NULL) {
332 controller->setDisplaySize(width, height);
Jeff Brown2352b972011-04-12 22:39:53 -0700333 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700334 }
Jeff Brown2352b972011-04-12 22:39:53 -0700335
Jeff Brown65fd2512011-08-18 11:20:58 -0700336 if (mLocked.displayExternalWidth != externalWidth
337 || mLocked.displayExternalHeight != externalHeight) {
338 changed = true;
Jeff Brownbc68a592011-07-25 12:58:12 -0700339 mLocked.displayExternalWidth = externalWidth;
340 mLocked.displayExternalHeight = externalHeight;
Jeff Brown65fd2512011-08-18 11:20:58 -0700341 }
342 }
343
344 if (changed) {
345 mInputManager->getReader()->requestRefreshConfiguration(
346 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700347 }
348}
349
Jeff Brown93de7462012-05-02 16:29:42 -0700350void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation,
351 int32_t externalOrientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700352 bool changed = false;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700353 if (displayId == 0) {
Jeff Brown83c09682010-12-23 17:50:18 -0800354 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700355
Jeff Brown83c09682010-12-23 17:50:18 -0800356 if (mLocked.displayOrientation != orientation) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700357 changed = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800358 mLocked.displayOrientation = orientation;
359
360 sp<PointerController> controller = mLocked.pointerController.promote();
361 if (controller != NULL) {
362 controller->setDisplayOrientation(orientation);
363 }
364 }
Jeff Brown93de7462012-05-02 16:29:42 -0700365
366 if (mLocked.displayExternalOrientation != externalOrientation) {
367 changed = true;
368 mLocked.displayExternalOrientation = externalOrientation;
369 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700370 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700371
372 if (changed) {
373 mInputManager->getReader()->requestRefreshConfiguration(
374 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
375 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700376}
377
Jeff Brown7fbdc842010-06-17 20:52:56 -0700378status_t NativeInputManager::registerInputChannel(JNIEnv* env,
Jeff Brown928e0542011-01-10 11:17:36 -0800379 const sp<InputChannel>& inputChannel,
380 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
381 return mInputManager->getDispatcher()->registerInputChannel(
382 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700383}
384
385status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
386 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700387 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700388}
389
Jeff Brown214eaf42011-05-26 19:17:02 -0700390void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700391 JNIEnv* env = jniEnv();
392
Jeff Brown4532e612012-04-05 14:27:12 -0700393 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
394 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700395 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
396 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
397 }
398
399 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700400 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
401 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700402 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
403 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700404 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700405 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700406 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700407 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700408 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700409 env->DeleteLocalRef(item);
410 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700411 env->DeleteLocalRef(excludedDeviceNames);
412 }
413
Jeff Brown4532e612012-04-05 14:27:12 -0700414 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
415 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700416 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700417 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
418 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700419 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700420 jint longPressTimeout = env->CallIntMethod(mServiceObj,
421 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700422 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700423 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700424
425 // We must ensure that the tap-drag interval is significantly shorter than
426 // the long-press timeout because the tap is held down for the entire duration
427 // of the double-tap timeout.
428 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700429 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700430 outConfig->pointerGestureTapDragInterval =
431 milliseconds_to_nanoseconds(tapDragInterval);
432 }
433 }
434 }
435
Jeff Brown4532e612012-04-05 14:27:12 -0700436 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
437 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700438 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
439 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700440 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700441
442 { // acquire lock
443 AutoMutex _l(mLock);
444
445 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
446 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700447 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700448
Jeff Browndaf4a122011-08-26 17:14:14 -0700449 outConfig->showTouches = mLocked.showTouches;
450
Jeff Brown65fd2512011-08-18 11:20:58 -0700451 outConfig->setDisplayInfo(0, false /*external*/,
452 mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
453 outConfig->setDisplayInfo(0, true /*external*/,
454 mLocked.displayExternalWidth, mLocked.displayExternalHeight,
Jeff Brown93de7462012-05-02 16:29:42 -0700455 mLocked.displayExternalOrientation);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700456 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700457}
458
Jeff Brown83c09682010-12-23 17:50:18 -0800459sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
460 AutoMutex _l(mLock);
461
462 sp<PointerController> controller = mLocked.pointerController.promote();
463 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700464 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800465
Jeff Brown2352b972011-04-12 22:39:53 -0700466 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800467 mLocked.pointerController = controller;
468
469 controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight);
470 controller->setDisplayOrientation(mLocked.displayOrientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800471
Jeff Brown5541de92011-04-11 11:54:25 -0700472 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700473 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
474 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700475 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
476 PointerIcon pointerIcon;
477 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
478 mContextObj, &pointerIcon);
479 if (!status && !pointerIcon.isNullIcon()) {
480 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
481 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
482 } else {
483 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800484 }
Jeff Brown2352b972011-04-12 22:39:53 -0700485 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800486 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800487
Jeff Brown2352b972011-04-12 22:39:53 -0700488 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800489 }
490 return controller;
491}
492
Jeff Brown5541de92011-04-11 11:54:25 -0700493void NativeInputManager::ensureSpriteControllerLocked() {
494 if (mLocked.spriteController == NULL) {
495 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700496 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700497 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
498 layer = -1;
499 }
500 mLocked.spriteController = new SpriteController(mLooper, layer);
501 }
502}
503
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700504void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
505 JNIEnv* env = jniEnv();
506
507 size_t count = inputDevices.size();
508 jobjectArray inputDevicesObjArray = env->NewObjectArray(
509 count, gInputDeviceClassInfo.clazz, NULL);
510 if (inputDevicesObjArray) {
511 bool error = false;
512 for (size_t i = 0; i < count; i++) {
513 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
514 if (!inputDeviceObj) {
515 error = true;
516 break;
517 }
518
519 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
520 env->DeleteLocalRef(inputDeviceObj);
521 }
522
523 if (!error) {
524 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
525 inputDevicesObjArray);
526 }
527
528 env->DeleteLocalRef(inputDevicesObjArray);
529 }
530
531 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
532}
533
Jeff Brown6ec6f792012-04-17 16:52:41 -0700534sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
535 const String8& inputDeviceDescriptor) {
536 JNIEnv* env = jniEnv();
537
538 sp<KeyCharacterMap> result;
539 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
540 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
541 gServiceClassInfo.getKeyboardLayoutOverlay, descriptorObj.get())));
542 if (arrayObj.get()) {
543 ScopedLocalRef<jstring> filenameObj(env,
544 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
545 ScopedLocalRef<jstring> contentsObj(env,
546 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
547 ScopedUtfChars filenameChars(env, filenameObj.get());
548 ScopedUtfChars contentsChars(env, contentsObj.get());
549
550 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
551 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
552 }
553 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
554 return result;
555}
556
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700557String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
558 JNIEnv* env = jniEnv();
559
560 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
561 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
562 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
563 String8 result;
564 if (aliasObj.get()) {
565 ScopedUtfChars aliasChars(env, aliasObj.get());
566 result.setTo(aliasChars.c_str());
567 }
568 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
569 return result;
570}
571
Jeff Browne20c9e02010-10-11 14:20:19 -0700572void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode,
573 int32_t switchValue, uint32_t policyFlags) {
574#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000575 ALOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x",
Jeff Browne20c9e02010-10-11 14:20:19 -0700576 when, switchCode, switchValue, policyFlags);
577#endif
578
579 JNIEnv* env = jniEnv();
580
581 switch (switchCode) {
582 case SW_LID:
Jeff Brown27fd3422012-04-09 11:05:16 -0700583 // When switch value is set indicates lid is closed.
Jeff Brown4532e612012-04-05 14:27:12 -0700584 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyLidSwitchChanged,
Jeff Brown27fd3422012-04-09 11:05:16 -0700585 when, switchValue == 0 /*lidOpen*/);
Jeff Browne20c9e02010-10-11 14:20:19 -0700586 checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged");
587 break;
588 }
589}
590
Jeff Brown9c3cda02010-06-15 01:31:58 -0700591void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
592#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000593 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700594#endif
595
596 JNIEnv* env = jniEnv();
597
Jeff Brown4532e612012-04-05 14:27:12 -0700598 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700599 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700600}
601
Jeff Brown519e0242010-09-15 15:18:56 -0700602nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brown928e0542011-01-10 11:17:36 -0800603 const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700604#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000605 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700606#endif
607
608 JNIEnv* env = jniEnv();
609
Jeff Brown928e0542011-01-10 11:17:36 -0800610 jobject inputApplicationHandleObj =
611 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
612 jobject inputWindowHandleObj =
613 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownb88102f2010-09-08 11:49:43 -0700614
Jeff Brown4532e612012-04-05 14:27:12 -0700615 jlong newTimeout = env->CallLongMethod(mServiceObj,
616 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700617 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
618 newTimeout = 0; // abort dispatch
619 } else {
620 assert(newTimeout >= 0);
621 }
622
Jeff Brown928e0542011-01-10 11:17:36 -0800623 env->DeleteLocalRef(inputWindowHandleObj);
624 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700625 return newTimeout;
626}
627
Jeff Brown928e0542011-01-10 11:17:36 -0800628void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700629#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000630 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700631#endif
632
Jeff Brown7fbdc842010-06-17 20:52:56 -0700633 JNIEnv* env = jniEnv();
634
Jeff Brown928e0542011-01-10 11:17:36 -0800635 jobject inputWindowHandleObj =
636 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
637 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700638 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800639 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700640 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
641
Jeff Brown928e0542011-01-10 11:17:36 -0800642 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700643 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700644}
645
Jeff Brown214eaf42011-05-26 19:17:02 -0700646void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
647 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800648
Jeff Brown4532e612012-04-05 14:27:12 -0700649 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
650 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700651 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
652 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
653 }
Jeff Browna4547672011-03-02 21:38:11 -0800654
Jeff Brown4532e612012-04-05 14:27:12 -0700655 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
656 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700657 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
658 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
659 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700660}
661
Jeff Brown214eaf42011-05-26 19:17:02 -0700662bool NativeInputManager::isKeyRepeatEnabled() {
663 // Only enable automatic key repeating when the screen is on.
664 return isScreenOn();
Jeff Brownae9fc032010-08-18 15:51:08 -0700665}
666
Jeff Brown9302c872011-07-13 22:51:29 -0700667void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
668 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700669
Jeff Brown9302c872011-07-13 22:51:29 -0700670 if (windowHandleObjArray) {
671 jsize length = env->GetArrayLength(windowHandleObjArray);
672 for (jsize i = 0; i < length; i++) {
673 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
674 if (! windowHandleObj) {
675 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700676 }
Jeff Brown9302c872011-07-13 22:51:29 -0700677
678 sp<InputWindowHandle> windowHandle =
679 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
680 if (windowHandle != NULL) {
681 windowHandles.push(windowHandle);
682 }
683 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700684 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700685 }
Jeff Brown349703e2010-06-22 01:27:15 -0700686
Jeff Brown9302c872011-07-13 22:51:29 -0700687 mInputManager->getDispatcher()->setInputWindows(windowHandles);
688
689 // Do this after the dispatcher has updated the window handle state.
690 bool newPointerGesturesEnabled = true;
691 size_t numWindows = windowHandles.size();
692 for (size_t i = 0; i < numWindows; i++) {
693 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700694 const InputWindowInfo* windowInfo = windowHandle->getInfo();
695 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
696 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700697 newPointerGesturesEnabled = false;
698 }
699 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700700
701 uint32_t changes = 0;
702 { // acquire lock
703 AutoMutex _l(mLock);
704
705 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
706 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
707 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
708 }
709 } // release lock
710
711 if (changes) {
712 mInputManager->getReader()->requestRefreshConfiguration(changes);
713 }
Jeff Brown349703e2010-06-22 01:27:15 -0700714}
715
Jeff Brown9302c872011-07-13 22:51:29 -0700716void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
717 sp<InputApplicationHandle> applicationHandle =
718 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
719 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700720}
721
722void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700723 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700724}
725
Jeff Brown05dc66a2011-03-02 14:41:58 -0800726void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
727 AutoMutex _l(mLock);
728
729 if (mLocked.systemUiVisibility != visibility) {
730 mLocked.systemUiVisibility = visibility;
731
732 sp<PointerController> controller = mLocked.pointerController.promote();
733 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700734 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800735 }
736 }
737}
738
Jeff Brown2352b972011-04-12 22:39:53 -0700739void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800740 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700741 controller->setInactivityTimeout(lightsOut
742 ? PointerController::INACTIVITY_TIMEOUT_SHORT
743 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800744}
745
Jeff Brown1a84fd12011-06-02 01:26:32 -0700746void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700747 { // acquire lock
748 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700749
Jeff Brown474dcb52011-06-14 20:22:50 -0700750 if (mLocked.pointerSpeed == speed) {
751 return;
752 }
753
Steve Block6215d3f2012-01-04 20:05:49 +0000754 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700755 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700756 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700757
Jeff Brown474dcb52011-06-14 20:22:50 -0700758 mInputManager->getReader()->requestRefreshConfiguration(
759 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700760}
761
Jeff Browndaf4a122011-08-26 17:14:14 -0700762void NativeInputManager::setShowTouches(bool enabled) {
763 { // acquire lock
764 AutoMutex _l(mLock);
765
766 if (mLocked.showTouches == enabled) {
767 return;
768 }
769
Steve Block6215d3f2012-01-04 20:05:49 +0000770 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700771 mLocked.showTouches = enabled;
772 } // release lock
773
774 mInputManager->getReader()->requestRefreshConfiguration(
775 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
776}
777
Jeff Browne20c9e02010-10-11 14:20:19 -0700778bool NativeInputManager::isScreenOn() {
779 return android_server_PowerManagerService_isScreenOn();
780}
781
782bool NativeInputManager::isScreenBright() {
783 return android_server_PowerManagerService_isScreenBright();
784}
785
Jeff Brown0029c662011-03-30 02:25:18 -0700786bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
787 jobject inputEventObj;
788
789 JNIEnv* env = jniEnv();
790 switch (inputEvent->getType()) {
791 case AINPUT_EVENT_TYPE_KEY:
792 inputEventObj = android_view_KeyEvent_fromNative(env,
793 static_cast<const KeyEvent*>(inputEvent));
794 break;
795 case AINPUT_EVENT_TYPE_MOTION:
796 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
797 static_cast<const MotionEvent*>(inputEvent));
798 break;
799 default:
800 return true; // dispatch the event normally
801 }
802
803 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000804 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700805 return true; // dispatch the event normally
806 }
807
808 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700809 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700810 inputEventObj, policyFlags);
811 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
812 pass = true;
813 }
814 env->DeleteLocalRef(inputEventObj);
815 return pass;
816}
817
Jeff Brown1f245102010-11-18 20:53:46 -0800818void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
819 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700820 // Policy:
821 // - Ignore untrusted events and pass them along.
822 // - Ask the window manager what to do with normal events and trusted injected events.
823 // - For normal events wake and brighten the screen if currently off or dim.
824 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800825 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700826 bool isScreenOn = this->isScreenOn();
827 bool isScreenBright = this->isScreenBright();
Jeff Browne20c9e02010-10-11 14:20:19 -0700828
Jeff Brown3122e442010-10-11 23:32:49 -0700829 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800830 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
831 jint wmActions;
832 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700833 wmActions = env->CallIntMethod(mServiceObj,
834 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown1f245102010-11-18 20:53:46 -0800835 keyEventObj, policyFlags, isScreenOn);
836 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
837 wmActions = 0;
838 }
839 android_view_KeyEvent_recycle(env, keyEventObj);
840 env->DeleteLocalRef(keyEventObj);
841 } else {
Steve Block3762c312012-01-06 19:20:56 +0000842 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700843 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700844 }
845
Jeff Brown1f245102010-11-18 20:53:46 -0800846 if (!(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown3122e442010-10-11 23:32:49 -0700847 if (!isScreenOn) {
848 policyFlags |= POLICY_FLAG_WOKE_HERE;
Jeff Brown3122e442010-10-11 23:32:49 -0700849 }
850
851 if (!isScreenBright) {
852 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
853 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700854 }
855
Jeff Brown56194eb2011-03-02 19:23:13 -0800856 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700857 } else {
Jeff Browne20c9e02010-10-11 14:20:19 -0700858 policyFlags |= POLICY_FLAG_PASS_TO_USER;
859 }
860}
861
Jeff Brown56194eb2011-03-02 19:23:13 -0800862void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700863 // Policy:
864 // - Ignore untrusted events and pass them along.
865 // - No special filtering for injected events required at this time.
866 // - Filter normal events based on screen state.
867 // - For normal events brighten (but do not wake) the screen if currently dim.
868 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
869 if (isScreenOn()) {
870 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700871
Jeff Brown3122e442010-10-11 23:32:49 -0700872 if (!isScreenBright()) {
873 policyFlags |= POLICY_FLAG_BRIGHT_HERE;
874 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800875 } else {
876 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700877 jint wmActions = env->CallIntMethod(mServiceObj,
878 gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Jeff Brown56194eb2011-03-02 19:23:13 -0800879 policyFlags);
880 if (checkAndClearExceptionFromCallback(env,
881 "interceptMotionBeforeQueueingWhenScreenOff")) {
882 wmActions = 0;
883 }
884
885 policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
886 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700887 }
Jeff Brown3122e442010-10-11 23:32:49 -0700888 } else {
889 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Jeff Browne20c9e02010-10-11 14:20:19 -0700890 }
891}
892
Jeff Brown56194eb2011-03-02 19:23:13 -0800893void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
894 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800895 if (wmActions & WM_ACTION_GO_TO_SLEEP) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800896#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000897 ALOGD("handleInterceptActions: Going to sleep.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800898#endif
899 android_server_PowerManagerService_goToSleep(when);
900 }
901
902 if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
Jeff Brown9267beb2011-03-07 20:11:22 -0800903#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000904 ALOGD("handleInterceptActions: Poking user activity.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800905#endif
906 android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
907 }
908
909 if (wmActions & WM_ACTION_PASS_TO_USER) {
910 policyFlags |= POLICY_FLAG_PASS_TO_USER;
911 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800912#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000913 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800914#endif
915 }
916}
917
Jeff Brown905805a2011-10-12 13:57:59 -0700918nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800919 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700920 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700921 // Policy:
922 // - Ignore untrusted events and pass them along.
923 // - Filter normal events and trusted injected events through the window manager policy to
924 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700925 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700926 if (policyFlags & POLICY_FLAG_TRUSTED) {
927 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700928
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 jlong delayMillis = env->CallLongMethod(mServiceObj,
934 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800935 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800936 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
937 android_view_KeyEvent_recycle(env, keyEventObj);
938 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700939 if (!error) {
940 if (delayMillis < 0) {
941 result = -1;
942 } else if (delayMillis > 0) {
943 result = milliseconds_to_nanoseconds(delayMillis);
944 }
945 }
Jeff Brown1f245102010-11-18 20:53:46 -0800946 } else {
Steve Block3762c312012-01-06 19:20:56 +0000947 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800948 }
Jeff Brown928e0542011-01-10 11:17:36 -0800949 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700950 }
Jeff Brown1f245102010-11-18 20:53:46 -0800951 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700952}
953
Jeff Brown928e0542011-01-10 11:17:36 -0800954bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800955 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700956 // Policy:
957 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800958 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700959 if (policyFlags & POLICY_FLAG_TRUSTED) {
960 JNIEnv* env = jniEnv();
961
Jeff Brown928e0542011-01-10 11:17:36 -0800962 // Note: inputWindowHandle may be null.
963 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800964 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
965 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700966 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
967 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800968 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700969 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
970 fallbackKeyEventObj = NULL;
971 }
Jeff Brown1f245102010-11-18 20:53:46 -0800972 android_view_KeyEvent_recycle(env, keyEventObj);
973 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -0800974
975 if (fallbackKeyEventObj) {
976 // Note: outFallbackKeyEvent may be the same object as keyEvent.
977 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
978 outFallbackKeyEvent)) {
979 result = true;
980 }
981 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
982 env->DeleteLocalRef(fallbackKeyEventObj);
983 }
Jeff Brown1f245102010-11-18 20:53:46 -0800984 } else {
Steve Block3762c312012-01-06 19:20:56 +0000985 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -0800986 }
Jeff Brown928e0542011-01-10 11:17:36 -0800987 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -0700988 }
Jeff Brown1f245102010-11-18 20:53:46 -0800989 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -0700990}
991
Jeff Brown01ce2e92010-09-26 22:20:12 -0700992void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
993 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -0700994}
995
Jeff Brown349703e2010-06-22 01:27:15 -0700996
Jeff Brownb88102f2010-09-08 11:49:43 -0700997bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
998 int32_t injectorPid, int32_t injectorUid) {
999 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -07001000 jboolean result = env->CallBooleanMethod(mServiceObj,
1001 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001002 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
1003 result = false;
1004 }
Jeff Brown349703e2010-06-22 01:27:15 -07001005 return result;
1006}
1007
Jeff Brown2352b972011-04-12 22:39:53 -07001008void NativeInputManager::loadPointerResources(PointerResources* outResources) {
1009 JNIEnv* env = jniEnv();
1010
1011 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
1012 &outResources->spotHover);
1013 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
1014 &outResources->spotTouch);
1015 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
1016 &outResources->spotAnchor);
1017}
1018
Jeff Brown83c09682010-12-23 17:50:18 -08001019
Jeff Brown9c3cda02010-06-15 01:31:58 -07001020// ----------------------------------------------------------------------------
1021
Jeff Brown4532e612012-04-05 14:27:12 -07001022static jint nativeInit(JNIEnv* env, jclass clazz,
1023 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -07001024 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
1025 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
1026 messageQueue->getLooper());
Jeff Brown4532e612012-04-05 14:27:12 -07001027 im->incStrong(serviceObj);
1028 return reinterpret_cast<jint>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001029}
1030
Jeff Brown4532e612012-04-05 14:27:12 -07001031static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
1032 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001033
Jeff Brown4532e612012-04-05 14:27:12 -07001034 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001035 if (result) {
1036 jniThrowRuntimeException(env, "Input manager could not be started.");
1037 }
1038}
1039
Jeff Brown4532e612012-04-05 14:27:12 -07001040static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, jint ptr,
Jeff Brownbc68a592011-07-25 12:58:12 -07001041 jint displayId, jint width, jint height, jint externalWidth, jint externalHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001042 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001043
1044 // XXX we could get this from the SurfaceFlinger directly instead of requiring it
1045 // to be passed in like this, not sure which is better but leaving it like this
1046 // keeps the window manager in direct control of when display transitions propagate down
1047 // to the input dispatcher
Jeff Brown4532e612012-04-05 14:27:12 -07001048 im->setDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001049}
1050
Jeff Brown4532e612012-04-05 14:27:12 -07001051static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
Jeff Brown93de7462012-05-02 16:29:42 -07001052 jint ptr, jint displayId, jint orientation, jint externalOrientation) {
Jeff Brown4532e612012-04-05 14:27:12 -07001053 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001054
Jeff Brown93de7462012-05-02 16:29:42 -07001055 im->setDisplayOrientation(displayId, orientation, externalOrientation);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001056}
1057
Jeff Brown4532e612012-04-05 14:27:12 -07001058static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
1059 jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
1060 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001061
Jeff Brown4532e612012-04-05 14:27:12 -07001062 return im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001063 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001064}
1065
Jeff Brown4532e612012-04-05 14:27:12 -07001066static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
1067 jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
1068 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001069
Jeff Brown4532e612012-04-05 14:27:12 -07001070 return im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001071 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001072}
1073
Jeff Brown4532e612012-04-05 14:27:12 -07001074static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
1075 jint ptr, jint deviceId, jint sourceMask, jint sw) {
1076 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001077
Jeff Brown4532e612012-04-05 14:27:12 -07001078 return im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001079 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001080}
1081
Jeff Brown4532e612012-04-05 14:27:12 -07001082static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
1083 jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
1084 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001085
1086 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1087 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1088 jsize numCodes = env->GetArrayLength(keyCodes);
1089 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001090 if (numCodes == env->GetArrayLength(keyCodes)) {
Jeff Brown4532e612012-04-05 14:27:12 -07001091 result = im->getInputManager()->getReader()->hasKeys(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001092 deviceId, uint32_t(sourceMask), numCodes, codes, flags);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001093 } else {
1094 result = JNI_FALSE;
1095 }
1096
1097 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1098 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1099 return result;
1100}
1101
1102static void throwInputChannelNotInitialized(JNIEnv* env) {
1103 jniThrowException(env, "java/lang/IllegalStateException",
1104 "inputChannel is not initialized");
1105}
1106
Jeff Brown4532e612012-04-05 14:27:12 -07001107static void handleInputChannelDisposed(JNIEnv* env,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001108 jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001109 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1110
Steve Block8564c8d2012-01-05 23:22:43 +00001111 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001112 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001113 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001114}
1115
Jeff Brown4532e612012-04-05 14:27:12 -07001116static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
1117 jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
1118 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001119
1120 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1121 inputChannelObj);
1122 if (inputChannel == NULL) {
1123 throwInputChannelNotInitialized(env);
1124 return;
1125 }
1126
Jeff Brown928e0542011-01-10 11:17:36 -08001127 sp<InputWindowHandle> inputWindowHandle =
1128 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001129
Jeff Brown4532e612012-04-05 14:27:12 -07001130 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001131 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001132 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001133 String8 message;
1134 message.appendFormat("Failed to register input channel. status=%d", status);
1135 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001136 return;
1137 }
1138
Jeff Browna41ca772010-08-11 14:46:32 -07001139 if (! monitor) {
1140 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001141 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001142 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001143}
1144
Jeff Brown4532e612012-04-05 14:27:12 -07001145static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
1146 jint ptr, jobject inputChannelObj) {
1147 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001148
1149 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1150 inputChannelObj);
1151 if (inputChannel == NULL) {
1152 throwInputChannelNotInitialized(env);
1153 return;
1154 }
1155
1156 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1157
Jeff Brown4532e612012-04-05 14:27:12 -07001158 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001159 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1160 String8 message;
1161 message.appendFormat("Failed to unregister input channel. status=%d", status);
1162 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001163 }
1164}
1165
Jeff Brown4532e612012-04-05 14:27:12 -07001166static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
1167 jint ptr, jboolean enabled) {
1168 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001169
Jeff Brown4532e612012-04-05 14:27:12 -07001170 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001171}
1172
Jeff Brown4532e612012-04-05 14:27:12 -07001173static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
1174 jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001175 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001176 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001177
Jeff Brown6ec402b2010-07-28 15:48:59 -07001178 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1179 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001180 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1181 if (status) {
1182 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1183 return INPUT_EVENT_INJECTION_FAILED;
1184 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001185
Jeff Brown4532e612012-04-05 14:27:12 -07001186 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001187 & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1188 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001189 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001190 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1191 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001192 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1193 return INPUT_EVENT_INJECTION_FAILED;
1194 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001195
Jeff Brown4532e612012-04-05 14:27:12 -07001196 return im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brown0029c662011-03-30 02:25:18 -07001197 motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
1198 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001199 } else {
1200 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001201 return INPUT_EVENT_INJECTION_FAILED;
1202 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001203}
1204
Jeff Brown4532e612012-04-05 14:27:12 -07001205static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
1206 jint ptr, jobjectArray windowHandleObjArray) {
1207 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001208
Jeff Brown4532e612012-04-05 14:27:12 -07001209 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001210}
1211
Jeff Brown4532e612012-04-05 14:27:12 -07001212static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
1213 jint ptr, jobject applicationHandleObj) {
1214 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001215
Jeff Brown4532e612012-04-05 14:27:12 -07001216 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001217}
1218
Jeff Brown4532e612012-04-05 14:27:12 -07001219static void nativeSetInputDispatchMode(JNIEnv* env,
1220 jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
1221 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001222
Jeff Brown4532e612012-04-05 14:27:12 -07001223 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001224}
1225
Jeff Brown4532e612012-04-05 14:27:12 -07001226static void nativeSetSystemUiVisibility(JNIEnv* env,
1227 jclass clazz, jint ptr, jint visibility) {
1228 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001229
Jeff Brown4532e612012-04-05 14:27:12 -07001230 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001231}
1232
Jeff Brown4532e612012-04-05 14:27:12 -07001233static jboolean nativeTransferTouchFocus(JNIEnv* env,
1234 jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
1235 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001236
1237 sp<InputChannel> fromChannel =
1238 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1239 sp<InputChannel> toChannel =
1240 android_view_InputChannel_getInputChannel(env, toChannelObj);
1241
1242 if (fromChannel == NULL || toChannel == NULL) {
1243 return false;
1244 }
1245
Jeff Brown4532e612012-04-05 14:27:12 -07001246 return im->getInputManager()->getDispatcher()->
Jeff Browne6504122010-09-27 14:52:15 -07001247 transferTouchFocus(fromChannel, toChannel);
1248}
1249
Jeff Brown4532e612012-04-05 14:27:12 -07001250static void nativeSetPointerSpeed(JNIEnv* env,
1251 jclass clazz, jint ptr, jint speed) {
1252 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001253
Jeff Brown4532e612012-04-05 14:27:12 -07001254 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001255}
1256
Jeff Brown4532e612012-04-05 14:27:12 -07001257static void nativeSetShowTouches(JNIEnv* env,
1258 jclass clazz, jint ptr, jboolean enabled) {
1259 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001260
Jeff Brown4532e612012-04-05 14:27:12 -07001261 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001262}
1263
Jeff Browna47425a2012-04-13 04:09:27 -07001264static void nativeVibrate(JNIEnv* env,
1265 jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
1266 jint repeat, jint token) {
1267 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1268
1269 size_t patternSize = env->GetArrayLength(patternObj);
1270 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
1271 ALOGI("Skipped requested vibration because the pattern size is %d "
1272 "which is more than the maximum supported size of %d.",
1273 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1274 return; // limit to reasonable size
1275 }
1276
1277 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1278 patternObj, NULL));
1279 nsecs_t pattern[patternSize];
1280 for (size_t i = 0; i < patternSize; i++) {
1281 pattern[i] = max(jlong(0), min(patternMillis[i],
1282 MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
1283 }
1284 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1285
1286 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1287}
1288
1289static void nativeCancelVibrate(JNIEnv* env,
1290 jclass clazz, jint ptr, jint deviceId, jint token) {
1291 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1292
1293 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1294}
1295
Jeff Brown6ec6f792012-04-17 16:52:41 -07001296static void nativeReloadKeyboardLayouts(JNIEnv* env,
1297 jclass clazz, jint ptr) {
1298 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1299
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001300 im->getInputManager()->getReader()->requestRefreshConfiguration(
1301 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1302}
1303
1304static void nativeReloadDeviceAliases(JNIEnv* env,
1305 jclass clazz, jint ptr) {
1306 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1307
1308 im->getInputManager()->getReader()->requestRefreshConfiguration(
1309 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001310}
1311
Jeff Brown4532e612012-04-05 14:27:12 -07001312static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
1313 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001314
Jeff Brownb88102f2010-09-08 11:49:43 -07001315 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001316 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001317 return env->NewStringUTF(dump.string());
1318}
1319
Jeff Brown4532e612012-04-05 14:27:12 -07001320static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
1321 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001322
Jeff Brown4532e612012-04-05 14:27:12 -07001323 im->getInputManager()->getReader()->monitor();
1324 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001325}
1326
Jeff Brown9c3cda02010-06-15 01:31:58 -07001327// ----------------------------------------------------------------------------
1328
Jeff Brown46b9ac02010-04-22 18:58:52 -07001329static JNINativeMethod gInputManagerMethods[] = {
1330 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001331 { "nativeInit",
1332 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
1333 (void*) nativeInit },
1334 { "nativeStart", "(I)V",
1335 (void*) nativeStart },
1336 { "nativeSetDisplaySize", "(IIIIII)V",
1337 (void*) nativeSetDisplaySize },
Jeff Brown93de7462012-05-02 16:29:42 -07001338 { "nativeSetDisplayOrientation", "(IIII)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001339 (void*) nativeSetDisplayOrientation },
1340 { "nativeGetScanCodeState", "(IIII)I",
1341 (void*) nativeGetScanCodeState },
1342 { "nativeGetKeyCodeState", "(IIII)I",
1343 (void*) nativeGetKeyCodeState },
1344 { "nativeGetSwitchState", "(IIII)I",
1345 (void*) nativeGetSwitchState },
1346 { "nativeHasKeys", "(III[I[Z)Z",
1347 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001348 { "nativeRegisterInputChannel",
Jeff Brown4532e612012-04-05 14:27:12 -07001349 "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
1350 (void*) nativeRegisterInputChannel },
1351 { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
1352 (void*) nativeUnregisterInputChannel },
1353 { "nativeSetInputFilterEnabled", "(IZ)V",
1354 (void*) nativeSetInputFilterEnabled },
1355 { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
1356 (void*) nativeInjectInputEvent },
1357 { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
1358 (void*) nativeSetInputWindows },
1359 { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
1360 (void*) nativeSetFocusedApplication },
1361 { "nativeSetInputDispatchMode", "(IZZ)V",
1362 (void*) nativeSetInputDispatchMode },
1363 { "nativeSetSystemUiVisibility", "(II)V",
1364 (void*) nativeSetSystemUiVisibility },
Jeff Brown4532e612012-04-05 14:27:12 -07001365 { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
1366 (void*) nativeTransferTouchFocus },
1367 { "nativeSetPointerSpeed", "(II)V",
1368 (void*) nativeSetPointerSpeed },
1369 { "nativeSetShowTouches", "(IZ)V",
1370 (void*) nativeSetShowTouches },
Jeff Browna47425a2012-04-13 04:09:27 -07001371 { "nativeVibrate", "(II[JII)V",
1372 (void*) nativeVibrate },
1373 { "nativeCancelVibrate", "(III)V",
1374 (void*) nativeCancelVibrate },
Jeff Brown6ec6f792012-04-17 16:52:41 -07001375 { "nativeReloadKeyboardLayouts", "(I)V",
1376 (void*) nativeReloadKeyboardLayouts },
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001377 { "nativeReloadDeviceAliases", "(I)V",
1378 (void*) nativeReloadDeviceAliases },
Jeff Brown4532e612012-04-05 14:27:12 -07001379 { "nativeDump", "(I)Ljava/lang/String;",
1380 (void*) nativeDump },
1381 { "nativeMonitor", "(I)V",
1382 (void*) nativeMonitor },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001383};
1384
1385#define FIND_CLASS(var, className) \
1386 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001387 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001388
1389#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1390 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1391 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1392
1393#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1394 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1395 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1396
1397int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001398 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001399 gInputManagerMethods, NELEM(gInputManagerMethods));
1400 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1401
Jeff Brown9c3cda02010-06-15 01:31:58 -07001402 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001403
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001404 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001405 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001406
Jeff Brown4532e612012-04-05 14:27:12 -07001407 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001408 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001409
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001410 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1411 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1412
Jeff Brown4532e612012-04-05 14:27:12 -07001413 GET_METHOD_ID(gServiceClassInfo.notifyLidSwitchChanged, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001414 "notifyLidSwitchChanged", "(JZ)V");
1415
Jeff Brown4532e612012-04-05 14:27:12 -07001416 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1417 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001418
Jeff Brown4532e612012-04-05 14:27:12 -07001419 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001420 "notifyANR",
Jeff Brown4532e612012-04-05 14:27:12 -07001421 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001422
Jeff Brown4532e612012-04-05 14:27:12 -07001423 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001424 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1425
Jeff Brown4532e612012-04-05 14:27:12 -07001426 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001427 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001428
Jeff Brown4532e612012-04-05 14:27:12 -07001429 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001430 clazz,
Jeff Brown56194eb2011-03-02 19:23:13 -08001431 "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
1432
Jeff Brown4532e612012-04-05 14:27:12 -07001433 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001434 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001435 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001436
Jeff Brown4532e612012-04-05 14:27:12 -07001437 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001438 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001439 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001440
Jeff Brown4532e612012-04-05 14:27:12 -07001441 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001442 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001443
Jeff Brown4532e612012-04-05 14:27:12 -07001444 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001445 "getVirtualKeyQuietTimeMillis", "()I");
1446
Jeff Brown4532e612012-04-05 14:27:12 -07001447 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001448 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1449
Jeff Brown4532e612012-04-05 14:27:12 -07001450 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001451 "getKeyRepeatTimeout", "()I");
1452
Jeff Brown4532e612012-04-05 14:27:12 -07001453 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001454 "getKeyRepeatDelay", "()I");
1455
Jeff Brown4532e612012-04-05 14:27:12 -07001456 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001457 "getHoverTapTimeout", "()I");
1458
Jeff Brown4532e612012-04-05 14:27:12 -07001459 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001460 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001461
Jeff Brown4532e612012-04-05 14:27:12 -07001462 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001463 "getDoubleTapTimeout", "()I");
1464
Jeff Brown4532e612012-04-05 14:27:12 -07001465 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001466 "getLongPressTimeout", "()I");
1467
Jeff Brown4532e612012-04-05 14:27:12 -07001468 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001469 "getPointerLayer", "()I");
1470
Jeff Brown4532e612012-04-05 14:27:12 -07001471 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001472 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001473
Jeff Brown6ec6f792012-04-17 16:52:41 -07001474 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
1475 "getKeyboardLayoutOverlay", "(Ljava/lang/String;)[Ljava/lang/String;");
1476
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001477 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1478 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1479
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001480 // InputDevice
1481
1482 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1483 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1484
Jeff Brown6ec402b2010-07-28 15:48:59 -07001485 // KeyEvent
1486
1487 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001488 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1489
Jeff Brown8d608662010-08-30 03:02:23 -07001490 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001491
1492 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001493 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001494
Jeff Brown46b9ac02010-04-22 18:58:52 -07001495 return 0;
1496}
1497
Jeff Brown46b9ac02010-04-22 18:58:52 -07001498} /* namespace android */