Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 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 Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | // Log debug messages about InputReaderPolicy |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 22 | #define DEBUG_INPUT_READER_POLICY 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 23 | |
| 24 | // Log debug messages about InputDispatcherPolicy |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 25 | #define DEBUG_INPUT_DISPATCHER_POLICY 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 26 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 27 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 28 | #include "JNIHelp.h" |
| 29 | #include "jni.h" |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 30 | #include <atomic> |
| 31 | #include <cinttypes> |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 32 | #include <limits.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 33 | #include <android_runtime/AndroidRuntime.h> |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 34 | #include <android_runtime/Log.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 35 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 36 | #include <utils/Log.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 37 | #include <utils/Looper.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 38 | #include <utils/threads.h> |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 39 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 40 | #include <input/PointerController.h> |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 41 | #include <input/SpriteController.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 42 | |
Michael Wright | d6b47371 | 2014-02-10 15:56:36 -0800 | [diff] [blame] | 43 | #include <inputflinger/InputManager.h> |
| 44 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 45 | #include <android_os_MessageQueue.h> |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 46 | #include <android_view_InputDevice.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 47 | #include <android_view_KeyEvent.h> |
| 48 | #include <android_view_MotionEvent.h> |
| 49 | #include <android_view_InputChannel.h> |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 50 | #include <android_view_PointerIcon.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 51 | #include <android/graphics/GraphicsJNI.h> |
| 52 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 53 | #include <ScopedLocalRef.h> |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 54 | #include <ScopedPrimitiveArray.h> |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 55 | #include <ScopedUtfChars.h> |
| 56 | |
Jeff Brown | 4f8ecd8 | 2012-06-18 18:29:13 -0700 | [diff] [blame] | 57 | #include "com_android_server_power_PowerManagerService.h" |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 58 | #include "com_android_server_input_InputApplicationHandle.h" |
| 59 | #include "com_android_server_input_InputWindowHandle.h" |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 60 | |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 61 | #define INDENT " " |
| 62 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 63 | namespace android { |
| 64 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 65 | // 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 Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 68 | static const float POINTER_SPEED_EXPONENT = 1.0f / 4; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 69 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 70 | static struct { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 71 | jmethodID notifyConfigurationChanged; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 72 | jmethodID notifyInputDevicesChanged; |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 73 | jmethodID notifySwitch; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 74 | jmethodID notifyInputChannelBroken; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 75 | jmethodID notifyANR; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 76 | jmethodID filterInputEvent; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 77 | jmethodID interceptKeyBeforeQueueing; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 78 | jmethodID interceptMotionBeforeQueueingNonInteractive; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 79 | jmethodID interceptKeyBeforeDispatching; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 80 | jmethodID dispatchUnhandledKey; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 81 | jmethodID checkInjectEventsPermission; |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 82 | jmethodID getVirtualKeyQuietTimeMillis; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 83 | jmethodID getExcludedDeviceNames; |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 84 | jmethodID getKeyRepeatTimeout; |
| 85 | jmethodID getKeyRepeatDelay; |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 86 | jmethodID getHoverTapTimeout; |
| 87 | jmethodID getHoverTapSlop; |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 88 | jmethodID getDoubleTapTimeout; |
| 89 | jmethodID getLongPressTimeout; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 90 | jmethodID getPointerLayer; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 91 | jmethodID getPointerIcon; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 92 | jmethodID getKeyboardLayoutOverlay; |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 93 | jmethodID getDeviceAlias; |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 94 | jmethodID getTouchCalibrationForInputDevice; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 95 | } gServiceClassInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 96 | |
| 97 | static struct { |
| 98 | jclass clazz; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 99 | } gInputDeviceClassInfo; |
| 100 | |
| 101 | static struct { |
| 102 | jclass clazz; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 103 | } gKeyEventClassInfo; |
| 104 | |
| 105 | static struct { |
| 106 | jclass clazz; |
| 107 | } gMotionEventClassInfo; |
| 108 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 109 | static struct { |
| 110 | jclass clazz; |
| 111 | jmethodID constructor; |
| 112 | } gInputDeviceIdentifierInfo; |
| 113 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 114 | static struct { |
| 115 | jclass clazz; |
| 116 | jmethodID getAffineTransform; |
| 117 | } gTouchCalibrationClassInfo; |
| 118 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 119 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 120 | |
| 121 | // --- Global functions --- |
| 122 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 123 | template<typename T> |
| 124 | inline static T min(const T& a, const T& b) { |
| 125 | return a < b ? a : b; |
| 126 | } |
| 127 | |
| 128 | template<typename T> |
| 129 | inline static T max(const T& a, const T& b) { |
| 130 | return a > b ? a : b; |
| 131 | } |
| 132 | |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 133 | static inline const char* toString(bool value) { |
| 134 | return value ? "true" : "false"; |
| 135 | } |
| 136 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 137 | static 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 | |
| 146 | static 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 Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 155 | static void loadSystemIconAsSpriteWithPointerIcon(JNIEnv* env, jobject contextObj, int32_t style, |
| 156 | PointerIcon* outPointerIcon, SpriteIcon* outSpriteIcon) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 157 | status_t status = android_view_PointerIcon_loadSystemIcon(env, |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 158 | contextObj, style, outPointerIcon); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 159 | if (!status) { |
Matt Sarett | 155d521 | 2017-04-25 17:32:34 -0400 | [diff] [blame^] | 160 | SkBitmap* bitmapCopy = &outSpriteIcon->bitmap; |
| 161 | SkImageInfo bitmapCopyInfo = outPointerIcon->bitmap.info().makeColorType(kN32_SkColorType); |
| 162 | if (bitmapCopy->tryAllocPixels(bitmapCopyInfo)) { |
| 163 | outPointerIcon->bitmap.readPixels(bitmapCopy->info(), bitmapCopy->getPixels(), |
| 164 | bitmapCopy->rowBytes(), 0, 0); |
| 165 | } |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 166 | outSpriteIcon->hotSpotX = outPointerIcon->hotSpotX; |
| 167 | outSpriteIcon->hotSpotY = outPointerIcon->hotSpotY; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 171 | static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style, |
| 172 | SpriteIcon* outSpriteIcon) { |
| 173 | PointerIcon pointerIcon; |
| 174 | loadSystemIconAsSpriteWithPointerIcon(env, contextObj, style, &pointerIcon, outSpriteIcon); |
| 175 | } |
| 176 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 177 | enum { |
| 178 | WM_ACTION_PASS_TO_USER = 1, |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 179 | }; |
| 180 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 181 | |
| 182 | // --- NativeInputManager --- |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 183 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 184 | class NativeInputManager : public virtual RefBase, |
| 185 | public virtual InputReaderPolicyInterface, |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 186 | public virtual InputDispatcherPolicyInterface, |
| 187 | public virtual PointerControllerPolicyInterface { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 188 | protected: |
| 189 | virtual ~NativeInputManager(); |
| 190 | |
| 191 | public: |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 192 | NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 193 | |
| 194 | inline sp<InputManager> getInputManager() const { return mInputManager; } |
| 195 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 196 | void dump(String8& dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 197 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 198 | void setDisplayViewport(bool external, const DisplayViewport& viewport); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 199 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 200 | status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 201 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 202 | status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel); |
| 203 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 204 | void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray); |
| 205 | void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 206 | void setInputDispatchMode(bool enabled, bool frozen); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 207 | void setSystemUiVisibility(int32_t visibility); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 208 | void setPointerSpeed(int32_t speed); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 209 | void setShowTouches(bool enabled); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 210 | void setInteractive(bool interactive); |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 211 | void reloadCalibration(); |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 212 | void setPointerIconType(int32_t iconId); |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 213 | void reloadPointerIcons(); |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 214 | void setCustomPointerIcon(const SpriteIcon& icon); |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 215 | void setPointerCapture(bool enabled); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 216 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 217 | /* --- InputReaderPolicyInterface implementation --- */ |
| 218 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 219 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 220 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 221 | virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices); |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 222 | virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 223 | virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier); |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 224 | virtual TouchAffineTransformation getTouchAffineTransformation(JNIEnv *env, |
| 225 | jfloatArray matrixArr); |
| 226 | virtual TouchAffineTransformation getTouchAffineTransformation( |
| 227 | const String8& inputDeviceDescriptor, int32_t surfaceRotation); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 228 | |
| 229 | /* --- InputDispatcherPolicyInterface implementation --- */ |
| 230 | |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 231 | virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 232 | uint32_t policyFlags); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 233 | virtual void notifyConfigurationChanged(nsecs_t when); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 234 | virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 235 | const sp<InputWindowHandle>& inputWindowHandle, |
| 236 | const String8& reason); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 237 | virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 238 | virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 239 | virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 240 | virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 241 | virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags); |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 242 | virtual nsecs_t interceptKeyBeforeDispatching( |
| 243 | const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 244 | const KeyEvent* keyEvent, uint32_t policyFlags); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 245 | virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 246 | const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 247 | virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 248 | virtual bool checkInjectEventsPermissionNonReentrant( |
| 249 | int32_t injectorPid, int32_t injectorUid); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 250 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 251 | /* --- PointerControllerPolicyInterface implementation --- */ |
| 252 | |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 253 | virtual void loadPointerIcon(SpriteIcon* icon); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 254 | virtual void loadPointerResources(PointerResources* outResources); |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 255 | virtual void loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources, |
| 256 | std::map<int32_t, PointerAnimation>* outAnimationResources); |
Jun Mukai | 5ec7420 | 2015-10-07 16:58:09 +0900 | [diff] [blame] | 257 | virtual int32_t getDefaultPointerIconId(); |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 258 | virtual int32_t getCustomPointerIconId(); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 259 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 260 | private: |
| 261 | sp<InputManager> mInputManager; |
| 262 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 263 | jobject mContextObj; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 264 | jobject mServiceObj; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 265 | sp<Looper> mLooper; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 266 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 267 | Mutex mLock; |
| 268 | struct Locked { |
| 269 | // Display size information. |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 270 | DisplayViewport internalViewport; |
| 271 | DisplayViewport externalViewport; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 272 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 273 | // System UI visibility. |
| 274 | int32_t systemUiVisibility; |
| 275 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 276 | // Pointer speed. |
| 277 | int32_t pointerSpeed; |
| 278 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 279 | // True if pointer gestures are enabled. |
| 280 | bool pointerGesturesEnabled; |
| 281 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 282 | // Show touches feature enable/disable. |
| 283 | bool showTouches; |
| 284 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 285 | // Pointer capture feature enable/disable. |
| 286 | bool pointerCapture; |
| 287 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 288 | // Sprite controller singleton, created on first use. |
| 289 | sp<SpriteController> spriteController; |
| 290 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 291 | // Pointer controller singleton, created and destroyed as needed. |
| 292 | wp<PointerController> pointerController; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 293 | } mLocked; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 294 | |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 295 | std::atomic<bool> mInteractive; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 296 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 297 | void updateInactivityTimeoutLocked(const sp<PointerController>& controller); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 298 | void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags); |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 299 | void ensureSpriteControllerLocked(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 300 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 301 | static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 302 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 303 | static inline JNIEnv* jniEnv() { |
| 304 | return AndroidRuntime::getJNIEnv(); |
| 305 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 306 | }; |
| 307 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 308 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 309 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 310 | NativeInputManager::NativeInputManager(jobject contextObj, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 311 | jobject serviceObj, const sp<Looper>& looper) : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 312 | mLooper(looper), mInteractive(true) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 313 | JNIEnv* env = jniEnv(); |
| 314 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 315 | mContextObj = env->NewGlobalRef(contextObj); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 316 | mServiceObj = env->NewGlobalRef(serviceObj); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 317 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 318 | { |
| 319 | AutoMutex _l(mLock); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 320 | mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 321 | mLocked.pointerSpeed = 0; |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 322 | mLocked.pointerGesturesEnabled = true; |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 323 | mLocked.showTouches = false; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 324 | mLocked.pointerCapture = false; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 325 | } |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 326 | mInteractive = true; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 327 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 328 | sp<EventHub> eventHub = new EventHub(); |
| 329 | mInputManager = new InputManager(eventHub, this, this); |
| 330 | } |
| 331 | |
| 332 | NativeInputManager::~NativeInputManager() { |
| 333 | JNIEnv* env = jniEnv(); |
| 334 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 335 | env->DeleteGlobalRef(mContextObj); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 336 | env->DeleteGlobalRef(mServiceObj); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 339 | void NativeInputManager::dump(String8& dump) { |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 340 | dump.append("Input Manager State:\n"); |
| 341 | { |
| 342 | dump.appendFormat(INDENT "Interactive: %s\n", toString(mInteractive.load())); |
| 343 | } |
| 344 | { |
| 345 | AutoMutex _l(mLock); |
| 346 | dump.appendFormat(INDENT "System UI Visibility: 0x%0" PRIx32 "\n", |
| 347 | mLocked.systemUiVisibility); |
| 348 | dump.appendFormat(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed); |
| 349 | dump.appendFormat(INDENT "Pointer Gestures Enabled: %s\n", |
| 350 | toString(mLocked.pointerGesturesEnabled)); |
| 351 | dump.appendFormat(INDENT "Show Touches: %s\n", toString(mLocked.showTouches)); |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 352 | dump.appendFormat(INDENT "Pointer Capture Enabled: %s\n", toString(mLocked.pointerCapture)); |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 353 | } |
| 354 | dump.append("\n"); |
| 355 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 356 | mInputManager->getReader()->dump(dump); |
| 357 | dump.append("\n"); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 358 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 359 | mInputManager->getDispatcher()->dump(dump); |
| 360 | dump.append("\n"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 363 | bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 364 | if (env->ExceptionCheck()) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 365 | ALOGE("An exception was thrown by callback '%s'.", methodName); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 366 | LOGE_EX(env); |
| 367 | env->ExceptionClear(); |
| 368 | return true; |
| 369 | } |
| 370 | return false; |
| 371 | } |
| 372 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 373 | void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 374 | bool changed = false; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 375 | { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 376 | AutoMutex _l(mLock); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 377 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 378 | DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport; |
| 379 | if (v != viewport) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 380 | changed = true; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 381 | v = viewport; |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 382 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 383 | if (!external) { |
| 384 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 385 | if (controller != NULL) { |
| 386 | controller->setDisplayViewport( |
| 387 | viewport.logicalRight - viewport.logicalLeft, |
| 388 | viewport.logicalBottom - viewport.logicalTop, |
| 389 | viewport.orientation); |
| 390 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 391 | } |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 392 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 393 | } |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 394 | |
| 395 | if (changed) { |
| 396 | mInputManager->getReader()->requestRefreshConfiguration( |
| 397 | InputReaderConfiguration::CHANGE_DISPLAY_INFO); |
| 398 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 401 | status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 402 | const sp<InputChannel>& inputChannel, |
| 403 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor) { |
| 404 | return mInputManager->getDispatcher()->registerInputChannel( |
| 405 | inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 408 | status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */, |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 409 | const sp<InputChannel>& inputChannel) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 410 | return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 413 | void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 414 | JNIEnv* env = jniEnv(); |
| 415 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 416 | jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj, |
| 417 | gServiceClassInfo.getVirtualKeyQuietTimeMillis); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 418 | if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) { |
| 419 | outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime); |
| 420 | } |
| 421 | |
| 422 | outConfig->excludedDeviceNames.clear(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 423 | jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj, |
| 424 | gServiceClassInfo.getExcludedDeviceNames)); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 425 | if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) { |
| 426 | jsize length = env->GetArrayLength(excludedDeviceNames); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 427 | for (jsize i = 0; i < length; i++) { |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 428 | jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i)); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 429 | const char* deviceNameChars = env->GetStringUTFChars(item, NULL); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 430 | outConfig->excludedDeviceNames.add(String8(deviceNameChars)); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 431 | env->ReleaseStringUTFChars(item, deviceNameChars); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 432 | env->DeleteLocalRef(item); |
| 433 | } |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 434 | env->DeleteLocalRef(excludedDeviceNames); |
| 435 | } |
| 436 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 437 | jint hoverTapTimeout = env->CallIntMethod(mServiceObj, |
| 438 | gServiceClassInfo.getHoverTapTimeout); |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 439 | if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 440 | jint doubleTapTimeout = env->CallIntMethod(mServiceObj, |
| 441 | gServiceClassInfo.getDoubleTapTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 442 | if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 443 | jint longPressTimeout = env->CallIntMethod(mServiceObj, |
| 444 | gServiceClassInfo.getLongPressTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 445 | if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) { |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 446 | outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 447 | |
| 448 | // We must ensure that the tap-drag interval is significantly shorter than |
| 449 | // the long-press timeout because the tap is held down for the entire duration |
| 450 | // of the double-tap timeout. |
| 451 | jint tapDragInterval = max(min(longPressTimeout - 100, |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 452 | doubleTapTimeout), hoverTapTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 453 | outConfig->pointerGestureTapDragInterval = |
| 454 | milliseconds_to_nanoseconds(tapDragInterval); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 459 | jint hoverTapSlop = env->CallIntMethod(mServiceObj, |
| 460 | gServiceClassInfo.getHoverTapSlop); |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 461 | if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) { |
| 462 | outConfig->pointerGestureTapSlop = hoverTapSlop; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 463 | } |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 464 | |
| 465 | { // acquire lock |
| 466 | AutoMutex _l(mLock); |
| 467 | |
| 468 | outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed |
| 469 | * POINTER_SPEED_EXPONENT); |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 470 | outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 471 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 472 | outConfig->showTouches = mLocked.showTouches; |
| 473 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 474 | outConfig->pointerCapture = mLocked.pointerCapture; |
| 475 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 476 | outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport); |
| 477 | outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 478 | } // release lock |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 481 | sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t /* deviceId */) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 482 | AutoMutex _l(mLock); |
| 483 | |
| 484 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 485 | if (controller == NULL) { |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 486 | ensureSpriteControllerLocked(); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 487 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 488 | controller = new PointerController(this, mLooper, mLocked.spriteController); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 489 | mLocked.pointerController = controller; |
| 490 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 491 | DisplayViewport& v = mLocked.internalViewport; |
| 492 | controller->setDisplayViewport( |
| 493 | v.logicalRight - v.logicalLeft, |
| 494 | v.logicalBottom - v.logicalTop, |
| 495 | v.orientation); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 496 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 497 | updateInactivityTimeoutLocked(controller); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 498 | } |
| 499 | return controller; |
| 500 | } |
| 501 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 502 | void NativeInputManager::ensureSpriteControllerLocked() { |
| 503 | if (mLocked.spriteController == NULL) { |
| 504 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 505 | jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer); |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 506 | if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) { |
| 507 | layer = -1; |
| 508 | } |
| 509 | mLocked.spriteController = new SpriteController(mLooper, layer); |
| 510 | } |
| 511 | } |
| 512 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 513 | void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) { |
| 514 | JNIEnv* env = jniEnv(); |
| 515 | |
| 516 | size_t count = inputDevices.size(); |
| 517 | jobjectArray inputDevicesObjArray = env->NewObjectArray( |
| 518 | count, gInputDeviceClassInfo.clazz, NULL); |
| 519 | if (inputDevicesObjArray) { |
| 520 | bool error = false; |
| 521 | for (size_t i = 0; i < count; i++) { |
| 522 | jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i)); |
| 523 | if (!inputDeviceObj) { |
| 524 | error = true; |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj); |
| 529 | env->DeleteLocalRef(inputDeviceObj); |
| 530 | } |
| 531 | |
| 532 | if (!error) { |
| 533 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged, |
| 534 | inputDevicesObjArray); |
| 535 | } |
| 536 | |
| 537 | env->DeleteLocalRef(inputDevicesObjArray); |
| 538 | } |
| 539 | |
| 540 | checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged"); |
| 541 | } |
| 542 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 543 | sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay( |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 544 | const InputDeviceIdentifier& identifier) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 545 | JNIEnv* env = jniEnv(); |
| 546 | |
| 547 | sp<KeyCharacterMap> result; |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 548 | ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string())); |
| 549 | ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz, |
| 550 | gInputDeviceIdentifierInfo.constructor, descriptor.get(), |
| 551 | identifier.vendor, identifier.product)); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 552 | ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj, |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 553 | gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get()))); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 554 | if (arrayObj.get()) { |
| 555 | ScopedLocalRef<jstring> filenameObj(env, |
| 556 | jstring(env->GetObjectArrayElement(arrayObj.get(), 0))); |
| 557 | ScopedLocalRef<jstring> contentsObj(env, |
| 558 | jstring(env->GetObjectArrayElement(arrayObj.get(), 1))); |
| 559 | ScopedUtfChars filenameChars(env, filenameObj.get()); |
| 560 | ScopedUtfChars contentsChars(env, contentsObj.get()); |
| 561 | |
| 562 | KeyCharacterMap::loadContents(String8(filenameChars.c_str()), |
| 563 | String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result); |
| 564 | } |
| 565 | checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay"); |
| 566 | return result; |
| 567 | } |
| 568 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 569 | String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) { |
| 570 | JNIEnv* env = jniEnv(); |
| 571 | |
| 572 | ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string())); |
| 573 | ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj, |
| 574 | gServiceClassInfo.getDeviceAlias, uniqueIdObj.get()))); |
| 575 | String8 result; |
| 576 | if (aliasObj.get()) { |
| 577 | ScopedUtfChars aliasChars(env, aliasObj.get()); |
| 578 | result.setTo(aliasChars.c_str()); |
| 579 | } |
| 580 | checkAndClearExceptionFromCallback(env, "getDeviceAlias"); |
| 581 | return result; |
| 582 | } |
| 583 | |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 584 | void NativeInputManager::notifySwitch(nsecs_t when, |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 585 | uint32_t switchValues, uint32_t switchMask, uint32_t /* policyFlags */) { |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 586 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 587 | ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x", |
| 588 | when, switchValues, switchMask, policyFlags); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 589 | #endif |
| 590 | |
| 591 | JNIEnv* env = jniEnv(); |
| 592 | |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 593 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch, |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 594 | when, switchValues, switchMask); |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 595 | checkAndClearExceptionFromCallback(env, "notifySwitch"); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 598 | void NativeInputManager::notifyConfigurationChanged(nsecs_t when) { |
| 599 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 600 | ALOGD("notifyConfigurationChanged - when=%lld", when); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 601 | #endif |
| 602 | |
| 603 | JNIEnv* env = jniEnv(); |
| 604 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 605 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 606 | checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 609 | nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 610 | const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 611 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 612 | ALOGD("notifyANR"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 613 | #endif |
| 614 | |
| 615 | JNIEnv* env = jniEnv(); |
| 616 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 617 | jobject inputApplicationHandleObj = |
| 618 | getInputApplicationHandleObjLocalRef(env, inputApplicationHandle); |
| 619 | jobject inputWindowHandleObj = |
| 620 | getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 621 | jstring reasonObj = env->NewStringUTF(reason.string()); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 622 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 623 | jlong newTimeout = env->CallLongMethod(mServiceObj, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 624 | gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj, |
| 625 | reasonObj); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 626 | if (checkAndClearExceptionFromCallback(env, "notifyANR")) { |
| 627 | newTimeout = 0; // abort dispatch |
| 628 | } else { |
| 629 | assert(newTimeout >= 0); |
| 630 | } |
| 631 | |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 632 | env->DeleteLocalRef(reasonObj); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 633 | env->DeleteLocalRef(inputWindowHandleObj); |
| 634 | env->DeleteLocalRef(inputApplicationHandleObj); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 635 | return newTimeout; |
| 636 | } |
| 637 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 638 | void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 639 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 640 | ALOGD("notifyInputChannelBroken"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 641 | #endif |
| 642 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 643 | JNIEnv* env = jniEnv(); |
| 644 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 645 | jobject inputWindowHandleObj = |
| 646 | getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
| 647 | if (inputWindowHandleObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 648 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 649 | inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 650 | checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken"); |
| 651 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 652 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 653 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 656 | void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) { |
| 657 | JNIEnv* env = jniEnv(); |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 658 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 659 | jint keyRepeatTimeout = env->CallIntMethod(mServiceObj, |
| 660 | gServiceClassInfo.getKeyRepeatTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 661 | if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) { |
| 662 | outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout); |
| 663 | } |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 664 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 665 | jint keyRepeatDelay = env->CallIntMethod(mServiceObj, |
| 666 | gServiceClassInfo.getKeyRepeatDelay); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 667 | if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) { |
| 668 | outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay); |
| 669 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 672 | void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) { |
| 673 | Vector<sp<InputWindowHandle> > windowHandles; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 674 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 675 | if (windowHandleObjArray) { |
| 676 | jsize length = env->GetArrayLength(windowHandleObjArray); |
| 677 | for (jsize i = 0; i < length; i++) { |
| 678 | jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i); |
| 679 | if (! windowHandleObj) { |
| 680 | break; // found null element indicating end of used portion of the array |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 681 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 682 | |
| 683 | sp<InputWindowHandle> windowHandle = |
| 684 | android_server_InputWindowHandle_getHandle(env, windowHandleObj); |
| 685 | if (windowHandle != NULL) { |
| 686 | windowHandles.push(windowHandle); |
| 687 | } |
| 688 | env->DeleteLocalRef(windowHandleObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 689 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 690 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 691 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 692 | mInputManager->getDispatcher()->setInputWindows(windowHandles); |
| 693 | |
| 694 | // Do this after the dispatcher has updated the window handle state. |
| 695 | bool newPointerGesturesEnabled = true; |
| 696 | size_t numWindows = windowHandles.size(); |
| 697 | for (size_t i = 0; i < numWindows; i++) { |
| 698 | const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 699 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
| 700 | if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures |
| 701 | & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 702 | newPointerGesturesEnabled = false; |
| 703 | } |
| 704 | } |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 705 | |
| 706 | uint32_t changes = 0; |
| 707 | { // acquire lock |
| 708 | AutoMutex _l(mLock); |
| 709 | |
| 710 | if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) { |
| 711 | mLocked.pointerGesturesEnabled = newPointerGesturesEnabled; |
| 712 | changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT; |
| 713 | } |
| 714 | } // release lock |
| 715 | |
| 716 | if (changes) { |
| 717 | mInputManager->getReader()->requestRefreshConfiguration(changes); |
| 718 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 721 | void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) { |
| 722 | sp<InputApplicationHandle> applicationHandle = |
| 723 | android_server_InputApplicationHandle_getHandle(env, applicationHandleObj); |
| 724 | mInputManager->getDispatcher()->setFocusedApplication(applicationHandle); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 728 | mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 731 | void NativeInputManager::setSystemUiVisibility(int32_t visibility) { |
| 732 | AutoMutex _l(mLock); |
| 733 | |
| 734 | if (mLocked.systemUiVisibility != visibility) { |
| 735 | mLocked.systemUiVisibility = visibility; |
| 736 | |
| 737 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 738 | if (controller != NULL) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 739 | updateInactivityTimeoutLocked(controller); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 744 | void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 745 | bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 746 | controller->setInactivityTimeout(lightsOut |
| 747 | ? PointerController::INACTIVITY_TIMEOUT_SHORT |
| 748 | : PointerController::INACTIVITY_TIMEOUT_NORMAL); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 751 | void NativeInputManager::setPointerSpeed(int32_t speed) { |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 752 | { // acquire lock |
| 753 | AutoMutex _l(mLock); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 754 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 755 | if (mLocked.pointerSpeed == speed) { |
| 756 | return; |
| 757 | } |
| 758 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 759 | ALOGI("Setting pointer speed to %d.", speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 760 | mLocked.pointerSpeed = speed; |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 761 | } // release lock |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 762 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 763 | mInputManager->getReader()->requestRefreshConfiguration( |
| 764 | InputReaderConfiguration::CHANGE_POINTER_SPEED); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 767 | void NativeInputManager::setShowTouches(bool enabled) { |
| 768 | { // acquire lock |
| 769 | AutoMutex _l(mLock); |
| 770 | |
| 771 | if (mLocked.showTouches == enabled) { |
| 772 | return; |
| 773 | } |
| 774 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 775 | ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled"); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 776 | mLocked.showTouches = enabled; |
| 777 | } // release lock |
| 778 | |
| 779 | mInputManager->getReader()->requestRefreshConfiguration( |
| 780 | InputReaderConfiguration::CHANGE_SHOW_TOUCHES); |
| 781 | } |
| 782 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 783 | void NativeInputManager::setPointerCapture(bool enabled) { |
| 784 | { // acquire lock |
| 785 | AutoMutex _l(mLock); |
| 786 | |
| 787 | if (mLocked.pointerCapture == enabled) { |
| 788 | return; |
| 789 | } |
| 790 | |
| 791 | ALOGI("Setting pointer capture to %s.", enabled ? "enabled" : "disabled"); |
| 792 | mLocked.pointerCapture = enabled; |
| 793 | } // release lock |
| 794 | |
| 795 | mInputManager->getReader()->requestRefreshConfiguration( |
| 796 | InputReaderConfiguration::CHANGE_POINTER_CAPTURE); |
| 797 | } |
| 798 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 799 | void NativeInputManager::setInteractive(bool interactive) { |
| 800 | mInteractive = interactive; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 803 | void NativeInputManager::reloadCalibration() { |
| 804 | mInputManager->getReader()->requestRefreshConfiguration( |
Michael Wright | 357285c | 2015-04-17 00:50:31 +0100 | [diff] [blame] | 805 | InputReaderConfiguration::CHANGE_TOUCH_AFFINE_TRANSFORMATION); |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 808 | void NativeInputManager::setPointerIconType(int32_t iconId) { |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 809 | AutoMutex _l(mLock); |
| 810 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 811 | if (controller != NULL) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 812 | controller->updatePointerIcon(iconId); |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | |
| 816 | void NativeInputManager::reloadPointerIcons() { |
| 817 | AutoMutex _l(mLock); |
| 818 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 819 | if (controller != NULL) { |
| 820 | controller->reloadPointerResources(); |
| 821 | } |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 824 | void NativeInputManager::setCustomPointerIcon(const SpriteIcon& icon) { |
| 825 | AutoMutex _l(mLock); |
| 826 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 827 | if (controller != NULL) { |
| 828 | controller->setCustomPointerIcon(icon); |
| 829 | } |
| 830 | } |
| 831 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 832 | TouchAffineTransformation NativeInputManager::getTouchAffineTransformation( |
| 833 | JNIEnv *env, jfloatArray matrixArr) { |
| 834 | ScopedFloatArrayRO matrix(env, matrixArr); |
| 835 | assert(matrix.size() == 6); |
| 836 | |
| 837 | TouchAffineTransformation transform; |
| 838 | transform.x_scale = matrix[0]; |
| 839 | transform.x_ymix = matrix[1]; |
| 840 | transform.x_offset = matrix[2]; |
| 841 | transform.y_xmix = matrix[3]; |
| 842 | transform.y_scale = matrix[4]; |
| 843 | transform.y_offset = matrix[5]; |
| 844 | |
| 845 | return transform; |
| 846 | } |
| 847 | |
| 848 | TouchAffineTransformation NativeInputManager::getTouchAffineTransformation( |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 849 | const String8& inputDeviceDescriptor, int32_t surfaceRotation) { |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 850 | JNIEnv* env = jniEnv(); |
| 851 | |
| 852 | ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string())); |
| 853 | |
| 854 | jobject cal = env->CallObjectMethod(mServiceObj, |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 855 | gServiceClassInfo.getTouchCalibrationForInputDevice, descriptorObj.get(), |
| 856 | surfaceRotation); |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 857 | |
| 858 | jfloatArray matrixArr = jfloatArray(env->CallObjectMethod(cal, |
| 859 | gTouchCalibrationClassInfo.getAffineTransform)); |
| 860 | |
| 861 | TouchAffineTransformation transform = getTouchAffineTransformation(env, matrixArr); |
| 862 | |
| 863 | env->DeleteLocalRef(matrixArr); |
| 864 | env->DeleteLocalRef(cal); |
| 865 | |
| 866 | return transform; |
| 867 | } |
| 868 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 869 | bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) { |
| 870 | jobject inputEventObj; |
| 871 | |
| 872 | JNIEnv* env = jniEnv(); |
| 873 | switch (inputEvent->getType()) { |
| 874 | case AINPUT_EVENT_TYPE_KEY: |
| 875 | inputEventObj = android_view_KeyEvent_fromNative(env, |
| 876 | static_cast<const KeyEvent*>(inputEvent)); |
| 877 | break; |
| 878 | case AINPUT_EVENT_TYPE_MOTION: |
| 879 | inputEventObj = android_view_MotionEvent_obtainAsCopy(env, |
| 880 | static_cast<const MotionEvent*>(inputEvent)); |
| 881 | break; |
| 882 | default: |
| 883 | return true; // dispatch the event normally |
| 884 | } |
| 885 | |
| 886 | if (!inputEventObj) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 887 | ALOGE("Failed to obtain input event object for filterInputEvent."); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 888 | return true; // dispatch the event normally |
| 889 | } |
| 890 | |
| 891 | // The callee is responsible for recycling the event. |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 892 | jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 893 | inputEventObj, policyFlags); |
| 894 | if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) { |
| 895 | pass = true; |
| 896 | } |
| 897 | env->DeleteLocalRef(inputEventObj); |
| 898 | return pass; |
| 899 | } |
| 900 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 901 | void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent, |
| 902 | uint32_t& policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 903 | // Policy: |
| 904 | // - Ignore untrusted events and pass them along. |
| 905 | // - Ask the window manager what to do with normal events and trusted injected events. |
| 906 | // - For normal events wake and brighten the screen if currently off or dim. |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 907 | bool interactive = mInteractive.load(); |
| 908 | if (interactive) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 909 | policyFlags |= POLICY_FLAG_INTERACTIVE; |
| 910 | } |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 911 | if ((policyFlags & POLICY_FLAG_TRUSTED)) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 912 | nsecs_t when = keyEvent->getEventTime(); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 913 | JNIEnv* env = jniEnv(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 914 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 915 | jint wmActions; |
| 916 | if (keyEventObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 917 | wmActions = env->CallIntMethod(mServiceObj, |
| 918 | gServiceClassInfo.interceptKeyBeforeQueueing, |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 919 | keyEventObj, policyFlags); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 920 | if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) { |
| 921 | wmActions = 0; |
| 922 | } |
| 923 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 924 | env->DeleteLocalRef(keyEventObj); |
| 925 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 926 | ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing."); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 927 | wmActions = 0; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 930 | handleInterceptActions(wmActions, when, /*byref*/ policyFlags); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 931 | } else { |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 932 | if (interactive) { |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 933 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 934 | } |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 938 | void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 939 | // Policy: |
| 940 | // - Ignore untrusted events and pass them along. |
| 941 | // - No special filtering for injected events required at this time. |
| 942 | // - Filter normal events based on screen state. |
| 943 | // - For normal events brighten (but do not wake) the screen if currently dim. |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 944 | bool interactive = mInteractive.load(); |
| 945 | if (interactive) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 946 | policyFlags |= POLICY_FLAG_INTERACTIVE; |
| 947 | } |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 948 | if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 949 | if (policyFlags & POLICY_FLAG_INTERACTIVE) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 950 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 951 | } else { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 952 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 953 | jint wmActions = env->CallIntMethod(mServiceObj, |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 954 | gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 955 | when, policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 956 | if (checkAndClearExceptionFromCallback(env, |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 957 | "interceptMotionBeforeQueueingNonInteractive")) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 958 | wmActions = 0; |
| 959 | } |
| 960 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 961 | handleInterceptActions(wmActions, when, /*byref*/ policyFlags); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 962 | } |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 963 | } else { |
Michael Wright | a405121 | 2015-07-23 17:04:40 +0100 | [diff] [blame] | 964 | if (interactive) { |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 965 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 966 | } |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 970 | void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when, |
| 971 | uint32_t& policyFlags) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 972 | if (wmActions & WM_ACTION_PASS_TO_USER) { |
| 973 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 974 | } else { |
Jeff Brown | 9267beb | 2011-03-07 20:11:22 -0800 | [diff] [blame] | 975 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 976 | ALOGD("handleInterceptActions: Not passing key to user."); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 977 | #endif |
| 978 | } |
| 979 | } |
| 980 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 981 | nsecs_t NativeInputManager::interceptKeyBeforeDispatching( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 982 | const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 983 | const KeyEvent* keyEvent, uint32_t policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 984 | // Policy: |
| 985 | // - Ignore untrusted events and pass them along. |
| 986 | // - Filter normal events and trusted injected events through the window manager policy to |
| 987 | // handle the HOME key and the like. |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 988 | nsecs_t result = 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 989 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 990 | JNIEnv* env = jniEnv(); |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 991 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 992 | // Note: inputWindowHandle may be null. |
| 993 | jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 994 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 995 | if (keyEventObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 996 | jlong delayMillis = env->CallLongMethod(mServiceObj, |
| 997 | gServiceClassInfo.interceptKeyBeforeDispatching, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 998 | inputWindowHandleObj, keyEventObj, policyFlags); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 999 | bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching"); |
| 1000 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 1001 | env->DeleteLocalRef(keyEventObj); |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1002 | if (!error) { |
| 1003 | if (delayMillis < 0) { |
| 1004 | result = -1; |
| 1005 | } else if (delayMillis > 0) { |
| 1006 | result = milliseconds_to_nanoseconds(delayMillis); |
| 1007 | } |
| 1008 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1009 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1010 | ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching."); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1011 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1012 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 1013 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1014 | return result; |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1017 | bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1018 | const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1019 | // Policy: |
| 1020 | // - Ignore untrusted events and do not perform default handling. |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1021 | bool result = false; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1022 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 1023 | JNIEnv* env = jniEnv(); |
| 1024 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1025 | // Note: inputWindowHandle may be null. |
| 1026 | jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1027 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 1028 | if (keyEventObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1029 | jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj, |
| 1030 | gServiceClassInfo.dispatchUnhandledKey, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1031 | inputWindowHandleObj, keyEventObj, policyFlags); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 1032 | if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) { |
| 1033 | fallbackKeyEventObj = NULL; |
| 1034 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1035 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 1036 | env->DeleteLocalRef(keyEventObj); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1037 | |
| 1038 | if (fallbackKeyEventObj) { |
| 1039 | // Note: outFallbackKeyEvent may be the same object as keyEvent. |
| 1040 | if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj, |
| 1041 | outFallbackKeyEvent)) { |
| 1042 | result = true; |
| 1043 | } |
| 1044 | android_view_KeyEvent_recycle(env, fallbackKeyEventObj); |
| 1045 | env->DeleteLocalRef(fallbackKeyEventObj); |
| 1046 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1047 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1048 | ALOGE("Failed to obtain key event object for dispatchUnhandledKey."); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1049 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1050 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1051 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1052 | return result; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 1055 | void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) { |
| 1056 | android_server_PowerManagerService_userActivity(eventTime, eventType); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1059 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1060 | bool NativeInputManager::checkInjectEventsPermissionNonReentrant( |
| 1061 | int32_t injectorPid, int32_t injectorUid) { |
| 1062 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1063 | jboolean result = env->CallBooleanMethod(mServiceObj, |
| 1064 | gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 1065 | if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) { |
| 1066 | result = false; |
| 1067 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1068 | return result; |
| 1069 | } |
| 1070 | |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 1071 | void NativeInputManager::loadPointerIcon(SpriteIcon* icon) { |
| 1072 | JNIEnv* env = jniEnv(); |
| 1073 | |
| 1074 | ScopedLocalRef<jobject> pointerIconObj(env, env->CallObjectMethod( |
| 1075 | mServiceObj, gServiceClassInfo.getPointerIcon)); |
| 1076 | if (checkAndClearExceptionFromCallback(env, "getPointerIcon")) { |
| 1077 | return; |
| 1078 | } |
| 1079 | |
| 1080 | PointerIcon pointerIcon; |
| 1081 | status_t status = android_view_PointerIcon_load(env, pointerIconObj.get(), |
| 1082 | mContextObj, &pointerIcon); |
| 1083 | if (!status && !pointerIcon.isNullIcon()) { |
| 1084 | *icon = SpriteIcon(pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY); |
| 1085 | } else { |
| 1086 | *icon = SpriteIcon(); |
| 1087 | } |
| 1088 | } |
| 1089 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1090 | void NativeInputManager::loadPointerResources(PointerResources* outResources) { |
| 1091 | JNIEnv* env = jniEnv(); |
| 1092 | |
| 1093 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER, |
| 1094 | &outResources->spotHover); |
| 1095 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH, |
| 1096 | &outResources->spotTouch); |
| 1097 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR, |
| 1098 | &outResources->spotAnchor); |
| 1099 | } |
| 1100 | |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 1101 | void NativeInputManager::loadAdditionalMouseResources(std::map<int32_t, SpriteIcon>* outResources, |
| 1102 | std::map<int32_t, PointerAnimation>* outAnimationResources) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1103 | JNIEnv* env = jniEnv(); |
| 1104 | |
| 1105 | for (int iconId = POINTER_ICON_STYLE_CONTEXT_MENU; iconId <= POINTER_ICON_STYLE_GRABBING; |
| 1106 | ++iconId) { |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 1107 | PointerIcon pointerIcon; |
| 1108 | loadSystemIconAsSpriteWithPointerIcon( |
| 1109 | env, mContextObj, iconId, &pointerIcon, &((*outResources)[iconId])); |
| 1110 | if (!pointerIcon.bitmapFrames.empty()) { |
| 1111 | PointerAnimation& animationData = (*outAnimationResources)[iconId]; |
| 1112 | size_t numFrames = pointerIcon.bitmapFrames.size() + 1; |
| 1113 | animationData.durationPerFrame = |
| 1114 | milliseconds_to_nanoseconds(pointerIcon.durationPerFrame); |
| 1115 | animationData.animationFrames.reserve(numFrames); |
| 1116 | animationData.animationFrames.push_back(SpriteIcon( |
| 1117 | pointerIcon.bitmap, pointerIcon.hotSpotX, pointerIcon.hotSpotY)); |
| 1118 | for (size_t i = 0; i < numFrames - 1; ++i) { |
| 1119 | animationData.animationFrames.push_back(SpriteIcon( |
| 1120 | pointerIcon.bitmapFrames[i], pointerIcon.hotSpotX, pointerIcon.hotSpotY)); |
| 1121 | } |
| 1122 | } |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1123 | } |
Jun Mukai | 808196f | 2015-10-28 16:46:44 -0700 | [diff] [blame] | 1124 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_NULL, |
| 1125 | &((*outResources)[POINTER_ICON_STYLE_NULL])); |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Jun Mukai | 5ec7420 | 2015-10-07 16:58:09 +0900 | [diff] [blame] | 1128 | int32_t NativeInputManager::getDefaultPointerIconId() { |
| 1129 | return POINTER_ICON_STYLE_ARROW; |
| 1130 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1131 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 1132 | int32_t NativeInputManager::getCustomPointerIconId() { |
| 1133 | return POINTER_ICON_STYLE_CUSTOM; |
| 1134 | } |
| 1135 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1136 | // ---------------------------------------------------------------------------- |
| 1137 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1138 | static jlong nativeInit(JNIEnv* env, jclass /* clazz */, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1139 | jobject serviceObj, jobject contextObj, jobject messageQueueObj) { |
Jeff Brown | 603b445 | 2012-04-06 17:39:41 -0700 | [diff] [blame] | 1140 | sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj); |
Jeff Brown | 86469346 | 2013-01-28 14:25:53 -0800 | [diff] [blame] | 1141 | if (messageQueue == NULL) { |
| 1142 | jniThrowRuntimeException(env, "MessageQueue is not initialized."); |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
Jeff Brown | 603b445 | 2012-04-06 17:39:41 -0700 | [diff] [blame] | 1146 | NativeInputManager* im = new NativeInputManager(contextObj, serviceObj, |
| 1147 | messageQueue->getLooper()); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 1148 | im->incStrong(0); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1149 | return reinterpret_cast<jlong>(im); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1152 | static void nativeStart(JNIEnv* env, jclass /* clazz */, jlong ptr) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1153 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1154 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1155 | status_t result = im->getInputManager()->start(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1156 | if (result) { |
| 1157 | jniThrowRuntimeException(env, "Input manager could not be started."); |
| 1158 | } |
| 1159 | } |
| 1160 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1161 | static void nativeSetDisplayViewport(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, |
| 1162 | jboolean external, jint displayId, jint orientation, |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1163 | jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 1164 | jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom, |
| 1165 | jint deviceWidth, jint deviceHeight) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1166 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1167 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1168 | DisplayViewport v; |
| 1169 | v.displayId = displayId; |
| 1170 | v.orientation = orientation; |
| 1171 | v.logicalLeft = logicalLeft; |
| 1172 | v.logicalTop = logicalTop; |
| 1173 | v.logicalRight = logicalRight; |
| 1174 | v.logicalBottom = logicalBottom; |
| 1175 | v.physicalLeft = physicalLeft; |
| 1176 | v.physicalTop = physicalTop; |
| 1177 | v.physicalRight = physicalRight; |
| 1178 | v.physicalBottom = physicalBottom; |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 1179 | v.deviceWidth = deviceWidth; |
| 1180 | v.deviceHeight = deviceHeight; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1181 | im->setDisplayViewport(external, v); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1184 | static jint nativeGetScanCodeState(JNIEnv* /* env */, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1185 | jlong ptr, jint deviceId, jint sourceMask, jint scanCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1186 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1187 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1188 | return (jint) im->getInputManager()->getReader()->getScanCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1189 | deviceId, uint32_t(sourceMask), scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1192 | static jint nativeGetKeyCodeState(JNIEnv* /* env */, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1193 | jlong ptr, jint deviceId, jint sourceMask, jint keyCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1194 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1195 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1196 | return (jint) im->getInputManager()->getReader()->getKeyCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1197 | deviceId, uint32_t(sourceMask), keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1200 | static jint nativeGetSwitchState(JNIEnv* /* env */, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1201 | jlong ptr, jint deviceId, jint sourceMask, jint sw) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1202 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1203 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1204 | return (jint) im->getInputManager()->getReader()->getSwitchState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1205 | deviceId, uint32_t(sourceMask), sw); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1208 | static jboolean nativeHasKeys(JNIEnv* env, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1209 | jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1210 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1211 | |
| 1212 | int32_t* codes = env->GetIntArrayElements(keyCodes, NULL); |
| 1213 | uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL); |
| 1214 | jsize numCodes = env->GetArrayLength(keyCodes); |
| 1215 | jboolean result; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1216 | if (numCodes == env->GetArrayLength(keyCodes)) { |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1217 | if (im->getInputManager()->getReader()->hasKeys( |
| 1218 | deviceId, uint32_t(sourceMask), numCodes, codes, flags)) { |
| 1219 | result = JNI_TRUE; |
| 1220 | } else { |
| 1221 | result = JNI_FALSE; |
| 1222 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1223 | } else { |
| 1224 | result = JNI_FALSE; |
| 1225 | } |
| 1226 | |
| 1227 | env->ReleaseBooleanArrayElements(outFlags, flags, 0); |
| 1228 | env->ReleaseIntArrayElements(keyCodes, codes, 0); |
| 1229 | return result; |
| 1230 | } |
| 1231 | |
| 1232 | static void throwInputChannelNotInitialized(JNIEnv* env) { |
| 1233 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1234 | "inputChannel is not initialized"); |
| 1235 | } |
| 1236 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1237 | static void handleInputChannelDisposed(JNIEnv* env, |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1238 | jobject /* inputChannelObj */, const sp<InputChannel>& inputChannel, void* data) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1239 | NativeInputManager* im = static_cast<NativeInputManager*>(data); |
| 1240 | |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1241 | ALOGW("Input channel object '%s' was disposed without first being unregistered with " |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1242 | "the input manager!", inputChannel->getName().string()); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1243 | im->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1246 | static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1247 | jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1248 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1249 | |
| 1250 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1251 | inputChannelObj); |
| 1252 | if (inputChannel == NULL) { |
| 1253 | throwInputChannelNotInitialized(env); |
| 1254 | return; |
| 1255 | } |
| 1256 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1257 | sp<InputWindowHandle> inputWindowHandle = |
| 1258 | android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1259 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1260 | status_t status = im->registerInputChannel( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1261 | env, inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1262 | if (status) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1263 | String8 message; |
| 1264 | message.appendFormat("Failed to register input channel. status=%d", status); |
| 1265 | jniThrowRuntimeException(env, message.string()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1269 | if (! monitor) { |
| 1270 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1271 | handleInputChannelDisposed, im); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1272 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1275 | static void nativeUnregisterInputChannel(JNIEnv* env, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1276 | jlong ptr, jobject inputChannelObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1277 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1278 | |
| 1279 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1280 | inputChannelObj); |
| 1281 | if (inputChannel == NULL) { |
| 1282 | throwInputChannelNotInitialized(env); |
| 1283 | return; |
| 1284 | } |
| 1285 | |
| 1286 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL); |
| 1287 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1288 | status_t status = im->unregisterInputChannel(env, inputChannel); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1289 | if (status && status != BAD_VALUE) { // ignore already unregistered channel |
| 1290 | String8 message; |
| 1291 | message.appendFormat("Failed to unregister input channel. status=%d", status); |
| 1292 | jniThrowRuntimeException(env, message.string()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1296 | static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1297 | jlong ptr, jboolean enabled) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1298 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1299 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1300 | im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1303 | static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */, |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 1304 | jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1305 | jint syncMode, jint timeoutMillis, jint policyFlags) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1306 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1307 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1308 | if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) { |
| 1309 | KeyEvent keyEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1310 | status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent); |
| 1311 | if (status) { |
| 1312 | jniThrowRuntimeException(env, "Could not read contents of KeyEvent object."); |
| 1313 | return INPUT_EVENT_INJECTION_FAILED; |
| 1314 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1315 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1316 | return (jint) im->getInputManager()->getDispatcher()->injectInputEvent( |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 1317 | & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1318 | uint32_t(policyFlags)); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1319 | } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) { |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 1320 | const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj); |
| 1321 | if (!motionEvent) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1322 | jniThrowRuntimeException(env, "Could not read contents of MotionEvent object."); |
| 1323 | return INPUT_EVENT_INJECTION_FAILED; |
| 1324 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1325 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1326 | return (jint) im->getInputManager()->getDispatcher()->injectInputEvent( |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 1327 | motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1328 | uint32_t(policyFlags)); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1329 | } else { |
| 1330 | jniThrowRuntimeException(env, "Invalid input event type."); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1331 | return INPUT_EVENT_INJECTION_FAILED; |
| 1332 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1335 | static void nativeToggleCapsLock(JNIEnv* env, jclass /* clazz */, |
| 1336 | jlong ptr, jint deviceId) { |
| 1337 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1338 | im->getInputManager()->getReader()->toggleCapsLockState(deviceId); |
| 1339 | } |
| 1340 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1341 | static void nativeSetInputWindows(JNIEnv* env, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1342 | jlong ptr, jobjectArray windowHandleObjArray) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1343 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1344 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1345 | im->setInputWindows(env, windowHandleObjArray); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1348 | static void nativeSetFocusedApplication(JNIEnv* env, jclass /* clazz */, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1349 | jlong ptr, jobject applicationHandleObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1350 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1351 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1352 | im->setFocusedApplication(env, applicationHandleObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 1355 | static void nativeSetPointerCapture(JNIEnv* env, jclass /* clazz */, jlong ptr, |
| 1356 | jboolean enabled) { |
| 1357 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1358 | im->setPointerCapture(enabled); |
| 1359 | } |
| 1360 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1361 | static void nativeSetInputDispatchMode(JNIEnv* /* env */, |
| 1362 | jclass /* clazz */, jlong ptr, jboolean enabled, jboolean frozen) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1363 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1364 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1365 | im->setInputDispatchMode(enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1368 | static void nativeSetSystemUiVisibility(JNIEnv* /* env */, |
| 1369 | jclass /* clazz */, jlong ptr, jint visibility) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1370 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1371 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1372 | im->setSystemUiVisibility(visibility); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1375 | static jboolean nativeTransferTouchFocus(JNIEnv* env, |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1376 | jclass /* clazz */, jlong ptr, jobject fromChannelObj, jobject toChannelObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1377 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1378 | |
| 1379 | sp<InputChannel> fromChannel = |
| 1380 | android_view_InputChannel_getInputChannel(env, fromChannelObj); |
| 1381 | sp<InputChannel> toChannel = |
| 1382 | android_view_InputChannel_getInputChannel(env, toChannelObj); |
| 1383 | |
| 1384 | if (fromChannel == NULL || toChannel == NULL) { |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1385 | return JNI_FALSE; |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1388 | if (im->getInputManager()->getDispatcher()-> |
| 1389 | transferTouchFocus(fromChannel, toChannel)) { |
| 1390 | return JNI_TRUE; |
| 1391 | } else { |
| 1392 | return JNI_FALSE; |
| 1393 | } |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1396 | static void nativeSetPointerSpeed(JNIEnv* /* env */, |
| 1397 | jclass /* clazz */, jlong ptr, jint speed) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1398 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1399 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1400 | im->setPointerSpeed(speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1403 | static void nativeSetShowTouches(JNIEnv* /* env */, |
| 1404 | jclass /* clazz */, jlong ptr, jboolean enabled) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1405 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1406 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1407 | im->setShowTouches(enabled); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1410 | static void nativeSetInteractive(JNIEnv* env, |
| 1411 | jclass clazz, jlong ptr, jboolean interactive) { |
| 1412 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1413 | |
| 1414 | im->setInteractive(interactive); |
| 1415 | } |
| 1416 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1417 | static void nativeReloadCalibration(JNIEnv* env, jclass clazz, jlong ptr) { |
| 1418 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1419 | im->reloadCalibration(); |
| 1420 | } |
| 1421 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1422 | static void nativeVibrate(JNIEnv* env, |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1423 | jclass /* clazz */, jlong ptr, jint deviceId, jlongArray patternObj, |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1424 | jint repeat, jint token) { |
| 1425 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1426 | |
| 1427 | size_t patternSize = env->GetArrayLength(patternObj); |
| 1428 | if (patternSize > MAX_VIBRATE_PATTERN_SIZE) { |
Michael Wright | 9ecba52 | 2014-04-04 15:29:53 -0700 | [diff] [blame] | 1429 | ALOGI("Skipped requested vibration because the pattern size is %zu " |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1430 | "which is more than the maximum supported size of %d.", |
| 1431 | patternSize, MAX_VIBRATE_PATTERN_SIZE); |
| 1432 | return; // limit to reasonable size |
| 1433 | } |
| 1434 | |
| 1435 | jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical( |
| 1436 | patternObj, NULL)); |
| 1437 | nsecs_t pattern[patternSize]; |
| 1438 | for (size_t i = 0; i < patternSize; i++) { |
| 1439 | pattern[i] = max(jlong(0), min(patternMillis[i], |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1440 | (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL; |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1441 | } |
| 1442 | env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT); |
| 1443 | |
| 1444 | im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token); |
| 1445 | } |
| 1446 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1447 | static void nativeCancelVibrate(JNIEnv* /* env */, |
| 1448 | jclass /* clazz */, jlong ptr, jint deviceId, jint token) { |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1449 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1450 | |
| 1451 | im->getInputManager()->getReader()->cancelVibrate(deviceId, token); |
| 1452 | } |
| 1453 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1454 | static void nativeReloadKeyboardLayouts(JNIEnv* /* env */, |
| 1455 | jclass /* clazz */, jlong ptr) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1456 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1457 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1458 | im->getInputManager()->getReader()->requestRefreshConfiguration( |
| 1459 | InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS); |
| 1460 | } |
| 1461 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1462 | static void nativeReloadDeviceAliases(JNIEnv* /* env */, |
| 1463 | jclass /* clazz */, jlong ptr) { |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1464 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1465 | |
| 1466 | im->getInputManager()->getReader()->requestRefreshConfiguration( |
| 1467 | InputReaderConfiguration::CHANGE_DEVICE_ALIAS); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1470 | static jstring nativeDump(JNIEnv* env, jclass /* clazz */, jlong ptr) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1471 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1472 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1473 | String8 dump; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1474 | im->dump(dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1475 | return env->NewStringUTF(dump.string()); |
| 1476 | } |
| 1477 | |
Andreas Gampe | 8dcf593 | 2014-09-30 16:41:19 -0700 | [diff] [blame] | 1478 | static void nativeMonitor(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1479 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1480 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1481 | im->getInputManager()->getReader()->monitor(); |
| 1482 | im->getInputManager()->getDispatcher()->monitor(); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 1485 | static void nativeSetPointerIconType(JNIEnv* /* env */, jclass /* clazz */, jlong ptr, jint iconId) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1486 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 1487 | im->setPointerIconType(iconId); |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 1490 | static void nativeReloadPointerIcons(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) { |
| 1491 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1492 | im->reloadPointerIcons(); |
| 1493 | } |
| 1494 | |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 1495 | static void nativeSetCustomPointerIcon(JNIEnv* env, jclass /* clazz */, |
| 1496 | jlong ptr, jobject iconObj) { |
| 1497 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1498 | |
| 1499 | PointerIcon pointerIcon; |
Michael Wright | b004b51 | 2017-01-18 18:09:29 +0000 | [diff] [blame] | 1500 | status_t result = android_view_PointerIcon_getLoadedIcon(env, iconObj, &pointerIcon); |
| 1501 | if (result) { |
| 1502 | jniThrowRuntimeException(env, "Failed to load custom pointer icon."); |
| 1503 | return; |
| 1504 | } |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 1505 | |
| 1506 | SpriteIcon spriteIcon; |
| 1507 | pointerIcon.bitmap.copyTo(&spriteIcon.bitmap, kN32_SkColorType); |
| 1508 | spriteIcon.hotSpotX = pointerIcon.hotSpotX; |
| 1509 | spriteIcon.hotSpotY = pointerIcon.hotSpotY; |
| 1510 | im->setCustomPointerIcon(spriteIcon); |
| 1511 | } |
| 1512 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1513 | // ---------------------------------------------------------------------------- |
| 1514 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1515 | static const JNINativeMethod gInputManagerMethods[] = { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1516 | /* name, signature, funcPtr */ |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1517 | { "nativeInit", |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1518 | "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1519 | (void*) nativeInit }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1520 | { "nativeStart", "(J)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1521 | (void*) nativeStart }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1522 | { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V", |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1523 | (void*) nativeSetDisplayViewport }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1524 | { "nativeGetScanCodeState", "(JIII)I", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1525 | (void*) nativeGetScanCodeState }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1526 | { "nativeGetKeyCodeState", "(JIII)I", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1527 | (void*) nativeGetKeyCodeState }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1528 | { "nativeGetSwitchState", "(JIII)I", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1529 | (void*) nativeGetSwitchState }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1530 | { "nativeHasKeys", "(JII[I[Z)Z", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1531 | (void*) nativeHasKeys }, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1532 | { "nativeRegisterInputChannel", |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1533 | "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1534 | (void*) nativeRegisterInputChannel }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1535 | { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1536 | (void*) nativeUnregisterInputChannel }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1537 | { "nativeSetInputFilterEnabled", "(JZ)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1538 | (void*) nativeSetInputFilterEnabled }, |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 1539 | { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1540 | (void*) nativeInjectInputEvent }, |
Andrii Kulian | 112d056 | 2016-03-08 10:44:22 -0800 | [diff] [blame] | 1541 | { "nativeToggleCapsLock", "(JI)V", |
| 1542 | (void*) nativeToggleCapsLock }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1543 | { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1544 | (void*) nativeSetInputWindows }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1545 | { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1546 | (void*) nativeSetFocusedApplication }, |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 1547 | { "nativeSetPointerCapture", "(JZ)V", |
| 1548 | (void*) nativeSetPointerCapture }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1549 | { "nativeSetInputDispatchMode", "(JZZ)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1550 | (void*) nativeSetInputDispatchMode }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1551 | { "nativeSetSystemUiVisibility", "(JI)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1552 | (void*) nativeSetSystemUiVisibility }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1553 | { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1554 | (void*) nativeTransferTouchFocus }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1555 | { "nativeSetPointerSpeed", "(JI)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1556 | (void*) nativeSetPointerSpeed }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1557 | { "nativeSetShowTouches", "(JZ)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1558 | (void*) nativeSetShowTouches }, |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1559 | { "nativeSetInteractive", "(JZ)V", |
| 1560 | (void*) nativeSetInteractive }, |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1561 | { "nativeReloadCalibration", "(J)V", |
| 1562 | (void*) nativeReloadCalibration }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1563 | { "nativeVibrate", "(JI[JII)V", |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1564 | (void*) nativeVibrate }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1565 | { "nativeCancelVibrate", "(JII)V", |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1566 | (void*) nativeCancelVibrate }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1567 | { "nativeReloadKeyboardLayouts", "(J)V", |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1568 | (void*) nativeReloadKeyboardLayouts }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1569 | { "nativeReloadDeviceAliases", "(J)V", |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1570 | (void*) nativeReloadDeviceAliases }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1571 | { "nativeDump", "(J)Ljava/lang/String;", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1572 | (void*) nativeDump }, |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 1573 | { "nativeMonitor", "(J)V", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1574 | (void*) nativeMonitor }, |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 1575 | { "nativeSetPointerIconType", "(JI)V", |
| 1576 | (void*) nativeSetPointerIconType }, |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 1577 | { "nativeReloadPointerIcons", "(J)V", |
| 1578 | (void*) nativeReloadPointerIcons }, |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 1579 | { "nativeSetCustomPointerIcon", "(JLandroid/view/PointerIcon;)V", |
| 1580 | (void*) nativeSetCustomPointerIcon }, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1581 | }; |
| 1582 | |
| 1583 | #define FIND_CLASS(var, className) \ |
| 1584 | var = env->FindClass(className); \ |
Chih-Hung Hsieh | 6c89616 | 2016-05-19 15:29:38 -0700 | [diff] [blame] | 1585 | LOG_FATAL_IF(! (var), "Unable to find class " className); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1586 | |
| 1587 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1588 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
Chih-Hung Hsieh | 6c89616 | 2016-05-19 15:29:38 -0700 | [diff] [blame] | 1589 | LOG_FATAL_IF(! (var), "Unable to find method " methodName); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1590 | |
| 1591 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 1592 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
Chih-Hung Hsieh | 6c89616 | 2016-05-19 15:29:38 -0700 | [diff] [blame] | 1593 | LOG_FATAL_IF(! (var), "Unable to find field " fieldName); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1594 | |
| 1595 | int register_android_server_InputManager(JNIEnv* env) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1596 | int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1597 | gInputManagerMethods, NELEM(gInputManagerMethods)); |
Bernhard Rosenkränzer | 9c1c90e | 2014-11-12 14:45:58 +0100 | [diff] [blame] | 1598 | (void) res; // Faked use when LOG_NDEBUG. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1599 | LOG_FATAL_IF(res < 0, "Unable to register native methods."); |
| 1600 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1601 | // Callbacks |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1602 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1603 | jclass clazz; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1604 | FIND_CLASS(clazz, "com/android/server/input/InputManagerService"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1605 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1606 | GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1607 | "notifyConfigurationChanged", "(J)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1608 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1609 | GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz, |
| 1610 | "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V"); |
| 1611 | |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 1612 | GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz, |
| 1613 | "notifySwitch", "(JII)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1614 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1615 | GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz, |
| 1616 | "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1617 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1618 | GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1619 | "notifyANR", |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 1620 | "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1621 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1622 | GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1623 | "filterInputEvent", "(Landroid/view/InputEvent;I)Z"); |
| 1624 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1625 | GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz, |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1626 | "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;I)I"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1627 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 1628 | GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingNonInteractive, clazz, |
| 1629 | "interceptMotionBeforeQueueingNonInteractive", "(JI)I"); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1630 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1631 | GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1632 | "interceptKeyBeforeDispatching", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1633 | "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1634 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1635 | GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1636 | "dispatchUnhandledKey", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1637 | "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;"); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1638 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1639 | GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz, |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1640 | "checkInjectEventsPermission", "(II)Z"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1641 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1642 | GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz, |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 1643 | "getVirtualKeyQuietTimeMillis", "()I"); |
| 1644 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1645 | GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1646 | "getExcludedDeviceNames", "()[Ljava/lang/String;"); |
| 1647 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1648 | GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz, |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 1649 | "getKeyRepeatTimeout", "()I"); |
| 1650 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1651 | GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz, |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 1652 | "getKeyRepeatDelay", "()I"); |
| 1653 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1654 | GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz, |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 1655 | "getHoverTapTimeout", "()I"); |
| 1656 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1657 | GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz, |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 1658 | "getHoverTapSlop", "()I"); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1659 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1660 | GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz, |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1661 | "getDoubleTapTimeout", "()I"); |
| 1662 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1663 | GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz, |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1664 | "getLongPressTimeout", "()I"); |
| 1665 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1666 | GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz, |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1667 | "getPointerLayer", "()I"); |
| 1668 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1669 | GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz, |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1670 | "getPointerIcon", "()Landroid/view/PointerIcon;"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1671 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1672 | GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz, |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1673 | "getKeyboardLayoutOverlay", |
| 1674 | "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;"); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1675 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1676 | GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz, |
| 1677 | "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;"); |
| 1678 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1679 | GET_METHOD_ID(gServiceClassInfo.getTouchCalibrationForInputDevice, clazz, |
| 1680 | "getTouchCalibrationForInputDevice", |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 1681 | "(Ljava/lang/String;I)Landroid/hardware/input/TouchCalibration;"); |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1682 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1683 | // InputDevice |
| 1684 | |
| 1685 | FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice"); |
| 1686 | gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz)); |
| 1687 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1688 | // KeyEvent |
| 1689 | |
| 1690 | FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1691 | gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz)); |
| 1692 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1693 | // MotionEvent |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1694 | |
| 1695 | FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1696 | gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz)); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1697 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1698 | // InputDeviceIdentifier |
| 1699 | |
| 1700 | FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier"); |
| 1701 | gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz)); |
| 1702 | GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz, |
| 1703 | "<init>", "(Ljava/lang/String;II)V"); |
| 1704 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 1705 | // TouchCalibration |
| 1706 | |
| 1707 | FIND_CLASS(gTouchCalibrationClassInfo.clazz, "android/hardware/input/TouchCalibration"); |
| 1708 | gTouchCalibrationClassInfo.clazz = jclass(env->NewGlobalRef(gTouchCalibrationClassInfo.clazz)); |
| 1709 | |
| 1710 | GET_METHOD_ID(gTouchCalibrationClassInfo.getAffineTransform, gTouchCalibrationClassInfo.clazz, |
| 1711 | "getAffineTransform", "()[F"); |
| 1712 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1713 | return 0; |
| 1714 | } |
| 1715 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1716 | } /* namespace android */ |