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