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