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