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 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | // Log debug messages about InputReaderPolicy |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 22 | #define DEBUG_INPUT_READER_POLICY 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 23 | |
| 24 | // Log debug messages about InputDispatcherPolicy |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 25 | #define DEBUG_INPUT_DISPATCHER_POLICY 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 26 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 27 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 28 | #include "JNIHelp.h" |
| 29 | #include "jni.h" |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 30 | #include <limits.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 31 | #include <android_runtime/AndroidRuntime.h> |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 32 | #include <android_runtime/Log.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 33 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 34 | #include <utils/Log.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 35 | #include <utils/Looper.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 36 | #include <utils/threads.h> |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 37 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 38 | #include <input/InputManager.h> |
| 39 | #include <input/PointerController.h> |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 40 | #include <input/SpriteController.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 41 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 42 | #include <android_os_MessageQueue.h> |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 43 | #include <android_view_InputDevice.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 44 | #include <android_view_KeyEvent.h> |
| 45 | #include <android_view_MotionEvent.h> |
| 46 | #include <android_view_InputChannel.h> |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 47 | #include <android_view_PointerIcon.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 48 | #include <android/graphics/GraphicsJNI.h> |
| 49 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 50 | #include <ScopedLocalRef.h> |
| 51 | #include <ScopedUtfChars.h> |
| 52 | |
Jeff Brown | 4f8ecd8 | 2012-06-18 18:29:13 -0700 | [diff] [blame] | 53 | #include "com_android_server_power_PowerManagerService.h" |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 54 | #include "com_android_server_input_InputApplicationHandle.h" |
| 55 | #include "com_android_server_input_InputWindowHandle.h" |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 56 | |
| 57 | namespace android { |
| 58 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 59 | // The exponent used to calculate the pointer speed scaling factor. |
| 60 | // The scaling factor is calculated as 2 ^ (speed * exponent), |
| 61 | // 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] | 62 | static const float POINTER_SPEED_EXPONENT = 1.0f / 4; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 63 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 64 | static struct { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 65 | jmethodID notifyConfigurationChanged; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 66 | jmethodID notifyInputDevicesChanged; |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 67 | jmethodID notifySwitch; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 68 | jmethodID notifyInputChannelBroken; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 69 | jmethodID notifyANR; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 70 | jmethodID filterInputEvent; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 71 | jmethodID interceptKeyBeforeQueueing; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 72 | jmethodID interceptMotionBeforeQueueingWhenScreenOff; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 73 | jmethodID interceptKeyBeforeDispatching; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 74 | jmethodID dispatchUnhandledKey; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 75 | jmethodID checkInjectEventsPermission; |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 76 | jmethodID getVirtualKeyQuietTimeMillis; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 77 | jmethodID getExcludedDeviceNames; |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 78 | jmethodID getKeyRepeatTimeout; |
| 79 | jmethodID getKeyRepeatDelay; |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 80 | jmethodID getHoverTapTimeout; |
| 81 | jmethodID getHoverTapSlop; |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 82 | jmethodID getDoubleTapTimeout; |
| 83 | jmethodID getLongPressTimeout; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 84 | jmethodID getPointerLayer; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 85 | jmethodID getPointerIcon; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 86 | jmethodID getKeyboardLayoutOverlay; |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 87 | jmethodID getDeviceAlias; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 88 | } gServiceClassInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 89 | |
| 90 | static struct { |
| 91 | jclass clazz; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 92 | } gInputDeviceClassInfo; |
| 93 | |
| 94 | static struct { |
| 95 | jclass clazz; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 96 | } gKeyEventClassInfo; |
| 97 | |
| 98 | static struct { |
| 99 | jclass clazz; |
| 100 | } gMotionEventClassInfo; |
| 101 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 102 | static struct { |
| 103 | jclass clazz; |
| 104 | jmethodID constructor; |
| 105 | } gInputDeviceIdentifierInfo; |
| 106 | |
| 107 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 108 | |
| 109 | // --- Global functions --- |
| 110 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 111 | template<typename T> |
| 112 | inline static T min(const T& a, const T& b) { |
| 113 | return a < b ? a : b; |
| 114 | } |
| 115 | |
| 116 | template<typename T> |
| 117 | inline static T max(const T& a, const T& b) { |
| 118 | return a > b ? a : b; |
| 119 | } |
| 120 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 121 | static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env, |
| 122 | const sp<InputApplicationHandle>& inputApplicationHandle) { |
| 123 | if (inputApplicationHandle == NULL) { |
| 124 | return NULL; |
| 125 | } |
| 126 | return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())-> |
| 127 | getInputApplicationHandleObjLocalRef(env); |
| 128 | } |
| 129 | |
| 130 | static jobject getInputWindowHandleObjLocalRef(JNIEnv* env, |
| 131 | const sp<InputWindowHandle>& inputWindowHandle) { |
| 132 | if (inputWindowHandle == NULL) { |
| 133 | return NULL; |
| 134 | } |
| 135 | return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())-> |
| 136 | getInputWindowHandleObjLocalRef(env); |
| 137 | } |
| 138 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 139 | static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style, |
| 140 | SpriteIcon* outSpriteIcon) { |
| 141 | PointerIcon pointerIcon; |
| 142 | status_t status = android_view_PointerIcon_loadSystemIcon(env, |
| 143 | contextObj, style, &pointerIcon); |
| 144 | if (!status) { |
| 145 | pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config); |
| 146 | outSpriteIcon->hotSpotX = pointerIcon.hotSpotX; |
| 147 | outSpriteIcon->hotSpotY = pointerIcon.hotSpotY; |
| 148 | } |
| 149 | } |
| 150 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 151 | enum { |
| 152 | WM_ACTION_PASS_TO_USER = 1, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 153 | WM_ACTION_WAKE_UP = 2, |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 154 | WM_ACTION_GO_TO_SLEEP = 4, |
| 155 | }; |
| 156 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 157 | |
| 158 | // --- NativeInputManager --- |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 159 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 160 | class NativeInputManager : public virtual RefBase, |
| 161 | public virtual InputReaderPolicyInterface, |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 162 | public virtual InputDispatcherPolicyInterface, |
| 163 | public virtual PointerControllerPolicyInterface { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 164 | protected: |
| 165 | virtual ~NativeInputManager(); |
| 166 | |
| 167 | public: |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 168 | NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 169 | |
| 170 | inline sp<InputManager> getInputManager() const { return mInputManager; } |
| 171 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 172 | void dump(String8& dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 173 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 174 | void setDisplayViewport(bool external, const DisplayViewport& viewport); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 175 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 176 | status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 177 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 178 | status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel); |
| 179 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 180 | void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray); |
| 181 | void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 182 | void setInputDispatchMode(bool enabled, bool frozen); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 183 | void setSystemUiVisibility(int32_t visibility); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 184 | void setPointerSpeed(int32_t speed); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 185 | void setShowTouches(bool enabled); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 186 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 187 | /* --- InputReaderPolicyInterface implementation --- */ |
| 188 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 189 | virtual void getReaderConfiguration(InputReaderConfiguration* outConfig); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 190 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 191 | virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices); |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 192 | virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 193 | virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 194 | |
| 195 | /* --- InputDispatcherPolicyInterface implementation --- */ |
| 196 | |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 197 | virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 198 | uint32_t policyFlags); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 199 | virtual void notifyConfigurationChanged(nsecs_t when); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 200 | virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 201 | const sp<InputWindowHandle>& inputWindowHandle, |
| 202 | const String8& reason); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 203 | virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 204 | virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 205 | virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig); |
| 206 | virtual bool isKeyRepeatEnabled(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 207 | virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 208 | virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags); |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 209 | virtual nsecs_t interceptKeyBeforeDispatching( |
| 210 | const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 211 | const KeyEvent* keyEvent, uint32_t policyFlags); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 212 | virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 213 | const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 214 | virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 215 | virtual bool checkInjectEventsPermissionNonReentrant( |
| 216 | int32_t injectorPid, int32_t injectorUid); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 217 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 218 | /* --- PointerControllerPolicyInterface implementation --- */ |
| 219 | |
| 220 | virtual void loadPointerResources(PointerResources* outResources); |
| 221 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 222 | private: |
| 223 | sp<InputManager> mInputManager; |
| 224 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 225 | jobject mContextObj; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 226 | jobject mServiceObj; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 227 | sp<Looper> mLooper; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 228 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 229 | Mutex mLock; |
| 230 | struct Locked { |
| 231 | // Display size information. |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 232 | DisplayViewport internalViewport; |
| 233 | DisplayViewport externalViewport; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 234 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 235 | // System UI visibility. |
| 236 | int32_t systemUiVisibility; |
| 237 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 238 | // Pointer speed. |
| 239 | int32_t pointerSpeed; |
| 240 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 241 | // True if pointer gestures are enabled. |
| 242 | bool pointerGesturesEnabled; |
| 243 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 244 | // Show touches feature enable/disable. |
| 245 | bool showTouches; |
| 246 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 247 | // Sprite controller singleton, created on first use. |
| 248 | sp<SpriteController> spriteController; |
| 249 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 250 | // Pointer controller singleton, created and destroyed as needed. |
| 251 | wp<PointerController> pointerController; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 252 | } mLocked; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 253 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 254 | void updateInactivityTimeoutLocked(const sp<PointerController>& controller); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 255 | void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags); |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 256 | void ensureSpriteControllerLocked(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 257 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 258 | // Power manager interactions. |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 259 | bool isScreenOn(); |
| 260 | bool isScreenBright(); |
| 261 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 262 | static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 263 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 264 | static inline JNIEnv* jniEnv() { |
| 265 | return AndroidRuntime::getJNIEnv(); |
| 266 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 267 | }; |
| 268 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 269 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 270 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 271 | NativeInputManager::NativeInputManager(jobject contextObj, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 272 | jobject serviceObj, const sp<Looper>& looper) : |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 273 | mLooper(looper) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 274 | JNIEnv* env = jniEnv(); |
| 275 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 276 | mContextObj = env->NewGlobalRef(contextObj); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 277 | mServiceObj = env->NewGlobalRef(serviceObj); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 278 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 279 | { |
| 280 | AutoMutex _l(mLock); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 281 | mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 282 | mLocked.pointerSpeed = 0; |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 283 | mLocked.pointerGesturesEnabled = true; |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 284 | mLocked.showTouches = false; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 287 | sp<EventHub> eventHub = new EventHub(); |
| 288 | mInputManager = new InputManager(eventHub, this, this); |
| 289 | } |
| 290 | |
| 291 | NativeInputManager::~NativeInputManager() { |
| 292 | JNIEnv* env = jniEnv(); |
| 293 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 294 | env->DeleteGlobalRef(mContextObj); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 295 | env->DeleteGlobalRef(mServiceObj); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 298 | void NativeInputManager::dump(String8& dump) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 299 | mInputManager->getReader()->dump(dump); |
| 300 | dump.append("\n"); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 301 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 302 | mInputManager->getDispatcher()->dump(dump); |
| 303 | dump.append("\n"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 306 | bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 307 | if (env->ExceptionCheck()) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 308 | ALOGE("An exception was thrown by callback '%s'.", methodName); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 309 | LOGE_EX(env); |
| 310 | env->ExceptionClear(); |
| 311 | return true; |
| 312 | } |
| 313 | return false; |
| 314 | } |
| 315 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 316 | void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 317 | bool changed = false; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 318 | { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 319 | AutoMutex _l(mLock); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 320 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 321 | DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport; |
| 322 | if (v != viewport) { |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 323 | changed = true; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 324 | v = viewport; |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 325 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 326 | if (!external) { |
| 327 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 328 | if (controller != NULL) { |
| 329 | controller->setDisplayViewport( |
| 330 | viewport.logicalRight - viewport.logicalLeft, |
| 331 | viewport.logicalBottom - viewport.logicalTop, |
| 332 | viewport.orientation); |
| 333 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 334 | } |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 335 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 336 | } |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 337 | |
| 338 | if (changed) { |
| 339 | mInputManager->getReader()->requestRefreshConfiguration( |
| 340 | InputReaderConfiguration::CHANGE_DISPLAY_INFO); |
| 341 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 344 | status_t NativeInputManager::registerInputChannel(JNIEnv* env, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 345 | const sp<InputChannel>& inputChannel, |
| 346 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor) { |
| 347 | return mInputManager->getDispatcher()->registerInputChannel( |
| 348 | inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | status_t NativeInputManager::unregisterInputChannel(JNIEnv* env, |
| 352 | const sp<InputChannel>& inputChannel) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 353 | return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 356 | void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 357 | JNIEnv* env = jniEnv(); |
| 358 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 359 | jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj, |
| 360 | gServiceClassInfo.getVirtualKeyQuietTimeMillis); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 361 | if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) { |
| 362 | outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime); |
| 363 | } |
| 364 | |
| 365 | outConfig->excludedDeviceNames.clear(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 366 | jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj, |
| 367 | gServiceClassInfo.getExcludedDeviceNames)); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 368 | if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) { |
| 369 | jsize length = env->GetArrayLength(excludedDeviceNames); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 370 | for (jsize i = 0; i < length; i++) { |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 371 | jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i)); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 372 | const char* deviceNameChars = env->GetStringUTFChars(item, NULL); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 373 | outConfig->excludedDeviceNames.add(String8(deviceNameChars)); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 374 | env->ReleaseStringUTFChars(item, deviceNameChars); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 375 | env->DeleteLocalRef(item); |
| 376 | } |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 377 | env->DeleteLocalRef(excludedDeviceNames); |
| 378 | } |
| 379 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 380 | jint hoverTapTimeout = env->CallIntMethod(mServiceObj, |
| 381 | gServiceClassInfo.getHoverTapTimeout); |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 382 | if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 383 | jint doubleTapTimeout = env->CallIntMethod(mServiceObj, |
| 384 | gServiceClassInfo.getDoubleTapTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 385 | if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 386 | jint longPressTimeout = env->CallIntMethod(mServiceObj, |
| 387 | gServiceClassInfo.getLongPressTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 388 | if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) { |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 389 | outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 390 | |
| 391 | // We must ensure that the tap-drag interval is significantly shorter than |
| 392 | // the long-press timeout because the tap is held down for the entire duration |
| 393 | // of the double-tap timeout. |
| 394 | jint tapDragInterval = max(min(longPressTimeout - 100, |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 395 | doubleTapTimeout), hoverTapTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 396 | outConfig->pointerGestureTapDragInterval = |
| 397 | milliseconds_to_nanoseconds(tapDragInterval); |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 402 | jint hoverTapSlop = env->CallIntMethod(mServiceObj, |
| 403 | gServiceClassInfo.getHoverTapSlop); |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 404 | if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) { |
| 405 | outConfig->pointerGestureTapSlop = hoverTapSlop; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 406 | } |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 407 | |
| 408 | { // acquire lock |
| 409 | AutoMutex _l(mLock); |
| 410 | |
| 411 | outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed |
| 412 | * POINTER_SPEED_EXPONENT); |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 413 | outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled; |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 414 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 415 | outConfig->showTouches = mLocked.showTouches; |
| 416 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 417 | outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport); |
| 418 | outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 419 | } // release lock |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 422 | sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) { |
| 423 | AutoMutex _l(mLock); |
| 424 | |
| 425 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 426 | if (controller == NULL) { |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 427 | ensureSpriteControllerLocked(); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 428 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 429 | controller = new PointerController(this, mLooper, mLocked.spriteController); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 430 | mLocked.pointerController = controller; |
| 431 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 432 | DisplayViewport& v = mLocked.internalViewport; |
| 433 | controller->setDisplayViewport( |
| 434 | v.logicalRight - v.logicalLeft, |
| 435 | v.logicalBottom - v.logicalTop, |
| 436 | v.orientation); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 437 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 438 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 439 | jobject pointerIconObj = env->CallObjectMethod(mServiceObj, |
| 440 | gServiceClassInfo.getPointerIcon); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 441 | if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) { |
| 442 | PointerIcon pointerIcon; |
| 443 | status_t status = android_view_PointerIcon_load(env, pointerIconObj, |
| 444 | mContextObj, &pointerIcon); |
| 445 | if (!status && !pointerIcon.isNullIcon()) { |
| 446 | controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap, |
| 447 | pointerIcon.hotSpotX, pointerIcon.hotSpotY)); |
| 448 | } else { |
| 449 | controller->setPointerIcon(SpriteIcon()); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 450 | } |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 451 | env->DeleteLocalRef(pointerIconObj); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 452 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 453 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 454 | updateInactivityTimeoutLocked(controller); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 455 | } |
| 456 | return controller; |
| 457 | } |
| 458 | |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 459 | void NativeInputManager::ensureSpriteControllerLocked() { |
| 460 | if (mLocked.spriteController == NULL) { |
| 461 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 462 | jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer); |
Jeff Brown | 5541de9 | 2011-04-11 11:54:25 -0700 | [diff] [blame] | 463 | if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) { |
| 464 | layer = -1; |
| 465 | } |
| 466 | mLocked.spriteController = new SpriteController(mLooper, layer); |
| 467 | } |
| 468 | } |
| 469 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 470 | void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) { |
| 471 | JNIEnv* env = jniEnv(); |
| 472 | |
| 473 | size_t count = inputDevices.size(); |
| 474 | jobjectArray inputDevicesObjArray = env->NewObjectArray( |
| 475 | count, gInputDeviceClassInfo.clazz, NULL); |
| 476 | if (inputDevicesObjArray) { |
| 477 | bool error = false; |
| 478 | for (size_t i = 0; i < count; i++) { |
| 479 | jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i)); |
| 480 | if (!inputDeviceObj) { |
| 481 | error = true; |
| 482 | break; |
| 483 | } |
| 484 | |
| 485 | env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj); |
| 486 | env->DeleteLocalRef(inputDeviceObj); |
| 487 | } |
| 488 | |
| 489 | if (!error) { |
| 490 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged, |
| 491 | inputDevicesObjArray); |
| 492 | } |
| 493 | |
| 494 | env->DeleteLocalRef(inputDevicesObjArray); |
| 495 | } |
| 496 | |
| 497 | checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged"); |
| 498 | } |
| 499 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 500 | sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay( |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 501 | const InputDeviceIdentifier& identifier) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 502 | JNIEnv* env = jniEnv(); |
| 503 | |
| 504 | sp<KeyCharacterMap> result; |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 505 | ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string())); |
| 506 | ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz, |
| 507 | gInputDeviceIdentifierInfo.constructor, descriptor.get(), |
| 508 | identifier.vendor, identifier.product)); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 509 | ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj, |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 510 | gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get()))); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 511 | if (arrayObj.get()) { |
| 512 | ScopedLocalRef<jstring> filenameObj(env, |
| 513 | jstring(env->GetObjectArrayElement(arrayObj.get(), 0))); |
| 514 | ScopedLocalRef<jstring> contentsObj(env, |
| 515 | jstring(env->GetObjectArrayElement(arrayObj.get(), 1))); |
| 516 | ScopedUtfChars filenameChars(env, filenameObj.get()); |
| 517 | ScopedUtfChars contentsChars(env, contentsObj.get()); |
| 518 | |
| 519 | KeyCharacterMap::loadContents(String8(filenameChars.c_str()), |
| 520 | String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result); |
| 521 | } |
| 522 | checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay"); |
| 523 | return result; |
| 524 | } |
| 525 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 526 | String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) { |
| 527 | JNIEnv* env = jniEnv(); |
| 528 | |
| 529 | ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string())); |
| 530 | ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj, |
| 531 | gServiceClassInfo.getDeviceAlias, uniqueIdObj.get()))); |
| 532 | String8 result; |
| 533 | if (aliasObj.get()) { |
| 534 | ScopedUtfChars aliasChars(env, aliasObj.get()); |
| 535 | result.setTo(aliasChars.c_str()); |
| 536 | } |
| 537 | checkAndClearExceptionFromCallback(env, "getDeviceAlias"); |
| 538 | return result; |
| 539 | } |
| 540 | |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 541 | void NativeInputManager::notifySwitch(nsecs_t when, |
| 542 | uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) { |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 543 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 544 | ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x", |
| 545 | when, switchValues, switchMask, policyFlags); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 546 | #endif |
| 547 | |
| 548 | JNIEnv* env = jniEnv(); |
| 549 | |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 550 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch, |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 551 | when, switchValues, switchMask); |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 552 | checkAndClearExceptionFromCallback(env, "notifySwitch"); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 555 | void NativeInputManager::notifyConfigurationChanged(nsecs_t when) { |
| 556 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 557 | ALOGD("notifyConfigurationChanged - when=%lld", when); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 558 | #endif |
| 559 | |
| 560 | JNIEnv* env = jniEnv(); |
| 561 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 562 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 563 | checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 566 | nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 567 | const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 568 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 569 | ALOGD("notifyANR"); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 570 | #endif |
| 571 | |
| 572 | JNIEnv* env = jniEnv(); |
| 573 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 574 | jobject inputApplicationHandleObj = |
| 575 | getInputApplicationHandleObjLocalRef(env, inputApplicationHandle); |
| 576 | jobject inputWindowHandleObj = |
| 577 | getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 578 | jstring reasonObj = env->NewStringUTF(reason.string()); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 579 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 580 | jlong newTimeout = env->CallLongMethod(mServiceObj, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 581 | gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj, |
| 582 | reasonObj); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 583 | if (checkAndClearExceptionFromCallback(env, "notifyANR")) { |
| 584 | newTimeout = 0; // abort dispatch |
| 585 | } else { |
| 586 | assert(newTimeout >= 0); |
| 587 | } |
| 588 | |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 589 | env->DeleteLocalRef(reasonObj); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 590 | env->DeleteLocalRef(inputWindowHandleObj); |
| 591 | env->DeleteLocalRef(inputApplicationHandleObj); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 592 | return newTimeout; |
| 593 | } |
| 594 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 595 | void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 596 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 597 | ALOGD("notifyInputChannelBroken"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 598 | #endif |
| 599 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 600 | JNIEnv* env = jniEnv(); |
| 601 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 602 | jobject inputWindowHandleObj = |
| 603 | getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
| 604 | if (inputWindowHandleObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 605 | env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 606 | inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 607 | checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken"); |
| 608 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 609 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 610 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 613 | void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) { |
| 614 | JNIEnv* env = jniEnv(); |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 615 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 616 | jint keyRepeatTimeout = env->CallIntMethod(mServiceObj, |
| 617 | gServiceClassInfo.getKeyRepeatTimeout); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 618 | if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) { |
| 619 | outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout); |
| 620 | } |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 621 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 622 | jint keyRepeatDelay = env->CallIntMethod(mServiceObj, |
| 623 | gServiceClassInfo.getKeyRepeatDelay); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 624 | if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) { |
| 625 | outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay); |
| 626 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 629 | bool NativeInputManager::isKeyRepeatEnabled() { |
| 630 | // Only enable automatic key repeating when the screen is on. |
| 631 | return isScreenOn(); |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 634 | void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) { |
| 635 | Vector<sp<InputWindowHandle> > windowHandles; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 636 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 637 | if (windowHandleObjArray) { |
| 638 | jsize length = env->GetArrayLength(windowHandleObjArray); |
| 639 | for (jsize i = 0; i < length; i++) { |
| 640 | jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i); |
| 641 | if (! windowHandleObj) { |
| 642 | break; // found null element indicating end of used portion of the array |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 643 | } |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 644 | |
| 645 | sp<InputWindowHandle> windowHandle = |
| 646 | android_server_InputWindowHandle_getHandle(env, windowHandleObj); |
| 647 | if (windowHandle != NULL) { |
| 648 | windowHandles.push(windowHandle); |
| 649 | } |
| 650 | env->DeleteLocalRef(windowHandleObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 651 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 652 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 653 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 654 | mInputManager->getDispatcher()->setInputWindows(windowHandles); |
| 655 | |
| 656 | // Do this after the dispatcher has updated the window handle state. |
| 657 | bool newPointerGesturesEnabled = true; |
| 658 | size_t numWindows = windowHandles.size(); |
| 659 | for (size_t i = 0; i < numWindows; i++) { |
| 660 | const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 661 | const InputWindowInfo* windowInfo = windowHandle->getInfo(); |
| 662 | if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures |
| 663 | & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 664 | newPointerGesturesEnabled = false; |
| 665 | } |
| 666 | } |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 667 | |
| 668 | uint32_t changes = 0; |
| 669 | { // acquire lock |
| 670 | AutoMutex _l(mLock); |
| 671 | |
| 672 | if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) { |
| 673 | mLocked.pointerGesturesEnabled = newPointerGesturesEnabled; |
| 674 | changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT; |
| 675 | } |
| 676 | } // release lock |
| 677 | |
| 678 | if (changes) { |
| 679 | mInputManager->getReader()->requestRefreshConfiguration(changes); |
| 680 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 683 | void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) { |
| 684 | sp<InputApplicationHandle> applicationHandle = |
| 685 | android_server_InputApplicationHandle_getHandle(env, applicationHandleObj); |
| 686 | mInputManager->getDispatcher()->setFocusedApplication(applicationHandle); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 690 | mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 693 | void NativeInputManager::setSystemUiVisibility(int32_t visibility) { |
| 694 | AutoMutex _l(mLock); |
| 695 | |
| 696 | if (mLocked.systemUiVisibility != visibility) { |
| 697 | mLocked.systemUiVisibility = visibility; |
| 698 | |
| 699 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 700 | if (controller != NULL) { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 701 | updateInactivityTimeoutLocked(controller); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 706 | void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 707 | bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 708 | controller->setInactivityTimeout(lightsOut |
| 709 | ? PointerController::INACTIVITY_TIMEOUT_SHORT |
| 710 | : PointerController::INACTIVITY_TIMEOUT_NORMAL); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 711 | } |
| 712 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 713 | void NativeInputManager::setPointerSpeed(int32_t speed) { |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 714 | { // acquire lock |
| 715 | AutoMutex _l(mLock); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 716 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 717 | if (mLocked.pointerSpeed == speed) { |
| 718 | return; |
| 719 | } |
| 720 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 721 | ALOGI("Setting pointer speed to %d.", speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 722 | mLocked.pointerSpeed = speed; |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 723 | } // release lock |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 724 | |
Jeff Brown | 474dcb5 | 2011-06-14 20:22:50 -0700 | [diff] [blame] | 725 | mInputManager->getReader()->requestRefreshConfiguration( |
| 726 | InputReaderConfiguration::CHANGE_POINTER_SPEED); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 729 | void NativeInputManager::setShowTouches(bool enabled) { |
| 730 | { // acquire lock |
| 731 | AutoMutex _l(mLock); |
| 732 | |
| 733 | if (mLocked.showTouches == enabled) { |
| 734 | return; |
| 735 | } |
| 736 | |
Steve Block | 6215d3f | 2012-01-04 20:05:49 +0000 | [diff] [blame] | 737 | ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled"); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 738 | mLocked.showTouches = enabled; |
| 739 | } // release lock |
| 740 | |
| 741 | mInputManager->getReader()->requestRefreshConfiguration( |
| 742 | InputReaderConfiguration::CHANGE_SHOW_TOUCHES); |
| 743 | } |
| 744 | |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 745 | bool NativeInputManager::isScreenOn() { |
| 746 | return android_server_PowerManagerService_isScreenOn(); |
| 747 | } |
| 748 | |
| 749 | bool NativeInputManager::isScreenBright() { |
| 750 | return android_server_PowerManagerService_isScreenBright(); |
| 751 | } |
| 752 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 753 | bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) { |
| 754 | jobject inputEventObj; |
| 755 | |
| 756 | JNIEnv* env = jniEnv(); |
| 757 | switch (inputEvent->getType()) { |
| 758 | case AINPUT_EVENT_TYPE_KEY: |
| 759 | inputEventObj = android_view_KeyEvent_fromNative(env, |
| 760 | static_cast<const KeyEvent*>(inputEvent)); |
| 761 | break; |
| 762 | case AINPUT_EVENT_TYPE_MOTION: |
| 763 | inputEventObj = android_view_MotionEvent_obtainAsCopy(env, |
| 764 | static_cast<const MotionEvent*>(inputEvent)); |
| 765 | break; |
| 766 | default: |
| 767 | return true; // dispatch the event normally |
| 768 | } |
| 769 | |
| 770 | if (!inputEventObj) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 771 | ALOGE("Failed to obtain input event object for filterInputEvent."); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 772 | return true; // dispatch the event normally |
| 773 | } |
| 774 | |
| 775 | // The callee is responsible for recycling the event. |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 776 | jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 777 | inputEventObj, policyFlags); |
| 778 | if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) { |
| 779 | pass = true; |
| 780 | } |
| 781 | env->DeleteLocalRef(inputEventObj); |
| 782 | return pass; |
| 783 | } |
| 784 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 785 | void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent, |
| 786 | uint32_t& policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 787 | // Policy: |
| 788 | // - Ignore untrusted events and pass them along. |
| 789 | // - Ask the window manager what to do with normal events and trusted injected events. |
| 790 | // - For normal events wake and brighten the screen if currently off or dim. |
| 791 | if ((policyFlags & POLICY_FLAG_TRUSTED)) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 792 | nsecs_t when = keyEvent->getEventTime(); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 793 | bool isScreenOn = this->isScreenOn(); |
| 794 | bool isScreenBright = this->isScreenBright(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 795 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 796 | JNIEnv* env = jniEnv(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 797 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 798 | jint wmActions; |
| 799 | if (keyEventObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 800 | wmActions = env->CallIntMethod(mServiceObj, |
| 801 | gServiceClassInfo.interceptKeyBeforeQueueing, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 802 | keyEventObj, policyFlags, isScreenOn); |
| 803 | if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) { |
| 804 | wmActions = 0; |
| 805 | } |
| 806 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 807 | env->DeleteLocalRef(keyEventObj); |
| 808 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 809 | ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing."); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 810 | wmActions = 0; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 813 | if (!(policyFlags & POLICY_FLAG_INJECTED)) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 814 | if (!isScreenOn) { |
| 815 | policyFlags |= POLICY_FLAG_WOKE_HERE; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | if (!isScreenBright) { |
| 819 | policyFlags |= POLICY_FLAG_BRIGHT_HERE; |
| 820 | } |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 823 | handleInterceptActions(wmActions, when, /*byref*/ policyFlags); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 824 | } else { |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 825 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 826 | } |
| 827 | } |
| 828 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 829 | void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 830 | // Policy: |
| 831 | // - Ignore untrusted events and pass them along. |
| 832 | // - No special filtering for injected events required at this time. |
| 833 | // - Filter normal events based on screen state. |
| 834 | // - For normal events brighten (but do not wake) the screen if currently dim. |
| 835 | if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) { |
| 836 | if (isScreenOn()) { |
| 837 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 838 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 839 | if (!isScreenBright()) { |
| 840 | policyFlags |= POLICY_FLAG_BRIGHT_HERE; |
| 841 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 842 | } else { |
| 843 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 844 | jint wmActions = env->CallIntMethod(mServiceObj, |
| 845 | gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff, |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 846 | policyFlags); |
| 847 | if (checkAndClearExceptionFromCallback(env, |
| 848 | "interceptMotionBeforeQueueingWhenScreenOff")) { |
| 849 | wmActions = 0; |
| 850 | } |
| 851 | |
| 852 | policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE; |
| 853 | handleInterceptActions(wmActions, when, /*byref*/ policyFlags); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 854 | } |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 855 | } else { |
| 856 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 860 | void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when, |
| 861 | uint32_t& policyFlags) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 862 | if (wmActions & WM_ACTION_GO_TO_SLEEP) { |
Jeff Brown | 9267beb | 2011-03-07 20:11:22 -0800 | [diff] [blame] | 863 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 864 | ALOGD("handleInterceptActions: Going to sleep."); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 865 | #endif |
| 866 | android_server_PowerManagerService_goToSleep(when); |
| 867 | } |
| 868 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 869 | if (wmActions & WM_ACTION_WAKE_UP) { |
Jeff Brown | 9267beb | 2011-03-07 20:11:22 -0800 | [diff] [blame] | 870 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 871 | ALOGD("handleInterceptActions: Waking up."); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 872 | #endif |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 873 | android_server_PowerManagerService_wakeUp(when); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | if (wmActions & WM_ACTION_PASS_TO_USER) { |
| 877 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 878 | } else { |
Jeff Brown | 9267beb | 2011-03-07 20:11:22 -0800 | [diff] [blame] | 879 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 880 | ALOGD("handleInterceptActions: Not passing key to user."); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 881 | #endif |
| 882 | } |
| 883 | } |
| 884 | |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 885 | nsecs_t NativeInputManager::interceptKeyBeforeDispatching( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 886 | const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 887 | const KeyEvent* keyEvent, uint32_t policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 888 | // Policy: |
| 889 | // - Ignore untrusted events and pass them along. |
| 890 | // - Filter normal events and trusted injected events through the window manager policy to |
| 891 | // handle the HOME key and the like. |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 892 | nsecs_t result = 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 893 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 894 | JNIEnv* env = jniEnv(); |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 895 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 896 | // Note: inputWindowHandle may be null. |
| 897 | jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 898 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 899 | if (keyEventObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 900 | jlong delayMillis = env->CallLongMethod(mServiceObj, |
| 901 | gServiceClassInfo.interceptKeyBeforeDispatching, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 902 | inputWindowHandleObj, keyEventObj, policyFlags); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 903 | bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching"); |
| 904 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 905 | env->DeleteLocalRef(keyEventObj); |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 906 | if (!error) { |
| 907 | if (delayMillis < 0) { |
| 908 | result = -1; |
| 909 | } else if (delayMillis > 0) { |
| 910 | result = milliseconds_to_nanoseconds(delayMillis); |
| 911 | } |
| 912 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 913 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 914 | ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching."); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 915 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 916 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 917 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 918 | return result; |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 921 | bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 922 | const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 923 | // Policy: |
| 924 | // - Ignore untrusted events and do not perform default handling. |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 925 | bool result = false; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 926 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 927 | JNIEnv* env = jniEnv(); |
| 928 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 929 | // Note: inputWindowHandle may be null. |
| 930 | jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 931 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 932 | if (keyEventObj) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 933 | jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj, |
| 934 | gServiceClassInfo.dispatchUnhandledKey, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 935 | inputWindowHandleObj, keyEventObj, policyFlags); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 936 | if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) { |
| 937 | fallbackKeyEventObj = NULL; |
| 938 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 939 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 940 | env->DeleteLocalRef(keyEventObj); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 941 | |
| 942 | if (fallbackKeyEventObj) { |
| 943 | // Note: outFallbackKeyEvent may be the same object as keyEvent. |
| 944 | if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj, |
| 945 | outFallbackKeyEvent)) { |
| 946 | result = true; |
| 947 | } |
| 948 | android_view_KeyEvent_recycle(env, fallbackKeyEventObj); |
| 949 | env->DeleteLocalRef(fallbackKeyEventObj); |
| 950 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 951 | } else { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 952 | ALOGE("Failed to obtain key event object for dispatchUnhandledKey."); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 953 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 954 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 955 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 956 | return result; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 959 | void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) { |
| 960 | android_server_PowerManagerService_userActivity(eventTime, eventType); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 963 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 964 | bool NativeInputManager::checkInjectEventsPermissionNonReentrant( |
| 965 | int32_t injectorPid, int32_t injectorUid) { |
| 966 | JNIEnv* env = jniEnv(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 967 | jboolean result = env->CallBooleanMethod(mServiceObj, |
| 968 | gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 969 | if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) { |
| 970 | result = false; |
| 971 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 972 | return result; |
| 973 | } |
| 974 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 975 | void NativeInputManager::loadPointerResources(PointerResources* outResources) { |
| 976 | JNIEnv* env = jniEnv(); |
| 977 | |
| 978 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER, |
| 979 | &outResources->spotHover); |
| 980 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH, |
| 981 | &outResources->spotTouch); |
| 982 | loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR, |
| 983 | &outResources->spotAnchor); |
| 984 | } |
| 985 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 986 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 987 | // ---------------------------------------------------------------------------- |
| 988 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 989 | static jint nativeInit(JNIEnv* env, jclass clazz, |
| 990 | jobject serviceObj, jobject contextObj, jobject messageQueueObj) { |
Jeff Brown | 603b445 | 2012-04-06 17:39:41 -0700 | [diff] [blame] | 991 | sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj); |
Jeff Brown | 86469346 | 2013-01-28 14:25:53 -0800 | [diff] [blame] | 992 | if (messageQueue == NULL) { |
| 993 | jniThrowRuntimeException(env, "MessageQueue is not initialized."); |
| 994 | return 0; |
| 995 | } |
| 996 | |
Jeff Brown | 603b445 | 2012-04-06 17:39:41 -0700 | [diff] [blame] | 997 | NativeInputManager* im = new NativeInputManager(contextObj, serviceObj, |
| 998 | messageQueue->getLooper()); |
Mathias Agopian | b1d90c8 | 2013-03-06 17:45:42 -0800 | [diff] [blame] | 999 | im->incStrong(0); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1000 | return reinterpret_cast<jint>(im); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1003 | static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) { |
| 1004 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1005 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1006 | status_t result = im->getInputManager()->start(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1007 | if (result) { |
| 1008 | jniThrowRuntimeException(env, "Input manager could not be started."); |
| 1009 | } |
| 1010 | } |
| 1011 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1012 | static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jint ptr, jboolean external, |
| 1013 | jint displayId, jint orientation, |
| 1014 | jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 1015 | jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom, |
| 1016 | jint deviceWidth, jint deviceHeight) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1017 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1018 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1019 | DisplayViewport v; |
| 1020 | v.displayId = displayId; |
| 1021 | v.orientation = orientation; |
| 1022 | v.logicalLeft = logicalLeft; |
| 1023 | v.logicalTop = logicalTop; |
| 1024 | v.logicalRight = logicalRight; |
| 1025 | v.logicalBottom = logicalBottom; |
| 1026 | v.physicalLeft = physicalLeft; |
| 1027 | v.physicalTop = physicalTop; |
| 1028 | v.physicalRight = physicalRight; |
| 1029 | v.physicalBottom = physicalBottom; |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 1030 | v.deviceWidth = deviceWidth; |
| 1031 | v.deviceHeight = deviceHeight; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1032 | im->setDisplayViewport(external, v); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1035 | static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz, |
| 1036 | jint ptr, jint deviceId, jint sourceMask, jint scanCode) { |
| 1037 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1038 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1039 | return im->getInputManager()->getReader()->getScanCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1040 | deviceId, uint32_t(sourceMask), scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1043 | static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz, |
| 1044 | jint ptr, jint deviceId, jint sourceMask, jint keyCode) { |
| 1045 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1046 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1047 | return im->getInputManager()->getReader()->getKeyCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1048 | deviceId, uint32_t(sourceMask), keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1051 | static jint nativeGetSwitchState(JNIEnv* env, jclass clazz, |
| 1052 | jint ptr, jint deviceId, jint sourceMask, jint sw) { |
| 1053 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1054 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1055 | return im->getInputManager()->getReader()->getSwitchState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1056 | deviceId, uint32_t(sourceMask), sw); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1059 | static jboolean nativeHasKeys(JNIEnv* env, jclass clazz, |
| 1060 | jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) { |
| 1061 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1062 | |
| 1063 | int32_t* codes = env->GetIntArrayElements(keyCodes, NULL); |
| 1064 | uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL); |
| 1065 | jsize numCodes = env->GetArrayLength(keyCodes); |
| 1066 | jboolean result; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1067 | if (numCodes == env->GetArrayLength(keyCodes)) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1068 | result = im->getInputManager()->getReader()->hasKeys( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1069 | deviceId, uint32_t(sourceMask), numCodes, codes, flags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1070 | } else { |
| 1071 | result = JNI_FALSE; |
| 1072 | } |
| 1073 | |
| 1074 | env->ReleaseBooleanArrayElements(outFlags, flags, 0); |
| 1075 | env->ReleaseIntArrayElements(keyCodes, codes, 0); |
| 1076 | return result; |
| 1077 | } |
| 1078 | |
| 1079 | static void throwInputChannelNotInitialized(JNIEnv* env) { |
| 1080 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1081 | "inputChannel is not initialized"); |
| 1082 | } |
| 1083 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1084 | static void handleInputChannelDisposed(JNIEnv* env, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1085 | jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1086 | NativeInputManager* im = static_cast<NativeInputManager*>(data); |
| 1087 | |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1088 | ALOGW("Input channel object '%s' was disposed without first being unregistered with " |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1089 | "the input manager!", inputChannel->getName().string()); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1090 | im->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1093 | static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz, |
| 1094 | jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) { |
| 1095 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1096 | |
| 1097 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1098 | inputChannelObj); |
| 1099 | if (inputChannel == NULL) { |
| 1100 | throwInputChannelNotInitialized(env); |
| 1101 | return; |
| 1102 | } |
| 1103 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1104 | sp<InputWindowHandle> inputWindowHandle = |
| 1105 | android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1106 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1107 | status_t status = im->registerInputChannel( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1108 | env, inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1109 | if (status) { |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1110 | String8 message; |
| 1111 | message.appendFormat("Failed to register input channel. status=%d", status); |
| 1112 | jniThrowRuntimeException(env, message.string()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1113 | return; |
| 1114 | } |
| 1115 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1116 | if (! monitor) { |
| 1117 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1118 | handleInputChannelDisposed, im); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1119 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1122 | static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz, |
| 1123 | jint ptr, jobject inputChannelObj) { |
| 1124 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1125 | |
| 1126 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1127 | inputChannelObj); |
| 1128 | if (inputChannel == NULL) { |
| 1129 | throwInputChannelNotInitialized(env); |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL); |
| 1134 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1135 | status_t status = im->unregisterInputChannel(env, inputChannel); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1136 | if (status && status != BAD_VALUE) { // ignore already unregistered channel |
| 1137 | String8 message; |
| 1138 | message.appendFormat("Failed to unregister input channel. status=%d", status); |
| 1139 | jniThrowRuntimeException(env, message.string()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1143 | static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz, |
| 1144 | jint ptr, jboolean enabled) { |
| 1145 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1146 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1147 | im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1150 | static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz, |
| 1151 | jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1152 | jint syncMode, jint timeoutMillis, jint policyFlags) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1153 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1154 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1155 | if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) { |
| 1156 | KeyEvent keyEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1157 | status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent); |
| 1158 | if (status) { |
| 1159 | jniThrowRuntimeException(env, "Could not read contents of KeyEvent object."); |
| 1160 | return INPUT_EVENT_INJECTION_FAILED; |
| 1161 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1162 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1163 | return im->getInputManager()->getDispatcher()->injectInputEvent( |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1164 | & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis, |
| 1165 | uint32_t(policyFlags)); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1166 | } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) { |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 1167 | const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj); |
| 1168 | if (!motionEvent) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1169 | jniThrowRuntimeException(env, "Could not read contents of MotionEvent object."); |
| 1170 | return INPUT_EVENT_INJECTION_FAILED; |
| 1171 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1172 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1173 | return im->getInputManager()->getDispatcher()->injectInputEvent( |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1174 | motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis, |
| 1175 | uint32_t(policyFlags)); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1176 | } else { |
| 1177 | jniThrowRuntimeException(env, "Invalid input event type."); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1178 | return INPUT_EVENT_INJECTION_FAILED; |
| 1179 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1182 | static void nativeSetInputWindows(JNIEnv* env, jclass clazz, |
| 1183 | jint ptr, jobjectArray windowHandleObjArray) { |
| 1184 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1185 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1186 | im->setInputWindows(env, windowHandleObjArray); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1189 | static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz, |
| 1190 | jint ptr, jobject applicationHandleObj) { |
| 1191 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1192 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1193 | im->setFocusedApplication(env, applicationHandleObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1196 | static void nativeSetInputDispatchMode(JNIEnv* env, |
| 1197 | jclass clazz, jint ptr, jboolean enabled, jboolean frozen) { |
| 1198 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1199 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1200 | im->setInputDispatchMode(enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1203 | static void nativeSetSystemUiVisibility(JNIEnv* env, |
| 1204 | jclass clazz, jint ptr, jint visibility) { |
| 1205 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1206 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1207 | im->setSystemUiVisibility(visibility); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1210 | static jboolean nativeTransferTouchFocus(JNIEnv* env, |
| 1211 | jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) { |
| 1212 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1213 | |
| 1214 | sp<InputChannel> fromChannel = |
| 1215 | android_view_InputChannel_getInputChannel(env, fromChannelObj); |
| 1216 | sp<InputChannel> toChannel = |
| 1217 | android_view_InputChannel_getInputChannel(env, toChannelObj); |
| 1218 | |
| 1219 | if (fromChannel == NULL || toChannel == NULL) { |
| 1220 | return false; |
| 1221 | } |
| 1222 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1223 | return im->getInputManager()->getDispatcher()-> |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1224 | transferTouchFocus(fromChannel, toChannel); |
| 1225 | } |
| 1226 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1227 | static void nativeSetPointerSpeed(JNIEnv* env, |
| 1228 | jclass clazz, jint ptr, jint speed) { |
| 1229 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1230 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1231 | im->setPointerSpeed(speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1234 | static void nativeSetShowTouches(JNIEnv* env, |
| 1235 | jclass clazz, jint ptr, jboolean enabled) { |
| 1236 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1237 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1238 | im->setShowTouches(enabled); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1241 | static void nativeVibrate(JNIEnv* env, |
| 1242 | jclass clazz, jint ptr, jint deviceId, jlongArray patternObj, |
| 1243 | jint repeat, jint token) { |
| 1244 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1245 | |
| 1246 | size_t patternSize = env->GetArrayLength(patternObj); |
| 1247 | if (patternSize > MAX_VIBRATE_PATTERN_SIZE) { |
| 1248 | ALOGI("Skipped requested vibration because the pattern size is %d " |
| 1249 | "which is more than the maximum supported size of %d.", |
| 1250 | patternSize, MAX_VIBRATE_PATTERN_SIZE); |
| 1251 | return; // limit to reasonable size |
| 1252 | } |
| 1253 | |
| 1254 | jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical( |
| 1255 | patternObj, NULL)); |
| 1256 | nsecs_t pattern[patternSize]; |
| 1257 | for (size_t i = 0; i < patternSize; i++) { |
| 1258 | pattern[i] = max(jlong(0), min(patternMillis[i], |
| 1259 | MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL; |
| 1260 | } |
| 1261 | env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT); |
| 1262 | |
| 1263 | im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token); |
| 1264 | } |
| 1265 | |
| 1266 | static void nativeCancelVibrate(JNIEnv* env, |
| 1267 | jclass clazz, jint ptr, jint deviceId, jint token) { |
| 1268 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1269 | |
| 1270 | im->getInputManager()->getReader()->cancelVibrate(deviceId, token); |
| 1271 | } |
| 1272 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1273 | static void nativeReloadKeyboardLayouts(JNIEnv* env, |
| 1274 | jclass clazz, jint ptr) { |
| 1275 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1276 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1277 | im->getInputManager()->getReader()->requestRefreshConfiguration( |
| 1278 | InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS); |
| 1279 | } |
| 1280 | |
| 1281 | static void nativeReloadDeviceAliases(JNIEnv* env, |
| 1282 | jclass clazz, jint ptr) { |
| 1283 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
| 1284 | |
| 1285 | im->getInputManager()->getReader()->requestRefreshConfiguration( |
| 1286 | InputReaderConfiguration::CHANGE_DEVICE_ALIAS); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1289 | static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) { |
| 1290 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1291 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1292 | String8 dump; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1293 | im->dump(dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1294 | return env->NewStringUTF(dump.string()); |
| 1295 | } |
| 1296 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1297 | static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) { |
| 1298 | NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1299 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1300 | im->getInputManager()->getReader()->monitor(); |
| 1301 | im->getInputManager()->getDispatcher()->monitor(); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1304 | // ---------------------------------------------------------------------------- |
| 1305 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1306 | static JNINativeMethod gInputManagerMethods[] = { |
| 1307 | /* name, signature, funcPtr */ |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1308 | { "nativeInit", |
| 1309 | "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I", |
| 1310 | (void*) nativeInit }, |
| 1311 | { "nativeStart", "(I)V", |
| 1312 | (void*) nativeStart }, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 1313 | { "nativeSetDisplayViewport", "(IZIIIIIIIIIIII)V", |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 1314 | (void*) nativeSetDisplayViewport }, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1315 | { "nativeGetScanCodeState", "(IIII)I", |
| 1316 | (void*) nativeGetScanCodeState }, |
| 1317 | { "nativeGetKeyCodeState", "(IIII)I", |
| 1318 | (void*) nativeGetKeyCodeState }, |
| 1319 | { "nativeGetSwitchState", "(IIII)I", |
| 1320 | (void*) nativeGetSwitchState }, |
| 1321 | { "nativeHasKeys", "(III[I[Z)Z", |
| 1322 | (void*) nativeHasKeys }, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1323 | { "nativeRegisterInputChannel", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1324 | "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V", |
| 1325 | (void*) nativeRegisterInputChannel }, |
| 1326 | { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V", |
| 1327 | (void*) nativeUnregisterInputChannel }, |
| 1328 | { "nativeSetInputFilterEnabled", "(IZ)V", |
| 1329 | (void*) nativeSetInputFilterEnabled }, |
| 1330 | { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I", |
| 1331 | (void*) nativeInjectInputEvent }, |
| 1332 | { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V", |
| 1333 | (void*) nativeSetInputWindows }, |
| 1334 | { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V", |
| 1335 | (void*) nativeSetFocusedApplication }, |
| 1336 | { "nativeSetInputDispatchMode", "(IZZ)V", |
| 1337 | (void*) nativeSetInputDispatchMode }, |
| 1338 | { "nativeSetSystemUiVisibility", "(II)V", |
| 1339 | (void*) nativeSetSystemUiVisibility }, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1340 | { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z", |
| 1341 | (void*) nativeTransferTouchFocus }, |
| 1342 | { "nativeSetPointerSpeed", "(II)V", |
| 1343 | (void*) nativeSetPointerSpeed }, |
| 1344 | { "nativeSetShowTouches", "(IZ)V", |
| 1345 | (void*) nativeSetShowTouches }, |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1346 | { "nativeVibrate", "(II[JII)V", |
| 1347 | (void*) nativeVibrate }, |
| 1348 | { "nativeCancelVibrate", "(III)V", |
| 1349 | (void*) nativeCancelVibrate }, |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1350 | { "nativeReloadKeyboardLayouts", "(I)V", |
| 1351 | (void*) nativeReloadKeyboardLayouts }, |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1352 | { "nativeReloadDeviceAliases", "(I)V", |
| 1353 | (void*) nativeReloadDeviceAliases }, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1354 | { "nativeDump", "(I)Ljava/lang/String;", |
| 1355 | (void*) nativeDump }, |
| 1356 | { "nativeMonitor", "(I)V", |
| 1357 | (void*) nativeMonitor }, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1358 | }; |
| 1359 | |
| 1360 | #define FIND_CLASS(var, className) \ |
| 1361 | var = env->FindClass(className); \ |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1362 | LOG_FATAL_IF(! var, "Unable to find class " className); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1363 | |
| 1364 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1365 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 1366 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 1367 | |
| 1368 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 1369 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 1370 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 1371 | |
| 1372 | int register_android_server_InputManager(JNIEnv* env) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1373 | int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1374 | gInputManagerMethods, NELEM(gInputManagerMethods)); |
| 1375 | LOG_FATAL_IF(res < 0, "Unable to register native methods."); |
| 1376 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1377 | // Callbacks |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1378 | |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1379 | jclass clazz; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1380 | FIND_CLASS(clazz, "com/android/server/input/InputManagerService"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1381 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1382 | GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1383 | "notifyConfigurationChanged", "(J)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1384 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1385 | GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz, |
| 1386 | "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V"); |
| 1387 | |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 1388 | GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz, |
| 1389 | "notifySwitch", "(JII)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1390 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1391 | GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz, |
| 1392 | "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1393 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1394 | GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1395 | "notifyANR", |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 1396 | "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1397 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1398 | GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1399 | "filterInputEvent", "(Landroid/view/InputEvent;I)Z"); |
| 1400 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1401 | GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1402 | "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1403 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1404 | GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff, |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1405 | clazz, |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1406 | "interceptMotionBeforeQueueingWhenScreenOff", "(I)I"); |
| 1407 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1408 | GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1409 | "interceptKeyBeforeDispatching", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1410 | "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1411 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1412 | GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1413 | "dispatchUnhandledKey", |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1414 | "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;"); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1415 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1416 | GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz, |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1417 | "checkInjectEventsPermission", "(II)Z"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1418 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1419 | GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz, |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 1420 | "getVirtualKeyQuietTimeMillis", "()I"); |
| 1421 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1422 | GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1423 | "getExcludedDeviceNames", "()[Ljava/lang/String;"); |
| 1424 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1425 | GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz, |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 1426 | "getKeyRepeatTimeout", "()I"); |
| 1427 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1428 | GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz, |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 1429 | "getKeyRepeatDelay", "()I"); |
| 1430 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1431 | GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz, |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 1432 | "getHoverTapTimeout", "()I"); |
| 1433 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1434 | GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz, |
Jeff Brown | bb3fcba0c | 2011-06-06 19:23:05 -0700 | [diff] [blame] | 1435 | "getHoverTapSlop", "()I"); |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1436 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1437 | GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz, |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1438 | "getDoubleTapTimeout", "()I"); |
| 1439 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1440 | GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz, |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 1441 | "getLongPressTimeout", "()I"); |
| 1442 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1443 | GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz, |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1444 | "getPointerLayer", "()I"); |
| 1445 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1446 | GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz, |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 1447 | "getPointerIcon", "()Landroid/view/PointerIcon;"); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1448 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1449 | GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz, |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 1450 | "getKeyboardLayoutOverlay", |
| 1451 | "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;"); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1452 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1453 | GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz, |
| 1454 | "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;"); |
| 1455 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1456 | // InputDevice |
| 1457 | |
| 1458 | FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice"); |
| 1459 | gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz)); |
| 1460 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1461 | // KeyEvent |
| 1462 | |
| 1463 | FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1464 | gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz)); |
| 1465 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1466 | // MotionEvent |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1467 | |
| 1468 | FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent"); |
Carl Shapiro | 17cc33a | 2011-03-05 20:53:16 -0800 | [diff] [blame] | 1469 | gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz)); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1470 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame^] | 1471 | // InputDeviceIdentifier |
| 1472 | |
| 1473 | FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier"); |
| 1474 | gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz)); |
| 1475 | GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz, |
| 1476 | "<init>", "(Ljava/lang/String;II)V"); |
| 1477 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1478 | return 0; |
| 1479 | } |
| 1480 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1481 | } /* namespace android */ |