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