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