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