blob: 8baa96bf9bae6d62a1a18e30ac18f6d36be022f0 [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) {
Jun Mukai808196f2015-10-28 16:46:44 -0700160 outPointerIcon->bitmap.copyTo(&outSpriteIcon->bitmap, kN32_SkColorType);
161 outSpriteIcon->hotSpotX = outPointerIcon->hotSpotX;
162 outSpriteIcon->hotSpotY = outPointerIcon->hotSpotY;
Jeff Brown2352b972011-04-12 22:39:53 -0700163 }
164}
165
Jun Mukai808196f2015-10-28 16:46:44 -0700166static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
167 SpriteIcon* outSpriteIcon) {
168 PointerIcon pointerIcon;
169 loadSystemIconAsSpriteWithPointerIcon(env, contextObj, style, &pointerIcon, outSpriteIcon);
170}
171
Jeff Brown905805a2011-10-12 13:57:59 -0700172enum {
173 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown905805a2011-10-12 13:57:59 -0700174};
175
Jeff Brown928e0542011-01-10 11:17:36 -0800176
177// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800178
Jeff Brown9c3cda02010-06-15 01:31:58 -0700179class NativeInputManager : public virtual RefBase,
180 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700181 public virtual InputDispatcherPolicyInterface,
182 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700183protected:
184 virtual ~NativeInputManager();
185
186public:
Jeff Brown4532e612012-04-05 14:27:12 -0700187 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700188
189 inline sp<InputManager> getInputManager() const { return mInputManager; }
190
Jeff Brownb88102f2010-09-08 11:49:43 -0700191 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700192
Jeff Brownd728bf52012-09-08 18:05:28 -0700193 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194
Jeff Brown7fbdc842010-06-17 20:52:56 -0700195 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800196 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700197 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
198
Jeff Brown9302c872011-07-13 22:51:29 -0700199 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
200 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700201 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800202 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700203 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700204 void setShowTouches(bool enabled);
Jeff Brown037c33e2014-04-09 00:31:55 -0700205 void setInteractive(bool interactive);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800206 void reloadCalibration();
Michael Wrighte051f6f2016-05-13 17:44:16 +0100207 void setPointerIconType(int32_t iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800208 void reloadPointerIcons();
Jun Mukaid4eaef72015-10-30 15:54:33 -0700209 void setCustomPointerIcon(const SpriteIcon& icon);
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800210 void setPointerCapture(bool enabled);
Jeff Brown349703e2010-06-22 01:27:15 -0700211
Jeff Brown9c3cda02010-06-15 01:31:58 -0700212 /* --- InputReaderPolicyInterface implementation --- */
213
Jeff Brown214eaf42011-05-26 19:17:02 -0700214 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800215 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700216 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
RoboErikfb290df2013-12-16 11:27:55 -0800217 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700218 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jason Gerecked5220742014-03-10 09:47:59 -0700219 virtual TouchAffineTransformation getTouchAffineTransformation(JNIEnv *env,
220 jfloatArray matrixArr);
221 virtual TouchAffineTransformation getTouchAffineTransformation(
222 const String8& inputDeviceDescriptor, int32_t surfaceRotation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700223
224 /* --- InputDispatcherPolicyInterface implementation --- */
225
Jeff Brownbcc046a2012-09-27 20:46:43 -0700226 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700227 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700228 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700229 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700230 const sp<InputWindowHandle>& inputWindowHandle,
231 const String8& reason);
Jeff Brown928e0542011-01-10 11:17:36 -0800232 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700233 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700234 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
Jeff Brown1f245102010-11-18 20:53:46 -0800235 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800236 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700237 virtual nsecs_t interceptKeyBeforeDispatching(
238 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700239 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800240 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800241 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700242 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700243 virtual bool checkInjectEventsPermissionNonReentrant(
244 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700245
Jeff Brown2352b972011-04-12 22:39:53 -0700246 /* --- PointerControllerPolicyInterface implementation --- */
247
Jun Mukai19a56012015-11-24 11:25:52 -0800248 virtual void loadPointerIcon(SpriteIcon* icon);
Jeff Brown2352b972011-04-12 22:39:53 -0700249 virtual void loadPointerResources(PointerResources* outResources);
Jun Mukai808196f2015-10-28 16:46:44 -0700250 virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
251 std::map<int32_t, PointerAnimation>* outAnimationResources);
Jun Mukai5ec74202015-10-07 16:58:09 +0900252 virtual int32_t getDefaultPointerIconId();
Jun Mukaid4eaef72015-10-30 15:54:33 -0700253 virtual int32_t getCustomPointerIconId();
Jeff Brown2352b972011-04-12 22:39:53 -0700254
Jeff Brown9c3cda02010-06-15 01:31:58 -0700255private:
256 sp<InputManager> mInputManager;
257
Jeff Brown2352b972011-04-12 22:39:53 -0700258 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700259 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800260 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700261
Jeff Brown83c09682010-12-23 17:50:18 -0800262 Mutex mLock;
263 struct Locked {
264 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700265 DisplayViewport internalViewport;
266 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800267
Jeff Brown05dc66a2011-03-02 14:41:58 -0800268 // System UI visibility.
269 int32_t systemUiVisibility;
270
Jeff Brown1a84fd12011-06-02 01:26:32 -0700271 // Pointer speed.
272 int32_t pointerSpeed;
273
Jeff Brown474dcb52011-06-14 20:22:50 -0700274 // True if pointer gestures are enabled.
275 bool pointerGesturesEnabled;
276
Jeff Browndaf4a122011-08-26 17:14:14 -0700277 // Show touches feature enable/disable.
278 bool showTouches;
279
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800280 // Pointer capture feature enable/disable.
281 bool pointerCapture;
282
Jeff Brown5541de92011-04-11 11:54:25 -0700283 // Sprite controller singleton, created on first use.
284 sp<SpriteController> spriteController;
285
Jeff Brown83c09682010-12-23 17:50:18 -0800286 // Pointer controller singleton, created and destroyed as needed.
287 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800288 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700289
Michael Wrighta4051212015-07-23 17:04:40 +0100290 std::atomic<bool> mInteractive;
Jeff Brown037c33e2014-04-09 00:31:55 -0700291
Jeff Brown2352b972011-04-12 22:39:53 -0700292 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800293 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700294 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800295
Jeff Brownb88102f2010-09-08 11:49:43 -0700296 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700297
Jeff Brown9c3cda02010-06-15 01:31:58 -0700298 static inline JNIEnv* jniEnv() {
299 return AndroidRuntime::getJNIEnv();
300 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700301};
302
Jeff Brown928e0542011-01-10 11:17:36 -0800303
Jeff Brown9c3cda02010-06-15 01:31:58 -0700304
Jeff Brown2352b972011-04-12 22:39:53 -0700305NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700306 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown037c33e2014-04-09 00:31:55 -0700307 mLooper(looper), mInteractive(true) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700308 JNIEnv* env = jniEnv();
309
Jeff Brown2352b972011-04-12 22:39:53 -0700310 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700311 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700312
Jeff Brown83c09682010-12-23 17:50:18 -0800313 {
314 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800315 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700316 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700317 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700318 mLocked.showTouches = false;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800319 mLocked.pointerCapture = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800320 }
Michael Wrighta4051212015-07-23 17:04:40 +0100321 mInteractive = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800322
Jeff Brown9c3cda02010-06-15 01:31:58 -0700323 sp<EventHub> eventHub = new EventHub();
324 mInputManager = new InputManager(eventHub, this, this);
325}
326
327NativeInputManager::~NativeInputManager() {
328 JNIEnv* env = jniEnv();
329
Jeff Brown2352b972011-04-12 22:39:53 -0700330 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700331 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700332}
333
Jeff Brownb88102f2010-09-08 11:49:43 -0700334void NativeInputManager::dump(String8& dump) {
Michael Wrighta4051212015-07-23 17:04:40 +0100335 dump.append("Input Manager State:\n");
336 {
337 dump.appendFormat(INDENT "Interactive: %s\n", toString(mInteractive.load()));
338 }
339 {
340 AutoMutex _l(mLock);
341 dump.appendFormat(INDENT "System UI Visibility: 0x%0" PRIx32 "\n",
342 mLocked.systemUiVisibility);
343 dump.appendFormat(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed);
344 dump.appendFormat(INDENT "Pointer Gestures Enabled: %s\n",
345 toString(mLocked.pointerGesturesEnabled));
346 dump.appendFormat(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800347 dump.appendFormat(INDENT "Pointer Capture Enabled: %s\n", toString(mLocked.pointerCapture));
Michael Wrighta4051212015-07-23 17:04:40 +0100348 }
349 dump.append("\n");
350
Jeff Brownb88102f2010-09-08 11:49:43 -0700351 mInputManager->getReader()->dump(dump);
352 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700353
Jeff Brownb88102f2010-09-08 11:49:43 -0700354 mInputManager->getDispatcher()->dump(dump);
355 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700356}
357
Jeff Brown7fbdc842010-06-17 20:52:56 -0700358bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700359 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000360 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700361 LOGE_EX(env);
362 env->ExceptionClear();
363 return true;
364 }
365 return false;
366}
367
Jeff Brownd728bf52012-09-08 18:05:28 -0700368void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700369 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700370 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700371 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700372
Jeff Brownd728bf52012-09-08 18:05:28 -0700373 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
374 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700375 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700376 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700377
Jeff Brownd728bf52012-09-08 18:05:28 -0700378 if (!external) {
379 sp<PointerController> controller = mLocked.pointerController.promote();
380 if (controller != NULL) {
381 controller->setDisplayViewport(
382 viewport.logicalRight - viewport.logicalLeft,
383 viewport.logicalBottom - viewport.logicalTop,
384 viewport.orientation);
385 }
Jeff Brown2352b972011-04-12 22:39:53 -0700386 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700387 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700388 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700389
390 if (changed) {
391 mInputManager->getReader()->requestRefreshConfiguration(
392 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
393 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700394}
395
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700396status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
Jeff Brown928e0542011-01-10 11:17:36 -0800397 const sp<InputChannel>& inputChannel,
398 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
399 return mInputManager->getDispatcher()->registerInputChannel(
400 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700401}
402
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700403status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700404 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700405 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700406}
407
Jeff Brown214eaf42011-05-26 19:17:02 -0700408void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700409 JNIEnv* env = jniEnv();
410
Jeff Brown4532e612012-04-05 14:27:12 -0700411 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
412 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700413 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
414 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
415 }
416
417 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700418 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
419 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700420 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
421 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700422 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700423 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700424 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700425 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700426 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700427 env->DeleteLocalRef(item);
428 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700429 env->DeleteLocalRef(excludedDeviceNames);
430 }
431
Jeff Brown4532e612012-04-05 14:27:12 -0700432 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
433 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700434 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700435 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
436 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700437 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700438 jint longPressTimeout = env->CallIntMethod(mServiceObj,
439 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700440 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700441 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700442
443 // We must ensure that the tap-drag interval is significantly shorter than
444 // the long-press timeout because the tap is held down for the entire duration
445 // of the double-tap timeout.
446 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700447 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700448 outConfig->pointerGestureTapDragInterval =
449 milliseconds_to_nanoseconds(tapDragInterval);
450 }
451 }
452 }
453
Jeff Brown4532e612012-04-05 14:27:12 -0700454 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
455 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700456 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
457 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700458 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700459
460 { // acquire lock
461 AutoMutex _l(mLock);
462
463 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
464 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700465 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700466
Jeff Browndaf4a122011-08-26 17:14:14 -0700467 outConfig->showTouches = mLocked.showTouches;
468
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800469 outConfig->pointerCapture = mLocked.pointerCapture;
470
Jeff Brownd728bf52012-09-08 18:05:28 -0700471 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
472 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700473 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700474}
475
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700476sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t /* deviceId */) {
Jeff Brown83c09682010-12-23 17:50:18 -0800477 AutoMutex _l(mLock);
478
479 sp<PointerController> controller = mLocked.pointerController.promote();
480 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700481 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800482
Jeff Brown2352b972011-04-12 22:39:53 -0700483 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800484 mLocked.pointerController = controller;
485
Jeff Brownd728bf52012-09-08 18:05:28 -0700486 DisplayViewport& v = mLocked.internalViewport;
487 controller->setDisplayViewport(
488 v.logicalRight - v.logicalLeft,
489 v.logicalBottom - v.logicalTop,
490 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800491
Jeff Brown2352b972011-04-12 22:39:53 -0700492 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800493 }
494 return controller;
495}
496
Jeff Brown5541de92011-04-11 11:54:25 -0700497void NativeInputManager::ensureSpriteControllerLocked() {
498 if (mLocked.spriteController == NULL) {
499 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700500 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700501 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
502 layer = -1;
503 }
504 mLocked.spriteController = new SpriteController(mLooper, layer);
505 }
506}
507
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700508void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
509 JNIEnv* env = jniEnv();
510
511 size_t count = inputDevices.size();
512 jobjectArray inputDevicesObjArray = env->NewObjectArray(
513 count, gInputDeviceClassInfo.clazz, NULL);
514 if (inputDevicesObjArray) {
515 bool error = false;
516 for (size_t i = 0; i < count; i++) {
517 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
518 if (!inputDeviceObj) {
519 error = true;
520 break;
521 }
522
523 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
524 env->DeleteLocalRef(inputDeviceObj);
525 }
526
527 if (!error) {
528 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
529 inputDevicesObjArray);
530 }
531
532 env->DeleteLocalRef(inputDevicesObjArray);
533 }
534
535 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
536}
537
Jeff Brown6ec6f792012-04-17 16:52:41 -0700538sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
RoboErikfb290df2013-12-16 11:27:55 -0800539 const InputDeviceIdentifier& identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700540 JNIEnv* env = jniEnv();
541
542 sp<KeyCharacterMap> result;
RoboErikfb290df2013-12-16 11:27:55 -0800543 ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
544 ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
545 gInputDeviceIdentifierInfo.constructor, descriptor.get(),
546 identifier.vendor, identifier.product));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700547 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
RoboErikfb290df2013-12-16 11:27:55 -0800548 gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700549 if (arrayObj.get()) {
550 ScopedLocalRef<jstring> filenameObj(env,
551 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
552 ScopedLocalRef<jstring> contentsObj(env,
553 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
554 ScopedUtfChars filenameChars(env, filenameObj.get());
555 ScopedUtfChars contentsChars(env, contentsObj.get());
556
557 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
558 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
559 }
560 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
561 return result;
562}
563
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700564String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
565 JNIEnv* env = jniEnv();
566
567 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
568 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
569 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
570 String8 result;
571 if (aliasObj.get()) {
572 ScopedUtfChars aliasChars(env, aliasObj.get());
573 result.setTo(aliasChars.c_str());
574 }
575 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
576 return result;
577}
578
Jeff Brownbcc046a2012-09-27 20:46:43 -0700579void NativeInputManager::notifySwitch(nsecs_t when,
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700580 uint32_t switchValues, uint32_t switchMask, uint32_t /* policyFlags */) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700581#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700582 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
583 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700584#endif
585
586 JNIEnv* env = jniEnv();
587
Jeff Brown53384282012-08-20 20:16:01 -0700588 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700589 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700590 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700591}
592
Jeff Brown9c3cda02010-06-15 01:31:58 -0700593void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
594#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000595 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700596#endif
597
598 JNIEnv* env = jniEnv();
599
Jeff Brown4532e612012-04-05 14:27:12 -0700600 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700601 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700602}
603
Jeff Brown519e0242010-09-15 15:18:56 -0700604nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700605 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700606#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000607 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700608#endif
609
610 JNIEnv* env = jniEnv();
611
Jeff Brown928e0542011-01-10 11:17:36 -0800612 jobject inputApplicationHandleObj =
613 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
614 jobject inputWindowHandleObj =
615 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownbd181bb2013-09-10 16:44:24 -0700616 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700617
Jeff Brown4532e612012-04-05 14:27:12 -0700618 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700619 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
620 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700621 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
622 newTimeout = 0; // abort dispatch
623 } else {
624 assert(newTimeout >= 0);
625 }
626
Jeff Brownbd181bb2013-09-10 16:44:24 -0700627 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800628 env->DeleteLocalRef(inputWindowHandleObj);
629 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700630 return newTimeout;
631}
632
Jeff Brown928e0542011-01-10 11:17:36 -0800633void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700634#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000635 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700636#endif
637
Jeff Brown7fbdc842010-06-17 20:52:56 -0700638 JNIEnv* env = jniEnv();
639
Jeff Brown928e0542011-01-10 11:17:36 -0800640 jobject inputWindowHandleObj =
641 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
642 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700643 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800644 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700645 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
646
Jeff Brown928e0542011-01-10 11:17:36 -0800647 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700648 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700649}
650
Jeff Brown214eaf42011-05-26 19:17:02 -0700651void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
652 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800653
Jeff Brown4532e612012-04-05 14:27:12 -0700654 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
655 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700656 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
657 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
658 }
Jeff Browna4547672011-03-02 21:38:11 -0800659
Jeff Brown4532e612012-04-05 14:27:12 -0700660 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
661 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700662 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
663 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
664 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700665}
666
Jeff Brown9302c872011-07-13 22:51:29 -0700667void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
668 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700669
Jeff Brown9302c872011-07-13 22:51:29 -0700670 if (windowHandleObjArray) {
671 jsize length = env->GetArrayLength(windowHandleObjArray);
672 for (jsize i = 0; i < length; i++) {
673 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
674 if (! windowHandleObj) {
675 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700676 }
Jeff Brown9302c872011-07-13 22:51:29 -0700677
678 sp<InputWindowHandle> windowHandle =
679 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
680 if (windowHandle != NULL) {
681 windowHandles.push(windowHandle);
682 }
683 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700684 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700685 }
Jeff Brown349703e2010-06-22 01:27:15 -0700686
Jeff Brown9302c872011-07-13 22:51:29 -0700687 mInputManager->getDispatcher()->setInputWindows(windowHandles);
688
689 // Do this after the dispatcher has updated the window handle state.
690 bool newPointerGesturesEnabled = true;
691 size_t numWindows = windowHandles.size();
692 for (size_t i = 0; i < numWindows; i++) {
693 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700694 const InputWindowInfo* windowInfo = windowHandle->getInfo();
695 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
696 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700697 newPointerGesturesEnabled = false;
698 }
699 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700700
701 uint32_t changes = 0;
702 { // acquire lock
703 AutoMutex _l(mLock);
704
705 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
706 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
707 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
708 }
709 } // release lock
710
711 if (changes) {
712 mInputManager->getReader()->requestRefreshConfiguration(changes);
713 }
Jeff Brown349703e2010-06-22 01:27:15 -0700714}
715
Jeff Brown9302c872011-07-13 22:51:29 -0700716void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
717 sp<InputApplicationHandle> applicationHandle =
718 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
719 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700720}
721
722void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700723 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700724}
725
Jeff Brown05dc66a2011-03-02 14:41:58 -0800726void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
727 AutoMutex _l(mLock);
728
729 if (mLocked.systemUiVisibility != visibility) {
730 mLocked.systemUiVisibility = visibility;
731
732 sp<PointerController> controller = mLocked.pointerController.promote();
733 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700734 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800735 }
736 }
737}
738
Jeff Brown2352b972011-04-12 22:39:53 -0700739void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800740 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700741 controller->setInactivityTimeout(lightsOut
742 ? PointerController::INACTIVITY_TIMEOUT_SHORT
743 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800744}
745
Jeff Brown1a84fd12011-06-02 01:26:32 -0700746void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700747 { // acquire lock
748 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700749
Jeff Brown474dcb52011-06-14 20:22:50 -0700750 if (mLocked.pointerSpeed == speed) {
751 return;
752 }
753
Steve Block6215d3f2012-01-04 20:05:49 +0000754 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700755 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700756 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700757
Jeff Brown474dcb52011-06-14 20:22:50 -0700758 mInputManager->getReader()->requestRefreshConfiguration(
759 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700760}
761
Jeff Browndaf4a122011-08-26 17:14:14 -0700762void NativeInputManager::setShowTouches(bool enabled) {
763 { // acquire lock
764 AutoMutex _l(mLock);
765
766 if (mLocked.showTouches == enabled) {
767 return;
768 }
769
Steve Block6215d3f2012-01-04 20:05:49 +0000770 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700771 mLocked.showTouches = enabled;
772 } // release lock
773
774 mInputManager->getReader()->requestRefreshConfiguration(
775 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
776}
777
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800778void NativeInputManager::setPointerCapture(bool enabled) {
779 { // acquire lock
780 AutoMutex _l(mLock);
781
782 if (mLocked.pointerCapture == enabled) {
783 return;
784 }
785
786 ALOGI("Setting pointer capture to %s.", enabled ? "enabled" : "disabled");
787 mLocked.pointerCapture = enabled;
788 } // release lock
789
790 mInputManager->getReader()->requestRefreshConfiguration(
791 InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
792}
793
Jeff Brown037c33e2014-04-09 00:31:55 -0700794void NativeInputManager::setInteractive(bool interactive) {
795 mInteractive = interactive;
Jeff Browne20c9e02010-10-11 14:20:19 -0700796}
797
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800798void NativeInputManager::reloadCalibration() {
799 mInputManager->getReader()->requestRefreshConfiguration(
Michael Wright357285c2015-04-17 00:50:31 +0100800 InputReaderConfiguration::CHANGE_TOUCH_AFFINE_TRANSFORMATION);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800801}
802
Michael Wrighte051f6f2016-05-13 17:44:16 +0100803void NativeInputManager::setPointerIconType(int32_t iconId) {
Jun Mukai19a56012015-11-24 11:25:52 -0800804 AutoMutex _l(mLock);
805 sp<PointerController> controller = mLocked.pointerController.promote();
806 if (controller != NULL) {
Michael Wrighte051f6f2016-05-13 17:44:16 +0100807 controller->updatePointerIcon(iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800808 }
809}
810
811void NativeInputManager::reloadPointerIcons() {
812 AutoMutex _l(mLock);
813 sp<PointerController> controller = mLocked.pointerController.promote();
814 if (controller != NULL) {
815 controller->reloadPointerResources();
816 }
Jun Mukai1db53972015-09-11 18:08:31 -0700817}
818
Jun Mukaid4eaef72015-10-30 15:54:33 -0700819void NativeInputManager::setCustomPointerIcon(const SpriteIcon& icon) {
820 AutoMutex _l(mLock);
821 sp<PointerController> controller = mLocked.pointerController.promote();
822 if (controller != NULL) {
823 controller->setCustomPointerIcon(icon);
824 }
825}
826
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800827TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
828 JNIEnv *env, jfloatArray matrixArr) {
829 ScopedFloatArrayRO matrix(env, matrixArr);
830 assert(matrix.size() == 6);
831
832 TouchAffineTransformation transform;
833 transform.x_scale = matrix[0];
834 transform.x_ymix = matrix[1];
835 transform.x_offset = matrix[2];
836 transform.y_xmix = matrix[3];
837 transform.y_scale = matrix[4];
838 transform.y_offset = matrix[5];
839
840 return transform;
841}
842
843TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
Jason Gerecked5220742014-03-10 09:47:59 -0700844 const String8& inputDeviceDescriptor, int32_t surfaceRotation) {
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800845 JNIEnv* env = jniEnv();
846
847 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
848
849 jobject cal = env->CallObjectMethod(mServiceObj,
Jason Gerecked5220742014-03-10 09:47:59 -0700850 gServiceClassInfo.getTouchCalibrationForInputDevice, descriptorObj.get(),
851 surfaceRotation);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800852
853 jfloatArray matrixArr = jfloatArray(env->CallObjectMethod(cal,
854 gTouchCalibrationClassInfo.getAffineTransform));
855
856 TouchAffineTransformation transform = getTouchAffineTransformation(env, matrixArr);
857
858 env->DeleteLocalRef(matrixArr);
859 env->DeleteLocalRef(cal);
860
861 return transform;
862}
863
Jeff Brown0029c662011-03-30 02:25:18 -0700864bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
865 jobject inputEventObj;
866
867 JNIEnv* env = jniEnv();
868 switch (inputEvent->getType()) {
869 case AINPUT_EVENT_TYPE_KEY:
870 inputEventObj = android_view_KeyEvent_fromNative(env,
871 static_cast<const KeyEvent*>(inputEvent));
872 break;
873 case AINPUT_EVENT_TYPE_MOTION:
874 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
875 static_cast<const MotionEvent*>(inputEvent));
876 break;
877 default:
878 return true; // dispatch the event normally
879 }
880
881 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000882 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700883 return true; // dispatch the event normally
884 }
885
886 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700887 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700888 inputEventObj, policyFlags);
889 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
890 pass = true;
891 }
892 env->DeleteLocalRef(inputEventObj);
893 return pass;
894}
895
Jeff Brown1f245102010-11-18 20:53:46 -0800896void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
897 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700898 // Policy:
899 // - Ignore untrusted events and pass them along.
900 // - Ask the window manager what to do with normal events and trusted injected events.
901 // - For normal events wake and brighten the screen if currently off or dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100902 bool interactive = mInteractive.load();
903 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700904 policyFlags |= POLICY_FLAG_INTERACTIVE;
905 }
Jeff Brown3122e442010-10-11 23:32:49 -0700906 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800907 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700908 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800909 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
910 jint wmActions;
911 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700912 wmActions = env->CallIntMethod(mServiceObj,
913 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown037c33e2014-04-09 00:31:55 -0700914 keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800915 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
916 wmActions = 0;
917 }
918 android_view_KeyEvent_recycle(env, keyEventObj);
919 env->DeleteLocalRef(keyEventObj);
920 } else {
Steve Block3762c312012-01-06 19:20:56 +0000921 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700922 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700923 }
924
Jeff Brown56194eb2011-03-02 19:23:13 -0800925 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700926 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100927 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700928 policyFlags |= POLICY_FLAG_PASS_TO_USER;
929 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700930 }
931}
932
Jeff Brown56194eb2011-03-02 19:23:13 -0800933void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700934 // Policy:
935 // - Ignore untrusted events and pass them along.
936 // - No special filtering for injected events required at this time.
937 // - Filter normal events based on screen state.
938 // - For normal events brighten (but do not wake) the screen if currently dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100939 bool interactive = mInteractive.load();
940 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700941 policyFlags |= POLICY_FLAG_INTERACTIVE;
942 }
Jeff Brown3122e442010-10-11 23:32:49 -0700943 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700944 if (policyFlags & POLICY_FLAG_INTERACTIVE) {
Jeff Brown3122e442010-10-11 23:32:49 -0700945 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Michael Wright70af00a2014-09-03 19:30:20 -0700946 } else {
Jeff Brown56194eb2011-03-02 19:23:13 -0800947 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700948 jint wmActions = env->CallIntMethod(mServiceObj,
Michael Wright70af00a2014-09-03 19:30:20 -0700949 gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive,
Jeff Brown26875502014-01-30 21:47:47 -0800950 when, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800951 if (checkAndClearExceptionFromCallback(env,
Michael Wright70af00a2014-09-03 19:30:20 -0700952 "interceptMotionBeforeQueueingNonInteractive")) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800953 wmActions = 0;
954 }
955
Jeff Brown56194eb2011-03-02 19:23:13 -0800956 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700957 }
Jeff Brown3122e442010-10-11 23:32:49 -0700958 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100959 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700960 policyFlags |= POLICY_FLAG_PASS_TO_USER;
961 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700962 }
963}
964
Jeff Brown56194eb2011-03-02 19:23:13 -0800965void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
966 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800967 if (wmActions & WM_ACTION_PASS_TO_USER) {
968 policyFlags |= POLICY_FLAG_PASS_TO_USER;
969 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800970#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000971 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800972#endif
973 }
974}
975
Jeff Brown905805a2011-10-12 13:57:59 -0700976nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800977 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700978 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700979 // Policy:
980 // - Ignore untrusted events and pass them along.
981 // - Filter normal events and trusted injected events through the window manager policy to
982 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700983 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700984 if (policyFlags & POLICY_FLAG_TRUSTED) {
985 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700986
Jeff Brown928e0542011-01-10 11:17:36 -0800987 // Note: inputWindowHandle may be null.
988 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800989 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
990 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700991 jlong delayMillis = env->CallLongMethod(mServiceObj,
992 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800993 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800994 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
995 android_view_KeyEvent_recycle(env, keyEventObj);
996 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700997 if (!error) {
998 if (delayMillis < 0) {
999 result = -1;
1000 } else if (delayMillis > 0) {
1001 result = milliseconds_to_nanoseconds(delayMillis);
1002 }
1003 }
Jeff Brown1f245102010-11-18 20:53:46 -08001004 } else {
Steve Block3762c312012-01-06 19:20:56 +00001005 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -08001006 }
Jeff Brown928e0542011-01-10 11:17:36 -08001007 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -07001008 }
Jeff Brown1f245102010-11-18 20:53:46 -08001009 return result;
Jeff Brownd0097872010-06-30 14:41:59 -07001010}
1011
Jeff Brown928e0542011-01-10 11:17:36 -08001012bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001013 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -07001014 // Policy:
1015 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -08001016 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -07001017 if (policyFlags & POLICY_FLAG_TRUSTED) {
1018 JNIEnv* env = jniEnv();
1019
Jeff Brown928e0542011-01-10 11:17:36 -08001020 // Note: inputWindowHandle may be null.
1021 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -08001022 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
1023 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001024 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
1025 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -08001026 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001027 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
1028 fallbackKeyEventObj = NULL;
1029 }
Jeff Brown1f245102010-11-18 20:53:46 -08001030 android_view_KeyEvent_recycle(env, keyEventObj);
1031 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001032
1033 if (fallbackKeyEventObj) {
1034 // Note: outFallbackKeyEvent may be the same object as keyEvent.
1035 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
1036 outFallbackKeyEvent)) {
1037 result = true;
1038 }
1039 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
1040 env->DeleteLocalRef(fallbackKeyEventObj);
1041 }
Jeff Brown1f245102010-11-18 20:53:46 -08001042 } else {
Steve Block3762c312012-01-06 19:20:56 +00001043 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -08001044 }
Jeff Brown928e0542011-01-10 11:17:36 -08001045 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -07001046 }
Jeff Brown1f245102010-11-18 20:53:46 -08001047 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -07001048}
1049
Jeff Brown01ce2e92010-09-26 22:20:12 -07001050void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
1051 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -07001052}
1053
Jeff Brown349703e2010-06-22 01:27:15 -07001054
Jeff Brownb88102f2010-09-08 11:49:43 -07001055bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
1056 int32_t injectorPid, int32_t injectorUid) {
1057 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -07001058 jboolean result = env->CallBooleanMethod(mServiceObj,
1059 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001060 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
1061 result = false;
1062 }
Jeff Brown349703e2010-06-22 01:27:15 -07001063 return result;
1064}
1065
Jun Mukai19a56012015-11-24 11:25:52 -08001066void NativeInputManager::loadPointerIcon(SpriteIcon* icon) {
1067 JNIEnv* env = jniEnv();
1068
1069 ScopedLocalRef<jobject> pointerIconObj(env, env->CallObjectMethod(
1070 mServiceObj, gServiceClassInfo.getPointerIcon));
1071 if (checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
1072 return;
1073 }
1074
1075 PointerIcon pointerIcon;
1076 status_t status = android_view_PointerIcon_load(env, pointerIconObj.get(),
1077 mContextObj, &pointerIcon);
1078 if (!status && !pointerIcon.isNullIcon()) {
1079 *icon = SpriteIcon(pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY);
1080 } else {
1081 *icon = SpriteIcon();
1082 }
1083}
1084
Jeff Brown2352b972011-04-12 22:39:53 -07001085void NativeInputManager::loadPointerResources(PointerResources* outResources) {
1086 JNIEnv* env = jniEnv();
1087
1088 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
1089 &outResources->spotHover);
1090 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
1091 &outResources->spotTouch);
1092 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
1093 &outResources->spotAnchor);
1094}
1095
Jun Mukai808196f2015-10-28 16:46:44 -07001096void NativeInputManager::loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
1097 std::map<int32_t, PointerAnimation>* outAnimationResources) {
Jun Mukai1db53972015-09-11 18:08:31 -07001098 JNIEnv* env = jniEnv();
1099
1100 for (int iconId = POINTER_ICON_STYLE_CONTEXT_MENU; iconId <= POINTER_ICON_STYLE_GRABBING;
1101 ++iconId) {
Jun Mukai808196f2015-10-28 16:46:44 -07001102 PointerIcon pointerIcon;
1103 loadSystemIconAsSpriteWithPointerIcon(
1104 env, mContextObj, iconId, &pointerIcon, &((*outResources)[iconId]));
1105 if (!pointerIcon.bitmapFrames.empty()) {
1106 PointerAnimation& animationData = (*outAnimationResources)[iconId];
1107 size_t numFrames = pointerIcon.bitmapFrames.size() + 1;
1108 animationData.durationPerFrame =
1109 milliseconds_to_nanoseconds(pointerIcon.durationPerFrame);
1110 animationData.animationFrames.reserve(numFrames);
1111 animationData.animationFrames.push_back(SpriteIcon(
1112 pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1113 for (size_t i = 0; i < numFrames - 1; ++i) {
1114 animationData.animationFrames.push_back(SpriteIcon(
1115 pointerIcon.bitmapFrames[i], pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1116 }
1117 }
Jun Mukai1db53972015-09-11 18:08:31 -07001118 }
Jun Mukai808196f2015-10-28 16:46:44 -07001119 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_NULL,
1120 &((*outResources)[POINTER_ICON_STYLE_NULL]));
Jun Mukai1db53972015-09-11 18:08:31 -07001121}
1122
Jun Mukai5ec74202015-10-07 16:58:09 +09001123int32_t NativeInputManager::getDefaultPointerIconId() {
1124 return POINTER_ICON_STYLE_ARROW;
1125}
Jeff Brown83c09682010-12-23 17:50:18 -08001126
Jun Mukaid4eaef72015-10-30 15:54:33 -07001127int32_t NativeInputManager::getCustomPointerIconId() {
1128 return POINTER_ICON_STYLE_CUSTOM;
1129}
1130
Jeff Brown9c3cda02010-06-15 01:31:58 -07001131// ----------------------------------------------------------------------------
1132
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001133static jlong nativeInit(JNIEnv* env, jclass /* clazz */,
Jeff Brown4532e612012-04-05 14:27:12 -07001134 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -07001135 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -08001136 if (messageQueue == NULL) {
1137 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
1138 return 0;
1139 }
1140
Jeff Brown603b4452012-04-06 17:39:41 -07001141 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
1142 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -08001143 im->incStrong(0);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001144 return reinterpret_cast<jlong>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001145}
1146
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001147static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001148 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001149
Jeff Brown4532e612012-04-05 14:27:12 -07001150 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001151 if (result) {
1152 jniThrowRuntimeException(env, "Input manager could not be started.");
1153 }
1154}
1155
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001156static void nativeSetDisplayViewport(JNIEnv* /* env */, jclass /* clazz */, jlong ptr,
1157 jboolean external, jint displayId, jint orientation,
Jeff Brownd728bf52012-09-08 18:05:28 -07001158 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001159 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1160 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001161 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001162
Jeff Brownd728bf52012-09-08 18:05:28 -07001163 DisplayViewport v;
1164 v.displayId = displayId;
1165 v.orientation = orientation;
1166 v.logicalLeft = logicalLeft;
1167 v.logicalTop = logicalTop;
1168 v.logicalRight = logicalRight;
1169 v.logicalBottom = logicalBottom;
1170 v.physicalLeft = physicalLeft;
1171 v.physicalTop = physicalTop;
1172 v.physicalRight = physicalRight;
1173 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001174 v.deviceWidth = deviceWidth;
1175 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001176 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001177}
1178
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001179static jint nativeGetScanCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001180 jlong ptr, jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001181 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001182
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001183 return (jint) im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001184 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001185}
1186
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001187static jint nativeGetKeyCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001188 jlong ptr, jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001189 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001190
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001191 return (jint) im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001192 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001193}
1194
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001195static jint nativeGetSwitchState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001196 jlong ptr, jint deviceId, jint sourceMask, jint sw) {
Jeff Brown4532e612012-04-05 14:27:12 -07001197 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001198
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001199 return (jint) im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001200 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001201}
1202
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001203static jboolean nativeHasKeys(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001204 jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001205 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001206
1207 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1208 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1209 jsize numCodes = env->GetArrayLength(keyCodes);
1210 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001211 if (numCodes == env->GetArrayLength(keyCodes)) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001212 if (im->getInputManager()->getReader()->hasKeys(
1213 deviceId, uint32_t(sourceMask), numCodes, codes, flags)) {
1214 result = JNI_TRUE;
1215 } else {
1216 result = JNI_FALSE;
1217 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001218 } else {
1219 result = JNI_FALSE;
1220 }
1221
1222 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1223 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1224 return result;
1225}
1226
1227static void throwInputChannelNotInitialized(JNIEnv* env) {
1228 jniThrowException(env, "java/lang/IllegalStateException",
1229 "inputChannel is not initialized");
1230}
1231
Jeff Brown4532e612012-04-05 14:27:12 -07001232static void handleInputChannelDisposed(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001233 jobject /* inputChannelObj */, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001234 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1235
Steve Block8564c8d2012-01-05 23:22:43 +00001236 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001237 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001238 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001239}
1240
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001241static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001242 jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown4532e612012-04-05 14:27:12 -07001243 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001244
1245 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1246 inputChannelObj);
1247 if (inputChannel == NULL) {
1248 throwInputChannelNotInitialized(env);
1249 return;
1250 }
1251
Jeff Brown928e0542011-01-10 11:17:36 -08001252 sp<InputWindowHandle> inputWindowHandle =
1253 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001254
Jeff Brown4532e612012-04-05 14:27:12 -07001255 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001256 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001257 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001258 String8 message;
1259 message.appendFormat("Failed to register input channel. status=%d", status);
1260 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001261 return;
1262 }
1263
Jeff Browna41ca772010-08-11 14:46:32 -07001264 if (! monitor) {
1265 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001266 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001267 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001268}
1269
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001270static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001271 jlong ptr, jobject inputChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001272 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001273
1274 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1275 inputChannelObj);
1276 if (inputChannel == NULL) {
1277 throwInputChannelNotInitialized(env);
1278 return;
1279 }
1280
1281 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1282
Jeff Brown4532e612012-04-05 14:27:12 -07001283 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001284 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1285 String8 message;
1286 message.appendFormat("Failed to unregister input channel. status=%d", status);
1287 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001288 }
1289}
1290
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001291static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001292 jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001293 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001294
Jeff Brown4532e612012-04-05 14:27:12 -07001295 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001296}
1297
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001298static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
Jeff Brownca9bc702014-02-11 14:32:56 -08001299 jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001300 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001301 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001302
Jeff Brown6ec402b2010-07-28 15:48:59 -07001303 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1304 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001305 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1306 if (status) {
1307 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1308 return INPUT_EVENT_INJECTION_FAILED;
1309 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001310
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001311 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001312 & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001313 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001314 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001315 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1316 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001317 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1318 return INPUT_EVENT_INJECTION_FAILED;
1319 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001320
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001321 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001322 motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001323 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001324 } else {
1325 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001326 return INPUT_EVENT_INJECTION_FAILED;
1327 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001328}
1329
Andrii Kulian112d0562016-03-08 10:44:22 -08001330static void nativeToggleCapsLock(JNIEnv* env, jclass /* clazz */,
1331 jlong ptr, jint deviceId) {
1332 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1333 im->getInputManager()->getReader()->toggleCapsLockState(deviceId);
1334}
1335
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001336static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001337 jlong ptr, jobjectArray windowHandleObjArray) {
Jeff Brown4532e612012-04-05 14:27:12 -07001338 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001339
Jeff Brown4532e612012-04-05 14:27:12 -07001340 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001341}
1342
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001343static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001344 jlong ptr, jobject applicationHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001345 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001346
Jeff Brown4532e612012-04-05 14:27:12 -07001347 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001348}
1349
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -08001350static void nativeSetPointerCapture(JNIEnv* env, jclass /* clazz */, jlong ptr,
1351 jboolean enabled) {
1352 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1353 im->setPointerCapture(enabled);
1354}
1355
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001356static void nativeSetInputDispatchMode(JNIEnv* /* env */,
1357 jclass /* clazz */, jlong ptr, jboolean enabled, jboolean frozen) {
Jeff Brown4532e612012-04-05 14:27:12 -07001358 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001359
Jeff Brown4532e612012-04-05 14:27:12 -07001360 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001361}
1362
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001363static void nativeSetSystemUiVisibility(JNIEnv* /* env */,
1364 jclass /* clazz */, jlong ptr, jint visibility) {
Jeff Brown4532e612012-04-05 14:27:12 -07001365 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001366
Jeff Brown4532e612012-04-05 14:27:12 -07001367 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001368}
1369
Jeff Brown4532e612012-04-05 14:27:12 -07001370static jboolean nativeTransferTouchFocus(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001371 jclass /* clazz */, jlong ptr, jobject fromChannelObj, jobject toChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001372 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001373
1374 sp<InputChannel> fromChannel =
1375 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1376 sp<InputChannel> toChannel =
1377 android_view_InputChannel_getInputChannel(env, toChannelObj);
1378
1379 if (fromChannel == NULL || toChannel == NULL) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001380 return JNI_FALSE;
Jeff Browne6504122010-09-27 14:52:15 -07001381 }
1382
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001383 if (im->getInputManager()->getDispatcher()->
1384 transferTouchFocus(fromChannel, toChannel)) {
1385 return JNI_TRUE;
1386 } else {
1387 return JNI_FALSE;
1388 }
Jeff Browne6504122010-09-27 14:52:15 -07001389}
1390
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001391static void nativeSetPointerSpeed(JNIEnv* /* env */,
1392 jclass /* clazz */, jlong ptr, jint speed) {
Jeff Brown4532e612012-04-05 14:27:12 -07001393 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001394
Jeff Brown4532e612012-04-05 14:27:12 -07001395 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001396}
1397
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001398static void nativeSetShowTouches(JNIEnv* /* env */,
1399 jclass /* clazz */, jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001400 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001401
Jeff Brown4532e612012-04-05 14:27:12 -07001402 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001403}
1404
Jeff Brown037c33e2014-04-09 00:31:55 -07001405static void nativeSetInteractive(JNIEnv* env,
1406 jclass clazz, jlong ptr, jboolean interactive) {
1407 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1408
1409 im->setInteractive(interactive);
1410}
1411
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001412static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) {
1413 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1414 im->reloadCalibration();
1415}
1416
Jeff Browna47425a2012-04-13 04:09:27 -07001417static void nativeVibrate(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001418 jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj,
Jeff Browna47425a2012-04-13 04:09:27 -07001419 jint repeat, jint token) {
1420 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1421
1422 size_t patternSize = env->GetArrayLength(patternObj);
1423 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
Michael Wright9ecba522014-04-04 15:29:53 -07001424 ALOGI("Skipped requested vibration because the pattern size is %zu "
Jeff Browna47425a2012-04-13 04:09:27 -07001425 "which is more than the maximum supported size of %d.",
1426 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1427 return; // limit to reasonable size
1428 }
1429
1430 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1431 patternObj, NULL));
1432 nsecs_t pattern[patternSize];
1433 for (size_t i = 0; i < patternSize; i++) {
1434 pattern[i] = max(jlong(0), min(patternMillis[i],
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001435 (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL;
Jeff Browna47425a2012-04-13 04:09:27 -07001436 }
1437 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1438
1439 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1440}
1441
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001442static void nativeCancelVibrate(JNIEnv* /* env */,
1443 jclass /* clazz */, jlong ptr, jint deviceId, jint token) {
Jeff Browna47425a2012-04-13 04:09:27 -07001444 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1445
1446 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1447}
1448
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001449static void nativeReloadKeyboardLayouts(JNIEnv* /* env */,
1450 jclass /* clazz */, jlong ptr) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001451 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1452
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001453 im->getInputManager()->getReader()->requestRefreshConfiguration(
1454 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1455}
1456
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001457static void nativeReloadDeviceAliases(JNIEnv* /* env */,
1458 jclass /* clazz */, jlong ptr) {
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001459 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1460
1461 im->getInputManager()->getReader()->requestRefreshConfiguration(
1462 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001463}
1464
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001465static jstring nativeDump(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001466 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001467
Jeff Brownb88102f2010-09-08 11:49:43 -07001468 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001469 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001470 return env->NewStringUTF(dump.string());
1471}
1472
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001473static void nativeMonitor(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001474 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001475
Jeff Brown4532e612012-04-05 14:27:12 -07001476 im->getInputManager()->getReader()->monitor();
1477 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001478}
1479
Michael Wrighte051f6f2016-05-13 17:44:16 +01001480static void nativeSetPointerIconType(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, jint iconId) {
Jun Mukai1db53972015-09-11 18:08:31 -07001481 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Michael Wrighte051f6f2016-05-13 17:44:16 +01001482 im->setPointerIconType(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -07001483}
1484
Jun Mukai19a56012015-11-24 11:25:52 -08001485static void nativeReloadPointerIcons(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
1486 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1487 im->reloadPointerIcons();
1488}
1489
Jun Mukaid4eaef72015-10-30 15:54:33 -07001490static void nativeSetCustomPointerIcon(JNIEnv* env, jclass /* clazz */,
1491 jlong ptr, jobject iconObj) {
1492 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1493
1494 PointerIcon pointerIcon;
Michael Wrightb004b512017-01-18 18:09:29 +00001495 status_t result = android_view_PointerIcon_getLoadedIcon(env, iconObj, &pointerIcon);
1496 if (result) {
1497 jniThrowRuntimeException(env, "Failed to load custom pointer icon.");
1498 return;
1499 }
Jun Mukaid4eaef72015-10-30 15:54:33 -07001500
1501 SpriteIcon spriteIcon;
1502 pointerIcon.bitmap.copyTo(&spriteIcon.bitmap, kN32_SkColorType);
1503 spriteIcon.hotSpotX = pointerIcon.hotSpotX;
1504 spriteIcon.hotSpotY = pointerIcon.hotSpotY;
1505 im->setCustomPointerIcon(spriteIcon);
1506}
1507
Jeff Brown9c3cda02010-06-15 01:31:58 -07001508// ----------------------------------------------------------------------------
1509
Daniel Micay76f6a862015-09-19 17:31:01 -04001510static const JNINativeMethod gInputManagerMethods[] = {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001511 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001512 { "nativeInit",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001513 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J",
Jeff Brown4532e612012-04-05 14:27:12 -07001514 (void*) nativeInit },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001515 { "nativeStart", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001516 (void*) nativeStart },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001517 { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001518 (void*) nativeSetDisplayViewport },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001519 { "nativeGetScanCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001520 (void*) nativeGetScanCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001521 { "nativeGetKeyCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001522 (void*) nativeGetKeyCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001523 { "nativeGetSwitchState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001524 (void*) nativeGetSwitchState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001525 { "nativeHasKeys", "(JII[I[Z)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001526 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001527 { "nativeRegisterInputChannel",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001528 "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001529 (void*) nativeRegisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001530 { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001531 (void*) nativeUnregisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001532 { "nativeSetInputFilterEnabled", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001533 (void*) nativeSetInputFilterEnabled },
Jeff Brownca9bc702014-02-11 14:32:56 -08001534 { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001535 (void*) nativeInjectInputEvent },
Andrii Kulian112d0562016-03-08 10:44:22 -08001536 { "nativeToggleCapsLock", "(JI)V",
1537 (void*) nativeToggleCapsLock },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001538 { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001539 (void*) nativeSetInputWindows },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001540 { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001541 (void*) nativeSetFocusedApplication },
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -08001542 { "nativeSetPointerCapture", "(JZ)V",
1543 (void*) nativeSetPointerCapture },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001544 { "nativeSetInputDispatchMode", "(JZZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001545 (void*) nativeSetInputDispatchMode },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001546 { "nativeSetSystemUiVisibility", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001547 (void*) nativeSetSystemUiVisibility },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001548 { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001549 (void*) nativeTransferTouchFocus },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001550 { "nativeSetPointerSpeed", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001551 (void*) nativeSetPointerSpeed },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001552 { "nativeSetShowTouches", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001553 (void*) nativeSetShowTouches },
Jeff Brown037c33e2014-04-09 00:31:55 -07001554 { "nativeSetInteractive", "(JZ)V",
1555 (void*) nativeSetInteractive },
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001556 { "nativeReloadCalibration", "(J)V",
1557 (void*) nativeReloadCalibration },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001558 { "nativeVibrate", "(JI[JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001559 (void*) nativeVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001560 { "nativeCancelVibrate", "(JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001561 (void*) nativeCancelVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001562 { "nativeReloadKeyboardLayouts", "(J)V",
Jeff Brown6ec6f792012-04-17 16:52:41 -07001563 (void*) nativeReloadKeyboardLayouts },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001564 { "nativeReloadDeviceAliases", "(J)V",
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001565 (void*) nativeReloadDeviceAliases },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001566 { "nativeDump", "(J)Ljava/lang/String;",
Jeff Brown4532e612012-04-05 14:27:12 -07001567 (void*) nativeDump },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001568 { "nativeMonitor", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001569 (void*) nativeMonitor },
Michael Wrighte051f6f2016-05-13 17:44:16 +01001570 { "nativeSetPointerIconType", "(JI)V",
1571 (void*) nativeSetPointerIconType },
Jun Mukai19a56012015-11-24 11:25:52 -08001572 { "nativeReloadPointerIcons", "(J)V",
1573 (void*) nativeReloadPointerIcons },
Jun Mukaid4eaef72015-10-30 15:54:33 -07001574 { "nativeSetCustomPointerIcon", "(JLandroid/view/PointerIcon;)V",
1575 (void*) nativeSetCustomPointerIcon },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001576};
1577
1578#define FIND_CLASS(var, className) \
1579 var = env->FindClass(className); \
Chih-Hung Hsieh6c896162016-05-19 15:29:38 -07001580 LOG_FATAL_IF(! (var), "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001581
1582#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1583 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
Chih-Hung Hsieh6c896162016-05-19 15:29:38 -07001584 LOG_FATAL_IF(! (var), "Unable to find method " methodName);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001585
1586#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1587 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
Chih-Hung Hsieh6c896162016-05-19 15:29:38 -07001588 LOG_FATAL_IF(! (var), "Unable to find field " fieldName);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001589
1590int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001591 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001592 gInputManagerMethods, NELEM(gInputManagerMethods));
Bernhard Rosenkränzer9c1c90e2014-11-12 14:45:58 +01001593 (void) res; // Faked use when LOG_NDEBUG.
Jeff Brown46b9ac02010-04-22 18:58:52 -07001594 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1595
Jeff Brown9c3cda02010-06-15 01:31:58 -07001596 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001597
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001598 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001599 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001600
Jeff Brown4532e612012-04-05 14:27:12 -07001601 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001602 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001603
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001604 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1605 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1606
Jeff Brown53384282012-08-20 20:16:01 -07001607 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1608 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001609
Jeff Brown4532e612012-04-05 14:27:12 -07001610 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1611 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001612
Jeff Brown4532e612012-04-05 14:27:12 -07001613 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001614 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001615 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001616
Jeff Brown4532e612012-04-05 14:27:12 -07001617 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001618 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1619
Jeff Brown4532e612012-04-05 14:27:12 -07001620 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown037c33e2014-04-09 00:31:55 -07001621 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001622
Michael Wright70af00a2014-09-03 19:30:20 -07001623 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz,
1624 "interceptMotionBeforeQueueingNonInteractive", "(JI)I");
Jeff Brown56194eb2011-03-02 19:23:13 -08001625
Jeff Brown4532e612012-04-05 14:27:12 -07001626 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001627 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001628 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001629
Jeff Brown4532e612012-04-05 14:27:12 -07001630 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001631 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001632 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001633
Jeff Brown4532e612012-04-05 14:27:12 -07001634 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001635 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001636
Jeff Brown4532e612012-04-05 14:27:12 -07001637 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001638 "getVirtualKeyQuietTimeMillis", "()I");
1639
Jeff Brown4532e612012-04-05 14:27:12 -07001640 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001641 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1642
Jeff Brown4532e612012-04-05 14:27:12 -07001643 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001644 "getKeyRepeatTimeout", "()I");
1645
Jeff Brown4532e612012-04-05 14:27:12 -07001646 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001647 "getKeyRepeatDelay", "()I");
1648
Jeff Brown4532e612012-04-05 14:27:12 -07001649 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001650 "getHoverTapTimeout", "()I");
1651
Jeff Brown4532e612012-04-05 14:27:12 -07001652 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001653 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001654
Jeff Brown4532e612012-04-05 14:27:12 -07001655 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001656 "getDoubleTapTimeout", "()I");
1657
Jeff Brown4532e612012-04-05 14:27:12 -07001658 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001659 "getLongPressTimeout", "()I");
1660
Jeff Brown4532e612012-04-05 14:27:12 -07001661 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001662 "getPointerLayer", "()I");
1663
Jeff Brown4532e612012-04-05 14:27:12 -07001664 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001665 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001666
Jeff Brown6ec6f792012-04-17 16:52:41 -07001667 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
RoboErikfb290df2013-12-16 11:27:55 -08001668 "getKeyboardLayoutOverlay",
1669 "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
Jeff Brown6ec6f792012-04-17 16:52:41 -07001670
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001671 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1672 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1673
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001674 GET_METHOD_ID(gServiceClassInfo.getTouchCalibrationForInputDevice, clazz,
1675 "getTouchCalibrationForInputDevice",
Jason Gerecked5220742014-03-10 09:47:59 -07001676 "(Ljava/lang/String;I)Landroid/hardware/input/TouchCalibration;");
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001677
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001678 // InputDevice
1679
1680 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1681 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1682
Jeff Brown6ec402b2010-07-28 15:48:59 -07001683 // KeyEvent
1684
1685 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001686 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1687
Jeff Brown8d608662010-08-30 03:02:23 -07001688 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001689
1690 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001691 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001692
RoboErikfb290df2013-12-16 11:27:55 -08001693 // InputDeviceIdentifier
1694
1695 FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
1696 gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
1697 GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
1698 "<init>", "(Ljava/lang/String;II)V");
1699
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001700 // TouchCalibration
1701
1702 FIND_CLASS(gTouchCalibrationClassInfo.clazz, "android/hardware/input/TouchCalibration");
1703 gTouchCalibrationClassInfo.clazz = jclass(env->NewGlobalRef(gTouchCalibrationClassInfo.clazz));
1704
1705 GET_METHOD_ID(gTouchCalibrationClassInfo.getAffineTransform, gTouchCalibrationClassInfo.clazz,
1706 "getAffineTransform", "()[F");
1707
Jeff Brown46b9ac02010-04-22 18:58:52 -07001708 return 0;
1709}
1710
Jeff Brown46b9ac02010-04-22 18:58:52 -07001711} /* namespace android */