blob: cd485c55c816bb04c761d2429a75e8e56d00b97e [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();
Jun Mukai1db53972015-09-11 18:08:31 -0700207 void setPointerIconShape(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);
Jun Mukai347e5d42015-12-03 01:13:31 -0800210 void setPointerIconDetached(bool detached);
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
Jeff Brown5541de92011-04-11 11:54:25 -0700280 // Sprite controller singleton, created on first use.
281 sp<SpriteController> spriteController;
282
Jeff Brown83c09682010-12-23 17:50:18 -0800283 // Pointer controller singleton, created and destroyed as needed.
284 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800285 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700286
Michael Wrighta4051212015-07-23 17:04:40 +0100287 std::atomic<bool> mInteractive;
Jeff Brown037c33e2014-04-09 00:31:55 -0700288
Jeff Brown2352b972011-04-12 22:39:53 -0700289 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800290 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700291 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800292
Jeff Brownb88102f2010-09-08 11:49:43 -0700293 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700294
Jeff Brown9c3cda02010-06-15 01:31:58 -0700295 static inline JNIEnv* jniEnv() {
296 return AndroidRuntime::getJNIEnv();
297 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700298};
299
Jeff Brown928e0542011-01-10 11:17:36 -0800300
Jeff Brown9c3cda02010-06-15 01:31:58 -0700301
Jeff Brown2352b972011-04-12 22:39:53 -0700302NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700303 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown037c33e2014-04-09 00:31:55 -0700304 mLooper(looper), mInteractive(true) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700305 JNIEnv* env = jniEnv();
306
Jeff Brown2352b972011-04-12 22:39:53 -0700307 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700308 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700309
Jeff Brown83c09682010-12-23 17:50:18 -0800310 {
311 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800312 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700313 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700314 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700315 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800316 }
Michael Wrighta4051212015-07-23 17:04:40 +0100317 mInteractive = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800318
Jeff Brown9c3cda02010-06-15 01:31:58 -0700319 sp<EventHub> eventHub = new EventHub();
320 mInputManager = new InputManager(eventHub, this, this);
321}
322
323NativeInputManager::~NativeInputManager() {
324 JNIEnv* env = jniEnv();
325
Jeff Brown2352b972011-04-12 22:39:53 -0700326 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700327 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700328}
329
Jeff Brownb88102f2010-09-08 11:49:43 -0700330void NativeInputManager::dump(String8& dump) {
Michael Wrighta4051212015-07-23 17:04:40 +0100331 dump.append("Input Manager State:\n");
332 {
333 dump.appendFormat(INDENT "Interactive: %s\n", toString(mInteractive.load()));
334 }
335 {
336 AutoMutex _l(mLock);
337 dump.appendFormat(INDENT "System UI Visibility: 0x%0" PRIx32 "\n",
338 mLocked.systemUiVisibility);
339 dump.appendFormat(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed);
340 dump.appendFormat(INDENT "Pointer Gestures Enabled: %s\n",
341 toString(mLocked.pointerGesturesEnabled));
342 dump.appendFormat(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
343 }
344 dump.append("\n");
345
Jeff Brownb88102f2010-09-08 11:49:43 -0700346 mInputManager->getReader()->dump(dump);
347 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700348
Jeff Brownb88102f2010-09-08 11:49:43 -0700349 mInputManager->getDispatcher()->dump(dump);
350 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700351}
352
Jeff Brown7fbdc842010-06-17 20:52:56 -0700353bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700354 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000355 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700356 LOGE_EX(env);
357 env->ExceptionClear();
358 return true;
359 }
360 return false;
361}
362
Jeff Brownd728bf52012-09-08 18:05:28 -0700363void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700364 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700365 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700366 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700367
Jeff Brownd728bf52012-09-08 18:05:28 -0700368 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
369 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700370 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700371 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700372
Jeff Brownd728bf52012-09-08 18:05:28 -0700373 if (!external) {
374 sp<PointerController> controller = mLocked.pointerController.promote();
375 if (controller != NULL) {
376 controller->setDisplayViewport(
377 viewport.logicalRight - viewport.logicalLeft,
378 viewport.logicalBottom - viewport.logicalTop,
379 viewport.orientation);
380 }
Jeff Brown2352b972011-04-12 22:39:53 -0700381 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700382 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700383 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700384
385 if (changed) {
386 mInputManager->getReader()->requestRefreshConfiguration(
387 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
388 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700389}
390
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700391status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
Jeff Brown928e0542011-01-10 11:17:36 -0800392 const sp<InputChannel>& inputChannel,
393 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
394 return mInputManager->getDispatcher()->registerInputChannel(
395 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700396}
397
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700398status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700399 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700400 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700401}
402
Jeff Brown214eaf42011-05-26 19:17:02 -0700403void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700404 JNIEnv* env = jniEnv();
405
Jeff Brown4532e612012-04-05 14:27:12 -0700406 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
407 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700408 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
409 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
410 }
411
412 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700413 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
414 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700415 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
416 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700417 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700418 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700419 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700420 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700421 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700422 env->DeleteLocalRef(item);
423 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700424 env->DeleteLocalRef(excludedDeviceNames);
425 }
426
Jeff Brown4532e612012-04-05 14:27:12 -0700427 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
428 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700429 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700430 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
431 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700432 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700433 jint longPressTimeout = env->CallIntMethod(mServiceObj,
434 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700435 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700436 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700437
438 // We must ensure that the tap-drag interval is significantly shorter than
439 // the long-press timeout because the tap is held down for the entire duration
440 // of the double-tap timeout.
441 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700442 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700443 outConfig->pointerGestureTapDragInterval =
444 milliseconds_to_nanoseconds(tapDragInterval);
445 }
446 }
447 }
448
Jeff Brown4532e612012-04-05 14:27:12 -0700449 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
450 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700451 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
452 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700453 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700454
455 { // acquire lock
456 AutoMutex _l(mLock);
457
458 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
459 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700460 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700461
Jeff Browndaf4a122011-08-26 17:14:14 -0700462 outConfig->showTouches = mLocked.showTouches;
463
Jeff Brownd728bf52012-09-08 18:05:28 -0700464 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
465 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700466 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700467}
468
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700469sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t /* deviceId */) {
Jeff Brown83c09682010-12-23 17:50:18 -0800470 AutoMutex _l(mLock);
471
472 sp<PointerController> controller = mLocked.pointerController.promote();
473 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700474 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800475
Jeff Brown2352b972011-04-12 22:39:53 -0700476 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800477 mLocked.pointerController = controller;
478
Jeff Brownd728bf52012-09-08 18:05:28 -0700479 DisplayViewport& v = mLocked.internalViewport;
480 controller->setDisplayViewport(
481 v.logicalRight - v.logicalLeft,
482 v.logicalBottom - v.logicalTop,
483 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800484
Jeff Brown2352b972011-04-12 22:39:53 -0700485 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800486 }
487 return controller;
488}
489
Jeff Brown5541de92011-04-11 11:54:25 -0700490void NativeInputManager::ensureSpriteControllerLocked() {
491 if (mLocked.spriteController == NULL) {
492 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700493 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700494 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
495 layer = -1;
496 }
497 mLocked.spriteController = new SpriteController(mLooper, layer);
498 }
499}
500
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700501void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
502 JNIEnv* env = jniEnv();
503
504 size_t count = inputDevices.size();
505 jobjectArray inputDevicesObjArray = env->NewObjectArray(
506 count, gInputDeviceClassInfo.clazz, NULL);
507 if (inputDevicesObjArray) {
508 bool error = false;
509 for (size_t i = 0; i < count; i++) {
510 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
511 if (!inputDeviceObj) {
512 error = true;
513 break;
514 }
515
516 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
517 env->DeleteLocalRef(inputDeviceObj);
518 }
519
520 if (!error) {
521 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
522 inputDevicesObjArray);
523 }
524
525 env->DeleteLocalRef(inputDevicesObjArray);
526 }
527
528 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
529}
530
Jeff Brown6ec6f792012-04-17 16:52:41 -0700531sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
RoboErikfb290df2013-12-16 11:27:55 -0800532 const InputDeviceIdentifier& identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700533 JNIEnv* env = jniEnv();
534
535 sp<KeyCharacterMap> result;
RoboErikfb290df2013-12-16 11:27:55 -0800536 ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
537 ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
538 gInputDeviceIdentifierInfo.constructor, descriptor.get(),
539 identifier.vendor, identifier.product));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700540 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
RoboErikfb290df2013-12-16 11:27:55 -0800541 gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700542 if (arrayObj.get()) {
543 ScopedLocalRef<jstring> filenameObj(env,
544 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
545 ScopedLocalRef<jstring> contentsObj(env,
546 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
547 ScopedUtfChars filenameChars(env, filenameObj.get());
548 ScopedUtfChars contentsChars(env, contentsObj.get());
549
550 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
551 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
552 }
553 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
554 return result;
555}
556
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700557String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
558 JNIEnv* env = jniEnv();
559
560 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
561 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
562 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
563 String8 result;
564 if (aliasObj.get()) {
565 ScopedUtfChars aliasChars(env, aliasObj.get());
566 result.setTo(aliasChars.c_str());
567 }
568 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
569 return result;
570}
571
Jeff Brownbcc046a2012-09-27 20:46:43 -0700572void NativeInputManager::notifySwitch(nsecs_t when,
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700573 uint32_t switchValues, uint32_t switchMask, uint32_t /* policyFlags */) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700574#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700575 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
576 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700577#endif
578
579 JNIEnv* env = jniEnv();
580
Jeff Brown53384282012-08-20 20:16:01 -0700581 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700582 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700583 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700584}
585
Jeff Brown9c3cda02010-06-15 01:31:58 -0700586void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
587#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000588 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700589#endif
590
591 JNIEnv* env = jniEnv();
592
Jeff Brown4532e612012-04-05 14:27:12 -0700593 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700594 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700595}
596
Jeff Brown519e0242010-09-15 15:18:56 -0700597nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700598 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700599#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000600 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700601#endif
602
603 JNIEnv* env = jniEnv();
604
Jeff Brown928e0542011-01-10 11:17:36 -0800605 jobject inputApplicationHandleObj =
606 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
607 jobject inputWindowHandleObj =
608 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownbd181bb2013-09-10 16:44:24 -0700609 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700610
Jeff Brown4532e612012-04-05 14:27:12 -0700611 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700612 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
613 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700614 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
615 newTimeout = 0; // abort dispatch
616 } else {
617 assert(newTimeout >= 0);
618 }
619
Jeff Brownbd181bb2013-09-10 16:44:24 -0700620 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800621 env->DeleteLocalRef(inputWindowHandleObj);
622 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700623 return newTimeout;
624}
625
Jeff Brown928e0542011-01-10 11:17:36 -0800626void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700627#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000628 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700629#endif
630
Jeff Brown7fbdc842010-06-17 20:52:56 -0700631 JNIEnv* env = jniEnv();
632
Jeff Brown928e0542011-01-10 11:17:36 -0800633 jobject inputWindowHandleObj =
634 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
635 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700636 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800637 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700638 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
639
Jeff Brown928e0542011-01-10 11:17:36 -0800640 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700641 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700642}
643
Jeff Brown214eaf42011-05-26 19:17:02 -0700644void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
645 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800646
Jeff Brown4532e612012-04-05 14:27:12 -0700647 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
648 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700649 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
650 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
651 }
Jeff Browna4547672011-03-02 21:38:11 -0800652
Jeff Brown4532e612012-04-05 14:27:12 -0700653 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
654 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700655 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
656 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
657 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700658}
659
Jeff Brown9302c872011-07-13 22:51:29 -0700660void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
661 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700662
Jeff Brown9302c872011-07-13 22:51:29 -0700663 if (windowHandleObjArray) {
664 jsize length = env->GetArrayLength(windowHandleObjArray);
665 for (jsize i = 0; i < length; i++) {
666 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
667 if (! windowHandleObj) {
668 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700669 }
Jeff Brown9302c872011-07-13 22:51:29 -0700670
671 sp<InputWindowHandle> windowHandle =
672 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
673 if (windowHandle != NULL) {
674 windowHandles.push(windowHandle);
675 }
676 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700677 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700678 }
Jeff Brown349703e2010-06-22 01:27:15 -0700679
Jeff Brown9302c872011-07-13 22:51:29 -0700680 mInputManager->getDispatcher()->setInputWindows(windowHandles);
681
682 // Do this after the dispatcher has updated the window handle state.
683 bool newPointerGesturesEnabled = true;
684 size_t numWindows = windowHandles.size();
685 for (size_t i = 0; i < numWindows; i++) {
686 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700687 const InputWindowInfo* windowInfo = windowHandle->getInfo();
688 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
689 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700690 newPointerGesturesEnabled = false;
691 }
692 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700693
694 uint32_t changes = 0;
695 { // acquire lock
696 AutoMutex _l(mLock);
697
698 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
699 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
700 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
701 }
702 } // release lock
703
704 if (changes) {
705 mInputManager->getReader()->requestRefreshConfiguration(changes);
706 }
Jeff Brown349703e2010-06-22 01:27:15 -0700707}
708
Jeff Brown9302c872011-07-13 22:51:29 -0700709void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
710 sp<InputApplicationHandle> applicationHandle =
711 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
712 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700713}
714
Jun Mukai347e5d42015-12-03 01:13:31 -0800715void NativeInputManager::setPointerIconDetached(bool detached) {
716 AutoMutex _l(mLock);
717 sp<PointerController> controller = mLocked.pointerController.promote();
718 if (controller != NULL) {
719 controller->detachPointerIcon(detached);
720 }
721}
722
Jeff Brown349703e2010-06-22 01:27:15 -0700723void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700724 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700725}
726
Jeff Brown05dc66a2011-03-02 14:41:58 -0800727void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
728 AutoMutex _l(mLock);
729
730 if (mLocked.systemUiVisibility != visibility) {
731 mLocked.systemUiVisibility = visibility;
732
733 sp<PointerController> controller = mLocked.pointerController.promote();
734 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700735 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800736 }
737 }
738}
739
Jeff Brown2352b972011-04-12 22:39:53 -0700740void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800741 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700742 controller->setInactivityTimeout(lightsOut
743 ? PointerController::INACTIVITY_TIMEOUT_SHORT
744 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800745}
746
Jeff Brown1a84fd12011-06-02 01:26:32 -0700747void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700748 { // acquire lock
749 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700750
Jeff Brown474dcb52011-06-14 20:22:50 -0700751 if (mLocked.pointerSpeed == speed) {
752 return;
753 }
754
Steve Block6215d3f2012-01-04 20:05:49 +0000755 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700756 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700757 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700758
Jeff Brown474dcb52011-06-14 20:22:50 -0700759 mInputManager->getReader()->requestRefreshConfiguration(
760 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700761}
762
Jeff Browndaf4a122011-08-26 17:14:14 -0700763void NativeInputManager::setShowTouches(bool enabled) {
764 { // acquire lock
765 AutoMutex _l(mLock);
766
767 if (mLocked.showTouches == enabled) {
768 return;
769 }
770
Steve Block6215d3f2012-01-04 20:05:49 +0000771 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700772 mLocked.showTouches = enabled;
773 } // release lock
774
775 mInputManager->getReader()->requestRefreshConfiguration(
776 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
777}
778
Jeff Brown037c33e2014-04-09 00:31:55 -0700779void NativeInputManager::setInteractive(bool interactive) {
780 mInteractive = interactive;
Jeff Browne20c9e02010-10-11 14:20:19 -0700781}
782
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800783void NativeInputManager::reloadCalibration() {
784 mInputManager->getReader()->requestRefreshConfiguration(
Michael Wright357285c2015-04-17 00:50:31 +0100785 InputReaderConfiguration::CHANGE_TOUCH_AFFINE_TRANSFORMATION);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800786}
787
Jun Mukai1db53972015-09-11 18:08:31 -0700788void NativeInputManager::setPointerIconShape(int32_t iconId) {
Jun Mukai19a56012015-11-24 11:25:52 -0800789 AutoMutex _l(mLock);
790 sp<PointerController> controller = mLocked.pointerController.promote();
791 if (controller != NULL) {
Jun Mukai5ec74202015-10-07 16:58:09 +0900792 controller->updatePointerShape(iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800793 }
794}
795
796void NativeInputManager::reloadPointerIcons() {
797 AutoMutex _l(mLock);
798 sp<PointerController> controller = mLocked.pointerController.promote();
799 if (controller != NULL) {
800 controller->reloadPointerResources();
801 }
Jun Mukai1db53972015-09-11 18:08:31 -0700802}
803
Jun Mukaid4eaef72015-10-30 15:54:33 -0700804void NativeInputManager::setCustomPointerIcon(const SpriteIcon& icon) {
805 AutoMutex _l(mLock);
806 sp<PointerController> controller = mLocked.pointerController.promote();
807 if (controller != NULL) {
808 controller->setCustomPointerIcon(icon);
809 }
810}
811
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800812TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
813 JNIEnv *env, jfloatArray matrixArr) {
814 ScopedFloatArrayRO matrix(env, matrixArr);
815 assert(matrix.size() == 6);
816
817 TouchAffineTransformation transform;
818 transform.x_scale = matrix[0];
819 transform.x_ymix = matrix[1];
820 transform.x_offset = matrix[2];
821 transform.y_xmix = matrix[3];
822 transform.y_scale = matrix[4];
823 transform.y_offset = matrix[5];
824
825 return transform;
826}
827
828TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
Jason Gerecked5220742014-03-10 09:47:59 -0700829 const String8& inputDeviceDescriptor, int32_t surfaceRotation) {
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800830 JNIEnv* env = jniEnv();
831
832 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
833
834 jobject cal = env->CallObjectMethod(mServiceObj,
Jason Gerecked5220742014-03-10 09:47:59 -0700835 gServiceClassInfo.getTouchCalibrationForInputDevice, descriptorObj.get(),
836 surfaceRotation);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800837
838 jfloatArray matrixArr = jfloatArray(env->CallObjectMethod(cal,
839 gTouchCalibrationClassInfo.getAffineTransform));
840
841 TouchAffineTransformation transform = getTouchAffineTransformation(env, matrixArr);
842
843 env->DeleteLocalRef(matrixArr);
844 env->DeleteLocalRef(cal);
845
846 return transform;
847}
848
Jeff Brown0029c662011-03-30 02:25:18 -0700849bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
850 jobject inputEventObj;
851
852 JNIEnv* env = jniEnv();
853 switch (inputEvent->getType()) {
854 case AINPUT_EVENT_TYPE_KEY:
855 inputEventObj = android_view_KeyEvent_fromNative(env,
856 static_cast<const KeyEvent*>(inputEvent));
857 break;
858 case AINPUT_EVENT_TYPE_MOTION:
859 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
860 static_cast<const MotionEvent*>(inputEvent));
861 break;
862 default:
863 return true; // dispatch the event normally
864 }
865
866 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000867 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700868 return true; // dispatch the event normally
869 }
870
871 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700872 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700873 inputEventObj, policyFlags);
874 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
875 pass = true;
876 }
877 env->DeleteLocalRef(inputEventObj);
878 return pass;
879}
880
Jeff Brown1f245102010-11-18 20:53:46 -0800881void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
882 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700883 // Policy:
884 // - Ignore untrusted events and pass them along.
885 // - Ask the window manager what to do with normal events and trusted injected events.
886 // - For normal events wake and brighten the screen if currently off or dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100887 bool interactive = mInteractive.load();
888 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700889 policyFlags |= POLICY_FLAG_INTERACTIVE;
890 }
Jeff Brown3122e442010-10-11 23:32:49 -0700891 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800892 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700893 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800894 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
895 jint wmActions;
896 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700897 wmActions = env->CallIntMethod(mServiceObj,
898 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown037c33e2014-04-09 00:31:55 -0700899 keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800900 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
901 wmActions = 0;
902 }
903 android_view_KeyEvent_recycle(env, keyEventObj);
904 env->DeleteLocalRef(keyEventObj);
905 } else {
Steve Block3762c312012-01-06 19:20:56 +0000906 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700907 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700908 }
909
Jeff Brown56194eb2011-03-02 19:23:13 -0800910 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700911 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100912 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700913 policyFlags |= POLICY_FLAG_PASS_TO_USER;
914 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700915 }
916}
917
Jeff Brown56194eb2011-03-02 19:23:13 -0800918void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700919 // Policy:
920 // - Ignore untrusted events and pass them along.
921 // - No special filtering for injected events required at this time.
922 // - Filter normal events based on screen state.
923 // - For normal events brighten (but do not wake) the screen if currently dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100924 bool interactive = mInteractive.load();
925 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700926 policyFlags |= POLICY_FLAG_INTERACTIVE;
927 }
Jeff Brown3122e442010-10-11 23:32:49 -0700928 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700929 if (policyFlags & POLICY_FLAG_INTERACTIVE) {
Jeff Brown3122e442010-10-11 23:32:49 -0700930 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Michael Wright70af00a2014-09-03 19:30:20 -0700931 } else {
Jeff Brown56194eb2011-03-02 19:23:13 -0800932 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700933 jint wmActions = env->CallIntMethod(mServiceObj,
Michael Wright70af00a2014-09-03 19:30:20 -0700934 gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive,
Jeff Brown26875502014-01-30 21:47:47 -0800935 when, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800936 if (checkAndClearExceptionFromCallback(env,
Michael Wright70af00a2014-09-03 19:30:20 -0700937 "interceptMotionBeforeQueueingNonInteractive")) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800938 wmActions = 0;
939 }
940
Jeff Brown56194eb2011-03-02 19:23:13 -0800941 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700942 }
Jeff Brown3122e442010-10-11 23:32:49 -0700943 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100944 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700945 policyFlags |= POLICY_FLAG_PASS_TO_USER;
946 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700947 }
948}
949
Jeff Brown56194eb2011-03-02 19:23:13 -0800950void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
951 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800952 if (wmActions & WM_ACTION_PASS_TO_USER) {
953 policyFlags |= POLICY_FLAG_PASS_TO_USER;
954 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800955#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000956 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800957#endif
958 }
959}
960
Jeff Brown905805a2011-10-12 13:57:59 -0700961nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800962 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700963 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700964 // Policy:
965 // - Ignore untrusted events and pass them along.
966 // - Filter normal events and trusted injected events through the window manager policy to
967 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700968 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700969 if (policyFlags & POLICY_FLAG_TRUSTED) {
970 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700971
Jeff Brown928e0542011-01-10 11:17:36 -0800972 // Note: inputWindowHandle may be null.
973 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800974 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
975 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700976 jlong delayMillis = env->CallLongMethod(mServiceObj,
977 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800978 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800979 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
980 android_view_KeyEvent_recycle(env, keyEventObj);
981 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700982 if (!error) {
983 if (delayMillis < 0) {
984 result = -1;
985 } else if (delayMillis > 0) {
986 result = milliseconds_to_nanoseconds(delayMillis);
987 }
988 }
Jeff Brown1f245102010-11-18 20:53:46 -0800989 } else {
Steve Block3762c312012-01-06 19:20:56 +0000990 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800991 }
Jeff Brown928e0542011-01-10 11:17:36 -0800992 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700993 }
Jeff Brown1f245102010-11-18 20:53:46 -0800994 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700995}
996
Jeff Brown928e0542011-01-10 11:17:36 -0800997bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800998 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700999 // Policy:
1000 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -08001001 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -07001002 if (policyFlags & POLICY_FLAG_TRUSTED) {
1003 JNIEnv* env = jniEnv();
1004
Jeff Brown928e0542011-01-10 11:17:36 -08001005 // Note: inputWindowHandle may be null.
1006 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -08001007 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
1008 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001009 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
1010 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -08001011 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001012 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
1013 fallbackKeyEventObj = NULL;
1014 }
Jeff Brown1f245102010-11-18 20:53:46 -08001015 android_view_KeyEvent_recycle(env, keyEventObj);
1016 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001017
1018 if (fallbackKeyEventObj) {
1019 // Note: outFallbackKeyEvent may be the same object as keyEvent.
1020 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
1021 outFallbackKeyEvent)) {
1022 result = true;
1023 }
1024 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
1025 env->DeleteLocalRef(fallbackKeyEventObj);
1026 }
Jeff Brown1f245102010-11-18 20:53:46 -08001027 } else {
Steve Block3762c312012-01-06 19:20:56 +00001028 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -08001029 }
Jeff Brown928e0542011-01-10 11:17:36 -08001030 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -07001031 }
Jeff Brown1f245102010-11-18 20:53:46 -08001032 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -07001033}
1034
Jeff Brown01ce2e92010-09-26 22:20:12 -07001035void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
1036 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -07001037}
1038
Jeff Brown349703e2010-06-22 01:27:15 -07001039
Jeff Brownb88102f2010-09-08 11:49:43 -07001040bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
1041 int32_t injectorPid, int32_t injectorUid) {
1042 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -07001043 jboolean result = env->CallBooleanMethod(mServiceObj,
1044 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001045 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
1046 result = false;
1047 }
Jeff Brown349703e2010-06-22 01:27:15 -07001048 return result;
1049}
1050
Jun Mukai19a56012015-11-24 11:25:52 -08001051void NativeInputManager::loadPointerIcon(SpriteIcon* icon) {
1052 JNIEnv* env = jniEnv();
1053
1054 ScopedLocalRef<jobject> pointerIconObj(env, env->CallObjectMethod(
1055 mServiceObj, gServiceClassInfo.getPointerIcon));
1056 if (checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
1057 return;
1058 }
1059
1060 PointerIcon pointerIcon;
1061 status_t status = android_view_PointerIcon_load(env, pointerIconObj.get(),
1062 mContextObj, &pointerIcon);
1063 if (!status && !pointerIcon.isNullIcon()) {
1064 *icon = SpriteIcon(pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY);
1065 } else {
1066 *icon = SpriteIcon();
1067 }
1068}
1069
Jeff Brown2352b972011-04-12 22:39:53 -07001070void NativeInputManager::loadPointerResources(PointerResources* outResources) {
1071 JNIEnv* env = jniEnv();
1072
1073 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
1074 &outResources->spotHover);
1075 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
1076 &outResources->spotTouch);
1077 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
1078 &outResources->spotAnchor);
1079}
1080
Jun Mukai808196f2015-10-28 16:46:44 -07001081void NativeInputManager::loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
1082 std::map<int32_t, PointerAnimation>* outAnimationResources) {
Jun Mukai1db53972015-09-11 18:08:31 -07001083 JNIEnv* env = jniEnv();
1084
1085 for (int iconId = POINTER_ICON_STYLE_CONTEXT_MENU; iconId <= POINTER_ICON_STYLE_GRABBING;
1086 ++iconId) {
Jun Mukai808196f2015-10-28 16:46:44 -07001087 PointerIcon pointerIcon;
1088 loadSystemIconAsSpriteWithPointerIcon(
1089 env, mContextObj, iconId, &pointerIcon, &((*outResources)[iconId]));
1090 if (!pointerIcon.bitmapFrames.empty()) {
1091 PointerAnimation& animationData = (*outAnimationResources)[iconId];
1092 size_t numFrames = pointerIcon.bitmapFrames.size() + 1;
1093 animationData.durationPerFrame =
1094 milliseconds_to_nanoseconds(pointerIcon.durationPerFrame);
1095 animationData.animationFrames.reserve(numFrames);
1096 animationData.animationFrames.push_back(SpriteIcon(
1097 pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1098 for (size_t i = 0; i < numFrames - 1; ++i) {
1099 animationData.animationFrames.push_back(SpriteIcon(
1100 pointerIcon.bitmapFrames[i], pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1101 }
1102 }
Jun Mukai1db53972015-09-11 18:08:31 -07001103 }
Jun Mukai808196f2015-10-28 16:46:44 -07001104 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_NULL,
1105 &((*outResources)[POINTER_ICON_STYLE_NULL]));
Jun Mukai1db53972015-09-11 18:08:31 -07001106}
1107
Jun Mukai5ec74202015-10-07 16:58:09 +09001108int32_t NativeInputManager::getDefaultPointerIconId() {
1109 return POINTER_ICON_STYLE_ARROW;
1110}
Jeff Brown83c09682010-12-23 17:50:18 -08001111
Jun Mukaid4eaef72015-10-30 15:54:33 -07001112int32_t NativeInputManager::getCustomPointerIconId() {
1113 return POINTER_ICON_STYLE_CUSTOM;
1114}
1115
Jeff Brown9c3cda02010-06-15 01:31:58 -07001116// ----------------------------------------------------------------------------
1117
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001118static jlong nativeInit(JNIEnv* env, jclass /* clazz */,
Jeff Brown4532e612012-04-05 14:27:12 -07001119 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -07001120 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -08001121 if (messageQueue == NULL) {
1122 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
1123 return 0;
1124 }
1125
Jeff Brown603b4452012-04-06 17:39:41 -07001126 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
1127 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -08001128 im->incStrong(0);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001129 return reinterpret_cast<jlong>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001130}
1131
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001132static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001133 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001134
Jeff Brown4532e612012-04-05 14:27:12 -07001135 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001136 if (result) {
1137 jniThrowRuntimeException(env, "Input manager could not be started.");
1138 }
1139}
1140
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001141static void nativeSetDisplayViewport(JNIEnv* /* env */, jclass /* clazz */, jlong ptr,
1142 jboolean external, jint displayId, jint orientation,
Jeff Brownd728bf52012-09-08 18:05:28 -07001143 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001144 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1145 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001146 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001147
Jeff Brownd728bf52012-09-08 18:05:28 -07001148 DisplayViewport v;
1149 v.displayId = displayId;
1150 v.orientation = orientation;
1151 v.logicalLeft = logicalLeft;
1152 v.logicalTop = logicalTop;
1153 v.logicalRight = logicalRight;
1154 v.logicalBottom = logicalBottom;
1155 v.physicalLeft = physicalLeft;
1156 v.physicalTop = physicalTop;
1157 v.physicalRight = physicalRight;
1158 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001159 v.deviceWidth = deviceWidth;
1160 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001161 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001162}
1163
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001164static jint nativeGetScanCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001165 jlong ptr, jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001166 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001167
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001168 return (jint) im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001169 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001170}
1171
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001172static jint nativeGetKeyCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001173 jlong ptr, jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001174 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001175
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001176 return (jint) im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001177 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001178}
1179
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001180static jint nativeGetSwitchState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001181 jlong ptr, jint deviceId, jint sourceMask, jint sw) {
Jeff Brown4532e612012-04-05 14:27:12 -07001182 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001183
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001184 return (jint) im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001185 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001186}
1187
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001188static jboolean nativeHasKeys(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001189 jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001190 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001191
1192 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1193 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1194 jsize numCodes = env->GetArrayLength(keyCodes);
1195 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001196 if (numCodes == env->GetArrayLength(keyCodes)) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001197 if (im->getInputManager()->getReader()->hasKeys(
1198 deviceId, uint32_t(sourceMask), numCodes, codes, flags)) {
1199 result = JNI_TRUE;
1200 } else {
1201 result = JNI_FALSE;
1202 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001203 } else {
1204 result = JNI_FALSE;
1205 }
1206
1207 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1208 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1209 return result;
1210}
1211
1212static void throwInputChannelNotInitialized(JNIEnv* env) {
1213 jniThrowException(env, "java/lang/IllegalStateException",
1214 "inputChannel is not initialized");
1215}
1216
Jeff Brown4532e612012-04-05 14:27:12 -07001217static void handleInputChannelDisposed(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001218 jobject /* inputChannelObj */, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001219 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1220
Steve Block8564c8d2012-01-05 23:22:43 +00001221 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001222 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001223 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001224}
1225
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001226static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001227 jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown4532e612012-04-05 14:27:12 -07001228 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001229
1230 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1231 inputChannelObj);
1232 if (inputChannel == NULL) {
1233 throwInputChannelNotInitialized(env);
1234 return;
1235 }
1236
Jeff Brown928e0542011-01-10 11:17:36 -08001237 sp<InputWindowHandle> inputWindowHandle =
1238 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001239
Jeff Brown4532e612012-04-05 14:27:12 -07001240 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001241 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001242 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001243 String8 message;
1244 message.appendFormat("Failed to register input channel. status=%d", status);
1245 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001246 return;
1247 }
1248
Jeff Browna41ca772010-08-11 14:46:32 -07001249 if (! monitor) {
1250 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001251 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001252 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001253}
1254
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001255static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001256 jlong ptr, jobject inputChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001257 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001258
1259 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1260 inputChannelObj);
1261 if (inputChannel == NULL) {
1262 throwInputChannelNotInitialized(env);
1263 return;
1264 }
1265
1266 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1267
Jeff Brown4532e612012-04-05 14:27:12 -07001268 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001269 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1270 String8 message;
1271 message.appendFormat("Failed to unregister input channel. status=%d", status);
1272 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001273 }
1274}
1275
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001276static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001277 jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001278 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001279
Jeff Brown4532e612012-04-05 14:27:12 -07001280 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001281}
1282
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001283static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
Jeff Brownca9bc702014-02-11 14:32:56 -08001284 jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001285 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001286 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001287
Jeff Brown6ec402b2010-07-28 15:48:59 -07001288 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1289 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001290 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1291 if (status) {
1292 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1293 return INPUT_EVENT_INJECTION_FAILED;
1294 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001295
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001296 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001297 & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001298 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001299 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001300 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1301 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001302 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1303 return INPUT_EVENT_INJECTION_FAILED;
1304 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001305
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001306 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001307 motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001308 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001309 } else {
1310 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001311 return INPUT_EVENT_INJECTION_FAILED;
1312 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001313}
1314
Andrii Kulian112d0562016-03-08 10:44:22 -08001315static void nativeToggleCapsLock(JNIEnv* env, jclass /* clazz */,
1316 jlong ptr, jint deviceId) {
1317 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1318 im->getInputManager()->getReader()->toggleCapsLockState(deviceId);
1319}
1320
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001321static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001322 jlong ptr, jobjectArray windowHandleObjArray) {
Jeff Brown4532e612012-04-05 14:27:12 -07001323 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001324
Jeff Brown4532e612012-04-05 14:27:12 -07001325 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001326}
1327
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001328static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001329 jlong ptr, jobject applicationHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001330 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001331
Jeff Brown4532e612012-04-05 14:27:12 -07001332 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001333}
1334
Jun Mukai347e5d42015-12-03 01:13:31 -08001335static void nativeSetPointerIconDetached(JNIEnv* env, jclass /* clazz */, jlong ptr,
1336 jboolean detached) {
1337 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1338 im->setPointerIconDetached(detached);
1339}
1340
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001341static void nativeSetInputDispatchMode(JNIEnv* /* env */,
1342 jclass /* clazz */, jlong ptr, jboolean enabled, jboolean frozen) {
Jeff Brown4532e612012-04-05 14:27:12 -07001343 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001344
Jeff Brown4532e612012-04-05 14:27:12 -07001345 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001346}
1347
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001348static void nativeSetSystemUiVisibility(JNIEnv* /* env */,
1349 jclass /* clazz */, jlong ptr, jint visibility) {
Jeff Brown4532e612012-04-05 14:27:12 -07001350 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001351
Jeff Brown4532e612012-04-05 14:27:12 -07001352 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001353}
1354
Jeff Brown4532e612012-04-05 14:27:12 -07001355static jboolean nativeTransferTouchFocus(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001356 jclass /* clazz */, jlong ptr, jobject fromChannelObj, jobject toChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001357 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001358
1359 sp<InputChannel> fromChannel =
1360 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1361 sp<InputChannel> toChannel =
1362 android_view_InputChannel_getInputChannel(env, toChannelObj);
1363
1364 if (fromChannel == NULL || toChannel == NULL) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001365 return JNI_FALSE;
Jeff Browne6504122010-09-27 14:52:15 -07001366 }
1367
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001368 if (im->getInputManager()->getDispatcher()->
1369 transferTouchFocus(fromChannel, toChannel)) {
1370 return JNI_TRUE;
1371 } else {
1372 return JNI_FALSE;
1373 }
Jeff Browne6504122010-09-27 14:52:15 -07001374}
1375
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001376static void nativeSetPointerSpeed(JNIEnv* /* env */,
1377 jclass /* clazz */, jlong ptr, jint speed) {
Jeff Brown4532e612012-04-05 14:27:12 -07001378 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001379
Jeff Brown4532e612012-04-05 14:27:12 -07001380 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001381}
1382
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001383static void nativeSetShowTouches(JNIEnv* /* env */,
1384 jclass /* clazz */, jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001385 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001386
Jeff Brown4532e612012-04-05 14:27:12 -07001387 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001388}
1389
Jeff Brown037c33e2014-04-09 00:31:55 -07001390static void nativeSetInteractive(JNIEnv* env,
1391 jclass clazz, jlong ptr, jboolean interactive) {
1392 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1393
1394 im->setInteractive(interactive);
1395}
1396
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001397static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) {
1398 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1399 im->reloadCalibration();
1400}
1401
Jeff Browna47425a2012-04-13 04:09:27 -07001402static void nativeVibrate(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001403 jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj,
Jeff Browna47425a2012-04-13 04:09:27 -07001404 jint repeat, jint token) {
1405 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1406
1407 size_t patternSize = env->GetArrayLength(patternObj);
1408 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
Michael Wright9ecba522014-04-04 15:29:53 -07001409 ALOGI("Skipped requested vibration because the pattern size is %zu "
Jeff Browna47425a2012-04-13 04:09:27 -07001410 "which is more than the maximum supported size of %d.",
1411 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1412 return; // limit to reasonable size
1413 }
1414
1415 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1416 patternObj, NULL));
1417 nsecs_t pattern[patternSize];
1418 for (size_t i = 0; i < patternSize; i++) {
1419 pattern[i] = max(jlong(0), min(patternMillis[i],
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001420 (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL;
Jeff Browna47425a2012-04-13 04:09:27 -07001421 }
1422 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1423
1424 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1425}
1426
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001427static void nativeCancelVibrate(JNIEnv* /* env */,
1428 jclass /* clazz */, jlong ptr, jint deviceId, jint token) {
Jeff Browna47425a2012-04-13 04:09:27 -07001429 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1430
1431 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1432}
1433
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001434static void nativeReloadKeyboardLayouts(JNIEnv* /* env */,
1435 jclass /* clazz */, jlong ptr) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001436 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1437
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001438 im->getInputManager()->getReader()->requestRefreshConfiguration(
1439 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1440}
1441
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001442static void nativeReloadDeviceAliases(JNIEnv* /* env */,
1443 jclass /* clazz */, jlong ptr) {
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001444 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1445
1446 im->getInputManager()->getReader()->requestRefreshConfiguration(
1447 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001448}
1449
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001450static jstring nativeDump(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001451 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001452
Jeff Brownb88102f2010-09-08 11:49:43 -07001453 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001454 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001455 return env->NewStringUTF(dump.string());
1456}
1457
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001458static void nativeMonitor(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001459 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001460
Jeff Brown4532e612012-04-05 14:27:12 -07001461 im->getInputManager()->getReader()->monitor();
1462 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001463}
1464
Jun Mukai1db53972015-09-11 18:08:31 -07001465static void nativeSetPointerIconShape(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, jint iconId) {
1466 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1467 im->setPointerIconShape(iconId);
1468}
1469
Jun Mukai19a56012015-11-24 11:25:52 -08001470static void nativeReloadPointerIcons(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
1471 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1472 im->reloadPointerIcons();
1473}
1474
Jun Mukaid4eaef72015-10-30 15:54:33 -07001475static void nativeSetCustomPointerIcon(JNIEnv* env, jclass /* clazz */,
1476 jlong ptr, jobject iconObj) {
1477 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1478
1479 PointerIcon pointerIcon;
1480 android_view_PointerIcon_getLoadedIcon(env, iconObj, &pointerIcon);
1481
1482 SpriteIcon spriteIcon;
1483 pointerIcon.bitmap.copyTo(&spriteIcon.bitmap, kN32_SkColorType);
1484 spriteIcon.hotSpotX = pointerIcon.hotSpotX;
1485 spriteIcon.hotSpotY = pointerIcon.hotSpotY;
1486 im->setCustomPointerIcon(spriteIcon);
1487}
1488
Jeff Brown9c3cda02010-06-15 01:31:58 -07001489// ----------------------------------------------------------------------------
1490
Daniel Micay76f6a862015-09-19 17:31:01 -04001491static const JNINativeMethod gInputManagerMethods[] = {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001492 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001493 { "nativeInit",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001494 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J",
Jeff Brown4532e612012-04-05 14:27:12 -07001495 (void*) nativeInit },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001496 { "nativeStart", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001497 (void*) nativeStart },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001498 { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001499 (void*) nativeSetDisplayViewport },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001500 { "nativeGetScanCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001501 (void*) nativeGetScanCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001502 { "nativeGetKeyCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001503 (void*) nativeGetKeyCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001504 { "nativeGetSwitchState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001505 (void*) nativeGetSwitchState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001506 { "nativeHasKeys", "(JII[I[Z)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001507 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001508 { "nativeRegisterInputChannel",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001509 "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001510 (void*) nativeRegisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001511 { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001512 (void*) nativeUnregisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001513 { "nativeSetInputFilterEnabled", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001514 (void*) nativeSetInputFilterEnabled },
Jeff Brownca9bc702014-02-11 14:32:56 -08001515 { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001516 (void*) nativeInjectInputEvent },
Andrii Kulian112d0562016-03-08 10:44:22 -08001517 { "nativeToggleCapsLock", "(JI)V",
1518 (void*) nativeToggleCapsLock },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001519 { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001520 (void*) nativeSetInputWindows },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001521 { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001522 (void*) nativeSetFocusedApplication },
Jun Mukai347e5d42015-12-03 01:13:31 -08001523 { "nativeSetPointerIconDetached", "(JZ)V",
1524 (void*) nativeSetPointerIconDetached },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001525 { "nativeSetInputDispatchMode", "(JZZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001526 (void*) nativeSetInputDispatchMode },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001527 { "nativeSetSystemUiVisibility", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001528 (void*) nativeSetSystemUiVisibility },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001529 { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001530 (void*) nativeTransferTouchFocus },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001531 { "nativeSetPointerSpeed", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001532 (void*) nativeSetPointerSpeed },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001533 { "nativeSetShowTouches", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001534 (void*) nativeSetShowTouches },
Jeff Brown037c33e2014-04-09 00:31:55 -07001535 { "nativeSetInteractive", "(JZ)V",
1536 (void*) nativeSetInteractive },
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001537 { "nativeReloadCalibration", "(J)V",
1538 (void*) nativeReloadCalibration },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001539 { "nativeVibrate", "(JI[JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001540 (void*) nativeVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001541 { "nativeCancelVibrate", "(JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001542 (void*) nativeCancelVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001543 { "nativeReloadKeyboardLayouts", "(J)V",
Jeff Brown6ec6f792012-04-17 16:52:41 -07001544 (void*) nativeReloadKeyboardLayouts },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001545 { "nativeReloadDeviceAliases", "(J)V",
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001546 (void*) nativeReloadDeviceAliases },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001547 { "nativeDump", "(J)Ljava/lang/String;",
Jeff Brown4532e612012-04-05 14:27:12 -07001548 (void*) nativeDump },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001549 { "nativeMonitor", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001550 (void*) nativeMonitor },
Jun Mukai1db53972015-09-11 18:08:31 -07001551 { "nativeSetPointerIconShape", "(JI)V",
1552 (void*) nativeSetPointerIconShape },
Jun Mukai19a56012015-11-24 11:25:52 -08001553 { "nativeReloadPointerIcons", "(J)V",
1554 (void*) nativeReloadPointerIcons },
Jun Mukaid4eaef72015-10-30 15:54:33 -07001555 { "nativeSetCustomPointerIcon", "(JLandroid/view/PointerIcon;)V",
1556 (void*) nativeSetCustomPointerIcon },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001557};
1558
1559#define FIND_CLASS(var, className) \
1560 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001561 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001562
1563#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1564 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1565 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1566
1567#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1568 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1569 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1570
1571int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001572 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001573 gInputManagerMethods, NELEM(gInputManagerMethods));
Bernhard Rosenkränzer9c1c90e2014-11-12 14:45:58 +01001574 (void) res; // Faked use when LOG_NDEBUG.
Jeff Brown46b9ac02010-04-22 18:58:52 -07001575 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1576
Jeff Brown9c3cda02010-06-15 01:31:58 -07001577 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001578
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001579 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001580 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001581
Jeff Brown4532e612012-04-05 14:27:12 -07001582 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001583 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001584
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001585 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1586 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1587
Jeff Brown53384282012-08-20 20:16:01 -07001588 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1589 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001590
Jeff Brown4532e612012-04-05 14:27:12 -07001591 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1592 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001593
Jeff Brown4532e612012-04-05 14:27:12 -07001594 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001595 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001596 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001597
Jeff Brown4532e612012-04-05 14:27:12 -07001598 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001599 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1600
Jeff Brown4532e612012-04-05 14:27:12 -07001601 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown037c33e2014-04-09 00:31:55 -07001602 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001603
Michael Wright70af00a2014-09-03 19:30:20 -07001604 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz,
1605 "interceptMotionBeforeQueueingNonInteractive", "(JI)I");
Jeff Brown56194eb2011-03-02 19:23:13 -08001606
Jeff Brown4532e612012-04-05 14:27:12 -07001607 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001608 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001609 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001610
Jeff Brown4532e612012-04-05 14:27:12 -07001611 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001612 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001613 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001614
Jeff Brown4532e612012-04-05 14:27:12 -07001615 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001616 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001617
Jeff Brown4532e612012-04-05 14:27:12 -07001618 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001619 "getVirtualKeyQuietTimeMillis", "()I");
1620
Jeff Brown4532e612012-04-05 14:27:12 -07001621 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001622 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1623
Jeff Brown4532e612012-04-05 14:27:12 -07001624 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001625 "getKeyRepeatTimeout", "()I");
1626
Jeff Brown4532e612012-04-05 14:27:12 -07001627 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001628 "getKeyRepeatDelay", "()I");
1629
Jeff Brown4532e612012-04-05 14:27:12 -07001630 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001631 "getHoverTapTimeout", "()I");
1632
Jeff Brown4532e612012-04-05 14:27:12 -07001633 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001634 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001635
Jeff Brown4532e612012-04-05 14:27:12 -07001636 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001637 "getDoubleTapTimeout", "()I");
1638
Jeff Brown4532e612012-04-05 14:27:12 -07001639 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001640 "getLongPressTimeout", "()I");
1641
Jeff Brown4532e612012-04-05 14:27:12 -07001642 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001643 "getPointerLayer", "()I");
1644
Jeff Brown4532e612012-04-05 14:27:12 -07001645 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001646 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001647
Jeff Brown6ec6f792012-04-17 16:52:41 -07001648 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
RoboErikfb290df2013-12-16 11:27:55 -08001649 "getKeyboardLayoutOverlay",
1650 "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
Jeff Brown6ec6f792012-04-17 16:52:41 -07001651
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001652 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1653 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1654
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001655 GET_METHOD_ID(gServiceClassInfo.getTouchCalibrationForInputDevice, clazz,
1656 "getTouchCalibrationForInputDevice",
Jason Gerecked5220742014-03-10 09:47:59 -07001657 "(Ljava/lang/String;I)Landroid/hardware/input/TouchCalibration;");
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001658
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001659 // InputDevice
1660
1661 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1662 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1663
Jeff Brown6ec402b2010-07-28 15:48:59 -07001664 // KeyEvent
1665
1666 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001667 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1668
Jeff Brown8d608662010-08-30 03:02:23 -07001669 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001670
1671 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001672 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001673
RoboErikfb290df2013-12-16 11:27:55 -08001674 // InputDeviceIdentifier
1675
1676 FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
1677 gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
1678 GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
1679 "<init>", "(Ljava/lang/String;II)V");
1680
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001681 // TouchCalibration
1682
1683 FIND_CLASS(gTouchCalibrationClassInfo.clazz, "android/hardware/input/TouchCalibration");
1684 gTouchCalibrationClassInfo.clazz = jclass(env->NewGlobalRef(gTouchCalibrationClassInfo.clazz));
1685
1686 GET_METHOD_ID(gTouchCalibrationClassInfo.getAffineTransform, gTouchCalibrationClassInfo.clazz,
1687 "getAffineTransform", "()[F");
1688
Jeff Brown46b9ac02010-04-22 18:58:52 -07001689 return 0;
1690}
1691
Jeff Brown46b9ac02010-04-22 18:58:52 -07001692} /* namespace android */