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