blob: b5654eebd34f9d7253f3d6606c74150fc0ac14cf [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);
Jeff Brown349703e2010-06-22 01:27:15 -0700208
Jeff Brown9c3cda02010-06-15 01:31:58 -0700209 /* --- InputReaderPolicyInterface implementation --- */
210
Jeff Brown214eaf42011-05-26 19:17:02 -0700211 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800212 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700213 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
RoboErikfb290df2013-12-16 11:27:55 -0800214 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700215 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jason Gerecked5220742014-03-10 09:47:59 -0700216 virtual TouchAffineTransformation getTouchAffineTransformation(JNIEnv *env,
217 jfloatArray matrixArr);
218 virtual TouchAffineTransformation getTouchAffineTransformation(
219 const String8& inputDeviceDescriptor, int32_t surfaceRotation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700220
221 /* --- InputDispatcherPolicyInterface implementation --- */
222
Jeff Brownbcc046a2012-09-27 20:46:43 -0700223 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700224 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700225 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700226 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700227 const sp<InputWindowHandle>& inputWindowHandle,
228 const String8& reason);
Jeff Brown928e0542011-01-10 11:17:36 -0800229 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700230 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700231 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
Jeff Brown1f245102010-11-18 20:53:46 -0800232 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800233 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700234 virtual nsecs_t interceptKeyBeforeDispatching(
235 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700236 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800237 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800238 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700239 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700240 virtual bool checkInjectEventsPermissionNonReentrant(
241 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700242
Jeff Brown2352b972011-04-12 22:39:53 -0700243 /* --- PointerControllerPolicyInterface implementation --- */
244
245 virtual void loadPointerResources(PointerResources* outResources);
Jun Mukai808196f2015-10-28 16:46:44 -0700246 virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
247 std::map<int32_t, PointerAnimation>* outAnimationResources);
Jun Mukai5ec74202015-10-07 16:58:09 +0900248 virtual int32_t getDefaultPointerIconId();
Jeff Brown2352b972011-04-12 22:39:53 -0700249
Jeff Brown9c3cda02010-06-15 01:31:58 -0700250private:
251 sp<InputManager> mInputManager;
252
Jeff Brown2352b972011-04-12 22:39:53 -0700253 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700254 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800255 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700256
Jeff Brown83c09682010-12-23 17:50:18 -0800257 Mutex mLock;
258 struct Locked {
259 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700260 DisplayViewport internalViewport;
261 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800262
Jeff Brown05dc66a2011-03-02 14:41:58 -0800263 // System UI visibility.
264 int32_t systemUiVisibility;
265
Jeff Brown1a84fd12011-06-02 01:26:32 -0700266 // Pointer speed.
267 int32_t pointerSpeed;
268
Jeff Brown474dcb52011-06-14 20:22:50 -0700269 // True if pointer gestures are enabled.
270 bool pointerGesturesEnabled;
271
Jeff Browndaf4a122011-08-26 17:14:14 -0700272 // Show touches feature enable/disable.
273 bool showTouches;
274
Jeff Brown5541de92011-04-11 11:54:25 -0700275 // Sprite controller singleton, created on first use.
276 sp<SpriteController> spriteController;
277
Jeff Brown83c09682010-12-23 17:50:18 -0800278 // Pointer controller singleton, created and destroyed as needed.
279 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800280 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700281
Michael Wrighta4051212015-07-23 17:04:40 +0100282 std::atomic<bool> mInteractive;
Jeff Brown037c33e2014-04-09 00:31:55 -0700283
Jeff Brown2352b972011-04-12 22:39:53 -0700284 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800285 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700286 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800287
Jeff Brownb88102f2010-09-08 11:49:43 -0700288 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700289
Jeff Brown9c3cda02010-06-15 01:31:58 -0700290 static inline JNIEnv* jniEnv() {
291 return AndroidRuntime::getJNIEnv();
292 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700293};
294
Jeff Brown928e0542011-01-10 11:17:36 -0800295
Jeff Brown9c3cda02010-06-15 01:31:58 -0700296
Jeff Brown2352b972011-04-12 22:39:53 -0700297NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700298 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown037c33e2014-04-09 00:31:55 -0700299 mLooper(looper), mInteractive(true) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700300 JNIEnv* env = jniEnv();
301
Jeff Brown2352b972011-04-12 22:39:53 -0700302 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700303 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700304
Jeff Brown83c09682010-12-23 17:50:18 -0800305 {
306 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800307 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700308 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700309 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700310 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800311 }
Michael Wrighta4051212015-07-23 17:04:40 +0100312 mInteractive = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800313
Jeff Brown9c3cda02010-06-15 01:31:58 -0700314 sp<EventHub> eventHub = new EventHub();
315 mInputManager = new InputManager(eventHub, this, this);
316}
317
318NativeInputManager::~NativeInputManager() {
319 JNIEnv* env = jniEnv();
320
Jeff Brown2352b972011-04-12 22:39:53 -0700321 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700322 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700323}
324
Jeff Brownb88102f2010-09-08 11:49:43 -0700325void NativeInputManager::dump(String8& dump) {
Michael Wrighta4051212015-07-23 17:04:40 +0100326 dump.append("Input Manager State:\n");
327 {
328 dump.appendFormat(INDENT "Interactive: %s\n", toString(mInteractive.load()));
329 }
330 {
331 AutoMutex _l(mLock);
332 dump.appendFormat(INDENT "System UI Visibility: 0x%0" PRIx32 "\n",
333 mLocked.systemUiVisibility);
334 dump.appendFormat(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed);
335 dump.appendFormat(INDENT "Pointer Gestures Enabled: %s\n",
336 toString(mLocked.pointerGesturesEnabled));
337 dump.appendFormat(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
338 }
339 dump.append("\n");
340
Jeff Brownb88102f2010-09-08 11:49:43 -0700341 mInputManager->getReader()->dump(dump);
342 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700343
Jeff Brownb88102f2010-09-08 11:49:43 -0700344 mInputManager->getDispatcher()->dump(dump);
345 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700346}
347
Jeff Brown7fbdc842010-06-17 20:52:56 -0700348bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700349 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000350 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700351 LOGE_EX(env);
352 env->ExceptionClear();
353 return true;
354 }
355 return false;
356}
357
Jeff Brownd728bf52012-09-08 18:05:28 -0700358void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700359 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700360 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700361 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700362
Jeff Brownd728bf52012-09-08 18:05:28 -0700363 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
364 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700365 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700366 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700367
Jeff Brownd728bf52012-09-08 18:05:28 -0700368 if (!external) {
369 sp<PointerController> controller = mLocked.pointerController.promote();
370 if (controller != NULL) {
371 controller->setDisplayViewport(
372 viewport.logicalRight - viewport.logicalLeft,
373 viewport.logicalBottom - viewport.logicalTop,
374 viewport.orientation);
375 }
Jeff Brown2352b972011-04-12 22:39:53 -0700376 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700377 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700378 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700379
380 if (changed) {
381 mInputManager->getReader()->requestRefreshConfiguration(
382 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
383 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700384}
385
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700386status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
Jeff Brown928e0542011-01-10 11:17:36 -0800387 const sp<InputChannel>& inputChannel,
388 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
389 return mInputManager->getDispatcher()->registerInputChannel(
390 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700391}
392
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700393status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700394 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700395 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700396}
397
Jeff Brown214eaf42011-05-26 19:17:02 -0700398void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700399 JNIEnv* env = jniEnv();
400
Jeff Brown4532e612012-04-05 14:27:12 -0700401 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
402 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700403 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
404 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
405 }
406
407 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700408 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
409 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700410 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
411 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700412 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700413 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700414 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700415 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700416 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700417 env->DeleteLocalRef(item);
418 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700419 env->DeleteLocalRef(excludedDeviceNames);
420 }
421
Jeff Brown4532e612012-04-05 14:27:12 -0700422 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
423 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700424 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700425 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
426 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700427 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700428 jint longPressTimeout = env->CallIntMethod(mServiceObj,
429 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700430 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700431 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700432
433 // We must ensure that the tap-drag interval is significantly shorter than
434 // the long-press timeout because the tap is held down for the entire duration
435 // of the double-tap timeout.
436 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700437 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700438 outConfig->pointerGestureTapDragInterval =
439 milliseconds_to_nanoseconds(tapDragInterval);
440 }
441 }
442 }
443
Jeff Brown4532e612012-04-05 14:27:12 -0700444 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
445 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700446 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
447 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700448 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700449
450 { // acquire lock
451 AutoMutex _l(mLock);
452
453 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
454 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700455 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700456
Jeff Browndaf4a122011-08-26 17:14:14 -0700457 outConfig->showTouches = mLocked.showTouches;
458
Jeff Brownd728bf52012-09-08 18:05:28 -0700459 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
460 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700461 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700462}
463
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700464sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t /* deviceId */) {
Jeff Brown83c09682010-12-23 17:50:18 -0800465 AutoMutex _l(mLock);
466
467 sp<PointerController> controller = mLocked.pointerController.promote();
468 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700469 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800470
Jeff Brown2352b972011-04-12 22:39:53 -0700471 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800472 mLocked.pointerController = controller;
473
Jeff Brownd728bf52012-09-08 18:05:28 -0700474 DisplayViewport& v = mLocked.internalViewport;
475 controller->setDisplayViewport(
476 v.logicalRight - v.logicalLeft,
477 v.logicalBottom - v.logicalTop,
478 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800479
Jeff Brown5541de92011-04-11 11:54:25 -0700480 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700481 jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
482 gServiceClassInfo.getPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700483 if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
484 PointerIcon pointerIcon;
485 status_t status = android_view_PointerIcon_load(env, pointerIconObj,
486 mContextObj, &pointerIcon);
487 if (!status && !pointerIcon.isNullIcon()) {
488 controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
489 pointerIcon.hotSpotX, pointerIcon.hotSpotY));
490 } else {
491 controller->setPointerIcon(SpriteIcon());
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800492 }
Jeff Brown2352b972011-04-12 22:39:53 -0700493 env->DeleteLocalRef(pointerIconObj);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800494 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800495
Jeff Brown2352b972011-04-12 22:39:53 -0700496 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800497 }
498 return controller;
499}
500
Jeff Brown5541de92011-04-11 11:54:25 -0700501void NativeInputManager::ensureSpriteControllerLocked() {
502 if (mLocked.spriteController == NULL) {
503 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700504 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700505 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
506 layer = -1;
507 }
508 mLocked.spriteController = new SpriteController(mLooper, layer);
509 }
510}
511
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700512void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
513 JNIEnv* env = jniEnv();
514
515 size_t count = inputDevices.size();
516 jobjectArray inputDevicesObjArray = env->NewObjectArray(
517 count, gInputDeviceClassInfo.clazz, NULL);
518 if (inputDevicesObjArray) {
519 bool error = false;
520 for (size_t i = 0; i < count; i++) {
521 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
522 if (!inputDeviceObj) {
523 error = true;
524 break;
525 }
526
527 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
528 env->DeleteLocalRef(inputDeviceObj);
529 }
530
531 if (!error) {
532 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
533 inputDevicesObjArray);
534 }
535
536 env->DeleteLocalRef(inputDevicesObjArray);
537 }
538
539 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
540}
541
Jeff Brown6ec6f792012-04-17 16:52:41 -0700542sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
RoboErikfb290df2013-12-16 11:27:55 -0800543 const InputDeviceIdentifier& identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700544 JNIEnv* env = jniEnv();
545
546 sp<KeyCharacterMap> result;
RoboErikfb290df2013-12-16 11:27:55 -0800547 ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
548 ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
549 gInputDeviceIdentifierInfo.constructor, descriptor.get(),
550 identifier.vendor, identifier.product));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700551 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
RoboErikfb290df2013-12-16 11:27:55 -0800552 gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700553 if (arrayObj.get()) {
554 ScopedLocalRef<jstring> filenameObj(env,
555 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
556 ScopedLocalRef<jstring> contentsObj(env,
557 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
558 ScopedUtfChars filenameChars(env, filenameObj.get());
559 ScopedUtfChars contentsChars(env, contentsObj.get());
560
561 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
562 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
563 }
564 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
565 return result;
566}
567
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700568String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
569 JNIEnv* env = jniEnv();
570
571 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
572 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
573 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
574 String8 result;
575 if (aliasObj.get()) {
576 ScopedUtfChars aliasChars(env, aliasObj.get());
577 result.setTo(aliasChars.c_str());
578 }
579 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
580 return result;
581}
582
Jeff Brownbcc046a2012-09-27 20:46:43 -0700583void NativeInputManager::notifySwitch(nsecs_t when,
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700584 uint32_t switchValues, uint32_t switchMask, uint32_t /* policyFlags */) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700585#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700586 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
587 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700588#endif
589
590 JNIEnv* env = jniEnv();
591
Jeff Brown53384282012-08-20 20:16:01 -0700592 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700593 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700594 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700595}
596
Jeff Brown9c3cda02010-06-15 01:31:58 -0700597void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
598#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000599 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700600#endif
601
602 JNIEnv* env = jniEnv();
603
Jeff Brown4532e612012-04-05 14:27:12 -0700604 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700605 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700606}
607
Jeff Brown519e0242010-09-15 15:18:56 -0700608nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700609 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700610#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000611 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700612#endif
613
614 JNIEnv* env = jniEnv();
615
Jeff Brown928e0542011-01-10 11:17:36 -0800616 jobject inputApplicationHandleObj =
617 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
618 jobject inputWindowHandleObj =
619 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownbd181bb2013-09-10 16:44:24 -0700620 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700621
Jeff Brown4532e612012-04-05 14:27:12 -0700622 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700623 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
624 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700625 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
626 newTimeout = 0; // abort dispatch
627 } else {
628 assert(newTimeout >= 0);
629 }
630
Jeff Brownbd181bb2013-09-10 16:44:24 -0700631 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800632 env->DeleteLocalRef(inputWindowHandleObj);
633 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700634 return newTimeout;
635}
636
Jeff Brown928e0542011-01-10 11:17:36 -0800637void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700638#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000639 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700640#endif
641
Jeff Brown7fbdc842010-06-17 20:52:56 -0700642 JNIEnv* env = jniEnv();
643
Jeff Brown928e0542011-01-10 11:17:36 -0800644 jobject inputWindowHandleObj =
645 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
646 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700647 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800648 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700649 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
650
Jeff Brown928e0542011-01-10 11:17:36 -0800651 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700652 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700653}
654
Jeff Brown214eaf42011-05-26 19:17:02 -0700655void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
656 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800657
Jeff Brown4532e612012-04-05 14:27:12 -0700658 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
659 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700660 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
661 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
662 }
Jeff Browna4547672011-03-02 21:38:11 -0800663
Jeff Brown4532e612012-04-05 14:27:12 -0700664 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
665 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700666 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
667 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
668 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700669}
670
Jeff Brown9302c872011-07-13 22:51:29 -0700671void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
672 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700673
Jeff Brown9302c872011-07-13 22:51:29 -0700674 if (windowHandleObjArray) {
675 jsize length = env->GetArrayLength(windowHandleObjArray);
676 for (jsize i = 0; i < length; i++) {
677 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
678 if (! windowHandleObj) {
679 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700680 }
Jeff Brown9302c872011-07-13 22:51:29 -0700681
682 sp<InputWindowHandle> windowHandle =
683 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
684 if (windowHandle != NULL) {
685 windowHandles.push(windowHandle);
686 }
687 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700688 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700689 }
Jeff Brown349703e2010-06-22 01:27:15 -0700690
Jeff Brown9302c872011-07-13 22:51:29 -0700691 mInputManager->getDispatcher()->setInputWindows(windowHandles);
692
693 // Do this after the dispatcher has updated the window handle state.
694 bool newPointerGesturesEnabled = true;
695 size_t numWindows = windowHandles.size();
696 for (size_t i = 0; i < numWindows; i++) {
697 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700698 const InputWindowInfo* windowInfo = windowHandle->getInfo();
699 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
700 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700701 newPointerGesturesEnabled = false;
702 }
703 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700704
705 uint32_t changes = 0;
706 { // acquire lock
707 AutoMutex _l(mLock);
708
709 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
710 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
711 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
712 }
713 } // release lock
714
715 if (changes) {
716 mInputManager->getReader()->requestRefreshConfiguration(changes);
717 }
Jeff Brown349703e2010-06-22 01:27:15 -0700718}
719
Jeff Brown9302c872011-07-13 22:51:29 -0700720void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
721 sp<InputApplicationHandle> applicationHandle =
722 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
723 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700724}
725
726void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700727 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700728}
729
Jeff Brown05dc66a2011-03-02 14:41:58 -0800730void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
731 AutoMutex _l(mLock);
732
733 if (mLocked.systemUiVisibility != visibility) {
734 mLocked.systemUiVisibility = visibility;
735
736 sp<PointerController> controller = mLocked.pointerController.promote();
737 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700738 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800739 }
740 }
741}
742
Jeff Brown2352b972011-04-12 22:39:53 -0700743void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800744 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700745 controller->setInactivityTimeout(lightsOut
746 ? PointerController::INACTIVITY_TIMEOUT_SHORT
747 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800748}
749
Jeff Brown1a84fd12011-06-02 01:26:32 -0700750void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700751 { // acquire lock
752 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700753
Jeff Brown474dcb52011-06-14 20:22:50 -0700754 if (mLocked.pointerSpeed == speed) {
755 return;
756 }
757
Steve Block6215d3f2012-01-04 20:05:49 +0000758 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700759 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700760 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700761
Jeff Brown474dcb52011-06-14 20:22:50 -0700762 mInputManager->getReader()->requestRefreshConfiguration(
763 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700764}
765
Jeff Browndaf4a122011-08-26 17:14:14 -0700766void NativeInputManager::setShowTouches(bool enabled) {
767 { // acquire lock
768 AutoMutex _l(mLock);
769
770 if (mLocked.showTouches == enabled) {
771 return;
772 }
773
Steve Block6215d3f2012-01-04 20:05:49 +0000774 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700775 mLocked.showTouches = enabled;
776 } // release lock
777
778 mInputManager->getReader()->requestRefreshConfiguration(
779 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
780}
781
Jeff Brown037c33e2014-04-09 00:31:55 -0700782void NativeInputManager::setInteractive(bool interactive) {
783 mInteractive = interactive;
Jeff Browne20c9e02010-10-11 14:20:19 -0700784}
785
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800786void NativeInputManager::reloadCalibration() {
787 mInputManager->getReader()->requestRefreshConfiguration(
Michael Wright357285c2015-04-17 00:50:31 +0100788 InputReaderConfiguration::CHANGE_TOUCH_AFFINE_TRANSFORMATION);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800789}
790
Jun Mukai1db53972015-09-11 18:08:31 -0700791void NativeInputManager::setPointerIconShape(int32_t iconId) {
792 AutoMutex _l(mLock);
793 sp<PointerController> controller = mLocked.pointerController.promote();
794 if (controller != NULL) {
795 // Use 0 (the default icon) for ARROW.
Jun Mukai5ec74202015-10-07 16:58:09 +0900796 controller->updatePointerShape(iconId);
Jun Mukai1db53972015-09-11 18:08:31 -0700797 }
798}
799
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800800TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
801 JNIEnv *env, jfloatArray matrixArr) {
802 ScopedFloatArrayRO matrix(env, matrixArr);
803 assert(matrix.size() == 6);
804
805 TouchAffineTransformation transform;
806 transform.x_scale = matrix[0];
807 transform.x_ymix = matrix[1];
808 transform.x_offset = matrix[2];
809 transform.y_xmix = matrix[3];
810 transform.y_scale = matrix[4];
811 transform.y_offset = matrix[5];
812
813 return transform;
814}
815
816TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
Jason Gerecked5220742014-03-10 09:47:59 -0700817 const String8& inputDeviceDescriptor, int32_t surfaceRotation) {
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800818 JNIEnv* env = jniEnv();
819
820 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
821
822 jobject cal = env->CallObjectMethod(mServiceObj,
Jason Gerecked5220742014-03-10 09:47:59 -0700823 gServiceClassInfo.getTouchCalibrationForInputDevice, descriptorObj.get(),
824 surfaceRotation);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800825
826 jfloatArray matrixArr = jfloatArray(env->CallObjectMethod(cal,
827 gTouchCalibrationClassInfo.getAffineTransform));
828
829 TouchAffineTransformation transform = getTouchAffineTransformation(env, matrixArr);
830
831 env->DeleteLocalRef(matrixArr);
832 env->DeleteLocalRef(cal);
833
834 return transform;
835}
836
Jeff Brown0029c662011-03-30 02:25:18 -0700837bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
838 jobject inputEventObj;
839
840 JNIEnv* env = jniEnv();
841 switch (inputEvent->getType()) {
842 case AINPUT_EVENT_TYPE_KEY:
843 inputEventObj = android_view_KeyEvent_fromNative(env,
844 static_cast<const KeyEvent*>(inputEvent));
845 break;
846 case AINPUT_EVENT_TYPE_MOTION:
847 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
848 static_cast<const MotionEvent*>(inputEvent));
849 break;
850 default:
851 return true; // dispatch the event normally
852 }
853
854 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000855 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700856 return true; // dispatch the event normally
857 }
858
859 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700860 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700861 inputEventObj, policyFlags);
862 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
863 pass = true;
864 }
865 env->DeleteLocalRef(inputEventObj);
866 return pass;
867}
868
Jeff Brown1f245102010-11-18 20:53:46 -0800869void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
870 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700871 // Policy:
872 // - Ignore untrusted events and pass them along.
873 // - Ask the window manager what to do with normal events and trusted injected events.
874 // - For normal events wake and brighten the screen if currently off or dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100875 bool interactive = mInteractive.load();
876 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700877 policyFlags |= POLICY_FLAG_INTERACTIVE;
878 }
Jeff Brown3122e442010-10-11 23:32:49 -0700879 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800880 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700881 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800882 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
883 jint wmActions;
884 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700885 wmActions = env->CallIntMethod(mServiceObj,
886 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown037c33e2014-04-09 00:31:55 -0700887 keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800888 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
889 wmActions = 0;
890 }
891 android_view_KeyEvent_recycle(env, keyEventObj);
892 env->DeleteLocalRef(keyEventObj);
893 } else {
Steve Block3762c312012-01-06 19:20:56 +0000894 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700895 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700896 }
897
Jeff Brown56194eb2011-03-02 19:23:13 -0800898 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700899 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100900 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700901 policyFlags |= POLICY_FLAG_PASS_TO_USER;
902 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700903 }
904}
905
Jeff Brown56194eb2011-03-02 19:23:13 -0800906void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700907 // Policy:
908 // - Ignore untrusted events and pass them along.
909 // - No special filtering for injected events required at this time.
910 // - Filter normal events based on screen state.
911 // - For normal events brighten (but do not wake) the screen if currently dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100912 bool interactive = mInteractive.load();
913 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700914 policyFlags |= POLICY_FLAG_INTERACTIVE;
915 }
Jeff Brown3122e442010-10-11 23:32:49 -0700916 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700917 if (policyFlags & POLICY_FLAG_INTERACTIVE) {
Jeff Brown3122e442010-10-11 23:32:49 -0700918 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Michael Wright70af00a2014-09-03 19:30:20 -0700919 } else {
Jeff Brown56194eb2011-03-02 19:23:13 -0800920 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700921 jint wmActions = env->CallIntMethod(mServiceObj,
Michael Wright70af00a2014-09-03 19:30:20 -0700922 gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive,
Jeff Brown26875502014-01-30 21:47:47 -0800923 when, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800924 if (checkAndClearExceptionFromCallback(env,
Michael Wright70af00a2014-09-03 19:30:20 -0700925 "interceptMotionBeforeQueueingNonInteractive")) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800926 wmActions = 0;
927 }
928
Jeff Brown56194eb2011-03-02 19:23:13 -0800929 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700930 }
Jeff Brown3122e442010-10-11 23:32:49 -0700931 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100932 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700933 policyFlags |= POLICY_FLAG_PASS_TO_USER;
934 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700935 }
936}
937
Jeff Brown56194eb2011-03-02 19:23:13 -0800938void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
939 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800940 if (wmActions & WM_ACTION_PASS_TO_USER) {
941 policyFlags |= POLICY_FLAG_PASS_TO_USER;
942 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800943#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000944 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800945#endif
946 }
947}
948
Jeff Brown905805a2011-10-12 13:57:59 -0700949nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800950 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700951 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700952 // Policy:
953 // - Ignore untrusted events and pass them along.
954 // - Filter normal events and trusted injected events through the window manager policy to
955 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700956 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700957 if (policyFlags & POLICY_FLAG_TRUSTED) {
958 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700959
Jeff Brown928e0542011-01-10 11:17:36 -0800960 // Note: inputWindowHandle may be null.
961 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800962 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
963 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700964 jlong delayMillis = env->CallLongMethod(mServiceObj,
965 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800966 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800967 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
968 android_view_KeyEvent_recycle(env, keyEventObj);
969 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700970 if (!error) {
971 if (delayMillis < 0) {
972 result = -1;
973 } else if (delayMillis > 0) {
974 result = milliseconds_to_nanoseconds(delayMillis);
975 }
976 }
Jeff Brown1f245102010-11-18 20:53:46 -0800977 } else {
Steve Block3762c312012-01-06 19:20:56 +0000978 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800979 }
Jeff Brown928e0542011-01-10 11:17:36 -0800980 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700981 }
Jeff Brown1f245102010-11-18 20:53:46 -0800982 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700983}
984
Jeff Brown928e0542011-01-10 11:17:36 -0800985bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800986 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700987 // Policy:
988 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800989 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700990 if (policyFlags & POLICY_FLAG_TRUSTED) {
991 JNIEnv* env = jniEnv();
992
Jeff Brown928e0542011-01-10 11:17:36 -0800993 // Note: inputWindowHandle may be null.
994 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800995 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
996 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700997 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
998 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -0800999 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001000 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
1001 fallbackKeyEventObj = NULL;
1002 }
Jeff Brown1f245102010-11-18 20:53:46 -08001003 android_view_KeyEvent_recycle(env, keyEventObj);
1004 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001005
1006 if (fallbackKeyEventObj) {
1007 // Note: outFallbackKeyEvent may be the same object as keyEvent.
1008 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
1009 outFallbackKeyEvent)) {
1010 result = true;
1011 }
1012 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
1013 env->DeleteLocalRef(fallbackKeyEventObj);
1014 }
Jeff Brown1f245102010-11-18 20:53:46 -08001015 } else {
Steve Block3762c312012-01-06 19:20:56 +00001016 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -08001017 }
Jeff Brown928e0542011-01-10 11:17:36 -08001018 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -07001019 }
Jeff Brown1f245102010-11-18 20:53:46 -08001020 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -07001021}
1022
Jeff Brown01ce2e92010-09-26 22:20:12 -07001023void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
1024 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -07001025}
1026
Jeff Brown349703e2010-06-22 01:27:15 -07001027
Jeff Brownb88102f2010-09-08 11:49:43 -07001028bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
1029 int32_t injectorPid, int32_t injectorUid) {
1030 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -07001031 jboolean result = env->CallBooleanMethod(mServiceObj,
1032 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001033 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
1034 result = false;
1035 }
Jeff Brown349703e2010-06-22 01:27:15 -07001036 return result;
1037}
1038
Jeff Brown2352b972011-04-12 22:39:53 -07001039void NativeInputManager::loadPointerResources(PointerResources* outResources) {
1040 JNIEnv* env = jniEnv();
1041
1042 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
1043 &outResources->spotHover);
1044 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
1045 &outResources->spotTouch);
1046 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
1047 &outResources->spotAnchor);
1048}
1049
Jun Mukai808196f2015-10-28 16:46:44 -07001050void NativeInputManager::loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
1051 std::map<int32_t, PointerAnimation>* outAnimationResources) {
Jun Mukai1db53972015-09-11 18:08:31 -07001052 JNIEnv* env = jniEnv();
1053
1054 for (int iconId = POINTER_ICON_STYLE_CONTEXT_MENU; iconId <= POINTER_ICON_STYLE_GRABBING;
1055 ++iconId) {
Jun Mukai808196f2015-10-28 16:46:44 -07001056 PointerIcon pointerIcon;
1057 loadSystemIconAsSpriteWithPointerIcon(
1058 env, mContextObj, iconId, &pointerIcon, &((*outResources)[iconId]));
1059 if (!pointerIcon.bitmapFrames.empty()) {
1060 PointerAnimation& animationData = (*outAnimationResources)[iconId];
1061 size_t numFrames = pointerIcon.bitmapFrames.size() + 1;
1062 animationData.durationPerFrame =
1063 milliseconds_to_nanoseconds(pointerIcon.durationPerFrame);
1064 animationData.animationFrames.reserve(numFrames);
1065 animationData.animationFrames.push_back(SpriteIcon(
1066 pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1067 for (size_t i = 0; i < numFrames - 1; ++i) {
1068 animationData.animationFrames.push_back(SpriteIcon(
1069 pointerIcon.bitmapFrames[i], pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1070 }
1071 }
Jun Mukai1db53972015-09-11 18:08:31 -07001072 }
Jun Mukai808196f2015-10-28 16:46:44 -07001073 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_NULL,
1074 &((*outResources)[POINTER_ICON_STYLE_NULL]));
Jun Mukai1db53972015-09-11 18:08:31 -07001075}
1076
Jun Mukai5ec74202015-10-07 16:58:09 +09001077int32_t NativeInputManager::getDefaultPointerIconId() {
1078 return POINTER_ICON_STYLE_ARROW;
1079}
Jeff Brown83c09682010-12-23 17:50:18 -08001080
Jeff Brown9c3cda02010-06-15 01:31:58 -07001081// ----------------------------------------------------------------------------
1082
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001083static jlong nativeInit(JNIEnv* env, jclass /* clazz */,
Jeff Brown4532e612012-04-05 14:27:12 -07001084 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -07001085 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -08001086 if (messageQueue == NULL) {
1087 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
1088 return 0;
1089 }
1090
Jeff Brown603b4452012-04-06 17:39:41 -07001091 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
1092 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -08001093 im->incStrong(0);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001094 return reinterpret_cast<jlong>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001095}
1096
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001097static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001098 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001099
Jeff Brown4532e612012-04-05 14:27:12 -07001100 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001101 if (result) {
1102 jniThrowRuntimeException(env, "Input manager could not be started.");
1103 }
1104}
1105
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001106static void nativeSetDisplayViewport(JNIEnv* /* env */, jclass /* clazz */, jlong ptr,
1107 jboolean external, jint displayId, jint orientation,
Jeff Brownd728bf52012-09-08 18:05:28 -07001108 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001109 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1110 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001111 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001112
Jeff Brownd728bf52012-09-08 18:05:28 -07001113 DisplayViewport v;
1114 v.displayId = displayId;
1115 v.orientation = orientation;
1116 v.logicalLeft = logicalLeft;
1117 v.logicalTop = logicalTop;
1118 v.logicalRight = logicalRight;
1119 v.logicalBottom = logicalBottom;
1120 v.physicalLeft = physicalLeft;
1121 v.physicalTop = physicalTop;
1122 v.physicalRight = physicalRight;
1123 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001124 v.deviceWidth = deviceWidth;
1125 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001126 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001127}
1128
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001129static jint nativeGetScanCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001130 jlong ptr, jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001131 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001132
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001133 return (jint) im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001134 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001135}
1136
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001137static jint nativeGetKeyCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001138 jlong ptr, jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001139 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001140
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001141 return (jint) im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001142 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001143}
1144
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001145static jint nativeGetSwitchState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001146 jlong ptr, jint deviceId, jint sourceMask, jint sw) {
Jeff Brown4532e612012-04-05 14:27:12 -07001147 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001148
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001149 return (jint) im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001150 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001151}
1152
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001153static jboolean nativeHasKeys(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001154 jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001155 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001156
1157 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1158 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1159 jsize numCodes = env->GetArrayLength(keyCodes);
1160 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001161 if (numCodes == env->GetArrayLength(keyCodes)) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001162 if (im->getInputManager()->getReader()->hasKeys(
1163 deviceId, uint32_t(sourceMask), numCodes, codes, flags)) {
1164 result = JNI_TRUE;
1165 } else {
1166 result = JNI_FALSE;
1167 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001168 } else {
1169 result = JNI_FALSE;
1170 }
1171
1172 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1173 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1174 return result;
1175}
1176
1177static void throwInputChannelNotInitialized(JNIEnv* env) {
1178 jniThrowException(env, "java/lang/IllegalStateException",
1179 "inputChannel is not initialized");
1180}
1181
Jeff Brown4532e612012-04-05 14:27:12 -07001182static void handleInputChannelDisposed(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001183 jobject /* inputChannelObj */, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001184 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1185
Steve Block8564c8d2012-01-05 23:22:43 +00001186 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001187 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001188 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001189}
1190
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001191static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001192 jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown4532e612012-04-05 14:27:12 -07001193 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001194
1195 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1196 inputChannelObj);
1197 if (inputChannel == NULL) {
1198 throwInputChannelNotInitialized(env);
1199 return;
1200 }
1201
Jeff Brown928e0542011-01-10 11:17:36 -08001202 sp<InputWindowHandle> inputWindowHandle =
1203 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001204
Jeff Brown4532e612012-04-05 14:27:12 -07001205 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001206 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001207 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001208 String8 message;
1209 message.appendFormat("Failed to register input channel. status=%d", status);
1210 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001211 return;
1212 }
1213
Jeff Browna41ca772010-08-11 14:46:32 -07001214 if (! monitor) {
1215 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001216 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001217 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001218}
1219
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001220static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001221 jlong ptr, jobject inputChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001222 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001223
1224 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1225 inputChannelObj);
1226 if (inputChannel == NULL) {
1227 throwInputChannelNotInitialized(env);
1228 return;
1229 }
1230
1231 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1232
Jeff Brown4532e612012-04-05 14:27:12 -07001233 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001234 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1235 String8 message;
1236 message.appendFormat("Failed to unregister input channel. status=%d", status);
1237 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001238 }
1239}
1240
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001241static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001242 jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001243 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001244
Jeff Brown4532e612012-04-05 14:27:12 -07001245 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001246}
1247
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001248static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
Jeff Brownca9bc702014-02-11 14:32:56 -08001249 jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001250 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001251 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001252
Jeff Brown6ec402b2010-07-28 15:48:59 -07001253 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1254 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001255 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1256 if (status) {
1257 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1258 return INPUT_EVENT_INJECTION_FAILED;
1259 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001260
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001261 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001262 & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001263 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001264 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001265 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1266 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001267 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1268 return INPUT_EVENT_INJECTION_FAILED;
1269 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001270
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001271 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001272 motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001273 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001274 } else {
1275 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001276 return INPUT_EVENT_INJECTION_FAILED;
1277 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001278}
1279
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001280static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001281 jlong ptr, jobjectArray windowHandleObjArray) {
Jeff Brown4532e612012-04-05 14:27:12 -07001282 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001283
Jeff Brown4532e612012-04-05 14:27:12 -07001284 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001285}
1286
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001287static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001288 jlong ptr, jobject applicationHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001289 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001290
Jeff Brown4532e612012-04-05 14:27:12 -07001291 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001292}
1293
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001294static void nativeSetInputDispatchMode(JNIEnv* /* env */,
1295 jclass /* clazz */, jlong ptr, jboolean enabled, jboolean frozen) {
Jeff Brown4532e612012-04-05 14:27:12 -07001296 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001297
Jeff Brown4532e612012-04-05 14:27:12 -07001298 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001299}
1300
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001301static void nativeSetSystemUiVisibility(JNIEnv* /* env */,
1302 jclass /* clazz */, jlong ptr, jint visibility) {
Jeff Brown4532e612012-04-05 14:27:12 -07001303 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001304
Jeff Brown4532e612012-04-05 14:27:12 -07001305 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001306}
1307
Jeff Brown4532e612012-04-05 14:27:12 -07001308static jboolean nativeTransferTouchFocus(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001309 jclass /* clazz */, jlong ptr, jobject fromChannelObj, jobject toChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001310 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001311
1312 sp<InputChannel> fromChannel =
1313 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1314 sp<InputChannel> toChannel =
1315 android_view_InputChannel_getInputChannel(env, toChannelObj);
1316
1317 if (fromChannel == NULL || toChannel == NULL) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001318 return JNI_FALSE;
Jeff Browne6504122010-09-27 14:52:15 -07001319 }
1320
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001321 if (im->getInputManager()->getDispatcher()->
1322 transferTouchFocus(fromChannel, toChannel)) {
1323 return JNI_TRUE;
1324 } else {
1325 return JNI_FALSE;
1326 }
Jeff Browne6504122010-09-27 14:52:15 -07001327}
1328
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001329static void nativeSetPointerSpeed(JNIEnv* /* env */,
1330 jclass /* clazz */, jlong ptr, jint speed) {
Jeff Brown4532e612012-04-05 14:27:12 -07001331 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001332
Jeff Brown4532e612012-04-05 14:27:12 -07001333 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001334}
1335
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001336static void nativeSetShowTouches(JNIEnv* /* env */,
1337 jclass /* clazz */, jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001338 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001339
Jeff Brown4532e612012-04-05 14:27:12 -07001340 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001341}
1342
Jeff Brown037c33e2014-04-09 00:31:55 -07001343static void nativeSetInteractive(JNIEnv* env,
1344 jclass clazz, jlong ptr, jboolean interactive) {
1345 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1346
1347 im->setInteractive(interactive);
1348}
1349
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001350static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) {
1351 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1352 im->reloadCalibration();
1353}
1354
Jeff Browna47425a2012-04-13 04:09:27 -07001355static void nativeVibrate(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001356 jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj,
Jeff Browna47425a2012-04-13 04:09:27 -07001357 jint repeat, jint token) {
1358 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1359
1360 size_t patternSize = env->GetArrayLength(patternObj);
1361 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
Michael Wright9ecba522014-04-04 15:29:53 -07001362 ALOGI("Skipped requested vibration because the pattern size is %zu "
Jeff Browna47425a2012-04-13 04:09:27 -07001363 "which is more than the maximum supported size of %d.",
1364 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1365 return; // limit to reasonable size
1366 }
1367
1368 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1369 patternObj, NULL));
1370 nsecs_t pattern[patternSize];
1371 for (size_t i = 0; i < patternSize; i++) {
1372 pattern[i] = max(jlong(0), min(patternMillis[i],
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001373 (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL;
Jeff Browna47425a2012-04-13 04:09:27 -07001374 }
1375 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1376
1377 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1378}
1379
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001380static void nativeCancelVibrate(JNIEnv* /* env */,
1381 jclass /* clazz */, jlong ptr, jint deviceId, jint token) {
Jeff Browna47425a2012-04-13 04:09:27 -07001382 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1383
1384 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1385}
1386
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001387static void nativeReloadKeyboardLayouts(JNIEnv* /* env */,
1388 jclass /* clazz */, jlong ptr) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001389 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1390
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001391 im->getInputManager()->getReader()->requestRefreshConfiguration(
1392 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1393}
1394
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001395static void nativeReloadDeviceAliases(JNIEnv* /* env */,
1396 jclass /* clazz */, jlong ptr) {
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001397 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1398
1399 im->getInputManager()->getReader()->requestRefreshConfiguration(
1400 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001401}
1402
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001403static jstring nativeDump(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001404 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001405
Jeff Brownb88102f2010-09-08 11:49:43 -07001406 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001407 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001408 return env->NewStringUTF(dump.string());
1409}
1410
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001411static void nativeMonitor(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001412 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001413
Jeff Brown4532e612012-04-05 14:27:12 -07001414 im->getInputManager()->getReader()->monitor();
1415 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001416}
1417
Jun Mukai1db53972015-09-11 18:08:31 -07001418static void nativeSetPointerIconShape(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, jint iconId) {
1419 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1420 im->setPointerIconShape(iconId);
1421}
1422
Jeff Brown9c3cda02010-06-15 01:31:58 -07001423// ----------------------------------------------------------------------------
1424
Daniel Micay76f6a862015-09-19 17:31:01 -04001425static const JNINativeMethod gInputManagerMethods[] = {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001426 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001427 { "nativeInit",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001428 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J",
Jeff Brown4532e612012-04-05 14:27:12 -07001429 (void*) nativeInit },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001430 { "nativeStart", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001431 (void*) nativeStart },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001432 { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001433 (void*) nativeSetDisplayViewport },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001434 { "nativeGetScanCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001435 (void*) nativeGetScanCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001436 { "nativeGetKeyCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001437 (void*) nativeGetKeyCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001438 { "nativeGetSwitchState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001439 (void*) nativeGetSwitchState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001440 { "nativeHasKeys", "(JII[I[Z)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001441 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001442 { "nativeRegisterInputChannel",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001443 "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001444 (void*) nativeRegisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001445 { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001446 (void*) nativeUnregisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001447 { "nativeSetInputFilterEnabled", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001448 (void*) nativeSetInputFilterEnabled },
Jeff Brownca9bc702014-02-11 14:32:56 -08001449 { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001450 (void*) nativeInjectInputEvent },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001451 { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001452 (void*) nativeSetInputWindows },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001453 { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001454 (void*) nativeSetFocusedApplication },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001455 { "nativeSetInputDispatchMode", "(JZZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001456 (void*) nativeSetInputDispatchMode },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001457 { "nativeSetSystemUiVisibility", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001458 (void*) nativeSetSystemUiVisibility },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001459 { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001460 (void*) nativeTransferTouchFocus },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001461 { "nativeSetPointerSpeed", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001462 (void*) nativeSetPointerSpeed },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001463 { "nativeSetShowTouches", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001464 (void*) nativeSetShowTouches },
Jeff Brown037c33e2014-04-09 00:31:55 -07001465 { "nativeSetInteractive", "(JZ)V",
1466 (void*) nativeSetInteractive },
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001467 { "nativeReloadCalibration", "(J)V",
1468 (void*) nativeReloadCalibration },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001469 { "nativeVibrate", "(JI[JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001470 (void*) nativeVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001471 { "nativeCancelVibrate", "(JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001472 (void*) nativeCancelVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001473 { "nativeReloadKeyboardLayouts", "(J)V",
Jeff Brown6ec6f792012-04-17 16:52:41 -07001474 (void*) nativeReloadKeyboardLayouts },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001475 { "nativeReloadDeviceAliases", "(J)V",
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001476 (void*) nativeReloadDeviceAliases },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001477 { "nativeDump", "(J)Ljava/lang/String;",
Jeff Brown4532e612012-04-05 14:27:12 -07001478 (void*) nativeDump },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001479 { "nativeMonitor", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001480 (void*) nativeMonitor },
Jun Mukai1db53972015-09-11 18:08:31 -07001481 { "nativeSetPointerIconShape", "(JI)V",
1482 (void*) nativeSetPointerIconShape },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001483};
1484
1485#define FIND_CLASS(var, className) \
1486 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001487 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001488
1489#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1490 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1491 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1492
1493#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1494 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1495 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1496
1497int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001498 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001499 gInputManagerMethods, NELEM(gInputManagerMethods));
Bernhard Rosenkränzer9c1c90e2014-11-12 14:45:58 +01001500 (void) res; // Faked use when LOG_NDEBUG.
Jeff Brown46b9ac02010-04-22 18:58:52 -07001501 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1502
Jeff Brown9c3cda02010-06-15 01:31:58 -07001503 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001504
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001505 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001506 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001507
Jeff Brown4532e612012-04-05 14:27:12 -07001508 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001509 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001510
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001511 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1512 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1513
Jeff Brown53384282012-08-20 20:16:01 -07001514 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1515 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001516
Jeff Brown4532e612012-04-05 14:27:12 -07001517 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1518 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001519
Jeff Brown4532e612012-04-05 14:27:12 -07001520 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001521 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001522 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001523
Jeff Brown4532e612012-04-05 14:27:12 -07001524 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001525 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1526
Jeff Brown4532e612012-04-05 14:27:12 -07001527 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown037c33e2014-04-09 00:31:55 -07001528 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001529
Michael Wright70af00a2014-09-03 19:30:20 -07001530 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz,
1531 "interceptMotionBeforeQueueingNonInteractive", "(JI)I");
Jeff Brown56194eb2011-03-02 19:23:13 -08001532
Jeff Brown4532e612012-04-05 14:27:12 -07001533 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001534 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001535 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001536
Jeff Brown4532e612012-04-05 14:27:12 -07001537 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001538 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001539 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001540
Jeff Brown4532e612012-04-05 14:27:12 -07001541 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001542 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001543
Jeff Brown4532e612012-04-05 14:27:12 -07001544 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001545 "getVirtualKeyQuietTimeMillis", "()I");
1546
Jeff Brown4532e612012-04-05 14:27:12 -07001547 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001548 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1549
Jeff Brown4532e612012-04-05 14:27:12 -07001550 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001551 "getKeyRepeatTimeout", "()I");
1552
Jeff Brown4532e612012-04-05 14:27:12 -07001553 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001554 "getKeyRepeatDelay", "()I");
1555
Jeff Brown4532e612012-04-05 14:27:12 -07001556 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001557 "getHoverTapTimeout", "()I");
1558
Jeff Brown4532e612012-04-05 14:27:12 -07001559 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001560 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001561
Jeff Brown4532e612012-04-05 14:27:12 -07001562 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001563 "getDoubleTapTimeout", "()I");
1564
Jeff Brown4532e612012-04-05 14:27:12 -07001565 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001566 "getLongPressTimeout", "()I");
1567
Jeff Brown4532e612012-04-05 14:27:12 -07001568 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001569 "getPointerLayer", "()I");
1570
Jeff Brown4532e612012-04-05 14:27:12 -07001571 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001572 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001573
Jeff Brown6ec6f792012-04-17 16:52:41 -07001574 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
RoboErikfb290df2013-12-16 11:27:55 -08001575 "getKeyboardLayoutOverlay",
1576 "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
Jeff Brown6ec6f792012-04-17 16:52:41 -07001577
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001578 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1579 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1580
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001581 GET_METHOD_ID(gServiceClassInfo.getTouchCalibrationForInputDevice, clazz,
1582 "getTouchCalibrationForInputDevice",
Jason Gerecked5220742014-03-10 09:47:59 -07001583 "(Ljava/lang/String;I)Landroid/hardware/input/TouchCalibration;");
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001584
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001585 // InputDevice
1586
1587 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1588 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1589
Jeff Brown6ec402b2010-07-28 15:48:59 -07001590 // KeyEvent
1591
1592 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001593 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1594
Jeff Brown8d608662010-08-30 03:02:23 -07001595 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001596
1597 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001598 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001599
RoboErikfb290df2013-12-16 11:27:55 -08001600 // InputDeviceIdentifier
1601
1602 FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
1603 gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
1604 GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
1605 "<init>", "(Ljava/lang/String;II)V");
1606
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001607 // TouchCalibration
1608
1609 FIND_CLASS(gTouchCalibrationClassInfo.clazz, "android/hardware/input/TouchCalibration");
1610 gTouchCalibrationClassInfo.clazz = jclass(env->NewGlobalRef(gTouchCalibrationClassInfo.clazz));
1611
1612 GET_METHOD_ID(gTouchCalibrationClassInfo.getAffineTransform, gTouchCalibrationClassInfo.clazz,
1613 "getAffineTransform", "()[F");
1614
Jeff Brown46b9ac02010-04-22 18:58:52 -07001615 return 0;
1616}
1617
Jeff Brown46b9ac02010-04-22 18:58:52 -07001618} /* namespace android */