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