blob: 1b0d2087e223d46ca524b1765dcd2cff91bb0faa [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"
Michael Wrighta4051212015-07-23 17:04:40 +010030#include <atomic>
31#include <cinttypes>
Jeff Brown349703e2010-06-22 01:27:15 -070032#include <limits.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070033#include <android_runtime/AndroidRuntime.h>
Ruben Brunk87eac992013-09-09 17:44:59 -070034#include <android_runtime/Log.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080035
Jeff Brown46b9ac02010-04-22 18:58:52 -070036#include <utils/Log.h>
Jeff Brown05dc66a2011-03-02 14:41:58 -080037#include <utils/Looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070038#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080039
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040#include <input/PointerController.h>
Jeff Brown5541de92011-04-11 11:54:25 -070041#include <input/SpriteController.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080042
Michael Wrightd6b473712014-02-10 15:56:36 -080043#include <inputflinger/InputManager.h>
44
Jeff Brown05dc66a2011-03-02 14:41:58 -080045#include <android_os_MessageQueue.h>
Jeff Brown9f25b7f2012-04-10 14:30:49 -070046#include <android_view_InputDevice.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080047#include <android_view_KeyEvent.h>
48#include <android_view_MotionEvent.h>
49#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070050#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080051#include <android/graphics/GraphicsJNI.h>
52
Jeff Brown6ec6f792012-04-17 16:52:41 -070053#include <ScopedLocalRef.h>
Jason Gerecke857aa7b2014-01-27 18:34:20 -080054#include <ScopedPrimitiveArray.h>
Jeff Brown6ec6f792012-04-17 16:52:41 -070055#include <ScopedUtfChars.h>
56
Jeff Brown4f8ecd82012-06-18 18:29:13 -070057#include "com_android_server_power_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070058#include "com_android_server_input_InputApplicationHandle.h"
59#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070060
Michael Wrighta4051212015-07-23 17:04:40 +010061#define INDENT " "
62
Jeff Brown46b9ac02010-04-22 18:58:52 -070063namespace android {
64
Jeff Brown1a84fd12011-06-02 01:26:32 -070065// The exponent used to calculate the pointer speed scaling factor.
66// The scaling factor is calculated as 2 ^ (speed * exponent),
67// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070068static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070069
Jeff Brown46b9ac02010-04-22 18:58:52 -070070static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070071 jmethodID notifyConfigurationChanged;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070072 jmethodID notifyInputDevicesChanged;
Jeff Brown53384282012-08-20 20:16:01 -070073 jmethodID notifySwitch;
Jeff Brown7fbdc842010-06-17 20:52:56 -070074 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070075 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070076 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070077 jmethodID interceptKeyBeforeQueueing;
Michael Wright70af00a2014-09-03 19:30:20 -070078 jmethodID interceptMotionBeforeQueueingNonInteractive;
Jeff Brown349703e2010-06-22 01:27:15 -070079 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070080 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070081 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080082 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070083 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080084 jmethodID getKeyRepeatTimeout;
85 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070086 jmethodID getHoverTapTimeout;
87 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070088 jmethodID getDoubleTapTimeout;
89 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080090 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080091 jmethodID getPointerIcon;
Jeff Brown6ec6f792012-04-17 16:52:41 -070092 jmethodID getKeyboardLayoutOverlay;
Jeff Brown5bbd4b42012-04-20 19:28:00 -070093 jmethodID getDeviceAlias;
Jason Gerecke857aa7b2014-01-27 18:34:20 -080094 jmethodID getTouchCalibrationForInputDevice;
Jeff Brown4532e612012-04-05 14:27:12 -070095} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070096
97static struct {
98 jclass clazz;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070099} gInputDeviceClassInfo;
100
101static struct {
102 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700103} gKeyEventClassInfo;
104
105static struct {
106 jclass clazz;
107} gMotionEventClassInfo;
108
RoboErikfb290df2013-12-16 11:27:55 -0800109static struct {
110 jclass clazz;
111 jmethodID constructor;
112} gInputDeviceIdentifierInfo;
113
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800114static struct {
115 jclass clazz;
116 jmethodID getAffineTransform;
117} gTouchCalibrationClassInfo;
118
RoboErikfb290df2013-12-16 11:27:55 -0800119
Jeff Brown928e0542011-01-10 11:17:36 -0800120
121// --- Global functions ---
122
Jeff Brown214eaf42011-05-26 19:17:02 -0700123template<typename T>
124inline static T min(const T& a, const T& b) {
125 return a < b ? a : b;
126}
127
128template<typename T>
129inline static T max(const T& a, const T& b) {
130 return a > b ? a : b;
131}
132
Michael Wrighta4051212015-07-23 17:04:40 +0100133static inline const char* toString(bool value) {
134 return value ? "true" : "false";
135}
136
Jeff Brown928e0542011-01-10 11:17:36 -0800137static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
138 const sp<InputApplicationHandle>& inputApplicationHandle) {
139 if (inputApplicationHandle == NULL) {
140 return NULL;
141 }
142 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
143 getInputApplicationHandleObjLocalRef(env);
144}
145
146static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
147 const sp<InputWindowHandle>& inputWindowHandle) {
148 if (inputWindowHandle == NULL) {
149 return NULL;
150 }
151 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
152 getInputWindowHandleObjLocalRef(env);
153}
154
Jun Mukai808196f2015-10-28 16:46:44 -0700155static void loadSystemIconAsSpriteWithPointerIcon(JNIEnv* env, jobject contextObj, int32_t style,
156 PointerIcon* outPointerIcon, SpriteIcon* outSpriteIcon) {
Jeff Brown2352b972011-04-12 22:39:53 -0700157 status_t status = android_view_PointerIcon_loadSystemIcon(env,
Jun Mukai808196f2015-10-28 16:46:44 -0700158 contextObj, style, outPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700159 if (!status) {
Matt Sarett155d5212017-04-25 17:32:34 -0400160 SkBitmap* bitmapCopy = &outSpriteIcon->bitmap;
161 SkImageInfo bitmapCopyInfo = outPointerIcon->bitmap.info().makeColorType(kN32_SkColorType);
162 if (bitmapCopy->tryAllocPixels(bitmapCopyInfo)) {
163 outPointerIcon->bitmap.readPixels(bitmapCopy->info(), bitmapCopy->getPixels(),
164 bitmapCopy->rowBytes(), 0, 0);
165 }
Jun Mukai808196f2015-10-28 16:46:44 -0700166 outSpriteIcon->hotSpotX = outPointerIcon->hotSpotX;
167 outSpriteIcon->hotSpotY = outPointerIcon->hotSpotY;
Jeff Brown2352b972011-04-12 22:39:53 -0700168 }
169}
170
Jun Mukai808196f2015-10-28 16:46:44 -0700171static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
172 SpriteIcon* outSpriteIcon) {
173 PointerIcon pointerIcon;
174 loadSystemIconAsSpriteWithPointerIcon(env, contextObj, style, &pointerIcon, outSpriteIcon);
175}
176
Jeff Brown905805a2011-10-12 13:57:59 -0700177enum {
178 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown905805a2011-10-12 13:57:59 -0700179};
180
Jeff Brown928e0542011-01-10 11:17:36 -0800181
182// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800183
Jeff Brown9c3cda02010-06-15 01:31:58 -0700184class NativeInputManager : public virtual RefBase,
185 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700186 public virtual InputDispatcherPolicyInterface,
187 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700188protected:
189 virtual ~NativeInputManager();
190
191public:
Jeff Brown4532e612012-04-05 14:27:12 -0700192 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700193
194 inline sp<InputManager> getInputManager() const { return mInputManager; }
195
Jeff Brownb88102f2010-09-08 11:49:43 -0700196 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700197
Jeff Brownd728bf52012-09-08 18:05:28 -0700198 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700199
Jeff Brown7fbdc842010-06-17 20:52:56 -0700200 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800201 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700202 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
203
Jeff Brown9302c872011-07-13 22:51:29 -0700204 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
205 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700206 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800207 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700208 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700209 void setShowTouches(bool enabled);
Jeff Brown037c33e2014-04-09 00:31:55 -0700210 void setInteractive(bool interactive);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800211 void reloadCalibration();
Michael Wrighte051f6f2016-05-13 17:44:16 +0100212 void setPointerIconType(int32_t iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800213 void reloadPointerIcons();
Jun Mukaid4eaef72015-10-30 15:54:33 -0700214 void setCustomPointerIcon(const SpriteIcon& icon);
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800215 void setPointerCapture(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700216
Jeff Brown9c3cda02010-06-15 01:31:58 -0700217 /* --- InputReaderPolicyInterface implementation --- */
218
Jeff Brown214eaf42011-05-26 19:17:02 -0700219 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800220 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700221 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
RoboErikfb290df2013-12-16 11:27:55 -0800222 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700223 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jason Gerecked5220742014-03-10 09:47:59 -0700224 virtual TouchAffineTransformation getTouchAffineTransformation(JNIEnv *env,
225 jfloatArray matrixArr);
226 virtual TouchAffineTransformation getTouchAffineTransformation(
227 const String8& inputDeviceDescriptor, int32_t surfaceRotation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700228
229 /* --- InputDispatcherPolicyInterface implementation --- */
230
Jeff Brownbcc046a2012-09-27 20:46:43 -0700231 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700232 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700233 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700234 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700235 const sp<InputWindowHandle>& inputWindowHandle,
236 const String8& reason);
Jeff Brown928e0542011-01-10 11:17:36 -0800237 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700238 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700239 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
Jeff Brown1f245102010-11-18 20:53:46 -0800240 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800241 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700242 virtual nsecs_t interceptKeyBeforeDispatching(
243 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700244 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800245 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800246 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700247 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700248 virtual bool checkInjectEventsPermissionNonReentrant(
249 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700250
Jeff Brown2352b972011-04-12 22:39:53 -0700251 /* --- PointerControllerPolicyInterface implementation --- */
252
Jun Mukai19a56012015-11-24 11:25:52 -0800253 virtual void loadPointerIcon(SpriteIcon* icon);
Jeff Brown2352b972011-04-12 22:39:53 -0700254 virtual void loadPointerResources(PointerResources* outResources);
Jun Mukai808196f2015-10-28 16:46:44 -0700255 virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
256 std::map<int32_t, PointerAnimation>* outAnimationResources);
Jun Mukai5ec74202015-10-07 16:58:09 +0900257 virtual int32_t getDefaultPointerIconId();
Jun Mukaid4eaef72015-10-30 15:54:33 -0700258 virtual int32_t getCustomPointerIconId();
Jeff Brown2352b972011-04-12 22:39:53 -0700259
Jeff Brown9c3cda02010-06-15 01:31:58 -0700260private:
261 sp<InputManager> mInputManager;
262
Jeff Brown2352b972011-04-12 22:39:53 -0700263 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700264 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800265 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700266
Jeff Brown83c09682010-12-23 17:50:18 -0800267 Mutex mLock;
268 struct Locked {
269 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700270 DisplayViewport internalViewport;
271 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800272
Jeff Brown05dc66a2011-03-02 14:41:58 -0800273 // System UI visibility.
274 int32_t systemUiVisibility;
275
Jeff Brown1a84fd12011-06-02 01:26:32 -0700276 // Pointer speed.
277 int32_t pointerSpeed;
278
Jeff Brown474dcb52011-06-14 20:22:50 -0700279 // True if pointer gestures are enabled.
280 bool pointerGesturesEnabled;
281
Jeff Browndaf4a122011-08-26 17:14:14 -0700282 // Show touches feature enable/disable.
283 bool showTouches;
284
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800285 // Pointer capture feature enable/disable.
286 bool pointerCapture;
287
Jeff Brown5541de92011-04-11 11:54:25 -0700288 // Sprite controller singleton, created on first use.
289 sp<SpriteController> spriteController;
290
Jeff Brown83c09682010-12-23 17:50:18 -0800291 // Pointer controller singleton, created and destroyed as needed.
292 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800293 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700294
Michael Wrighta4051212015-07-23 17:04:40 +0100295 std::atomic<bool> mInteractive;
Jeff Brown037c33e2014-04-09 00:31:55 -0700296
Jeff Brown2352b972011-04-12 22:39:53 -0700297 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800298 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700299 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800300
Jeff Brownb88102f2010-09-08 11:49:43 -0700301 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700302
Jeff Brown9c3cda02010-06-15 01:31:58 -0700303 static inline JNIEnv* jniEnv() {
304 return AndroidRuntime::getJNIEnv();
305 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700306};
307
Jeff Brown928e0542011-01-10 11:17:36 -0800308
Jeff Brown9c3cda02010-06-15 01:31:58 -0700309
Jeff Brown2352b972011-04-12 22:39:53 -0700310NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700311 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown037c33e2014-04-09 00:31:55 -0700312 mLooper(looper), mInteractive(true) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700313 JNIEnv* env = jniEnv();
314
Jeff Brown2352b972011-04-12 22:39:53 -0700315 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700316 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700317
Jeff Brown83c09682010-12-23 17:50:18 -0800318 {
319 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800320 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700321 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700322 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700323 mLocked.showTouches = false;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800324 mLocked.pointerCapture = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800325 }
Michael Wrighta4051212015-07-23 17:04:40 +0100326 mInteractive = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800327
Jeff Brown9c3cda02010-06-15 01:31:58 -0700328 sp<EventHub> eventHub = new EventHub();
329 mInputManager = new InputManager(eventHub, this, this);
330}
331
332NativeInputManager::~NativeInputManager() {
333 JNIEnv* env = jniEnv();
334
Jeff Brown2352b972011-04-12 22:39:53 -0700335 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700336 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700337}
338
Jeff Brownb88102f2010-09-08 11:49:43 -0700339void NativeInputManager::dump(String8& dump) {
Michael Wrighta4051212015-07-23 17:04:40 +0100340 dump.append("Input Manager State:\n");
341 {
342 dump.appendFormat(INDENT "Interactive: %s\n", toString(mInteractive.load()));
343 }
344 {
345 AutoMutex _l(mLock);
346 dump.appendFormat(INDENT "System UI Visibility: 0x%0" PRIx32 "\n",
347 mLocked.systemUiVisibility);
348 dump.appendFormat(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed);
349 dump.appendFormat(INDENT "Pointer Gestures Enabled: %s\n",
350 toString(mLocked.pointerGesturesEnabled));
351 dump.appendFormat(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800352 dump.appendFormat(INDENT "Pointer Capture Enabled: %s\n", toString(mLocked.pointerCapture));
Michael Wrighta4051212015-07-23 17:04:40 +0100353 }
354 dump.append("\n");
355
Jeff Brownb88102f2010-09-08 11:49:43 -0700356 mInputManager->getReader()->dump(dump);
357 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700358
Jeff Brownb88102f2010-09-08 11:49:43 -0700359 mInputManager->getDispatcher()->dump(dump);
360 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700361}
362
Jeff Brown7fbdc842010-06-17 20:52:56 -0700363bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700364 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000365 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700366 LOGE_EX(env);
367 env->ExceptionClear();
368 return true;
369 }
370 return false;
371}
372
Jeff Brownd728bf52012-09-08 18:05:28 -0700373void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700374 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700375 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700376 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700377
Jeff Brownd728bf52012-09-08 18:05:28 -0700378 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
379 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700380 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700381 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700382
Jeff Brownd728bf52012-09-08 18:05:28 -0700383 if (!external) {
384 sp<PointerController> controller = mLocked.pointerController.promote();
385 if (controller != NULL) {
386 controller->setDisplayViewport(
387 viewport.logicalRight - viewport.logicalLeft,
388 viewport.logicalBottom - viewport.logicalTop,
389 viewport.orientation);
390 }
Jeff Brown2352b972011-04-12 22:39:53 -0700391 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700392 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700393 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700394
395 if (changed) {
396 mInputManager->getReader()->requestRefreshConfiguration(
397 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
398 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700399}
400
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700401status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
Jeff Brown928e0542011-01-10 11:17:36 -0800402 const sp<InputChannel>& inputChannel,
403 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
404 return mInputManager->getDispatcher()->registerInputChannel(
405 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700406}
407
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700408status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700409 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700410 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700411}
412
Jeff Brown214eaf42011-05-26 19:17:02 -0700413void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700414 JNIEnv* env = jniEnv();
415
Jeff Brown4532e612012-04-05 14:27:12 -0700416 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
417 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700418 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
419 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
420 }
421
422 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700423 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
424 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700425 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
426 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700427 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700428 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700429 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700430 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700431 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700432 env->DeleteLocalRef(item);
433 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700434 env->DeleteLocalRef(excludedDeviceNames);
435 }
436
Jeff Brown4532e612012-04-05 14:27:12 -0700437 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
438 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700439 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700440 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
441 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700442 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700443 jint longPressTimeout = env->CallIntMethod(mServiceObj,
444 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700445 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700446 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700447
448 // We must ensure that the tap-drag interval is significantly shorter than
449 // the long-press timeout because the tap is held down for the entire duration
450 // of the double-tap timeout.
451 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700452 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700453 outConfig->pointerGestureTapDragInterval =
454 milliseconds_to_nanoseconds(tapDragInterval);
455 }
456 }
457 }
458
Jeff Brown4532e612012-04-05 14:27:12 -0700459 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
460 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700461 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
462 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700463 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700464
465 { // acquire lock
466 AutoMutex _l(mLock);
467
468 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
469 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700470 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700471
Jeff Browndaf4a122011-08-26 17:14:14 -0700472 outConfig->showTouches = mLocked.showTouches;
473
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800474 outConfig->pointerCapture = mLocked.pointerCapture;
475
Jeff Brownd728bf52012-09-08 18:05:28 -0700476 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
477 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700478 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700479}
480
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700481sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t /* deviceId */) {
Jeff Brown83c09682010-12-23 17:50:18 -0800482 AutoMutex _l(mLock);
483
484 sp<PointerController> controller = mLocked.pointerController.promote();
485 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700486 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800487
Jeff Brown2352b972011-04-12 22:39:53 -0700488 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800489 mLocked.pointerController = controller;
490
Jeff Brownd728bf52012-09-08 18:05:28 -0700491 DisplayViewport& v = mLocked.internalViewport;
492 controller->setDisplayViewport(
493 v.logicalRight - v.logicalLeft,
494 v.logicalBottom - v.logicalTop,
495 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800496
Jeff Brown2352b972011-04-12 22:39:53 -0700497 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800498 }
499 return controller;
500}
501
Jeff Brown5541de92011-04-11 11:54:25 -0700502void NativeInputManager::ensureSpriteControllerLocked() {
503 if (mLocked.spriteController == NULL) {
504 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700505 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700506 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
507 layer = -1;
508 }
509 mLocked.spriteController = new SpriteController(mLooper, layer);
510 }
511}
512
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700513void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
514 JNIEnv* env = jniEnv();
515
516 size_t count = inputDevices.size();
517 jobjectArray inputDevicesObjArray = env->NewObjectArray(
518 count, gInputDeviceClassInfo.clazz, NULL);
519 if (inputDevicesObjArray) {
520 bool error = false;
521 for (size_t i = 0; i < count; i++) {
522 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
523 if (!inputDeviceObj) {
524 error = true;
525 break;
526 }
527
528 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
529 env->DeleteLocalRef(inputDeviceObj);
530 }
531
532 if (!error) {
533 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
534 inputDevicesObjArray);
535 }
536
537 env->DeleteLocalRef(inputDevicesObjArray);
538 }
539
540 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
541}
542
Jeff Brown6ec6f792012-04-17 16:52:41 -0700543sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
RoboErikfb290df2013-12-16 11:27:55 -0800544 const InputDeviceIdentifier& identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700545 JNIEnv* env = jniEnv();
546
547 sp<KeyCharacterMap> result;
RoboErikfb290df2013-12-16 11:27:55 -0800548 ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
549 ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
550 gInputDeviceIdentifierInfo.constructor, descriptor.get(),
551 identifier.vendor, identifier.product));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700552 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
RoboErikfb290df2013-12-16 11:27:55 -0800553 gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700554 if (arrayObj.get()) {
555 ScopedLocalRef<jstring> filenameObj(env,
556 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
557 ScopedLocalRef<jstring> contentsObj(env,
558 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
559 ScopedUtfChars filenameChars(env, filenameObj.get());
560 ScopedUtfChars contentsChars(env, contentsObj.get());
561
562 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
563 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
564 }
565 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
566 return result;
567}
568
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700569String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
570 JNIEnv* env = jniEnv();
571
572 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
573 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
574 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
575 String8 result;
576 if (aliasObj.get()) {
577 ScopedUtfChars aliasChars(env, aliasObj.get());
578 result.setTo(aliasChars.c_str());
579 }
580 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
581 return result;
582}
583
Jeff Brownbcc046a2012-09-27 20:46:43 -0700584void NativeInputManager::notifySwitch(nsecs_t when,
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700585 uint32_t switchValues, uint32_t switchMask, uint32_t /* policyFlags */) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700586#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700587 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
588 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700589#endif
590
591 JNIEnv* env = jniEnv();
592
Jeff Brown53384282012-08-20 20:16:01 -0700593 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700594 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700595 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700596}
597
Jeff Brown9c3cda02010-06-15 01:31:58 -0700598void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
599#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000600 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700601#endif
602
603 JNIEnv* env = jniEnv();
604
Jeff Brown4532e612012-04-05 14:27:12 -0700605 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700606 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700607}
608
Jeff Brown519e0242010-09-15 15:18:56 -0700609nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700610 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700611#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000612 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700613#endif
614
615 JNIEnv* env = jniEnv();
616
Jeff Brown928e0542011-01-10 11:17:36 -0800617 jobject inputApplicationHandleObj =
618 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
619 jobject inputWindowHandleObj =
620 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownbd181bb2013-09-10 16:44:24 -0700621 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700622
Jeff Brown4532e612012-04-05 14:27:12 -0700623 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700624 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
625 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700626 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
627 newTimeout = 0; // abort dispatch
628 } else {
629 assert(newTimeout >= 0);
630 }
631
Jeff Brownbd181bb2013-09-10 16:44:24 -0700632 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800633 env->DeleteLocalRef(inputWindowHandleObj);
634 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700635 return newTimeout;
636}
637
Jeff Brown928e0542011-01-10 11:17:36 -0800638void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700639#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000640 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700641#endif
642
Jeff Brown7fbdc842010-06-17 20:52:56 -0700643 JNIEnv* env = jniEnv();
644
Jeff Brown928e0542011-01-10 11:17:36 -0800645 jobject inputWindowHandleObj =
646 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
647 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700648 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800649 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700650 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
651
Jeff Brown928e0542011-01-10 11:17:36 -0800652 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700653 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700654}
655
Jeff Brown214eaf42011-05-26 19:17:02 -0700656void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
657 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800658
Jeff Brown4532e612012-04-05 14:27:12 -0700659 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
660 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700661 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
662 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
663 }
Jeff Browna4547672011-03-02 21:38:11 -0800664
Jeff Brown4532e612012-04-05 14:27:12 -0700665 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
666 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700667 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
668 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
669 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700670}
671
Jeff Brown9302c872011-07-13 22:51:29 -0700672void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
673 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700674
Jeff Brown9302c872011-07-13 22:51:29 -0700675 if (windowHandleObjArray) {
676 jsize length = env->GetArrayLength(windowHandleObjArray);
677 for (jsize i = 0; i < length; i++) {
678 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
679 if (! windowHandleObj) {
680 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700681 }
Jeff Brown9302c872011-07-13 22:51:29 -0700682
683 sp<InputWindowHandle> windowHandle =
684 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
685 if (windowHandle != NULL) {
686 windowHandles.push(windowHandle);
687 }
688 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700689 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700690 }
Jeff Brown349703e2010-06-22 01:27:15 -0700691
Jeff Brown9302c872011-07-13 22:51:29 -0700692 mInputManager->getDispatcher()->setInputWindows(windowHandles);
693
694 // Do this after the dispatcher has updated the window handle state.
695 bool newPointerGesturesEnabled = true;
696 size_t numWindows = windowHandles.size();
697 for (size_t i = 0; i < numWindows; i++) {
698 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700699 const InputWindowInfo* windowInfo = windowHandle->getInfo();
700 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
701 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700702 newPointerGesturesEnabled = false;
703 }
704 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700705
706 uint32_t changes = 0;
707 { // acquire lock
708 AutoMutex _l(mLock);
709
710 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
711 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
712 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
713 }
714 } // release lock
715
716 if (changes) {
717 mInputManager->getReader()->requestRefreshConfiguration(changes);
718 }
Jeff Brown349703e2010-06-22 01:27:15 -0700719}
720
Jeff Brown9302c872011-07-13 22:51:29 -0700721void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
722 sp<InputApplicationHandle> applicationHandle =
723 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
724 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700725}
726
727void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700728 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700729}
730
Jeff Brown05dc66a2011-03-02 14:41:58 -0800731void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
732 AutoMutex _l(mLock);
733
734 if (mLocked.systemUiVisibility != visibility) {
735 mLocked.systemUiVisibility = visibility;
736
737 sp<PointerController> controller = mLocked.pointerController.promote();
738 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700739 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800740 }
741 }
742}
743
Jeff Brown2352b972011-04-12 22:39:53 -0700744void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800745 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700746 controller->setInactivityTimeout(lightsOut
747 ? PointerController::INACTIVITY_TIMEOUT_SHORT
748 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800749}
750
Jeff Brown1a84fd12011-06-02 01:26:32 -0700751void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700752 { // acquire lock
753 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700754
Jeff Brown474dcb52011-06-14 20:22:50 -0700755 if (mLocked.pointerSpeed == speed) {
756 return;
757 }
758
Steve Block6215d3f2012-01-04 20:05:49 +0000759 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700760 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700761 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700762
Jeff Brown474dcb52011-06-14 20:22:50 -0700763 mInputManager->getReader()->requestRefreshConfiguration(
764 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700765}
766
Jeff Browndaf4a122011-08-26 17:14:14 -0700767void NativeInputManager::setShowTouches(bool enabled) {
768 { // acquire lock
769 AutoMutex _l(mLock);
770
771 if (mLocked.showTouches == enabled) {
772 return;
773 }
774
Steve Block6215d3f2012-01-04 20:05:49 +0000775 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700776 mLocked.showTouches = enabled;
777 } // release lock
778
779 mInputManager->getReader()->requestRefreshConfiguration(
780 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
781}
782
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800783void NativeInputManager::setPointerCapture(bool enabled) {
784 { // acquire lock
785 AutoMutex _l(mLock);
786
787 if (mLocked.pointerCapture == enabled) {
788 return;
789 }
790
791 ALOGI("Setting pointer capture to %s.", enabled ? "enabled" : "disabled");
792 mLocked.pointerCapture = enabled;
793 } // release lock
794
795 mInputManager->getReader()->requestRefreshConfiguration(
796 InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
797}
798
Jeff Brown037c33e2014-04-09 00:31:55 -0700799void NativeInputManager::setInteractive(bool interactive) {
800 mInteractive = interactive;
Jeff Browne20c9e02010-10-11 14:20:19 -0700801}
802
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800803void NativeInputManager::reloadCalibration() {
804 mInputManager->getReader()->requestRefreshConfiguration(
Michael Wright357285c2015-04-17 00:50:31 +0100805 InputReaderConfiguration::CHANGE_TOUCH_AFFINE_TRANSFORMATION);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800806}
807
Michael Wrighte051f6f2016-05-13 17:44:16 +0100808void NativeInputManager::setPointerIconType(int32_t iconId) {
Jun Mukai19a56012015-11-24 11:25:52 -0800809 AutoMutex _l(mLock);
810 sp<PointerController> controller = mLocked.pointerController.promote();
811 if (controller != NULL) {
Michael Wrighte051f6f2016-05-13 17:44:16 +0100812 controller->updatePointerIcon(iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800813 }
814}
815
816void NativeInputManager::reloadPointerIcons() {
817 AutoMutex _l(mLock);
818 sp<PointerController> controller = mLocked.pointerController.promote();
819 if (controller != NULL) {
820 controller->reloadPointerResources();
821 }
Jun Mukai1db53972015-09-11 18:08:31 -0700822}
823
Jun Mukaid4eaef72015-10-30 15:54:33 -0700824void NativeInputManager::setCustomPointerIcon(const SpriteIcon& icon) {
825 AutoMutex _l(mLock);
826 sp<PointerController> controller = mLocked.pointerController.promote();
827 if (controller != NULL) {
828 controller->setCustomPointerIcon(icon);
829 }
830}
831
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800832TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
833 JNIEnv *env, jfloatArray matrixArr) {
834 ScopedFloatArrayRO matrix(env, matrixArr);
835 assert(matrix.size() == 6);
836
837 TouchAffineTransformation transform;
838 transform.x_scale = matrix[0];
839 transform.x_ymix = matrix[1];
840 transform.x_offset = matrix[2];
841 transform.y_xmix = matrix[3];
842 transform.y_scale = matrix[4];
843 transform.y_offset = matrix[5];
844
845 return transform;
846}
847
848TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
Jason Gerecked5220742014-03-10 09:47:59 -0700849 const String8& inputDeviceDescriptor, int32_t surfaceRotation) {
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800850 JNIEnv* env = jniEnv();
851
852 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
853
854 jobject cal = env->CallObjectMethod(mServiceObj,
Jason Gerecked5220742014-03-10 09:47:59 -0700855 gServiceClassInfo.getTouchCalibrationForInputDevice, descriptorObj.get(),
856 surfaceRotation);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800857
858 jfloatArray matrixArr = jfloatArray(env->CallObjectMethod(cal,
859 gTouchCalibrationClassInfo.getAffineTransform));
860
861 TouchAffineTransformation transform = getTouchAffineTransformation(env, matrixArr);
862
863 env->DeleteLocalRef(matrixArr);
864 env->DeleteLocalRef(cal);
865
866 return transform;
867}
868
Jeff Brown0029c662011-03-30 02:25:18 -0700869bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
870 jobject inputEventObj;
871
872 JNIEnv* env = jniEnv();
873 switch (inputEvent->getType()) {
874 case AINPUT_EVENT_TYPE_KEY:
875 inputEventObj = android_view_KeyEvent_fromNative(env,
876 static_cast<const KeyEvent*>(inputEvent));
877 break;
878 case AINPUT_EVENT_TYPE_MOTION:
879 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
880 static_cast<const MotionEvent*>(inputEvent));
881 break;
882 default:
883 return true; // dispatch the event normally
884 }
885
886 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000887 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700888 return true; // dispatch the event normally
889 }
890
891 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700892 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700893 inputEventObj, policyFlags);
894 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
895 pass = true;
896 }
897 env->DeleteLocalRef(inputEventObj);
898 return pass;
899}
900
Jeff Brown1f245102010-11-18 20:53:46 -0800901void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
902 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700903 // Policy:
904 // - Ignore untrusted events and pass them along.
905 // - Ask the window manager what to do with normal events and trusted injected events.
906 // - For normal events wake and brighten the screen if currently off or dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100907 bool interactive = mInteractive.load();
908 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700909 policyFlags |= POLICY_FLAG_INTERACTIVE;
910 }
Jeff Brown3122e442010-10-11 23:32:49 -0700911 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800912 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700913 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800914 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
915 jint wmActions;
916 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700917 wmActions = env->CallIntMethod(mServiceObj,
918 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown037c33e2014-04-09 00:31:55 -0700919 keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800920 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
921 wmActions = 0;
922 }
923 android_view_KeyEvent_recycle(env, keyEventObj);
924 env->DeleteLocalRef(keyEventObj);
925 } else {
Steve Block3762c312012-01-06 19:20:56 +0000926 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700927 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700928 }
929
Jeff Brown56194eb2011-03-02 19:23:13 -0800930 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700931 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100932 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700933 policyFlags |= POLICY_FLAG_PASS_TO_USER;
934 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700935 }
936}
937
Jeff Brown56194eb2011-03-02 19:23:13 -0800938void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700939 // Policy:
940 // - Ignore untrusted events and pass them along.
941 // - No special filtering for injected events required at this time.
942 // - Filter normal events based on screen state.
943 // - For normal events brighten (but do not wake) the screen if currently dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100944 bool interactive = mInteractive.load();
945 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700946 policyFlags |= POLICY_FLAG_INTERACTIVE;
947 }
Jeff Brown3122e442010-10-11 23:32:49 -0700948 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700949 if (policyFlags & POLICY_FLAG_INTERACTIVE) {
Jeff Brown3122e442010-10-11 23:32:49 -0700950 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Michael Wright70af00a2014-09-03 19:30:20 -0700951 } else {
Jeff Brown56194eb2011-03-02 19:23:13 -0800952 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700953 jint wmActions = env->CallIntMethod(mServiceObj,
Michael Wright70af00a2014-09-03 19:30:20 -0700954 gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive,
Jeff Brown26875502014-01-30 21:47:47 -0800955 when, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800956 if (checkAndClearExceptionFromCallback(env,
Michael Wright70af00a2014-09-03 19:30:20 -0700957 "interceptMotionBeforeQueueingNonInteractive")) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800958 wmActions = 0;
959 }
960
Jeff Brown56194eb2011-03-02 19:23:13 -0800961 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700962 }
Jeff Brown3122e442010-10-11 23:32:49 -0700963 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100964 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700965 policyFlags |= POLICY_FLAG_PASS_TO_USER;
966 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700967 }
968}
969
Jeff Brown56194eb2011-03-02 19:23:13 -0800970void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
971 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800972 if (wmActions & WM_ACTION_PASS_TO_USER) {
973 policyFlags |= POLICY_FLAG_PASS_TO_USER;
974 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800975#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000976 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800977#endif
978 }
979}
980
Jeff Brown905805a2011-10-12 13:57:59 -0700981nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800982 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700983 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700984 // Policy:
985 // - Ignore untrusted events and pass them along.
986 // - Filter normal events and trusted injected events through the window manager policy to
987 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700988 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700989 if (policyFlags & POLICY_FLAG_TRUSTED) {
990 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700991
Jeff Brown928e0542011-01-10 11:17:36 -0800992 // Note: inputWindowHandle may be null.
993 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800994 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
995 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700996 jlong delayMillis = env->CallLongMethod(mServiceObj,
997 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800998 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800999 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
1000 android_view_KeyEvent_recycle(env, keyEventObj);
1001 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -07001002 if (!error) {
1003 if (delayMillis < 0) {
1004 result = -1;
1005 } else if (delayMillis > 0) {
1006 result = milliseconds_to_nanoseconds(delayMillis);
1007 }
1008 }
Jeff Brown1f245102010-11-18 20:53:46 -08001009 } else {
Steve Block3762c312012-01-06 19:20:56 +00001010 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -08001011 }
Jeff Brown928e0542011-01-10 11:17:36 -08001012 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -07001013 }
Jeff Brown1f245102010-11-18 20:53:46 -08001014 return result;
Jeff Brownd0097872010-06-30 14:41:59 -07001015}
1016
Jeff Brown928e0542011-01-10 11:17:36 -08001017bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001018 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -07001019 // Policy:
1020 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -08001021 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -07001022 if (policyFlags & POLICY_FLAG_TRUSTED) {
1023 JNIEnv* env = jniEnv();
1024
Jeff Brown928e0542011-01-10 11:17:36 -08001025 // Note: inputWindowHandle may be null.
1026 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -08001027 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
1028 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001029 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
1030 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -08001031 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001032 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
1033 fallbackKeyEventObj = NULL;
1034 }
Jeff Brown1f245102010-11-18 20:53:46 -08001035 android_view_KeyEvent_recycle(env, keyEventObj);
1036 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001037
1038 if (fallbackKeyEventObj) {
1039 // Note: outFallbackKeyEvent may be the same object as keyEvent.
1040 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
1041 outFallbackKeyEvent)) {
1042 result = true;
1043 }
1044 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
1045 env->DeleteLocalRef(fallbackKeyEventObj);
1046 }
Jeff Brown1f245102010-11-18 20:53:46 -08001047 } else {
Steve Block3762c312012-01-06 19:20:56 +00001048 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -08001049 }
Jeff Brown928e0542011-01-10 11:17:36 -08001050 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -07001051 }
Jeff Brown1f245102010-11-18 20:53:46 -08001052 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -07001053}
1054
Jeff Brown01ce2e92010-09-26 22:20:12 -07001055void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
1056 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -07001057}
1058
Jeff Brown349703e2010-06-22 01:27:15 -07001059
Jeff Brownb88102f2010-09-08 11:49:43 -07001060bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
1061 int32_t injectorPid, int32_t injectorUid) {
1062 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -07001063 jboolean result = env->CallBooleanMethod(mServiceObj,
1064 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001065 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
1066 result = false;
1067 }
Jeff Brown349703e2010-06-22 01:27:15 -07001068 return result;
1069}
1070
Jun Mukai19a56012015-11-24 11:25:52 -08001071void NativeInputManager::loadPointerIcon(SpriteIcon* icon) {
1072 JNIEnv* env = jniEnv();
1073
1074 ScopedLocalRef<jobject> pointerIconObj(env, env->CallObjectMethod(
1075 mServiceObj, gServiceClassInfo.getPointerIcon));
1076 if (checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
1077 return;
1078 }
1079
1080 PointerIcon pointerIcon;
1081 status_t status = android_view_PointerIcon_load(env, pointerIconObj.get(),
1082 mContextObj, &pointerIcon);
1083 if (!status && !pointerIcon.isNullIcon()) {
1084 *icon = SpriteIcon(pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY);
1085 } else {
1086 *icon = SpriteIcon();
1087 }
1088}
1089
Jeff Brown2352b972011-04-12 22:39:53 -07001090void NativeInputManager::loadPointerResources(PointerResources* outResources) {
1091 JNIEnv* env = jniEnv();
1092
1093 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
1094 &outResources->spotHover);
1095 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
1096 &outResources->spotTouch);
1097 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
1098 &outResources->spotAnchor);
1099}
1100
Jun Mukai808196f2015-10-28 16:46:44 -07001101void NativeInputManager::loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
1102 std::map<int32_t, PointerAnimation>* outAnimationResources) {
Jun Mukai1db53972015-09-11 18:08:31 -07001103 JNIEnv* env = jniEnv();
1104
1105 for (int iconId = POINTER_ICON_STYLE_CONTEXT_MENU; iconId <= POINTER_ICON_STYLE_GRABBING;
1106 ++iconId) {
Jun Mukai808196f2015-10-28 16:46:44 -07001107 PointerIcon pointerIcon;
1108 loadSystemIconAsSpriteWithPointerIcon(
1109 env, mContextObj, iconId, &pointerIcon, &((*outResources)[iconId]));
1110 if (!pointerIcon.bitmapFrames.empty()) {
1111 PointerAnimation& animationData = (*outAnimationResources)[iconId];
1112 size_t numFrames = pointerIcon.bitmapFrames.size() + 1;
1113 animationData.durationPerFrame =
1114 milliseconds_to_nanoseconds(pointerIcon.durationPerFrame);
1115 animationData.animationFrames.reserve(numFrames);
1116 animationData.animationFrames.push_back(SpriteIcon(
1117 pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1118 for (size_t i = 0; i < numFrames - 1; ++i) {
1119 animationData.animationFrames.push_back(SpriteIcon(
1120 pointerIcon.bitmapFrames[i], pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1121 }
1122 }
Jun Mukai1db53972015-09-11 18:08:31 -07001123 }
Jun Mukai808196f2015-10-28 16:46:44 -07001124 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_NULL,
1125 &((*outResources)[POINTER_ICON_STYLE_NULL]));
Jun Mukai1db53972015-09-11 18:08:31 -07001126}
1127
Jun Mukai5ec74202015-10-07 16:58:09 +09001128int32_t NativeInputManager::getDefaultPointerIconId() {
1129 return POINTER_ICON_STYLE_ARROW;
1130}
Jeff Brown83c09682010-12-23 17:50:18 -08001131
Jun Mukaid4eaef72015-10-30 15:54:33 -07001132int32_t NativeInputManager::getCustomPointerIconId() {
1133 return POINTER_ICON_STYLE_CUSTOM;
1134}
1135
Jeff Brown9c3cda02010-06-15 01:31:58 -07001136// ----------------------------------------------------------------------------
1137
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001138static jlong nativeInit(JNIEnv* env, jclass /* clazz */,
Jeff Brown4532e612012-04-05 14:27:12 -07001139 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -07001140 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -08001141 if (messageQueue == NULL) {
1142 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
1143 return 0;
1144 }
1145
Jeff Brown603b4452012-04-06 17:39:41 -07001146 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
1147 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -08001148 im->incStrong(0);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001149 return reinterpret_cast<jlong>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001150}
1151
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001152static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001153 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001154
Jeff Brown4532e612012-04-05 14:27:12 -07001155 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001156 if (result) {
1157 jniThrowRuntimeException(env, "Input manager could not be started.");
1158 }
1159}
1160
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001161static void nativeSetDisplayViewport(JNIEnv* /* env */, jclass /* clazz */, jlong ptr,
1162 jboolean external, jint displayId, jint orientation,
Jeff Brownd728bf52012-09-08 18:05:28 -07001163 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001164 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1165 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001166 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001167
Jeff Brownd728bf52012-09-08 18:05:28 -07001168 DisplayViewport v;
1169 v.displayId = displayId;
1170 v.orientation = orientation;
1171 v.logicalLeft = logicalLeft;
1172 v.logicalTop = logicalTop;
1173 v.logicalRight = logicalRight;
1174 v.logicalBottom = logicalBottom;
1175 v.physicalLeft = physicalLeft;
1176 v.physicalTop = physicalTop;
1177 v.physicalRight = physicalRight;
1178 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001179 v.deviceWidth = deviceWidth;
1180 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001181 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001182}
1183
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001184static jint nativeGetScanCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001185 jlong ptr, jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001186 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001187
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001188 return (jint) im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001189 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001190}
1191
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001192static jint nativeGetKeyCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001193 jlong ptr, jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001194 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001195
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001196 return (jint) im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001197 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001198}
1199
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001200static jint nativeGetSwitchState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001201 jlong ptr, jint deviceId, jint sourceMask, jint sw) {
Jeff Brown4532e612012-04-05 14:27:12 -07001202 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001203
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001204 return (jint) im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001205 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001206}
1207
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001208static jboolean nativeHasKeys(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001209 jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001210 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001211
1212 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1213 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1214 jsize numCodes = env->GetArrayLength(keyCodes);
1215 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001216 if (numCodes == env->GetArrayLength(keyCodes)) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001217 if (im->getInputManager()->getReader()->hasKeys(
1218 deviceId, uint32_t(sourceMask), numCodes, codes, flags)) {
1219 result = JNI_TRUE;
1220 } else {
1221 result = JNI_FALSE;
1222 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001223 } else {
1224 result = JNI_FALSE;
1225 }
1226
1227 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1228 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1229 return result;
1230}
1231
1232static void throwInputChannelNotInitialized(JNIEnv* env) {
1233 jniThrowException(env, "java/lang/IllegalStateException",
1234 "inputChannel is not initialized");
1235}
1236
Jeff Brown4532e612012-04-05 14:27:12 -07001237static void handleInputChannelDisposed(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001238 jobject /* inputChannelObj */, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001239 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1240
Steve Block8564c8d2012-01-05 23:22:43 +00001241 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001242 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001243 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001244}
1245
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001246static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001247 jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown4532e612012-04-05 14:27:12 -07001248 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001249
1250 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1251 inputChannelObj);
1252 if (inputChannel == NULL) {
1253 throwInputChannelNotInitialized(env);
1254 return;
1255 }
1256
Jeff Brown928e0542011-01-10 11:17:36 -08001257 sp<InputWindowHandle> inputWindowHandle =
1258 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001259
Jeff Brown4532e612012-04-05 14:27:12 -07001260 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001261 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001262 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001263 String8 message;
1264 message.appendFormat("Failed to register input channel. status=%d", status);
1265 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001266 return;
1267 }
1268
Jeff Browna41ca772010-08-11 14:46:32 -07001269 if (! monitor) {
1270 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001271 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001272 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001273}
1274
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001275static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001276 jlong ptr, jobject inputChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001277 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001278
1279 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1280 inputChannelObj);
1281 if (inputChannel == NULL) {
1282 throwInputChannelNotInitialized(env);
1283 return;
1284 }
1285
1286 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1287
Jeff Brown4532e612012-04-05 14:27:12 -07001288 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001289 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1290 String8 message;
1291 message.appendFormat("Failed to unregister input channel. status=%d", status);
1292 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001293 }
1294}
1295
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001296static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001297 jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001298 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001299
Jeff Brown4532e612012-04-05 14:27:12 -07001300 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001301}
1302
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001303static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
Jeff Brownca9bc702014-02-11 14:32:56 -08001304 jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001305 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001306 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001307
Jeff Brown6ec402b2010-07-28 15:48:59 -07001308 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1309 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001310 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1311 if (status) {
1312 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1313 return INPUT_EVENT_INJECTION_FAILED;
1314 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001315
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001316 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001317 & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001318 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001319 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001320 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1321 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001322 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1323 return INPUT_EVENT_INJECTION_FAILED;
1324 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001325
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001326 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001327 motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001328 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001329 } else {
1330 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001331 return INPUT_EVENT_INJECTION_FAILED;
1332 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001333}
1334
Andrii Kulian112d0562016-03-08 10:44:22 -08001335static void nativeToggleCapsLock(JNIEnv* env, jclass /* clazz */,
1336 jlong ptr, jint deviceId) {
1337 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1338 im->getInputManager()->getReader()->toggleCapsLockState(deviceId);
1339}
1340
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001341static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001342 jlong ptr, jobjectArray windowHandleObjArray) {
Jeff Brown4532e612012-04-05 14:27:12 -07001343 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001344
Jeff Brown4532e612012-04-05 14:27:12 -07001345 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001346}
1347
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001348static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001349 jlong ptr, jobject applicationHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001350 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001351
Jeff Brown4532e612012-04-05 14:27:12 -07001352 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001353}
1354
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -08001355static void nativeSetPointerCapture(JNIEnv* env, jclass /* clazz */, jlong ptr,
1356 jboolean enabled) {
1357 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1358 im->setPointerCapture(enabled);
1359}
1360
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001361static void nativeSetInputDispatchMode(JNIEnv* /* env */,
1362 jclass /* clazz */, jlong ptr, jboolean enabled, jboolean frozen) {
Jeff Brown4532e612012-04-05 14:27:12 -07001363 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001364
Jeff Brown4532e612012-04-05 14:27:12 -07001365 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001366}
1367
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001368static void nativeSetSystemUiVisibility(JNIEnv* /* env */,
1369 jclass /* clazz */, jlong ptr, jint visibility) {
Jeff Brown4532e612012-04-05 14:27:12 -07001370 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001371
Jeff Brown4532e612012-04-05 14:27:12 -07001372 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001373}
1374
Jeff Brown4532e612012-04-05 14:27:12 -07001375static jboolean nativeTransferTouchFocus(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001376 jclass /* clazz */, jlong ptr, jobject fromChannelObj, jobject toChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001377 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001378
1379 sp<InputChannel> fromChannel =
1380 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1381 sp<InputChannel> toChannel =
1382 android_view_InputChannel_getInputChannel(env, toChannelObj);
1383
1384 if (fromChannel == NULL || toChannel == NULL) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001385 return JNI_FALSE;
Jeff Browne6504122010-09-27 14:52:15 -07001386 }
1387
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001388 if (im->getInputManager()->getDispatcher()->
1389 transferTouchFocus(fromChannel, toChannel)) {
1390 return JNI_TRUE;
1391 } else {
1392 return JNI_FALSE;
1393 }
Jeff Browne6504122010-09-27 14:52:15 -07001394}
1395
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001396static void nativeSetPointerSpeed(JNIEnv* /* env */,
1397 jclass /* clazz */, jlong ptr, jint speed) {
Jeff Brown4532e612012-04-05 14:27:12 -07001398 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001399
Jeff Brown4532e612012-04-05 14:27:12 -07001400 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001401}
1402
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001403static void nativeSetShowTouches(JNIEnv* /* env */,
1404 jclass /* clazz */, jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001405 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001406
Jeff Brown4532e612012-04-05 14:27:12 -07001407 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001408}
1409
Jeff Brown037c33e2014-04-09 00:31:55 -07001410static void nativeSetInteractive(JNIEnv* env,
1411 jclass clazz, jlong ptr, jboolean interactive) {
1412 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1413
1414 im->setInteractive(interactive);
1415}
1416
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001417static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) {
1418 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1419 im->reloadCalibration();
1420}
1421
Jeff Browna47425a2012-04-13 04:09:27 -07001422static void nativeVibrate(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001423 jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj,
Jeff Browna47425a2012-04-13 04:09:27 -07001424 jint repeat, jint token) {
1425 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1426
1427 size_t patternSize = env->GetArrayLength(patternObj);
1428 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
Michael Wright9ecba522014-04-04 15:29:53 -07001429 ALOGI("Skipped requested vibration because the pattern size is %zu "
Jeff Browna47425a2012-04-13 04:09:27 -07001430 "which is more than the maximum supported size of %d.",
1431 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1432 return; // limit to reasonable size
1433 }
1434
1435 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1436 patternObj, NULL));
1437 nsecs_t pattern[patternSize];
1438 for (size_t i = 0; i < patternSize; i++) {
1439 pattern[i] = max(jlong(0), min(patternMillis[i],
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001440 (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL;
Jeff Browna47425a2012-04-13 04:09:27 -07001441 }
1442 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1443
1444 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1445}
1446
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001447static void nativeCancelVibrate(JNIEnv* /* env */,
1448 jclass /* clazz */, jlong ptr, jint deviceId, jint token) {
Jeff Browna47425a2012-04-13 04:09:27 -07001449 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1450
1451 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1452}
1453
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001454static void nativeReloadKeyboardLayouts(JNIEnv* /* env */,
1455 jclass /* clazz */, jlong ptr) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001456 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1457
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001458 im->getInputManager()->getReader()->requestRefreshConfiguration(
1459 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1460}
1461
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001462static void nativeReloadDeviceAliases(JNIEnv* /* env */,
1463 jclass /* clazz */, jlong ptr) {
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001464 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1465
1466 im->getInputManager()->getReader()->requestRefreshConfiguration(
1467 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001468}
1469
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001470static jstring nativeDump(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001471 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001472
Jeff Brownb88102f2010-09-08 11:49:43 -07001473 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001474 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001475 return env->NewStringUTF(dump.string());
1476}
1477
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001478static void nativeMonitor(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001479 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001480
Jeff Brown4532e612012-04-05 14:27:12 -07001481 im->getInputManager()->getReader()->monitor();
1482 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001483}
1484
Michael Wrighte051f6f2016-05-13 17:44:16 +01001485static void nativeSetPointerIconType(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, jint iconId) {
Jun Mukai1db53972015-09-11 18:08:31 -07001486 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Michael Wrighte051f6f2016-05-13 17:44:16 +01001487 im->setPointerIconType(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -07001488}
1489
Jun Mukai19a56012015-11-24 11:25:52 -08001490static void nativeReloadPointerIcons(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
1491 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1492 im->reloadPointerIcons();
1493}
1494
Jun Mukaid4eaef72015-10-30 15:54:33 -07001495static void nativeSetCustomPointerIcon(JNIEnv* env, jclass /* clazz */,
1496 jlong ptr, jobject iconObj) {
1497 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1498
1499 PointerIcon pointerIcon;
Michael Wrightb004b512017-01-18 18:09:29 +00001500 status_t result = android_view_PointerIcon_getLoadedIcon(env, iconObj, &pointerIcon);
1501 if (result) {
1502 jniThrowRuntimeException(env, "Failed to load custom pointer icon.");
1503 return;
1504 }
Jun Mukaid4eaef72015-10-30 15:54:33 -07001505
1506 SpriteIcon spriteIcon;
1507 pointerIcon.bitmap.copyTo(&spriteIcon.bitmap, kN32_SkColorType);
1508 spriteIcon.hotSpotX = pointerIcon.hotSpotX;
1509 spriteIcon.hotSpotY = pointerIcon.hotSpotY;
1510 im->setCustomPointerIcon(spriteIcon);
1511}
1512
Jeff Brown9c3cda02010-06-15 01:31:58 -07001513// ----------------------------------------------------------------------------
1514
Daniel Micay76f6a862015-09-19 17:31:01 -04001515static const JNINativeMethod gInputManagerMethods[] = {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001516 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001517 { "nativeInit",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001518 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J",
Jeff Brown4532e612012-04-05 14:27:12 -07001519 (void*) nativeInit },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001520 { "nativeStart", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001521 (void*) nativeStart },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001522 { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001523 (void*) nativeSetDisplayViewport },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001524 { "nativeGetScanCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001525 (void*) nativeGetScanCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001526 { "nativeGetKeyCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001527 (void*) nativeGetKeyCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001528 { "nativeGetSwitchState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001529 (void*) nativeGetSwitchState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001530 { "nativeHasKeys", "(JII[I[Z)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001531 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001532 { "nativeRegisterInputChannel",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001533 "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001534 (void*) nativeRegisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001535 { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001536 (void*) nativeUnregisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001537 { "nativeSetInputFilterEnabled", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001538 (void*) nativeSetInputFilterEnabled },
Jeff Brownca9bc702014-02-11 14:32:56 -08001539 { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001540 (void*) nativeInjectInputEvent },
Andrii Kulian112d0562016-03-08 10:44:22 -08001541 { "nativeToggleCapsLock", "(JI)V",
1542 (void*) nativeToggleCapsLock },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001543 { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001544 (void*) nativeSetInputWindows },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001545 { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001546 (void*) nativeSetFocusedApplication },
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -08001547 { "nativeSetPointerCapture", "(JZ)V",
1548 (void*) nativeSetPointerCapture },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001549 { "nativeSetInputDispatchMode", "(JZZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001550 (void*) nativeSetInputDispatchMode },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001551 { "nativeSetSystemUiVisibility", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001552 (void*) nativeSetSystemUiVisibility },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001553 { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001554 (void*) nativeTransferTouchFocus },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001555 { "nativeSetPointerSpeed", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001556 (void*) nativeSetPointerSpeed },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001557 { "nativeSetShowTouches", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001558 (void*) nativeSetShowTouches },
Jeff Brown037c33e2014-04-09 00:31:55 -07001559 { "nativeSetInteractive", "(JZ)V",
1560 (void*) nativeSetInteractive },
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001561 { "nativeReloadCalibration", "(J)V",
1562 (void*) nativeReloadCalibration },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001563 { "nativeVibrate", "(JI[JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001564 (void*) nativeVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001565 { "nativeCancelVibrate", "(JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001566 (void*) nativeCancelVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001567 { "nativeReloadKeyboardLayouts", "(J)V",
Jeff Brown6ec6f792012-04-17 16:52:41 -07001568 (void*) nativeReloadKeyboardLayouts },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001569 { "nativeReloadDeviceAliases", "(J)V",
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001570 (void*) nativeReloadDeviceAliases },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001571 { "nativeDump", "(J)Ljava/lang/String;",
Jeff Brown4532e612012-04-05 14:27:12 -07001572 (void*) nativeDump },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001573 { "nativeMonitor", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001574 (void*) nativeMonitor },
Michael Wrighte051f6f2016-05-13 17:44:16 +01001575 { "nativeSetPointerIconType", "(JI)V",
1576 (void*) nativeSetPointerIconType },
Jun Mukai19a56012015-11-24 11:25:52 -08001577 { "nativeReloadPointerIcons", "(J)V",
1578 (void*) nativeReloadPointerIcons },
Jun Mukaid4eaef72015-10-30 15:54:33 -07001579 { "nativeSetCustomPointerIcon", "(JLandroid/view/PointerIcon;)V",
1580 (void*) nativeSetCustomPointerIcon },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001581};
1582
1583#define FIND_CLASS(var, className) \
1584 var = env->FindClass(className); \
Chih-Hung Hsieh6c896162016-05-19 15:29:38 -07001585 LOG_FATAL_IF(! (var), "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001586
1587#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1588 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
Chih-Hung Hsieh6c896162016-05-19 15:29:38 -07001589 LOG_FATAL_IF(! (var), "Unable to find method " methodName);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001590
1591#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1592 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
Chih-Hung Hsieh6c896162016-05-19 15:29:38 -07001593 LOG_FATAL_IF(! (var), "Unable to find field " fieldName);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001594
1595int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001596 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001597 gInputManagerMethods, NELEM(gInputManagerMethods));
Bernhard Rosenkränzer9c1c90e2014-11-12 14:45:58 +01001598 (void) res; // Faked use when LOG_NDEBUG.
Jeff Brown46b9ac02010-04-22 18:58:52 -07001599 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1600
Jeff Brown9c3cda02010-06-15 01:31:58 -07001601 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001602
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001603 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001604 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001605
Jeff Brown4532e612012-04-05 14:27:12 -07001606 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001607 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001608
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001609 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1610 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1611
Jeff Brown53384282012-08-20 20:16:01 -07001612 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1613 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001614
Jeff Brown4532e612012-04-05 14:27:12 -07001615 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1616 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001617
Jeff Brown4532e612012-04-05 14:27:12 -07001618 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001619 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001620 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001621
Jeff Brown4532e612012-04-05 14:27:12 -07001622 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001623 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1624
Jeff Brown4532e612012-04-05 14:27:12 -07001625 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown037c33e2014-04-09 00:31:55 -07001626 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001627
Michael Wright70af00a2014-09-03 19:30:20 -07001628 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz,
1629 "interceptMotionBeforeQueueingNonInteractive", "(JI)I");
Jeff Brown56194eb2011-03-02 19:23:13 -08001630
Jeff Brown4532e612012-04-05 14:27:12 -07001631 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001632 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001633 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001634
Jeff Brown4532e612012-04-05 14:27:12 -07001635 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001636 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001637 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001638
Jeff Brown4532e612012-04-05 14:27:12 -07001639 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001640 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001641
Jeff Brown4532e612012-04-05 14:27:12 -07001642 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001643 "getVirtualKeyQuietTimeMillis", "()I");
1644
Jeff Brown4532e612012-04-05 14:27:12 -07001645 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001646 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1647
Jeff Brown4532e612012-04-05 14:27:12 -07001648 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001649 "getKeyRepeatTimeout", "()I");
1650
Jeff Brown4532e612012-04-05 14:27:12 -07001651 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001652 "getKeyRepeatDelay", "()I");
1653
Jeff Brown4532e612012-04-05 14:27:12 -07001654 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001655 "getHoverTapTimeout", "()I");
1656
Jeff Brown4532e612012-04-05 14:27:12 -07001657 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001658 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001659
Jeff Brown4532e612012-04-05 14:27:12 -07001660 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001661 "getDoubleTapTimeout", "()I");
1662
Jeff Brown4532e612012-04-05 14:27:12 -07001663 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001664 "getLongPressTimeout", "()I");
1665
Jeff Brown4532e612012-04-05 14:27:12 -07001666 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001667 "getPointerLayer", "()I");
1668
Jeff Brown4532e612012-04-05 14:27:12 -07001669 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001670 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001671
Jeff Brown6ec6f792012-04-17 16:52:41 -07001672 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
RoboErikfb290df2013-12-16 11:27:55 -08001673 "getKeyboardLayoutOverlay",
1674 "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
Jeff Brown6ec6f792012-04-17 16:52:41 -07001675
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001676 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1677 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1678
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001679 GET_METHOD_ID(gServiceClassInfo.getTouchCalibrationForInputDevice, clazz,
1680 "getTouchCalibrationForInputDevice",
Jason Gerecked5220742014-03-10 09:47:59 -07001681 "(Ljava/lang/String;I)Landroid/hardware/input/TouchCalibration;");
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001682
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001683 // InputDevice
1684
1685 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1686 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1687
Jeff Brown6ec402b2010-07-28 15:48:59 -07001688 // KeyEvent
1689
1690 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001691 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1692
Jeff Brown8d608662010-08-30 03:02:23 -07001693 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001694
1695 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001696 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001697
RoboErikfb290df2013-12-16 11:27:55 -08001698 // InputDeviceIdentifier
1699
1700 FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
1701 gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
1702 GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
1703 "<init>", "(Ljava/lang/String;II)V");
1704
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001705 // TouchCalibration
1706
1707 FIND_CLASS(gTouchCalibrationClassInfo.clazz, "android/hardware/input/TouchCalibration");
1708 gTouchCalibrationClassInfo.clazz = jclass(env->NewGlobalRef(gTouchCalibrationClassInfo.clazz));
1709
1710 GET_METHOD_ID(gTouchCalibrationClassInfo.getAffineTransform, gTouchCalibrationClassInfo.clazz,
1711 "getAffineTransform", "()[F");
1712
Jeff Brown46b9ac02010-04-22 18:58:52 -07001713 return 0;
1714}
1715
Jeff Brown46b9ac02010-04-22 18:58:52 -07001716} /* namespace android */