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