blob: 4c8474ab29f1ebac957aee0cb264ef7e00efde6c [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "InputManager-JNI"
18
Jeff Brown9c3cda02010-06-15 01:31:58 -070019//#define LOG_NDEBUG 0
20
21// Log debug messages about InputReaderPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070022#define DEBUG_INPUT_READER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070023
24// Log debug messages about InputDispatcherPolicy
Jeff Brown349703e2010-06-22 01:27:15 -070025#define DEBUG_INPUT_DISPATCHER_POLICY 0
Jeff Brown9c3cda02010-06-15 01:31:58 -070026
Jeff Brown83c09682010-12-23 17:50:18 -080027
Jeff Brown46b9ac02010-04-22 18:58:52 -070028#include "JNIHelp.h"
29#include "jni.h"
Michael Wrighta4051212015-07-23 17:04:40 +010030#include <atomic>
31#include <cinttypes>
Jeff Brown349703e2010-06-22 01:27:15 -070032#include <limits.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070033#include <android_runtime/AndroidRuntime.h>
Ruben Brunk87eac992013-09-09 17:44:59 -070034#include <android_runtime/Log.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080035
Jeff Brown46b9ac02010-04-22 18:58:52 -070036#include <utils/Log.h>
Jeff Brown05dc66a2011-03-02 14:41:58 -080037#include <utils/Looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070038#include <utils/threads.h>
Jeff Brown83c09682010-12-23 17:50:18 -080039
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040#include <input/PointerController.h>
Jeff Brown5541de92011-04-11 11:54:25 -070041#include <input/SpriteController.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080042
Michael Wrightd6b473712014-02-10 15:56:36 -080043#include <inputflinger/InputManager.h>
44
Jeff Brown05dc66a2011-03-02 14:41:58 -080045#include <android_os_MessageQueue.h>
Jeff Brown9f25b7f2012-04-10 14:30:49 -070046#include <android_view_InputDevice.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080047#include <android_view_KeyEvent.h>
48#include <android_view_MotionEvent.h>
49#include <android_view_InputChannel.h>
Jeff Brown2352b972011-04-12 22:39:53 -070050#include <android_view_PointerIcon.h>
Jeff Brownb4ff35d2011-01-02 16:37:43 -080051#include <android/graphics/GraphicsJNI.h>
52
Jeff Brown6ec6f792012-04-17 16:52:41 -070053#include <ScopedLocalRef.h>
Jason Gerecke857aa7b2014-01-27 18:34:20 -080054#include <ScopedPrimitiveArray.h>
Jeff Brown6ec6f792012-04-17 16:52:41 -070055#include <ScopedUtfChars.h>
56
Jeff Brown4f8ecd82012-06-18 18:29:13 -070057#include "com_android_server_power_PowerManagerService.h"
Jeff Brown4532e612012-04-05 14:27:12 -070058#include "com_android_server_input_InputApplicationHandle.h"
59#include "com_android_server_input_InputWindowHandle.h"
Jeff Brown46b9ac02010-04-22 18:58:52 -070060
Michael Wrighta4051212015-07-23 17:04:40 +010061#define INDENT " "
62
Jeff Brown46b9ac02010-04-22 18:58:52 -070063namespace android {
64
Jeff Brown1a84fd12011-06-02 01:26:32 -070065// The exponent used to calculate the pointer speed scaling factor.
66// The scaling factor is calculated as 2 ^ (speed * exponent),
67// where the speed ranges from -7 to + 7 and is supplied by the user.
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070068static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
Jeff Brown1a84fd12011-06-02 01:26:32 -070069
Jeff Brown46b9ac02010-04-22 18:58:52 -070070static struct {
Jeff Brown46b9ac02010-04-22 18:58:52 -070071 jmethodID notifyConfigurationChanged;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070072 jmethodID notifyInputDevicesChanged;
Jeff Brown53384282012-08-20 20:16:01 -070073 jmethodID notifySwitch;
Jeff Brown7fbdc842010-06-17 20:52:56 -070074 jmethodID notifyInputChannelBroken;
Jeff Brown349703e2010-06-22 01:27:15 -070075 jmethodID notifyANR;
Jeff Brown0029c662011-03-30 02:25:18 -070076 jmethodID filterInputEvent;
Jeff Brown349703e2010-06-22 01:27:15 -070077 jmethodID interceptKeyBeforeQueueing;
Michael Wright70af00a2014-09-03 19:30:20 -070078 jmethodID interceptMotionBeforeQueueingNonInteractive;
Jeff Brown349703e2010-06-22 01:27:15 -070079 jmethodID interceptKeyBeforeDispatching;
Jeff Brown3915bb82010-11-05 15:02:16 -070080 jmethodID dispatchUnhandledKey;
Jeff Brown349703e2010-06-22 01:27:15 -070081 jmethodID checkInjectEventsPermission;
Jeff Brownfe508922011-01-18 15:10:10 -080082 jmethodID getVirtualKeyQuietTimeMillis;
Jeff Brown46b9ac02010-04-22 18:58:52 -070083 jmethodID getExcludedDeviceNames;
Jeff Browna4547672011-03-02 21:38:11 -080084 jmethodID getKeyRepeatTimeout;
85 jmethodID getKeyRepeatDelay;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -070086 jmethodID getHoverTapTimeout;
87 jmethodID getHoverTapSlop;
Jeff Brown214eaf42011-05-26 19:17:02 -070088 jmethodID getDoubleTapTimeout;
89 jmethodID getLongPressTimeout;
Jeff Brown83c09682010-12-23 17:50:18 -080090 jmethodID getPointerLayer;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080091 jmethodID getPointerIcon;
Jeff Brown6ec6f792012-04-17 16:52:41 -070092 jmethodID getKeyboardLayoutOverlay;
Jeff Brown5bbd4b42012-04-20 19:28:00 -070093 jmethodID getDeviceAlias;
Jason Gerecke857aa7b2014-01-27 18:34:20 -080094 jmethodID getTouchCalibrationForInputDevice;
Jeff Brown4532e612012-04-05 14:27:12 -070095} gServiceClassInfo;
Jeff Brown46b9ac02010-04-22 18:58:52 -070096
97static struct {
98 jclass clazz;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070099} gInputDeviceClassInfo;
100
101static struct {
102 jclass clazz;
Jeff Brown6ec402b2010-07-28 15:48:59 -0700103} gKeyEventClassInfo;
104
105static struct {
106 jclass clazz;
107} gMotionEventClassInfo;
108
RoboErikfb290df2013-12-16 11:27:55 -0800109static struct {
110 jclass clazz;
111 jmethodID constructor;
112} gInputDeviceIdentifierInfo;
113
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800114static struct {
115 jclass clazz;
116 jmethodID getAffineTransform;
117} gTouchCalibrationClassInfo;
118
RoboErikfb290df2013-12-16 11:27:55 -0800119
Jeff Brown928e0542011-01-10 11:17:36 -0800120
121// --- Global functions ---
122
Jeff Brown214eaf42011-05-26 19:17:02 -0700123template<typename T>
124inline static T min(const T& a, const T& b) {
125 return a < b ? a : b;
126}
127
128template<typename T>
129inline static T max(const T& a, const T& b) {
130 return a > b ? a : b;
131}
132
Michael Wrighta4051212015-07-23 17:04:40 +0100133static inline const char* toString(bool value) {
134 return value ? "true" : "false";
135}
136
Jeff Brown928e0542011-01-10 11:17:36 -0800137static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
138 const sp<InputApplicationHandle>& inputApplicationHandle) {
139 if (inputApplicationHandle == NULL) {
140 return NULL;
141 }
142 return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
143 getInputApplicationHandleObjLocalRef(env);
144}
145
146static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
147 const sp<InputWindowHandle>& inputWindowHandle) {
148 if (inputWindowHandle == NULL) {
149 return NULL;
150 }
151 return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
152 getInputWindowHandleObjLocalRef(env);
153}
154
Jun Mukai808196f2015-10-28 16:46:44 -0700155static void loadSystemIconAsSpriteWithPointerIcon(JNIEnv* env, jobject contextObj, int32_t style,
156 PointerIcon* outPointerIcon, SpriteIcon* outSpriteIcon) {
Jeff Brown2352b972011-04-12 22:39:53 -0700157 status_t status = android_view_PointerIcon_loadSystemIcon(env,
Jun Mukai808196f2015-10-28 16:46:44 -0700158 contextObj, style, outPointerIcon);
Jeff Brown2352b972011-04-12 22:39:53 -0700159 if (!status) {
Jun Mukai808196f2015-10-28 16:46:44 -0700160 outPointerIcon->bitmap.copyTo(&outSpriteIcon->bitmap, kN32_SkColorType);
161 outSpriteIcon->hotSpotX = outPointerIcon->hotSpotX;
162 outSpriteIcon->hotSpotY = outPointerIcon->hotSpotY;
Jeff Brown2352b972011-04-12 22:39:53 -0700163 }
164}
165
Jun Mukai808196f2015-10-28 16:46:44 -0700166static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
167 SpriteIcon* outSpriteIcon) {
168 PointerIcon pointerIcon;
169 loadSystemIconAsSpriteWithPointerIcon(env, contextObj, style, &pointerIcon, outSpriteIcon);
170}
171
Jeff Brown905805a2011-10-12 13:57:59 -0700172enum {
173 WM_ACTION_PASS_TO_USER = 1,
Jeff Brown905805a2011-10-12 13:57:59 -0700174};
175
Jeff Brown928e0542011-01-10 11:17:36 -0800176
177// --- NativeInputManager ---
Jeff Brown83c09682010-12-23 17:50:18 -0800178
Jeff Brown9c3cda02010-06-15 01:31:58 -0700179class NativeInputManager : public virtual RefBase,
180 public virtual InputReaderPolicyInterface,
Jeff Brown2352b972011-04-12 22:39:53 -0700181 public virtual InputDispatcherPolicyInterface,
182 public virtual PointerControllerPolicyInterface {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700183protected:
184 virtual ~NativeInputManager();
185
186public:
Jeff Brown4532e612012-04-05 14:27:12 -0700187 NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700188
189 inline sp<InputManager> getInputManager() const { return mInputManager; }
190
Jeff Brownb88102f2010-09-08 11:49:43 -0700191 void dump(String8& dump);
Jeff Browne33348b2010-07-15 23:54:05 -0700192
Jeff Brownd728bf52012-09-08 18:05:28 -0700193 void setDisplayViewport(bool external, const DisplayViewport& viewport);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700194
Jeff Brown7fbdc842010-06-17 20:52:56 -0700195 status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -0800196 const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700197 status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
198
Jeff Brown9302c872011-07-13 22:51:29 -0700199 void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
200 void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700201 void setInputDispatchMode(bool enabled, bool frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800202 void setSystemUiVisibility(int32_t visibility);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700203 void setPointerSpeed(int32_t speed);
Jeff Browndaf4a122011-08-26 17:14:14 -0700204 void setShowTouches(bool enabled);
Jeff Brown037c33e2014-04-09 00:31:55 -0700205 void setInteractive(bool interactive);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800206 void reloadCalibration();
Jun Mukai1db53972015-09-11 18:08:31 -0700207 void setPointerIconShape(int32_t iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800208 void reloadPointerIcons();
Jun Mukaid4eaef72015-10-30 15:54:33 -0700209 void setCustomPointerIcon(const SpriteIcon& icon);
Jeff Brown349703e2010-06-22 01:27:15 -0700210
Jeff Brown9c3cda02010-06-15 01:31:58 -0700211 /* --- InputReaderPolicyInterface implementation --- */
212
Jeff Brown214eaf42011-05-26 19:17:02 -0700213 virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
Jeff Brown83c09682010-12-23 17:50:18 -0800214 virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700215 virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
RoboErikfb290df2013-12-16 11:27:55 -0800216 virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700217 virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
Jason Gerecked5220742014-03-10 09:47:59 -0700218 virtual TouchAffineTransformation getTouchAffineTransformation(JNIEnv *env,
219 jfloatArray matrixArr);
220 virtual TouchAffineTransformation getTouchAffineTransformation(
221 const String8& inputDeviceDescriptor, int32_t surfaceRotation);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700222
223 /* --- InputDispatcherPolicyInterface implementation --- */
224
Jeff Brownbcc046a2012-09-27 20:46:43 -0700225 virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
Jeff Browne20c9e02010-10-11 14:20:19 -0700226 uint32_t policyFlags);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700227 virtual void notifyConfigurationChanged(nsecs_t when);
Jeff Brown519e0242010-09-15 15:18:56 -0700228 virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700229 const sp<InputWindowHandle>& inputWindowHandle,
230 const String8& reason);
Jeff Brown928e0542011-01-10 11:17:36 -0800231 virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
Jeff Brown0029c662011-03-30 02:25:18 -0700232 virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
Jeff Brown214eaf42011-05-26 19:17:02 -0700233 virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
Jeff Brown1f245102010-11-18 20:53:46 -0800234 virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800235 virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
Jeff Brown905805a2011-10-12 13:57:59 -0700236 virtual nsecs_t interceptKeyBeforeDispatching(
237 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brownb88102f2010-09-08 11:49:43 -0700238 const KeyEvent* keyEvent, uint32_t policyFlags);
Jeff Brown928e0542011-01-10 11:17:36 -0800239 virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800240 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
Jeff Brown01ce2e92010-09-26 22:20:12 -0700241 virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
Jeff Brownb88102f2010-09-08 11:49:43 -0700242 virtual bool checkInjectEventsPermissionNonReentrant(
243 int32_t injectorPid, int32_t injectorUid);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700244
Jeff Brown2352b972011-04-12 22:39:53 -0700245 /* --- PointerControllerPolicyInterface implementation --- */
246
Jun Mukai19a56012015-11-24 11:25:52 -0800247 virtual void loadPointerIcon(SpriteIcon* icon);
Jeff Brown2352b972011-04-12 22:39:53 -0700248 virtual void loadPointerResources(PointerResources* outResources);
Jun Mukai808196f2015-10-28 16:46:44 -0700249 virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
250 std::map<int32_t, PointerAnimation>* outAnimationResources);
Jun Mukai5ec74202015-10-07 16:58:09 +0900251 virtual int32_t getDefaultPointerIconId();
Jun Mukaid4eaef72015-10-30 15:54:33 -0700252 virtual int32_t getCustomPointerIconId();
Jeff Brown2352b972011-04-12 22:39:53 -0700253
Jeff Brown9c3cda02010-06-15 01:31:58 -0700254private:
255 sp<InputManager> mInputManager;
256
Jeff Brown2352b972011-04-12 22:39:53 -0700257 jobject mContextObj;
Jeff Brown4532e612012-04-05 14:27:12 -0700258 jobject mServiceObj;
Jeff Brown05dc66a2011-03-02 14:41:58 -0800259 sp<Looper> mLooper;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700260
Jeff Brown83c09682010-12-23 17:50:18 -0800261 Mutex mLock;
262 struct Locked {
263 // Display size information.
Jeff Brownd728bf52012-09-08 18:05:28 -0700264 DisplayViewport internalViewport;
265 DisplayViewport externalViewport;
Jeff Brown83c09682010-12-23 17:50:18 -0800266
Jeff Brown05dc66a2011-03-02 14:41:58 -0800267 // System UI visibility.
268 int32_t systemUiVisibility;
269
Jeff Brown1a84fd12011-06-02 01:26:32 -0700270 // Pointer speed.
271 int32_t pointerSpeed;
272
Jeff Brown474dcb52011-06-14 20:22:50 -0700273 // True if pointer gestures are enabled.
274 bool pointerGesturesEnabled;
275
Jeff Browndaf4a122011-08-26 17:14:14 -0700276 // Show touches feature enable/disable.
277 bool showTouches;
278
Jeff Brown5541de92011-04-11 11:54:25 -0700279 // Sprite controller singleton, created on first use.
280 sp<SpriteController> spriteController;
281
Jeff Brown83c09682010-12-23 17:50:18 -0800282 // Pointer controller singleton, created and destroyed as needed.
283 wp<PointerController> pointerController;
Jeff Brown83c09682010-12-23 17:50:18 -0800284 } mLocked;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700285
Michael Wrighta4051212015-07-23 17:04:40 +0100286 std::atomic<bool> mInteractive;
Jeff Brown037c33e2014-04-09 00:31:55 -0700287
Jeff Brown2352b972011-04-12 22:39:53 -0700288 void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
Jeff Brown56194eb2011-03-02 19:23:13 -0800289 void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
Jeff Brown5541de92011-04-11 11:54:25 -0700290 void ensureSpriteControllerLocked();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800291
Jeff Brownb88102f2010-09-08 11:49:43 -0700292 static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
Jeff Browna41ca772010-08-11 14:46:32 -0700293
Jeff Brown9c3cda02010-06-15 01:31:58 -0700294 static inline JNIEnv* jniEnv() {
295 return AndroidRuntime::getJNIEnv();
296 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700297};
298
Jeff Brown928e0542011-01-10 11:17:36 -0800299
Jeff Brown9c3cda02010-06-15 01:31:58 -0700300
Jeff Brown2352b972011-04-12 22:39:53 -0700301NativeInputManager::NativeInputManager(jobject contextObj,
Jeff Brown4532e612012-04-05 14:27:12 -0700302 jobject serviceObj, const sp<Looper>& looper) :
Jeff Brown037c33e2014-04-09 00:31:55 -0700303 mLooper(looper), mInteractive(true) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700304 JNIEnv* env = jniEnv();
305
Jeff Brown2352b972011-04-12 22:39:53 -0700306 mContextObj = env->NewGlobalRef(contextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700307 mServiceObj = env->NewGlobalRef(serviceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700308
Jeff Brown83c09682010-12-23 17:50:18 -0800309 {
310 AutoMutex _l(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800311 mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700312 mLocked.pointerSpeed = 0;
Jeff Brown474dcb52011-06-14 20:22:50 -0700313 mLocked.pointerGesturesEnabled = true;
Jeff Browndaf4a122011-08-26 17:14:14 -0700314 mLocked.showTouches = false;
Jeff Brown83c09682010-12-23 17:50:18 -0800315 }
Michael Wrighta4051212015-07-23 17:04:40 +0100316 mInteractive = true;
Jeff Brown83c09682010-12-23 17:50:18 -0800317
Jeff Brown9c3cda02010-06-15 01:31:58 -0700318 sp<EventHub> eventHub = new EventHub();
319 mInputManager = new InputManager(eventHub, this, this);
320}
321
322NativeInputManager::~NativeInputManager() {
323 JNIEnv* env = jniEnv();
324
Jeff Brown2352b972011-04-12 22:39:53 -0700325 env->DeleteGlobalRef(mContextObj);
Jeff Brown4532e612012-04-05 14:27:12 -0700326 env->DeleteGlobalRef(mServiceObj);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700327}
328
Jeff Brownb88102f2010-09-08 11:49:43 -0700329void NativeInputManager::dump(String8& dump) {
Michael Wrighta4051212015-07-23 17:04:40 +0100330 dump.append("Input Manager State:\n");
331 {
332 dump.appendFormat(INDENT "Interactive: %s\n", toString(mInteractive.load()));
333 }
334 {
335 AutoMutex _l(mLock);
336 dump.appendFormat(INDENT "System UI Visibility: 0x%0" PRIx32 "\n",
337 mLocked.systemUiVisibility);
338 dump.appendFormat(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed);
339 dump.appendFormat(INDENT "Pointer Gestures Enabled: %s\n",
340 toString(mLocked.pointerGesturesEnabled));
341 dump.appendFormat(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
342 }
343 dump.append("\n");
344
Jeff Brownb88102f2010-09-08 11:49:43 -0700345 mInputManager->getReader()->dump(dump);
346 dump.append("\n");
Jeff Brown6d0fec22010-07-23 21:28:06 -0700347
Jeff Brownb88102f2010-09-08 11:49:43 -0700348 mInputManager->getDispatcher()->dump(dump);
349 dump.append("\n");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700350}
351
Jeff Brown7fbdc842010-06-17 20:52:56 -0700352bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700353 if (env->ExceptionCheck()) {
Steve Block3762c312012-01-06 19:20:56 +0000354 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700355 LOGE_EX(env);
356 env->ExceptionClear();
357 return true;
358 }
359 return false;
360}
361
Jeff Brownd728bf52012-09-08 18:05:28 -0700362void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700363 bool changed = false;
Jeff Brownd728bf52012-09-08 18:05:28 -0700364 {
Jeff Brown65fd2512011-08-18 11:20:58 -0700365 AutoMutex _l(mLock);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700366
Jeff Brownd728bf52012-09-08 18:05:28 -0700367 DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
368 if (v != viewport) {
Jeff Brown65fd2512011-08-18 11:20:58 -0700369 changed = true;
Jeff Brownd728bf52012-09-08 18:05:28 -0700370 v = viewport;
Jeff Brownbc68a592011-07-25 12:58:12 -0700371
Jeff Brownd728bf52012-09-08 18:05:28 -0700372 if (!external) {
373 sp<PointerController> controller = mLocked.pointerController.promote();
374 if (controller != NULL) {
375 controller->setDisplayViewport(
376 viewport.logicalRight - viewport.logicalLeft,
377 viewport.logicalBottom - viewport.logicalTop,
378 viewport.orientation);
379 }
Jeff Brown2352b972011-04-12 22:39:53 -0700380 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700381 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700382 }
Jeff Brown65fd2512011-08-18 11:20:58 -0700383
384 if (changed) {
385 mInputManager->getReader()->requestRefreshConfiguration(
386 InputReaderConfiguration::CHANGE_DISPLAY_INFO);
387 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700388}
389
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700390status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
Jeff Brown928e0542011-01-10 11:17:36 -0800391 const sp<InputChannel>& inputChannel,
392 const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
393 return mInputManager->getDispatcher()->registerInputChannel(
394 inputChannel, inputWindowHandle, monitor);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700395}
396
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700397status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700398 const sp<InputChannel>& inputChannel) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700399 return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700400}
401
Jeff Brown214eaf42011-05-26 19:17:02 -0700402void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700403 JNIEnv* env = jniEnv();
404
Jeff Brown4532e612012-04-05 14:27:12 -0700405 jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
406 gServiceClassInfo.getVirtualKeyQuietTimeMillis);
Jeff Brown214eaf42011-05-26 19:17:02 -0700407 if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
408 outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
409 }
410
411 outConfig->excludedDeviceNames.clear();
Jeff Brown4532e612012-04-05 14:27:12 -0700412 jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
413 gServiceClassInfo.getExcludedDeviceNames));
Jeff Brown214eaf42011-05-26 19:17:02 -0700414 if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
415 jsize length = env->GetArrayLength(excludedDeviceNames);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700416 for (jsize i = 0; i < length; i++) {
Jeff Brown214eaf42011-05-26 19:17:02 -0700417 jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700418 const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
Jeff Brown214eaf42011-05-26 19:17:02 -0700419 outConfig->excludedDeviceNames.add(String8(deviceNameChars));
Jeff Brown9c3cda02010-06-15 01:31:58 -0700420 env->ReleaseStringUTFChars(item, deviceNameChars);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700421 env->DeleteLocalRef(item);
422 }
Jeff Brown214eaf42011-05-26 19:17:02 -0700423 env->DeleteLocalRef(excludedDeviceNames);
424 }
425
Jeff Brown4532e612012-04-05 14:27:12 -0700426 jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
427 gServiceClassInfo.getHoverTapTimeout);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700428 if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700429 jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
430 gServiceClassInfo.getDoubleTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700431 if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
Jeff Brown4532e612012-04-05 14:27:12 -0700432 jint longPressTimeout = env->CallIntMethod(mServiceObj,
433 gServiceClassInfo.getLongPressTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700434 if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700435 outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700436
437 // We must ensure that the tap-drag interval is significantly shorter than
438 // the long-press timeout because the tap is held down for the entire duration
439 // of the double-tap timeout.
440 jint tapDragInterval = max(min(longPressTimeout - 100,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700441 doubleTapTimeout), hoverTapTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700442 outConfig->pointerGestureTapDragInterval =
443 milliseconds_to_nanoseconds(tapDragInterval);
444 }
445 }
446 }
447
Jeff Brown4532e612012-04-05 14:27:12 -0700448 jint hoverTapSlop = env->CallIntMethod(mServiceObj,
449 gServiceClassInfo.getHoverTapSlop);
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700450 if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
451 outConfig->pointerGestureTapSlop = hoverTapSlop;
Jeff Brown9c3cda02010-06-15 01:31:58 -0700452 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700453
454 { // acquire lock
455 AutoMutex _l(mLock);
456
457 outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
458 * POINTER_SPEED_EXPONENT);
Jeff Brown474dcb52011-06-14 20:22:50 -0700459 outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
Jeff Brown65fd2512011-08-18 11:20:58 -0700460
Jeff Browndaf4a122011-08-26 17:14:14 -0700461 outConfig->showTouches = mLocked.showTouches;
462
Jeff Brownd728bf52012-09-08 18:05:28 -0700463 outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
464 outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700465 } // release lock
Jeff Brown9c3cda02010-06-15 01:31:58 -0700466}
467
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700468sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t /* deviceId */) {
Jeff Brown83c09682010-12-23 17:50:18 -0800469 AutoMutex _l(mLock);
470
471 sp<PointerController> controller = mLocked.pointerController.promote();
472 if (controller == NULL) {
Jeff Brown5541de92011-04-11 11:54:25 -0700473 ensureSpriteControllerLocked();
Jeff Brown83c09682010-12-23 17:50:18 -0800474
Jeff Brown2352b972011-04-12 22:39:53 -0700475 controller = new PointerController(this, mLooper, mLocked.spriteController);
Jeff Brown83c09682010-12-23 17:50:18 -0800476 mLocked.pointerController = controller;
477
Jeff Brownd728bf52012-09-08 18:05:28 -0700478 DisplayViewport& v = mLocked.internalViewport;
479 controller->setDisplayViewport(
480 v.logicalRight - v.logicalLeft,
481 v.logicalBottom - v.logicalTop,
482 v.orientation);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800483
Jeff Brown2352b972011-04-12 22:39:53 -0700484 updateInactivityTimeoutLocked(controller);
Jeff Brown83c09682010-12-23 17:50:18 -0800485 }
486 return controller;
487}
488
Jeff Brown5541de92011-04-11 11:54:25 -0700489void NativeInputManager::ensureSpriteControllerLocked() {
490 if (mLocked.spriteController == NULL) {
491 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700492 jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
Jeff Brown5541de92011-04-11 11:54:25 -0700493 if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
494 layer = -1;
495 }
496 mLocked.spriteController = new SpriteController(mLooper, layer);
497 }
498}
499
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700500void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
501 JNIEnv* env = jniEnv();
502
503 size_t count = inputDevices.size();
504 jobjectArray inputDevicesObjArray = env->NewObjectArray(
505 count, gInputDeviceClassInfo.clazz, NULL);
506 if (inputDevicesObjArray) {
507 bool error = false;
508 for (size_t i = 0; i < count; i++) {
509 jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
510 if (!inputDeviceObj) {
511 error = true;
512 break;
513 }
514
515 env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
516 env->DeleteLocalRef(inputDeviceObj);
517 }
518
519 if (!error) {
520 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
521 inputDevicesObjArray);
522 }
523
524 env->DeleteLocalRef(inputDevicesObjArray);
525 }
526
527 checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
528}
529
Jeff Brown6ec6f792012-04-17 16:52:41 -0700530sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
RoboErikfb290df2013-12-16 11:27:55 -0800531 const InputDeviceIdentifier& identifier) {
Jeff Brown6ec6f792012-04-17 16:52:41 -0700532 JNIEnv* env = jniEnv();
533
534 sp<KeyCharacterMap> result;
RoboErikfb290df2013-12-16 11:27:55 -0800535 ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
536 ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
537 gInputDeviceIdentifierInfo.constructor, descriptor.get(),
538 identifier.vendor, identifier.product));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700539 ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
RoboErikfb290df2013-12-16 11:27:55 -0800540 gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
Jeff Brown6ec6f792012-04-17 16:52:41 -0700541 if (arrayObj.get()) {
542 ScopedLocalRef<jstring> filenameObj(env,
543 jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
544 ScopedLocalRef<jstring> contentsObj(env,
545 jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
546 ScopedUtfChars filenameChars(env, filenameObj.get());
547 ScopedUtfChars contentsChars(env, contentsObj.get());
548
549 KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
550 String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
551 }
552 checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
553 return result;
554}
555
Jeff Brown5bbd4b42012-04-20 19:28:00 -0700556String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
557 JNIEnv* env = jniEnv();
558
559 ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
560 ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
561 gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
562 String8 result;
563 if (aliasObj.get()) {
564 ScopedUtfChars aliasChars(env, aliasObj.get());
565 result.setTo(aliasChars.c_str());
566 }
567 checkAndClearExceptionFromCallback(env, "getDeviceAlias");
568 return result;
569}
570
Jeff Brownbcc046a2012-09-27 20:46:43 -0700571void NativeInputManager::notifySwitch(nsecs_t when,
Andreas Gampe8dcf5932014-09-30 16:41:19 -0700572 uint32_t switchValues, uint32_t switchMask, uint32_t /* policyFlags */) {
Jeff Browne20c9e02010-10-11 14:20:19 -0700573#if DEBUG_INPUT_DISPATCHER_POLICY
Jeff Brownbcc046a2012-09-27 20:46:43 -0700574 ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
575 when, switchValues, switchMask, policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700576#endif
577
578 JNIEnv* env = jniEnv();
579
Jeff Brown53384282012-08-20 20:16:01 -0700580 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700581 when, switchValues, switchMask);
Jeff Brown53384282012-08-20 20:16:01 -0700582 checkAndClearExceptionFromCallback(env, "notifySwitch");
Jeff Browne20c9e02010-10-11 14:20:19 -0700583}
584
Jeff Brown9c3cda02010-06-15 01:31:58 -0700585void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
586#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000587 ALOGD("notifyConfigurationChanged - when=%lld", when);
Jeff Brown9c3cda02010-06-15 01:31:58 -0700588#endif
589
590 JNIEnv* env = jniEnv();
591
Jeff Brown4532e612012-04-05 14:27:12 -0700592 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700593 checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700594}
595
Jeff Brown519e0242010-09-15 15:18:56 -0700596nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700597 const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700598#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000599 ALOGD("notifyANR");
Jeff Brownb88102f2010-09-08 11:49:43 -0700600#endif
601
602 JNIEnv* env = jniEnv();
603
Jeff Brown928e0542011-01-10 11:17:36 -0800604 jobject inputApplicationHandleObj =
605 getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
606 jobject inputWindowHandleObj =
607 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brownbd181bb2013-09-10 16:44:24 -0700608 jstring reasonObj = env->NewStringUTF(reason.string());
Jeff Brownb88102f2010-09-08 11:49:43 -0700609
Jeff Brown4532e612012-04-05 14:27:12 -0700610 jlong newTimeout = env->CallLongMethod(mServiceObj,
Jeff Brownbd181bb2013-09-10 16:44:24 -0700611 gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
612 reasonObj);
Jeff Brown519e0242010-09-15 15:18:56 -0700613 if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
614 newTimeout = 0; // abort dispatch
615 } else {
616 assert(newTimeout >= 0);
617 }
618
Jeff Brownbd181bb2013-09-10 16:44:24 -0700619 env->DeleteLocalRef(reasonObj);
Jeff Brown928e0542011-01-10 11:17:36 -0800620 env->DeleteLocalRef(inputWindowHandleObj);
621 env->DeleteLocalRef(inputApplicationHandleObj);
Jeff Brownb88102f2010-09-08 11:49:43 -0700622 return newTimeout;
623}
624
Jeff Brown928e0542011-01-10 11:17:36 -0800625void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
Jeff Brown9c3cda02010-06-15 01:31:58 -0700626#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000627 ALOGD("notifyInputChannelBroken");
Jeff Brown9c3cda02010-06-15 01:31:58 -0700628#endif
629
Jeff Brown7fbdc842010-06-17 20:52:56 -0700630 JNIEnv* env = jniEnv();
631
Jeff Brown928e0542011-01-10 11:17:36 -0800632 jobject inputWindowHandleObj =
633 getInputWindowHandleObjLocalRef(env, inputWindowHandle);
634 if (inputWindowHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700635 env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
Jeff Brown928e0542011-01-10 11:17:36 -0800636 inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700637 checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
638
Jeff Brown928e0542011-01-10 11:17:36 -0800639 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700640 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700641}
642
Jeff Brown214eaf42011-05-26 19:17:02 -0700643void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
644 JNIEnv* env = jniEnv();
Jeff Browna4547672011-03-02 21:38:11 -0800645
Jeff Brown4532e612012-04-05 14:27:12 -0700646 jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
647 gServiceClassInfo.getKeyRepeatTimeout);
Jeff Brown214eaf42011-05-26 19:17:02 -0700648 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
649 outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
650 }
Jeff Browna4547672011-03-02 21:38:11 -0800651
Jeff Brown4532e612012-04-05 14:27:12 -0700652 jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
653 gServiceClassInfo.getKeyRepeatDelay);
Jeff Brown214eaf42011-05-26 19:17:02 -0700654 if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
655 outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
656 }
Jeff Brown9c3cda02010-06-15 01:31:58 -0700657}
658
Jeff Brown9302c872011-07-13 22:51:29 -0700659void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
660 Vector<sp<InputWindowHandle> > windowHandles;
Jeff Brown349703e2010-06-22 01:27:15 -0700661
Jeff Brown9302c872011-07-13 22:51:29 -0700662 if (windowHandleObjArray) {
663 jsize length = env->GetArrayLength(windowHandleObjArray);
664 for (jsize i = 0; i < length; i++) {
665 jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
666 if (! windowHandleObj) {
667 break; // found null element indicating end of used portion of the array
Jeff Brown474dcb52011-06-14 20:22:50 -0700668 }
Jeff Brown9302c872011-07-13 22:51:29 -0700669
670 sp<InputWindowHandle> windowHandle =
671 android_server_InputWindowHandle_getHandle(env, windowHandleObj);
672 if (windowHandle != NULL) {
673 windowHandles.push(windowHandle);
674 }
675 env->DeleteLocalRef(windowHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -0700676 }
Jeff Brownb88102f2010-09-08 11:49:43 -0700677 }
Jeff Brown349703e2010-06-22 01:27:15 -0700678
Jeff Brown9302c872011-07-13 22:51:29 -0700679 mInputManager->getDispatcher()->setInputWindows(windowHandles);
680
681 // Do this after the dispatcher has updated the window handle state.
682 bool newPointerGesturesEnabled = true;
683 size_t numWindows = windowHandles.size();
684 for (size_t i = 0; i < numWindows; i++) {
685 const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700686 const InputWindowInfo* windowInfo = windowHandle->getInfo();
687 if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
688 & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
Jeff Brown9302c872011-07-13 22:51:29 -0700689 newPointerGesturesEnabled = false;
690 }
691 }
Jeff Brown474dcb52011-06-14 20:22:50 -0700692
693 uint32_t changes = 0;
694 { // acquire lock
695 AutoMutex _l(mLock);
696
697 if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
698 mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
699 changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
700 }
701 } // release lock
702
703 if (changes) {
704 mInputManager->getReader()->requestRefreshConfiguration(changes);
705 }
Jeff Brown349703e2010-06-22 01:27:15 -0700706}
707
Jeff Brown9302c872011-07-13 22:51:29 -0700708void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
709 sp<InputApplicationHandle> applicationHandle =
710 android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
711 mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700712}
713
714void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
Jeff Brownb88102f2010-09-08 11:49:43 -0700715 mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -0700716}
717
Jeff Brown05dc66a2011-03-02 14:41:58 -0800718void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
719 AutoMutex _l(mLock);
720
721 if (mLocked.systemUiVisibility != visibility) {
722 mLocked.systemUiVisibility = visibility;
723
724 sp<PointerController> controller = mLocked.pointerController.promote();
725 if (controller != NULL) {
Jeff Brown2352b972011-04-12 22:39:53 -0700726 updateInactivityTimeoutLocked(controller);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800727 }
728 }
729}
730
Jeff Brown2352b972011-04-12 22:39:53 -0700731void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
Jeff Brown05dc66a2011-03-02 14:41:58 -0800732 bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
Jeff Brown2352b972011-04-12 22:39:53 -0700733 controller->setInactivityTimeout(lightsOut
734 ? PointerController::INACTIVITY_TIMEOUT_SHORT
735 : PointerController::INACTIVITY_TIMEOUT_NORMAL);
Jeff Brown05dc66a2011-03-02 14:41:58 -0800736}
737
Jeff Brown1a84fd12011-06-02 01:26:32 -0700738void NativeInputManager::setPointerSpeed(int32_t speed) {
Jeff Brown474dcb52011-06-14 20:22:50 -0700739 { // acquire lock
740 AutoMutex _l(mLock);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700741
Jeff Brown474dcb52011-06-14 20:22:50 -0700742 if (mLocked.pointerSpeed == speed) {
743 return;
744 }
745
Steve Block6215d3f2012-01-04 20:05:49 +0000746 ALOGI("Setting pointer speed to %d.", speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700747 mLocked.pointerSpeed = speed;
Jeff Brown474dcb52011-06-14 20:22:50 -0700748 } // release lock
Jeff Brown1a84fd12011-06-02 01:26:32 -0700749
Jeff Brown474dcb52011-06-14 20:22:50 -0700750 mInputManager->getReader()->requestRefreshConfiguration(
751 InputReaderConfiguration::CHANGE_POINTER_SPEED);
Jeff Brown1a84fd12011-06-02 01:26:32 -0700752}
753
Jeff Browndaf4a122011-08-26 17:14:14 -0700754void NativeInputManager::setShowTouches(bool enabled) {
755 { // acquire lock
756 AutoMutex _l(mLock);
757
758 if (mLocked.showTouches == enabled) {
759 return;
760 }
761
Steve Block6215d3f2012-01-04 20:05:49 +0000762 ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
Jeff Browndaf4a122011-08-26 17:14:14 -0700763 mLocked.showTouches = enabled;
764 } // release lock
765
766 mInputManager->getReader()->requestRefreshConfiguration(
767 InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
768}
769
Jeff Brown037c33e2014-04-09 00:31:55 -0700770void NativeInputManager::setInteractive(bool interactive) {
771 mInteractive = interactive;
Jeff Browne20c9e02010-10-11 14:20:19 -0700772}
773
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800774void NativeInputManager::reloadCalibration() {
775 mInputManager->getReader()->requestRefreshConfiguration(
Michael Wright357285c2015-04-17 00:50:31 +0100776 InputReaderConfiguration::CHANGE_TOUCH_AFFINE_TRANSFORMATION);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800777}
778
Jun Mukai1db53972015-09-11 18:08:31 -0700779void NativeInputManager::setPointerIconShape(int32_t iconId) {
Jun Mukai19a56012015-11-24 11:25:52 -0800780 AutoMutex _l(mLock);
781 sp<PointerController> controller = mLocked.pointerController.promote();
782 if (controller != NULL) {
Jun Mukai5ec74202015-10-07 16:58:09 +0900783 controller->updatePointerShape(iconId);
Jun Mukai19a56012015-11-24 11:25:52 -0800784 }
785}
786
787void NativeInputManager::reloadPointerIcons() {
788 AutoMutex _l(mLock);
789 sp<PointerController> controller = mLocked.pointerController.promote();
790 if (controller != NULL) {
791 controller->reloadPointerResources();
792 }
Jun Mukai1db53972015-09-11 18:08:31 -0700793}
794
Jun Mukaid4eaef72015-10-30 15:54:33 -0700795void NativeInputManager::setCustomPointerIcon(const SpriteIcon& icon) {
796 AutoMutex _l(mLock);
797 sp<PointerController> controller = mLocked.pointerController.promote();
798 if (controller != NULL) {
799 controller->setCustomPointerIcon(icon);
800 }
801}
802
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800803TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
804 JNIEnv *env, jfloatArray matrixArr) {
805 ScopedFloatArrayRO matrix(env, matrixArr);
806 assert(matrix.size() == 6);
807
808 TouchAffineTransformation transform;
809 transform.x_scale = matrix[0];
810 transform.x_ymix = matrix[1];
811 transform.x_offset = matrix[2];
812 transform.y_xmix = matrix[3];
813 transform.y_scale = matrix[4];
814 transform.y_offset = matrix[5];
815
816 return transform;
817}
818
819TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
Jason Gerecked5220742014-03-10 09:47:59 -0700820 const String8& inputDeviceDescriptor, int32_t surfaceRotation) {
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800821 JNIEnv* env = jniEnv();
822
823 ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
824
825 jobject cal = env->CallObjectMethod(mServiceObj,
Jason Gerecked5220742014-03-10 09:47:59 -0700826 gServiceClassInfo.getTouchCalibrationForInputDevice, descriptorObj.get(),
827 surfaceRotation);
Jason Gerecke857aa7b2014-01-27 18:34:20 -0800828
829 jfloatArray matrixArr = jfloatArray(env->CallObjectMethod(cal,
830 gTouchCalibrationClassInfo.getAffineTransform));
831
832 TouchAffineTransformation transform = getTouchAffineTransformation(env, matrixArr);
833
834 env->DeleteLocalRef(matrixArr);
835 env->DeleteLocalRef(cal);
836
837 return transform;
838}
839
Jeff Brown0029c662011-03-30 02:25:18 -0700840bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
841 jobject inputEventObj;
842
843 JNIEnv* env = jniEnv();
844 switch (inputEvent->getType()) {
845 case AINPUT_EVENT_TYPE_KEY:
846 inputEventObj = android_view_KeyEvent_fromNative(env,
847 static_cast<const KeyEvent*>(inputEvent));
848 break;
849 case AINPUT_EVENT_TYPE_MOTION:
850 inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
851 static_cast<const MotionEvent*>(inputEvent));
852 break;
853 default:
854 return true; // dispatch the event normally
855 }
856
857 if (!inputEventObj) {
Steve Block3762c312012-01-06 19:20:56 +0000858 ALOGE("Failed to obtain input event object for filterInputEvent.");
Jeff Brown0029c662011-03-30 02:25:18 -0700859 return true; // dispatch the event normally
860 }
861
862 // The callee is responsible for recycling the event.
Jeff Brown4532e612012-04-05 14:27:12 -0700863 jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
Jeff Brown0029c662011-03-30 02:25:18 -0700864 inputEventObj, policyFlags);
865 if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
866 pass = true;
867 }
868 env->DeleteLocalRef(inputEventObj);
869 return pass;
870}
871
Jeff Brown1f245102010-11-18 20:53:46 -0800872void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
873 uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700874 // Policy:
875 // - Ignore untrusted events and pass them along.
876 // - Ask the window manager what to do with normal events and trusted injected events.
877 // - For normal events wake and brighten the screen if currently off or dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100878 bool interactive = mInteractive.load();
879 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700880 policyFlags |= POLICY_FLAG_INTERACTIVE;
881 }
Jeff Brown3122e442010-10-11 23:32:49 -0700882 if ((policyFlags & POLICY_FLAG_TRUSTED)) {
Jeff Brown1f245102010-11-18 20:53:46 -0800883 nsecs_t when = keyEvent->getEventTime();
Jeff Brown3122e442010-10-11 23:32:49 -0700884 JNIEnv* env = jniEnv();
Jeff Brown1f245102010-11-18 20:53:46 -0800885 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
886 jint wmActions;
887 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700888 wmActions = env->CallIntMethod(mServiceObj,
889 gServiceClassInfo.interceptKeyBeforeQueueing,
Jeff Brown037c33e2014-04-09 00:31:55 -0700890 keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800891 if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
892 wmActions = 0;
893 }
894 android_view_KeyEvent_recycle(env, keyEventObj);
895 env->DeleteLocalRef(keyEventObj);
896 } else {
Steve Block3762c312012-01-06 19:20:56 +0000897 ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
Jeff Brown3122e442010-10-11 23:32:49 -0700898 wmActions = 0;
Jeff Browne20c9e02010-10-11 14:20:19 -0700899 }
900
Jeff Brown56194eb2011-03-02 19:23:13 -0800901 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Brown3122e442010-10-11 23:32:49 -0700902 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100903 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700904 policyFlags |= POLICY_FLAG_PASS_TO_USER;
905 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700906 }
907}
908
Jeff Brown56194eb2011-03-02 19:23:13 -0800909void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700910 // Policy:
911 // - Ignore untrusted events and pass them along.
912 // - No special filtering for injected events required at this time.
913 // - Filter normal events based on screen state.
914 // - For normal events brighten (but do not wake) the screen if currently dim.
Michael Wrighta4051212015-07-23 17:04:40 +0100915 bool interactive = mInteractive.load();
916 if (interactive) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700917 policyFlags |= POLICY_FLAG_INTERACTIVE;
918 }
Jeff Brown3122e442010-10-11 23:32:49 -0700919 if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
Jeff Brown037c33e2014-04-09 00:31:55 -0700920 if (policyFlags & POLICY_FLAG_INTERACTIVE) {
Jeff Brown3122e442010-10-11 23:32:49 -0700921 policyFlags |= POLICY_FLAG_PASS_TO_USER;
Michael Wright70af00a2014-09-03 19:30:20 -0700922 } else {
Jeff Brown56194eb2011-03-02 19:23:13 -0800923 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -0700924 jint wmActions = env->CallIntMethod(mServiceObj,
Michael Wright70af00a2014-09-03 19:30:20 -0700925 gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive,
Jeff Brown26875502014-01-30 21:47:47 -0800926 when, policyFlags);
Jeff Brown56194eb2011-03-02 19:23:13 -0800927 if (checkAndClearExceptionFromCallback(env,
Michael Wright70af00a2014-09-03 19:30:20 -0700928 "interceptMotionBeforeQueueingNonInteractive")) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800929 wmActions = 0;
930 }
931
Jeff Brown56194eb2011-03-02 19:23:13 -0800932 handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
Jeff Browne20c9e02010-10-11 14:20:19 -0700933 }
Jeff Brown3122e442010-10-11 23:32:49 -0700934 } else {
Michael Wrighta4051212015-07-23 17:04:40 +0100935 if (interactive) {
Michael Wright70af00a2014-09-03 19:30:20 -0700936 policyFlags |= POLICY_FLAG_PASS_TO_USER;
937 }
Jeff Browne20c9e02010-10-11 14:20:19 -0700938 }
939}
940
Jeff Brown56194eb2011-03-02 19:23:13 -0800941void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
942 uint32_t& policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -0800943 if (wmActions & WM_ACTION_PASS_TO_USER) {
944 policyFlags |= POLICY_FLAG_PASS_TO_USER;
945 } else {
Jeff Brown9267beb2011-03-07 20:11:22 -0800946#if DEBUG_INPUT_DISPATCHER_POLICY
Steve Block5baa3a62011-12-20 16:23:08 +0000947 ALOGD("handleInterceptActions: Not passing key to user.");
Jeff Brown56194eb2011-03-02 19:23:13 -0800948#endif
949 }
950}
951
Jeff Brown905805a2011-10-12 13:57:59 -0700952nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
Jeff Brown928e0542011-01-10 11:17:36 -0800953 const sp<InputWindowHandle>& inputWindowHandle,
Jeff Browne20c9e02010-10-11 14:20:19 -0700954 const KeyEvent* keyEvent, uint32_t policyFlags) {
Jeff Brown3122e442010-10-11 23:32:49 -0700955 // Policy:
956 // - Ignore untrusted events and pass them along.
957 // - Filter normal events and trusted injected events through the window manager policy to
958 // handle the HOME key and the like.
Jeff Brown905805a2011-10-12 13:57:59 -0700959 nsecs_t result = 0;
Jeff Brown3122e442010-10-11 23:32:49 -0700960 if (policyFlags & POLICY_FLAG_TRUSTED) {
961 JNIEnv* env = jniEnv();
Jeff Brownd0097872010-06-30 14:41:59 -0700962
Jeff Brown928e0542011-01-10 11:17:36 -0800963 // Note: inputWindowHandle may be null.
964 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800965 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
966 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -0700967 jlong delayMillis = env->CallLongMethod(mServiceObj,
968 gServiceClassInfo.interceptKeyBeforeDispatching,
Jeff Brown928e0542011-01-10 11:17:36 -0800969 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brown1f245102010-11-18 20:53:46 -0800970 bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
971 android_view_KeyEvent_recycle(env, keyEventObj);
972 env->DeleteLocalRef(keyEventObj);
Jeff Brown905805a2011-10-12 13:57:59 -0700973 if (!error) {
974 if (delayMillis < 0) {
975 result = -1;
976 } else if (delayMillis > 0) {
977 result = milliseconds_to_nanoseconds(delayMillis);
978 }
979 }
Jeff Brown1f245102010-11-18 20:53:46 -0800980 } else {
Steve Block3762c312012-01-06 19:20:56 +0000981 ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
Jeff Brown1f245102010-11-18 20:53:46 -0800982 }
Jeff Brown928e0542011-01-10 11:17:36 -0800983 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3122e442010-10-11 23:32:49 -0700984 }
Jeff Brown1f245102010-11-18 20:53:46 -0800985 return result;
Jeff Brownd0097872010-06-30 14:41:59 -0700986}
987
Jeff Brown928e0542011-01-10 11:17:36 -0800988bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
Jeff Brown49ed71d2010-12-06 17:13:33 -0800989 const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700990 // Policy:
991 // - Ignore untrusted events and do not perform default handling.
Jeff Brown49ed71d2010-12-06 17:13:33 -0800992 bool result = false;
Jeff Brown3915bb82010-11-05 15:02:16 -0700993 if (policyFlags & POLICY_FLAG_TRUSTED) {
994 JNIEnv* env = jniEnv();
995
Jeff Brown928e0542011-01-10 11:17:36 -0800996 // Note: inputWindowHandle may be null.
997 jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
Jeff Brown1f245102010-11-18 20:53:46 -0800998 jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
999 if (keyEventObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001000 jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
1001 gServiceClassInfo.dispatchUnhandledKey,
Jeff Brown928e0542011-01-10 11:17:36 -08001002 inputWindowHandleObj, keyEventObj, policyFlags);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001003 if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
1004 fallbackKeyEventObj = NULL;
1005 }
Jeff Brown1f245102010-11-18 20:53:46 -08001006 android_view_KeyEvent_recycle(env, keyEventObj);
1007 env->DeleteLocalRef(keyEventObj);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001008
1009 if (fallbackKeyEventObj) {
1010 // Note: outFallbackKeyEvent may be the same object as keyEvent.
1011 if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
1012 outFallbackKeyEvent)) {
1013 result = true;
1014 }
1015 android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
1016 env->DeleteLocalRef(fallbackKeyEventObj);
1017 }
Jeff Brown1f245102010-11-18 20:53:46 -08001018 } else {
Steve Block3762c312012-01-06 19:20:56 +00001019 ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
Jeff Brown1f245102010-11-18 20:53:46 -08001020 }
Jeff Brown928e0542011-01-10 11:17:36 -08001021 env->DeleteLocalRef(inputWindowHandleObj);
Jeff Brown3915bb82010-11-05 15:02:16 -07001022 }
Jeff Brown1f245102010-11-18 20:53:46 -08001023 return result;
Jeff Brown3915bb82010-11-05 15:02:16 -07001024}
1025
Jeff Brown01ce2e92010-09-26 22:20:12 -07001026void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
1027 android_server_PowerManagerService_userActivity(eventTime, eventType);
Jeff Brown349703e2010-06-22 01:27:15 -07001028}
1029
Jeff Brown349703e2010-06-22 01:27:15 -07001030
Jeff Brownb88102f2010-09-08 11:49:43 -07001031bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
1032 int32_t injectorPid, int32_t injectorUid) {
1033 JNIEnv* env = jniEnv();
Jeff Brown4532e612012-04-05 14:27:12 -07001034 jboolean result = env->CallBooleanMethod(mServiceObj,
1035 gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
Jeff Brownda3d5a92011-03-29 15:11:34 -07001036 if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
1037 result = false;
1038 }
Jeff Brown349703e2010-06-22 01:27:15 -07001039 return result;
1040}
1041
Jun Mukai19a56012015-11-24 11:25:52 -08001042void NativeInputManager::loadPointerIcon(SpriteIcon* icon) {
1043 JNIEnv* env = jniEnv();
1044
1045 ScopedLocalRef<jobject> pointerIconObj(env, env->CallObjectMethod(
1046 mServiceObj, gServiceClassInfo.getPointerIcon));
1047 if (checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
1048 return;
1049 }
1050
1051 PointerIcon pointerIcon;
1052 status_t status = android_view_PointerIcon_load(env, pointerIconObj.get(),
1053 mContextObj, &pointerIcon);
1054 if (!status && !pointerIcon.isNullIcon()) {
1055 *icon = SpriteIcon(pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY);
1056 } else {
1057 *icon = SpriteIcon();
1058 }
1059}
1060
Jeff Brown2352b972011-04-12 22:39:53 -07001061void NativeInputManager::loadPointerResources(PointerResources* outResources) {
1062 JNIEnv* env = jniEnv();
1063
1064 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
1065 &outResources->spotHover);
1066 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
1067 &outResources->spotTouch);
1068 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
1069 &outResources->spotAnchor);
1070}
1071
Jun Mukai808196f2015-10-28 16:46:44 -07001072void NativeInputManager::loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources,
1073 std::map<int32_t, PointerAnimation>* outAnimationResources) {
Jun Mukai1db53972015-09-11 18:08:31 -07001074 JNIEnv* env = jniEnv();
1075
1076 for (int iconId = POINTER_ICON_STYLE_CONTEXT_MENU; iconId <= POINTER_ICON_STYLE_GRABBING;
1077 ++iconId) {
Jun Mukai808196f2015-10-28 16:46:44 -07001078 PointerIcon pointerIcon;
1079 loadSystemIconAsSpriteWithPointerIcon(
1080 env, mContextObj, iconId, &pointerIcon, &((*outResources)[iconId]));
1081 if (!pointerIcon.bitmapFrames.empty()) {
1082 PointerAnimation& animationData = (*outAnimationResources)[iconId];
1083 size_t numFrames = pointerIcon.bitmapFrames.size() + 1;
1084 animationData.durationPerFrame =
1085 milliseconds_to_nanoseconds(pointerIcon.durationPerFrame);
1086 animationData.animationFrames.reserve(numFrames);
1087 animationData.animationFrames.push_back(SpriteIcon(
1088 pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1089 for (size_t i = 0; i < numFrames - 1; ++i) {
1090 animationData.animationFrames.push_back(SpriteIcon(
1091 pointerIcon.bitmapFrames[i], pointerIcon.hotSpotX, pointerIcon.hotSpotY));
1092 }
1093 }
Jun Mukai1db53972015-09-11 18:08:31 -07001094 }
Jun Mukai808196f2015-10-28 16:46:44 -07001095 loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_NULL,
1096 &((*outResources)[POINTER_ICON_STYLE_NULL]));
Jun Mukai1db53972015-09-11 18:08:31 -07001097}
1098
Jun Mukai5ec74202015-10-07 16:58:09 +09001099int32_t NativeInputManager::getDefaultPointerIconId() {
1100 return POINTER_ICON_STYLE_ARROW;
1101}
Jeff Brown83c09682010-12-23 17:50:18 -08001102
Jun Mukaid4eaef72015-10-30 15:54:33 -07001103int32_t NativeInputManager::getCustomPointerIconId() {
1104 return POINTER_ICON_STYLE_CUSTOM;
1105}
1106
Jeff Brown9c3cda02010-06-15 01:31:58 -07001107// ----------------------------------------------------------------------------
1108
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001109static jlong nativeInit(JNIEnv* env, jclass /* clazz */,
Jeff Brown4532e612012-04-05 14:27:12 -07001110 jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
Jeff Brown603b4452012-04-06 17:39:41 -07001111 sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
Jeff Brown864693462013-01-28 14:25:53 -08001112 if (messageQueue == NULL) {
1113 jniThrowRuntimeException(env, "MessageQueue is not initialized.");
1114 return 0;
1115 }
1116
Jeff Brown603b4452012-04-06 17:39:41 -07001117 NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
1118 messageQueue->getLooper());
Mathias Agopianb1d90c82013-03-06 17:45:42 -08001119 im->incStrong(0);
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001120 return reinterpret_cast<jlong>(im);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001121}
1122
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001123static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001124 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001125
Jeff Brown4532e612012-04-05 14:27:12 -07001126 status_t result = im->getInputManager()->start();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001127 if (result) {
1128 jniThrowRuntimeException(env, "Input manager could not be started.");
1129 }
1130}
1131
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001132static void nativeSetDisplayViewport(JNIEnv* /* env */, jclass /* clazz */, jlong ptr,
1133 jboolean external, jint displayId, jint orientation,
Jeff Brownd728bf52012-09-08 18:05:28 -07001134 jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
Jeff Brown83d616a2012-09-09 20:33:43 -07001135 jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
1136 jint deviceWidth, jint deviceHeight) {
Jeff Brown4532e612012-04-05 14:27:12 -07001137 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001138
Jeff Brownd728bf52012-09-08 18:05:28 -07001139 DisplayViewport v;
1140 v.displayId = displayId;
1141 v.orientation = orientation;
1142 v.logicalLeft = logicalLeft;
1143 v.logicalTop = logicalTop;
1144 v.logicalRight = logicalRight;
1145 v.logicalBottom = logicalBottom;
1146 v.physicalLeft = physicalLeft;
1147 v.physicalTop = physicalTop;
1148 v.physicalRight = physicalRight;
1149 v.physicalBottom = physicalBottom;
Jeff Brown83d616a2012-09-09 20:33:43 -07001150 v.deviceWidth = deviceWidth;
1151 v.deviceHeight = deviceHeight;
Jeff Brownd728bf52012-09-08 18:05:28 -07001152 im->setDisplayViewport(external, v);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001153}
1154
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001155static jint nativeGetScanCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001156 jlong ptr, jint deviceId, jint sourceMask, jint scanCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001157 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001158
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001159 return (jint) im->getInputManager()->getReader()->getScanCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001160 deviceId, uint32_t(sourceMask), scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001161}
1162
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001163static jint nativeGetKeyCodeState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001164 jlong ptr, jint deviceId, jint sourceMask, jint keyCode) {
Jeff Brown4532e612012-04-05 14:27:12 -07001165 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001166
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001167 return (jint) im->getInputManager()->getReader()->getKeyCodeState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001168 deviceId, uint32_t(sourceMask), keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001169}
1170
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001171static jint nativeGetSwitchState(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001172 jlong ptr, jint deviceId, jint sourceMask, jint sw) {
Jeff Brown4532e612012-04-05 14:27:12 -07001173 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001174
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001175 return (jint) im->getInputManager()->getReader()->getSwitchState(
Jeff Brown6d0fec22010-07-23 21:28:06 -07001176 deviceId, uint32_t(sourceMask), sw);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001177}
1178
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001179static jboolean nativeHasKeys(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001180 jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001181 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001182
1183 int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
1184 uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
1185 jsize numCodes = env->GetArrayLength(keyCodes);
1186 jboolean result;
Jeff Brown6d0fec22010-07-23 21:28:06 -07001187 if (numCodes == env->GetArrayLength(keyCodes)) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001188 if (im->getInputManager()->getReader()->hasKeys(
1189 deviceId, uint32_t(sourceMask), numCodes, codes, flags)) {
1190 result = JNI_TRUE;
1191 } else {
1192 result = JNI_FALSE;
1193 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001194 } else {
1195 result = JNI_FALSE;
1196 }
1197
1198 env->ReleaseBooleanArrayElements(outFlags, flags, 0);
1199 env->ReleaseIntArrayElements(keyCodes, codes, 0);
1200 return result;
1201}
1202
1203static void throwInputChannelNotInitialized(JNIEnv* env) {
1204 jniThrowException(env, "java/lang/IllegalStateException",
1205 "inputChannel is not initialized");
1206}
1207
Jeff Brown4532e612012-04-05 14:27:12 -07001208static void handleInputChannelDisposed(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001209 jobject /* inputChannelObj */, const sp<InputChannel>& inputChannel, void* data) {
Jeff Brown4532e612012-04-05 14:27:12 -07001210 NativeInputManager* im = static_cast<NativeInputManager*>(data);
1211
Steve Block8564c8d2012-01-05 23:22:43 +00001212 ALOGW("Input channel object '%s' was disposed without first being unregistered with "
Jeff Brown46b9ac02010-04-22 18:58:52 -07001213 "the input manager!", inputChannel->getName().string());
Jeff Brown4532e612012-04-05 14:27:12 -07001214 im->unregisterInputChannel(env, inputChannel);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001215}
1216
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001217static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001218 jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
Jeff Brown4532e612012-04-05 14:27:12 -07001219 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001220
1221 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1222 inputChannelObj);
1223 if (inputChannel == NULL) {
1224 throwInputChannelNotInitialized(env);
1225 return;
1226 }
1227
Jeff Brown928e0542011-01-10 11:17:36 -08001228 sp<InputWindowHandle> inputWindowHandle =
1229 android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001230
Jeff Brown4532e612012-04-05 14:27:12 -07001231 status_t status = im->registerInputChannel(
Jeff Brown928e0542011-01-10 11:17:36 -08001232 env, inputChannel, inputWindowHandle, monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001233 if (status) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001234 String8 message;
1235 message.appendFormat("Failed to register input channel. status=%d", status);
1236 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001237 return;
1238 }
1239
Jeff Browna41ca772010-08-11 14:46:32 -07001240 if (! monitor) {
1241 android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
Jeff Brown4532e612012-04-05 14:27:12 -07001242 handleInputChannelDisposed, im);
Jeff Browna41ca772010-08-11 14:46:32 -07001243 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001244}
1245
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001246static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001247 jlong ptr, jobject inputChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001248 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001249
1250 sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
1251 inputChannelObj);
1252 if (inputChannel == NULL) {
1253 throwInputChannelNotInitialized(env);
1254 return;
1255 }
1256
1257 android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
1258
Jeff Brown4532e612012-04-05 14:27:12 -07001259 status_t status = im->unregisterInputChannel(env, inputChannel);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001260 if (status && status != BAD_VALUE) { // ignore already unregistered channel
1261 String8 message;
1262 message.appendFormat("Failed to unregister input channel. status=%d", status);
1263 jniThrowRuntimeException(env, message.string());
Jeff Brown46b9ac02010-04-22 18:58:52 -07001264 }
1265}
1266
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001267static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001268 jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001269 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown0029c662011-03-30 02:25:18 -07001270
Jeff Brown4532e612012-04-05 14:27:12 -07001271 im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
Jeff Brown0029c662011-03-30 02:25:18 -07001272}
1273
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001274static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
Jeff Brownca9bc702014-02-11 14:32:56 -08001275 jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid,
Jeff Brown0029c662011-03-30 02:25:18 -07001276 jint syncMode, jint timeoutMillis, jint policyFlags) {
Jeff Brown4532e612012-04-05 14:27:12 -07001277 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown7fbdc842010-06-17 20:52:56 -07001278
Jeff Brown6ec402b2010-07-28 15:48:59 -07001279 if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
1280 KeyEvent keyEvent;
Jeff Brown1f245102010-11-18 20:53:46 -08001281 status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
1282 if (status) {
1283 jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
1284 return INPUT_EVENT_INJECTION_FAILED;
1285 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001286
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001287 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001288 & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001289 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001290 } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
Jeff Brown2ed24622011-03-14 19:39:54 -07001291 const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
1292 if (!motionEvent) {
Jeff Brown1f245102010-11-18 20:53:46 -08001293 jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
1294 return INPUT_EVENT_INJECTION_FAILED;
1295 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001296
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001297 return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
Jeff Brownca9bc702014-02-11 14:32:56 -08001298 motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
Jeff Brown0029c662011-03-30 02:25:18 -07001299 uint32_t(policyFlags));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001300 } else {
1301 jniThrowRuntimeException(env, "Invalid input event type.");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001302 return INPUT_EVENT_INJECTION_FAILED;
1303 }
Jeff Brown7fbdc842010-06-17 20:52:56 -07001304}
1305
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001306static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001307 jlong ptr, jobjectArray windowHandleObjArray) {
Jeff Brown4532e612012-04-05 14:27:12 -07001308 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001309
Jeff Brown4532e612012-04-05 14:27:12 -07001310 im->setInputWindows(env, windowHandleObjArray);
Jeff Brown349703e2010-06-22 01:27:15 -07001311}
1312
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001313static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */,
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001314 jlong ptr, jobject applicationHandleObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001315 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001316
Jeff Brown4532e612012-04-05 14:27:12 -07001317 im->setFocusedApplication(env, applicationHandleObj);
Jeff Brown349703e2010-06-22 01:27:15 -07001318}
1319
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001320static void nativeSetInputDispatchMode(JNIEnv* /* env */,
1321 jclass /* clazz */, jlong ptr, jboolean enabled, jboolean frozen) {
Jeff Brown4532e612012-04-05 14:27:12 -07001322 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown349703e2010-06-22 01:27:15 -07001323
Jeff Brown4532e612012-04-05 14:27:12 -07001324 im->setInputDispatchMode(enabled, frozen);
Jeff Brown349703e2010-06-22 01:27:15 -07001325}
1326
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001327static void nativeSetSystemUiVisibility(JNIEnv* /* env */,
1328 jclass /* clazz */, jlong ptr, jint visibility) {
Jeff Brown4532e612012-04-05 14:27:12 -07001329 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001330
Jeff Brown4532e612012-04-05 14:27:12 -07001331 im->setSystemUiVisibility(visibility);
Jeff Brown05dc66a2011-03-02 14:41:58 -08001332}
1333
Jeff Brown4532e612012-04-05 14:27:12 -07001334static jboolean nativeTransferTouchFocus(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001335 jclass /* clazz */, jlong ptr, jobject fromChannelObj, jobject toChannelObj) {
Jeff Brown4532e612012-04-05 14:27:12 -07001336 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne6504122010-09-27 14:52:15 -07001337
1338 sp<InputChannel> fromChannel =
1339 android_view_InputChannel_getInputChannel(env, fromChannelObj);
1340 sp<InputChannel> toChannel =
1341 android_view_InputChannel_getInputChannel(env, toChannelObj);
1342
1343 if (fromChannel == NULL || toChannel == NULL) {
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001344 return JNI_FALSE;
Jeff Browne6504122010-09-27 14:52:15 -07001345 }
1346
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001347 if (im->getInputManager()->getDispatcher()->
1348 transferTouchFocus(fromChannel, toChannel)) {
1349 return JNI_TRUE;
1350 } else {
1351 return JNI_FALSE;
1352 }
Jeff Browne6504122010-09-27 14:52:15 -07001353}
1354
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001355static void nativeSetPointerSpeed(JNIEnv* /* env */,
1356 jclass /* clazz */, jlong ptr, jint speed) {
Jeff Brown4532e612012-04-05 14:27:12 -07001357 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001358
Jeff Brown4532e612012-04-05 14:27:12 -07001359 im->setPointerSpeed(speed);
Jeff Brown1a84fd12011-06-02 01:26:32 -07001360}
1361
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001362static void nativeSetShowTouches(JNIEnv* /* env */,
1363 jclass /* clazz */, jlong ptr, jboolean enabled) {
Jeff Brown4532e612012-04-05 14:27:12 -07001364 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browndaf4a122011-08-26 17:14:14 -07001365
Jeff Brown4532e612012-04-05 14:27:12 -07001366 im->setShowTouches(enabled);
Jeff Browndaf4a122011-08-26 17:14:14 -07001367}
1368
Jeff Brown037c33e2014-04-09 00:31:55 -07001369static void nativeSetInteractive(JNIEnv* env,
1370 jclass clazz, jlong ptr, jboolean interactive) {
1371 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1372
1373 im->setInteractive(interactive);
1374}
1375
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001376static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) {
1377 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1378 im->reloadCalibration();
1379}
1380
Jeff Browna47425a2012-04-13 04:09:27 -07001381static void nativeVibrate(JNIEnv* env,
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001382 jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj,
Jeff Browna47425a2012-04-13 04:09:27 -07001383 jint repeat, jint token) {
1384 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1385
1386 size_t patternSize = env->GetArrayLength(patternObj);
1387 if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
Michael Wright9ecba522014-04-04 15:29:53 -07001388 ALOGI("Skipped requested vibration because the pattern size is %zu "
Jeff Browna47425a2012-04-13 04:09:27 -07001389 "which is more than the maximum supported size of %d.",
1390 patternSize, MAX_VIBRATE_PATTERN_SIZE);
1391 return; // limit to reasonable size
1392 }
1393
1394 jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
1395 patternObj, NULL));
1396 nsecs_t pattern[patternSize];
1397 for (size_t i = 0; i < patternSize; i++) {
1398 pattern[i] = max(jlong(0), min(patternMillis[i],
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001399 (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL;
Jeff Browna47425a2012-04-13 04:09:27 -07001400 }
1401 env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
1402
1403 im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
1404}
1405
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001406static void nativeCancelVibrate(JNIEnv* /* env */,
1407 jclass /* clazz */, jlong ptr, jint deviceId, jint token) {
Jeff Browna47425a2012-04-13 04:09:27 -07001408 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1409
1410 im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
1411}
1412
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001413static void nativeReloadKeyboardLayouts(JNIEnv* /* env */,
1414 jclass /* clazz */, jlong ptr) {
Jeff Brown6ec6f792012-04-17 16:52:41 -07001415 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1416
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001417 im->getInputManager()->getReader()->requestRefreshConfiguration(
1418 InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
1419}
1420
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001421static void nativeReloadDeviceAliases(JNIEnv* /* env */,
1422 jclass /* clazz */, jlong ptr) {
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001423 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1424
1425 im->getInputManager()->getReader()->requestRefreshConfiguration(
1426 InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
Jeff Brown6ec6f792012-04-17 16:52:41 -07001427}
1428
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001429static jstring nativeDump(JNIEnv* env, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001430 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Browne33348b2010-07-15 23:54:05 -07001431
Jeff Brownb88102f2010-09-08 11:49:43 -07001432 String8 dump;
Jeff Brown4532e612012-04-05 14:27:12 -07001433 im->dump(dump);
Jeff Browne33348b2010-07-15 23:54:05 -07001434 return env->NewStringUTF(dump.string());
1435}
1436
Andreas Gampe8dcf5932014-09-30 16:41:19 -07001437static void nativeMonitor(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
Jeff Brown4532e612012-04-05 14:27:12 -07001438 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
Jeff Brown89ef0722011-08-10 16:25:21 -07001439
Jeff Brown4532e612012-04-05 14:27:12 -07001440 im->getInputManager()->getReader()->monitor();
1441 im->getInputManager()->getDispatcher()->monitor();
Jeff Brown89ef0722011-08-10 16:25:21 -07001442}
1443
Jun Mukai1db53972015-09-11 18:08:31 -07001444static void nativeSetPointerIconShape(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, jint iconId) {
1445 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1446 im->setPointerIconShape(iconId);
1447}
1448
Jun Mukai19a56012015-11-24 11:25:52 -08001449static void nativeReloadPointerIcons(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) {
1450 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1451 im->reloadPointerIcons();
1452}
1453
Jun Mukaid4eaef72015-10-30 15:54:33 -07001454static void nativeSetCustomPointerIcon(JNIEnv* env, jclass /* clazz */,
1455 jlong ptr, jobject iconObj) {
1456 NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
1457
1458 PointerIcon pointerIcon;
1459 android_view_PointerIcon_getLoadedIcon(env, iconObj, &pointerIcon);
1460
1461 SpriteIcon spriteIcon;
1462 pointerIcon.bitmap.copyTo(&spriteIcon.bitmap, kN32_SkColorType);
1463 spriteIcon.hotSpotX = pointerIcon.hotSpotX;
1464 spriteIcon.hotSpotY = pointerIcon.hotSpotY;
1465 im->setCustomPointerIcon(spriteIcon);
1466}
1467
Jeff Brown9c3cda02010-06-15 01:31:58 -07001468// ----------------------------------------------------------------------------
1469
Daniel Micay76f6a862015-09-19 17:31:01 -04001470static const JNINativeMethod gInputManagerMethods[] = {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001471 /* name, signature, funcPtr */
Jeff Brown4532e612012-04-05 14:27:12 -07001472 { "nativeInit",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001473 "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J",
Jeff Brown4532e612012-04-05 14:27:12 -07001474 (void*) nativeInit },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001475 { "nativeStart", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001476 (void*) nativeStart },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001477 { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V",
Jeff Brownd728bf52012-09-08 18:05:28 -07001478 (void*) nativeSetDisplayViewport },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001479 { "nativeGetScanCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001480 (void*) nativeGetScanCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001481 { "nativeGetKeyCodeState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001482 (void*) nativeGetKeyCodeState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001483 { "nativeGetSwitchState", "(JIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001484 (void*) nativeGetSwitchState },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001485 { "nativeHasKeys", "(JII[I[Z)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001486 (void*) nativeHasKeys },
Jeff Brown928e0542011-01-10 11:17:36 -08001487 { "nativeRegisterInputChannel",
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001488 "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001489 (void*) nativeRegisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001490 { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001491 (void*) nativeUnregisterInputChannel },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001492 { "nativeSetInputFilterEnabled", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001493 (void*) nativeSetInputFilterEnabled },
Jeff Brownca9bc702014-02-11 14:32:56 -08001494 { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I",
Jeff Brown4532e612012-04-05 14:27:12 -07001495 (void*) nativeInjectInputEvent },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001496 { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001497 (void*) nativeSetInputWindows },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001498 { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001499 (void*) nativeSetFocusedApplication },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001500 { "nativeSetInputDispatchMode", "(JZZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001501 (void*) nativeSetInputDispatchMode },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001502 { "nativeSetSystemUiVisibility", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001503 (void*) nativeSetSystemUiVisibility },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001504 { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
Jeff Brown4532e612012-04-05 14:27:12 -07001505 (void*) nativeTransferTouchFocus },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001506 { "nativeSetPointerSpeed", "(JI)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001507 (void*) nativeSetPointerSpeed },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001508 { "nativeSetShowTouches", "(JZ)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001509 (void*) nativeSetShowTouches },
Jeff Brown037c33e2014-04-09 00:31:55 -07001510 { "nativeSetInteractive", "(JZ)V",
1511 (void*) nativeSetInteractive },
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001512 { "nativeReloadCalibration", "(J)V",
1513 (void*) nativeReloadCalibration },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001514 { "nativeVibrate", "(JI[JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001515 (void*) nativeVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001516 { "nativeCancelVibrate", "(JII)V",
Jeff Browna47425a2012-04-13 04:09:27 -07001517 (void*) nativeCancelVibrate },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001518 { "nativeReloadKeyboardLayouts", "(J)V",
Jeff Brown6ec6f792012-04-17 16:52:41 -07001519 (void*) nativeReloadKeyboardLayouts },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001520 { "nativeReloadDeviceAliases", "(J)V",
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001521 (void*) nativeReloadDeviceAliases },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001522 { "nativeDump", "(J)Ljava/lang/String;",
Jeff Brown4532e612012-04-05 14:27:12 -07001523 (void*) nativeDump },
Ashok Bhat7e2a9dc2014-01-02 19:43:30 +00001524 { "nativeMonitor", "(J)V",
Jeff Brown4532e612012-04-05 14:27:12 -07001525 (void*) nativeMonitor },
Jun Mukai1db53972015-09-11 18:08:31 -07001526 { "nativeSetPointerIconShape", "(JI)V",
1527 (void*) nativeSetPointerIconShape },
Jun Mukai19a56012015-11-24 11:25:52 -08001528 { "nativeReloadPointerIcons", "(J)V",
1529 (void*) nativeReloadPointerIcons },
Jun Mukaid4eaef72015-10-30 15:54:33 -07001530 { "nativeSetCustomPointerIcon", "(JLandroid/view/PointerIcon;)V",
1531 (void*) nativeSetCustomPointerIcon },
Jeff Brown46b9ac02010-04-22 18:58:52 -07001532};
1533
1534#define FIND_CLASS(var, className) \
1535 var = env->FindClass(className); \
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001536 LOG_FATAL_IF(! var, "Unable to find class " className);
Jeff Brown46b9ac02010-04-22 18:58:52 -07001537
1538#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
1539 var = env->GetMethodID(clazz, methodName, methodDescriptor); \
1540 LOG_FATAL_IF(! var, "Unable to find method " methodName);
1541
1542#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
1543 var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
1544 LOG_FATAL_IF(! var, "Unable to find field " fieldName);
1545
1546int register_android_server_InputManager(JNIEnv* env) {
Jeff Brown4532e612012-04-05 14:27:12 -07001547 int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
Jeff Brown46b9ac02010-04-22 18:58:52 -07001548 gInputManagerMethods, NELEM(gInputManagerMethods));
Bernhard Rosenkränzer9c1c90e2014-11-12 14:45:58 +01001549 (void) res; // Faked use when LOG_NDEBUG.
Jeff Brown46b9ac02010-04-22 18:58:52 -07001550 LOG_FATAL_IF(res < 0, "Unable to register native methods.");
1551
Jeff Brown9c3cda02010-06-15 01:31:58 -07001552 // Callbacks
Jeff Brown46b9ac02010-04-22 18:58:52 -07001553
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001554 jclass clazz;
Jeff Brown4532e612012-04-05 14:27:12 -07001555 FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001556
Jeff Brown4532e612012-04-05 14:27:12 -07001557 GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
Jeff Brown57c59372010-09-21 18:22:55 -07001558 "notifyConfigurationChanged", "(J)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001559
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001560 GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
1561 "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
1562
Jeff Brown53384282012-08-20 20:16:01 -07001563 GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
1564 "notifySwitch", "(JII)V");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001565
Jeff Brown4532e612012-04-05 14:27:12 -07001566 GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
1567 "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
Jeff Brown7fbdc842010-06-17 20:52:56 -07001568
Jeff Brown4532e612012-04-05 14:27:12 -07001569 GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
Jeff Brown928e0542011-01-10 11:17:36 -08001570 "notifyANR",
Jeff Brownbd181bb2013-09-10 16:44:24 -07001571 "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001572
Jeff Brown4532e612012-04-05 14:27:12 -07001573 GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
Jeff Brown0029c662011-03-30 02:25:18 -07001574 "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
1575
Jeff Brown4532e612012-04-05 14:27:12 -07001576 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
Jeff Brown037c33e2014-04-09 00:31:55 -07001577 "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I");
Jeff Brown349703e2010-06-22 01:27:15 -07001578
Michael Wright70af00a2014-09-03 19:30:20 -07001579 GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz,
1580 "interceptMotionBeforeQueueingNonInteractive", "(JI)I");
Jeff Brown56194eb2011-03-02 19:23:13 -08001581
Jeff Brown4532e612012-04-05 14:27:12 -07001582 GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
Jeff Brown1f245102010-11-18 20:53:46 -08001583 "interceptKeyBeforeDispatching",
Jeff Brown4532e612012-04-05 14:27:12 -07001584 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
Jeff Brown349703e2010-06-22 01:27:15 -07001585
Jeff Brown4532e612012-04-05 14:27:12 -07001586 GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
Jeff Brown49ed71d2010-12-06 17:13:33 -08001587 "dispatchUnhandledKey",
Jeff Brown4532e612012-04-05 14:27:12 -07001588 "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
Jeff Brown3915bb82010-11-05 15:02:16 -07001589
Jeff Brown4532e612012-04-05 14:27:12 -07001590 GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
Jeff Brown349703e2010-06-22 01:27:15 -07001591 "checkInjectEventsPermission", "(II)Z");
Jeff Brown46b9ac02010-04-22 18:58:52 -07001592
Jeff Brown4532e612012-04-05 14:27:12 -07001593 GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
Jeff Brownfe508922011-01-18 15:10:10 -08001594 "getVirtualKeyQuietTimeMillis", "()I");
1595
Jeff Brown4532e612012-04-05 14:27:12 -07001596 GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
Jeff Brown46b9ac02010-04-22 18:58:52 -07001597 "getExcludedDeviceNames", "()[Ljava/lang/String;");
1598
Jeff Brown4532e612012-04-05 14:27:12 -07001599 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001600 "getKeyRepeatTimeout", "()I");
1601
Jeff Brown4532e612012-04-05 14:27:12 -07001602 GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
Jeff Browna4547672011-03-02 21:38:11 -08001603 "getKeyRepeatDelay", "()I");
1604
Jeff Brown4532e612012-04-05 14:27:12 -07001605 GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001606 "getHoverTapTimeout", "()I");
1607
Jeff Brown4532e612012-04-05 14:27:12 -07001608 GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -07001609 "getHoverTapSlop", "()I");
Jeff Brown214eaf42011-05-26 19:17:02 -07001610
Jeff Brown4532e612012-04-05 14:27:12 -07001611 GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001612 "getDoubleTapTimeout", "()I");
1613
Jeff Brown4532e612012-04-05 14:27:12 -07001614 GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
Jeff Brown214eaf42011-05-26 19:17:02 -07001615 "getLongPressTimeout", "()I");
1616
Jeff Brown4532e612012-04-05 14:27:12 -07001617 GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
Jeff Brown83c09682010-12-23 17:50:18 -08001618 "getPointerLayer", "()I");
1619
Jeff Brown4532e612012-04-05 14:27:12 -07001620 GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
Jeff Brown2352b972011-04-12 22:39:53 -07001621 "getPointerIcon", "()Landroid/view/PointerIcon;");
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001622
Jeff Brown6ec6f792012-04-17 16:52:41 -07001623 GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
RoboErikfb290df2013-12-16 11:27:55 -08001624 "getKeyboardLayoutOverlay",
1625 "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
Jeff Brown6ec6f792012-04-17 16:52:41 -07001626
Jeff Brown5bbd4b42012-04-20 19:28:00 -07001627 GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
1628 "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
1629
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001630 GET_METHOD_ID(gServiceClassInfo.getTouchCalibrationForInputDevice, clazz,
1631 "getTouchCalibrationForInputDevice",
Jason Gerecked5220742014-03-10 09:47:59 -07001632 "(Ljava/lang/String;I)Landroid/hardware/input/TouchCalibration;");
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001633
Jeff Brownaf9e8d32012-04-12 17:32:48 -07001634 // InputDevice
1635
1636 FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
1637 gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
1638
Jeff Brown6ec402b2010-07-28 15:48:59 -07001639 // KeyEvent
1640
1641 FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001642 gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
1643
Jeff Brown8d608662010-08-30 03:02:23 -07001644 // MotionEvent
Jeff Brown6ec402b2010-07-28 15:48:59 -07001645
1646 FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
Carl Shapiro17cc33a2011-03-05 20:53:16 -08001647 gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
Jeff Brown6ec402b2010-07-28 15:48:59 -07001648
RoboErikfb290df2013-12-16 11:27:55 -08001649 // InputDeviceIdentifier
1650
1651 FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
1652 gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
1653 GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
1654 "<init>", "(Ljava/lang/String;II)V");
1655
Jason Gerecke857aa7b2014-01-27 18:34:20 -08001656 // TouchCalibration
1657
1658 FIND_CLASS(gTouchCalibrationClassInfo.clazz, "android/hardware/input/TouchCalibration");
1659 gTouchCalibrationClassInfo.clazz = jclass(env->NewGlobalRef(gTouchCalibrationClassInfo.clazz));
1660
1661 GET_METHOD_ID(gTouchCalibrationClassInfo.getAffineTransform, gTouchCalibrationClassInfo.clazz,
1662 "getAffineTransform", "()[F");
1663
Jeff Brown46b9ac02010-04-22 18:58:52 -07001664 return 0;
1665}
1666
Jeff Brown46b9ac02010-04-22 18:58:52 -07001667} /* namespace android */