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