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