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