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