Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "InputManager-JNI" |
| 18 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | // Log debug messages about InputReaderPolicy |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 22 | #define DEBUG_INPUT_READER_POLICY 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 23 | |
| 24 | // Log debug messages about InputDispatcherPolicy |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 25 | #define DEBUG_INPUT_DISPATCHER_POLICY 0 |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 26 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 27 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 28 | #include "JNIHelp.h" |
| 29 | #include "jni.h" |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 30 | #include <limits.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 31 | #include <android_runtime/AndroidRuntime.h> |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 32 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 33 | #include <utils/Log.h> |
| 34 | #include <utils/threads.h> |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 35 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 36 | #include <input/InputManager.h> |
| 37 | #include <input/PointerController.h> |
| 38 | |
| 39 | #include <android_view_KeyEvent.h> |
| 40 | #include <android_view_MotionEvent.h> |
| 41 | #include <android_view_InputChannel.h> |
| 42 | #include <android/graphics/GraphicsJNI.h> |
| 43 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 44 | #include "com_android_server_PowerManagerService.h" |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 45 | #include "com_android_server_InputApplication.h" |
| 46 | #include "com_android_server_InputApplicationHandle.h" |
| 47 | #include "com_android_server_InputWindow.h" |
| 48 | #include "com_android_server_InputWindowHandle.h" |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 49 | |
| 50 | namespace android { |
| 51 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 52 | static struct { |
| 53 | jclass clazz; |
| 54 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 55 | jmethodID notifyConfigurationChanged; |
| 56 | jmethodID notifyLidSwitchChanged; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 57 | jmethodID notifyInputChannelBroken; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 58 | jmethodID notifyANR; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 59 | jmethodID interceptKeyBeforeQueueing; |
| 60 | jmethodID interceptKeyBeforeDispatching; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 61 | jmethodID dispatchUnhandledKey; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 62 | jmethodID checkInjectEventsPermission; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 63 | jmethodID filterTouchEvents; |
| 64 | jmethodID filterJumpyTouchEvents; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 65 | jmethodID getExcludedDeviceNames; |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 66 | jmethodID getMaxEventsPerSecond; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 67 | jmethodID getPointerLayer; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 68 | jmethodID getPointerIcon; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 69 | } gCallbacksClassInfo; |
| 70 | |
| 71 | static struct { |
| 72 | jclass clazz; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 73 | } gKeyEventClassInfo; |
| 74 | |
| 75 | static struct { |
| 76 | jclass clazz; |
| 77 | } gMotionEventClassInfo; |
| 78 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 79 | static struct { |
| 80 | jclass clazz; |
| 81 | |
| 82 | jmethodID ctor; |
| 83 | jmethodID addMotionRange; |
| 84 | |
| 85 | jfieldID mId; |
| 86 | jfieldID mName; |
| 87 | jfieldID mSources; |
| 88 | jfieldID mKeyboardType; |
| 89 | jfieldID mMotionRanges; |
| 90 | } gInputDeviceClassInfo; |
| 91 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 92 | static struct { |
| 93 | jclass clazz; |
| 94 | |
| 95 | jfieldID touchscreen; |
| 96 | jfieldID keyboard; |
| 97 | jfieldID navigation; |
| 98 | } gConfigurationClassInfo; |
| 99 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 100 | static struct { |
| 101 | jclass clazz; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 102 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 103 | jfieldID bitmap; |
| 104 | jfieldID hotSpotX; |
| 105 | jfieldID hotSpotY; |
| 106 | } gPointerIconClassInfo; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 107 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 108 | |
| 109 | // --- Global functions --- |
| 110 | |
| 111 | static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env, |
| 112 | const sp<InputApplicationHandle>& inputApplicationHandle) { |
| 113 | if (inputApplicationHandle == NULL) { |
| 114 | return NULL; |
| 115 | } |
| 116 | return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())-> |
| 117 | getInputApplicationHandleObjLocalRef(env); |
| 118 | } |
| 119 | |
| 120 | static jobject getInputWindowHandleObjLocalRef(JNIEnv* env, |
| 121 | const sp<InputWindowHandle>& inputWindowHandle) { |
| 122 | if (inputWindowHandle == NULL) { |
| 123 | return NULL; |
| 124 | } |
| 125 | return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())-> |
| 126 | getInputWindowHandleObjLocalRef(env); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | // --- NativeInputManager --- |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 131 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 132 | class NativeInputManager : public virtual RefBase, |
| 133 | public virtual InputReaderPolicyInterface, |
| 134 | public virtual InputDispatcherPolicyInterface { |
| 135 | protected: |
| 136 | virtual ~NativeInputManager(); |
| 137 | |
| 138 | public: |
| 139 | NativeInputManager(jobject callbacksObj); |
| 140 | |
| 141 | inline sp<InputManager> getInputManager() const { return mInputManager; } |
| 142 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 143 | void dump(String8& dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 144 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 145 | void setDisplaySize(int32_t displayId, int32_t width, int32_t height); |
| 146 | void setDisplayOrientation(int32_t displayId, int32_t orientation); |
| 147 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 148 | status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 149 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 150 | status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel); |
| 151 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 152 | void setInputWindows(JNIEnv* env, jobjectArray windowObjArray); |
| 153 | void setFocusedApplication(JNIEnv* env, jobject applicationObj); |
| 154 | void setInputDispatchMode(bool enabled, bool frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 155 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 156 | /* --- InputReaderPolicyInterface implementation --- */ |
| 157 | |
| 158 | virtual bool getDisplayInfo(int32_t displayId, |
| 159 | int32_t* width, int32_t* height, int32_t* orientation); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 160 | virtual bool filterTouchEvents(); |
| 161 | virtual bool filterJumpyTouchEvents(); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 162 | virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames); |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 163 | virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 164 | |
| 165 | /* --- InputDispatcherPolicyInterface implementation --- */ |
| 166 | |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 167 | virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue, |
| 168 | uint32_t policyFlags); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 169 | virtual void notifyConfigurationChanged(nsecs_t when); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 170 | virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 171 | const sp<InputWindowHandle>& inputWindowHandle); |
| 172 | virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 173 | virtual nsecs_t getKeyRepeatTimeout(); |
Jeff Brown | b21fb10 | 2010-09-07 10:44:57 -0700 | [diff] [blame] | 174 | virtual nsecs_t getKeyRepeatDelay(); |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 175 | virtual int32_t getMaxEventsPerSecond(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 176 | virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 177 | virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 178 | virtual bool interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 179 | const KeyEvent* keyEvent, uint32_t policyFlags); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 180 | virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 181 | const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 182 | virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 183 | virtual bool checkInjectEventsPermissionNonReentrant( |
| 184 | int32_t injectorPid, int32_t injectorUid); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 185 | |
| 186 | private: |
| 187 | sp<InputManager> mInputManager; |
| 188 | |
| 189 | jobject mCallbacksObj; |
| 190 | |
| 191 | // Cached filtering policies. |
| 192 | int32_t mFilterTouchEvents; |
| 193 | int32_t mFilterJumpyTouchEvents; |
| 194 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 195 | // Cached throttling policy. |
| 196 | int32_t mMaxEventsPerSecond; |
| 197 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 198 | Mutex mLock; |
| 199 | struct Locked { |
| 200 | // Display size information. |
| 201 | int32_t displayWidth, displayHeight; // -1 when initialized |
| 202 | int32_t displayOrientation; |
| 203 | |
| 204 | // Pointer controller singleton, created and destroyed as needed. |
| 205 | wp<PointerController> pointerController; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 206 | } mLocked; |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 207 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 208 | // Power manager interactions. |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 209 | bool isScreenOn(); |
| 210 | bool isScreenBright(); |
| 211 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 212 | static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 213 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 214 | static inline JNIEnv* jniEnv() { |
| 215 | return AndroidRuntime::getJNIEnv(); |
| 216 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 219 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 220 | |
| 221 | NativeInputManager::NativeInputManager(jobject callbacksObj) : |
| 222 | mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1), |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 223 | mMaxEventsPerSecond(-1) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 224 | JNIEnv* env = jniEnv(); |
| 225 | |
| 226 | mCallbacksObj = env->NewGlobalRef(callbacksObj); |
| 227 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 228 | { |
| 229 | AutoMutex _l(mLock); |
| 230 | mLocked.displayWidth = -1; |
| 231 | mLocked.displayHeight = -1; |
| 232 | mLocked.displayOrientation = ROTATION_0; |
| 233 | } |
| 234 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 235 | sp<EventHub> eventHub = new EventHub(); |
| 236 | mInputManager = new InputManager(eventHub, this, this); |
| 237 | } |
| 238 | |
| 239 | NativeInputManager::~NativeInputManager() { |
| 240 | JNIEnv* env = jniEnv(); |
| 241 | |
| 242 | env->DeleteGlobalRef(mCallbacksObj); |
| 243 | } |
| 244 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 245 | void NativeInputManager::dump(String8& dump) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 246 | mInputManager->getReader()->dump(dump); |
| 247 | dump.append("\n"); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 248 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 249 | mInputManager->getDispatcher()->dump(dump); |
| 250 | dump.append("\n"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 253 | bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 254 | if (env->ExceptionCheck()) { |
| 255 | LOGE("An exception was thrown by callback '%s'.", methodName); |
| 256 | LOGE_EX(env); |
| 257 | env->ExceptionClear(); |
| 258 | return true; |
| 259 | } |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height) { |
| 264 | if (displayId == 0) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 265 | AutoMutex _l(mLock); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 266 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 267 | if (mLocked.displayWidth != width || mLocked.displayHeight != height) { |
| 268 | mLocked.displayWidth = width; |
| 269 | mLocked.displayHeight = height; |
| 270 | |
| 271 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 272 | if (controller != NULL) { |
| 273 | controller->setDisplaySize(width, height); |
| 274 | } |
| 275 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) { |
| 280 | if (displayId == 0) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 281 | AutoMutex _l(mLock); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 282 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 283 | if (mLocked.displayOrientation != orientation) { |
| 284 | mLocked.displayOrientation = orientation; |
| 285 | |
| 286 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 287 | if (controller != NULL) { |
| 288 | controller->setDisplayOrientation(orientation); |
| 289 | } |
| 290 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 294 | status_t NativeInputManager::registerInputChannel(JNIEnv* env, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 295 | const sp<InputChannel>& inputChannel, |
| 296 | const sp<InputWindowHandle>& inputWindowHandle, bool monitor) { |
| 297 | return mInputManager->getDispatcher()->registerInputChannel( |
| 298 | inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | status_t NativeInputManager::unregisterInputChannel(JNIEnv* env, |
| 302 | const sp<InputChannel>& inputChannel) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 303 | return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 306 | bool NativeInputManager::getDisplayInfo(int32_t displayId, |
| 307 | int32_t* width, int32_t* height, int32_t* orientation) { |
| 308 | bool result = false; |
| 309 | if (displayId == 0) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 310 | AutoMutex _l(mLock); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 311 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 312 | if (mLocked.displayWidth > 0 && mLocked.displayHeight > 0) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 313 | if (width) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 314 | *width = mLocked.displayWidth; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 315 | } |
| 316 | if (height) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 317 | *height = mLocked.displayHeight; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 318 | } |
| 319 | if (orientation) { |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 320 | *orientation = mLocked.displayOrientation; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 321 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 322 | result = true; |
| 323 | } |
| 324 | } |
| 325 | return result; |
| 326 | } |
| 327 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 328 | bool NativeInputManager::filterTouchEvents() { |
| 329 | if (mFilterTouchEvents < 0) { |
| 330 | JNIEnv* env = jniEnv(); |
| 331 | |
| 332 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 333 | gCallbacksClassInfo.filterTouchEvents); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 334 | if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 335 | result = false; |
| 336 | } |
| 337 | |
| 338 | mFilterTouchEvents = result ? 1 : 0; |
| 339 | } |
| 340 | return mFilterTouchEvents; |
| 341 | } |
| 342 | |
| 343 | bool NativeInputManager::filterJumpyTouchEvents() { |
| 344 | if (mFilterJumpyTouchEvents < 0) { |
| 345 | JNIEnv* env = jniEnv(); |
| 346 | |
| 347 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 348 | gCallbacksClassInfo.filterJumpyTouchEvents); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 349 | if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 350 | result = false; |
| 351 | } |
| 352 | |
| 353 | mFilterJumpyTouchEvents = result ? 1 : 0; |
| 354 | } |
| 355 | return mFilterJumpyTouchEvents; |
| 356 | } |
| 357 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 358 | void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 359 | outExcludedDeviceNames.clear(); |
| 360 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 361 | JNIEnv* env = jniEnv(); |
| 362 | |
| 363 | jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj, |
| 364 | gCallbacksClassInfo.getExcludedDeviceNames)); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 365 | if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 366 | jsize length = env->GetArrayLength(result); |
| 367 | for (jsize i = 0; i < length; i++) { |
| 368 | jstring item = jstring(env->GetObjectArrayElement(result, i)); |
| 369 | |
| 370 | const char* deviceNameChars = env->GetStringUTFChars(item, NULL); |
| 371 | outExcludedDeviceNames.add(String8(deviceNameChars)); |
| 372 | env->ReleaseStringUTFChars(item, deviceNameChars); |
| 373 | |
| 374 | env->DeleteLocalRef(item); |
| 375 | } |
| 376 | env->DeleteLocalRef(result); |
| 377 | } |
| 378 | } |
| 379 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 380 | sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) { |
| 381 | AutoMutex _l(mLock); |
| 382 | |
| 383 | sp<PointerController> controller = mLocked.pointerController.promote(); |
| 384 | if (controller == NULL) { |
| 385 | JNIEnv* env = jniEnv(); |
| 386 | jint layer = env->CallIntMethod(mCallbacksObj, gCallbacksClassInfo.getPointerLayer); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 387 | if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) { |
| 388 | layer = -1; |
| 389 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 390 | |
| 391 | controller = new PointerController(layer); |
| 392 | mLocked.pointerController = controller; |
| 393 | |
| 394 | controller->setDisplaySize(mLocked.displayWidth, mLocked.displayHeight); |
| 395 | controller->setDisplayOrientation(mLocked.displayOrientation); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 396 | |
| 397 | jobject iconObj = env->CallObjectMethod(mCallbacksObj, gCallbacksClassInfo.getPointerIcon); |
| 398 | if (!checkAndClearExceptionFromCallback(env, "getPointerIcon") && iconObj) { |
| 399 | jfloat iconHotSpotX = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotX); |
| 400 | jfloat iconHotSpotY = env->GetFloatField(iconObj, gPointerIconClassInfo.hotSpotY); |
| 401 | jobject iconBitmapObj = env->GetObjectField(iconObj, gPointerIconClassInfo.bitmap); |
| 402 | if (iconBitmapObj) { |
| 403 | SkBitmap* iconBitmap = GraphicsJNI::getNativeBitmap(env, iconBitmapObj); |
| 404 | if (iconBitmap) { |
| 405 | controller->setPointerIcon(iconBitmap, iconHotSpotX, iconHotSpotY); |
| 406 | } |
| 407 | env->DeleteLocalRef(iconBitmapObj); |
| 408 | } |
| 409 | env->DeleteLocalRef(iconObj); |
| 410 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 411 | } |
| 412 | return controller; |
| 413 | } |
| 414 | |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 415 | void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode, |
| 416 | int32_t switchValue, uint32_t policyFlags) { |
| 417 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 418 | LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x", |
| 419 | when, switchCode, switchValue, policyFlags); |
| 420 | #endif |
| 421 | |
| 422 | JNIEnv* env = jniEnv(); |
| 423 | |
| 424 | switch (switchCode) { |
| 425 | case SW_LID: |
| 426 | env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged, |
| 427 | when, switchValue == 0); |
| 428 | checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged"); |
| 429 | break; |
| 430 | } |
| 431 | } |
| 432 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 433 | void NativeInputManager::notifyConfigurationChanged(nsecs_t when) { |
| 434 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 435 | LOGD("notifyConfigurationChanged - when=%lld", when); |
| 436 | #endif |
| 437 | |
| 438 | JNIEnv* env = jniEnv(); |
| 439 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 440 | env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 441 | checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 444 | nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 445 | const sp<InputWindowHandle>& inputWindowHandle) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 446 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 447 | LOGD("notifyANR"); |
| 448 | #endif |
| 449 | |
| 450 | JNIEnv* env = jniEnv(); |
| 451 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 452 | jobject inputApplicationHandleObj = |
| 453 | getInputApplicationHandleObjLocalRef(env, inputApplicationHandle); |
| 454 | jobject inputWindowHandleObj = |
| 455 | getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 456 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 457 | jlong newTimeout = env->CallLongMethod(mCallbacksObj, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 458 | gCallbacksClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 459 | if (checkAndClearExceptionFromCallback(env, "notifyANR")) { |
| 460 | newTimeout = 0; // abort dispatch |
| 461 | } else { |
| 462 | assert(newTimeout >= 0); |
| 463 | } |
| 464 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 465 | env->DeleteLocalRef(inputWindowHandleObj); |
| 466 | env->DeleteLocalRef(inputApplicationHandleObj); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 467 | return newTimeout; |
| 468 | } |
| 469 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 470 | void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 471 | #if DEBUG_INPUT_DISPATCHER_POLICY |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 472 | LOGD("notifyInputChannelBroken"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 473 | #endif |
| 474 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 475 | JNIEnv* env = jniEnv(); |
| 476 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 477 | jobject inputWindowHandleObj = |
| 478 | getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
| 479 | if (inputWindowHandleObj) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 480 | env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 481 | inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 482 | checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken"); |
| 483 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 484 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 485 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 488 | nsecs_t NativeInputManager::getKeyRepeatTimeout() { |
| 489 | if (! isScreenOn()) { |
| 490 | // Disable key repeat when the screen is off. |
| 491 | return -1; |
| 492 | } else { |
| 493 | // TODO use ViewConfiguration.getLongPressTimeout() |
| 494 | return milliseconds_to_nanoseconds(500); |
| 495 | } |
| 496 | } |
| 497 | |
Jeff Brown | b21fb10 | 2010-09-07 10:44:57 -0700 | [diff] [blame] | 498 | nsecs_t NativeInputManager::getKeyRepeatDelay() { |
| 499 | return milliseconds_to_nanoseconds(50); |
| 500 | } |
| 501 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 502 | int32_t NativeInputManager::getMaxEventsPerSecond() { |
| 503 | if (mMaxEventsPerSecond < 0) { |
| 504 | JNIEnv* env = jniEnv(); |
| 505 | |
| 506 | jint result = env->CallIntMethod(mCallbacksObj, |
| 507 | gCallbacksClassInfo.getMaxEventsPerSecond); |
| 508 | if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) { |
Jeff Brown | 3d8c9bd | 2010-08-18 17:48:53 -0700 | [diff] [blame] | 509 | result = 60; |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | mMaxEventsPerSecond = result; |
| 513 | } |
| 514 | return mMaxEventsPerSecond; |
| 515 | } |
| 516 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 517 | void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 518 | Vector<InputWindow> windows; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 519 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 520 | jsize length = env->GetArrayLength(windowObjArray); |
| 521 | for (jsize i = 0; i < length; i++) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 522 | jobject windowObj = env->GetObjectArrayElement(windowObjArray, i); |
| 523 | if (! windowObj) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 524 | break; // found null element indicating end of used portion of the array |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 527 | windows.push(); |
| 528 | InputWindow& window = windows.editTop(); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 529 | android_server_InputWindow_toNative(env, windowObj, &window); |
| 530 | if (window.inputChannel == NULL) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 531 | windows.pop(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 532 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 533 | env->DeleteLocalRef(windowObj); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 534 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 535 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 536 | mInputManager->getDispatcher()->setInputWindows(windows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 539 | void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationObj) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 540 | if (applicationObj) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 541 | InputApplication application; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 542 | android_server_InputApplication_toNative(env, applicationObj, &application); |
| 543 | if (application.inputApplicationHandle != NULL) { |
| 544 | mInputManager->getDispatcher()->setFocusedApplication(&application); |
| 545 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 546 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 547 | mInputManager->getDispatcher()->setFocusedApplication(NULL); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 551 | mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 554 | bool NativeInputManager::isScreenOn() { |
| 555 | return android_server_PowerManagerService_isScreenOn(); |
| 556 | } |
| 557 | |
| 558 | bool NativeInputManager::isScreenBright() { |
| 559 | return android_server_PowerManagerService_isScreenBright(); |
| 560 | } |
| 561 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 562 | void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent, |
| 563 | uint32_t& policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 564 | // Policy: |
| 565 | // - Ignore untrusted events and pass them along. |
| 566 | // - Ask the window manager what to do with normal events and trusted injected events. |
| 567 | // - For normal events wake and brighten the screen if currently off or dim. |
| 568 | if ((policyFlags & POLICY_FLAG_TRUSTED)) { |
| 569 | const int32_t WM_ACTION_PASS_TO_USER = 1; |
| 570 | const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2; |
| 571 | const int32_t WM_ACTION_GO_TO_SLEEP = 4; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 572 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 573 | nsecs_t when = keyEvent->getEventTime(); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 574 | bool isScreenOn = this->isScreenOn(); |
| 575 | bool isScreenBright = this->isScreenBright(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 576 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 577 | JNIEnv* env = jniEnv(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 578 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 579 | jint wmActions; |
| 580 | if (keyEventObj) { |
| 581 | wmActions = env->CallIntMethod(mCallbacksObj, |
| 582 | gCallbacksClassInfo.interceptKeyBeforeQueueing, |
| 583 | keyEventObj, policyFlags, isScreenOn); |
| 584 | if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) { |
| 585 | wmActions = 0; |
| 586 | } |
| 587 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 588 | env->DeleteLocalRef(keyEventObj); |
| 589 | } else { |
| 590 | LOGE("Failed to obtain key event object for interceptKeyBeforeQueueing."); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 591 | wmActions = 0; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 594 | if (!(policyFlags & POLICY_FLAG_INJECTED)) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 595 | if (!isScreenOn) { |
| 596 | policyFlags |= POLICY_FLAG_WOKE_HERE; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | if (!isScreenBright) { |
| 600 | policyFlags |= POLICY_FLAG_BRIGHT_HERE; |
| 601 | } |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | if (wmActions & WM_ACTION_GO_TO_SLEEP) { |
| 605 | android_server_PowerManagerService_goToSleep(when); |
| 606 | } |
| 607 | |
| 608 | if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) { |
| 609 | android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT); |
| 610 | } |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 611 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 612 | if (wmActions & WM_ACTION_PASS_TO_USER) { |
| 613 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 614 | } |
| 615 | } else { |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 616 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | void NativeInputManager::interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 621 | // Policy: |
| 622 | // - Ignore untrusted events and pass them along. |
| 623 | // - No special filtering for injected events required at this time. |
| 624 | // - Filter normal events based on screen state. |
| 625 | // - For normal events brighten (but do not wake) the screen if currently dim. |
| 626 | if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) { |
| 627 | if (isScreenOn()) { |
| 628 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 629 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 630 | if (!isScreenBright()) { |
| 631 | policyFlags |= POLICY_FLAG_BRIGHT_HERE; |
| 632 | } |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 633 | } |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 634 | } else { |
| 635 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 639 | bool NativeInputManager::interceptKeyBeforeDispatching( |
| 640 | const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 641 | const KeyEvent* keyEvent, uint32_t policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 642 | // Policy: |
| 643 | // - Ignore untrusted events and pass them along. |
| 644 | // - Filter normal events and trusted injected events through the window manager policy to |
| 645 | // handle the HOME key and the like. |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 646 | bool result = false; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 647 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 648 | JNIEnv* env = jniEnv(); |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 649 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 650 | // Note: inputWindowHandle may be null. |
| 651 | jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 652 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 653 | if (keyEventObj) { |
| 654 | jboolean consumed = env->CallBooleanMethod(mCallbacksObj, |
| 655 | gCallbacksClassInfo.interceptKeyBeforeDispatching, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 656 | inputWindowHandleObj, keyEventObj, policyFlags); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 657 | bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching"); |
| 658 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 659 | env->DeleteLocalRef(keyEventObj); |
| 660 | result = consumed && !error; |
| 661 | } else { |
| 662 | LOGE("Failed to obtain key event object for interceptKeyBeforeDispatching."); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 663 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 664 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 665 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 666 | return result; |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 669 | bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 670 | const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 671 | // Policy: |
| 672 | // - Ignore untrusted events and do not perform default handling. |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 673 | bool result = false; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 674 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 675 | JNIEnv* env = jniEnv(); |
| 676 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 677 | // Note: inputWindowHandle may be null. |
| 678 | jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 679 | jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent); |
| 680 | if (keyEventObj) { |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 681 | jobject fallbackKeyEventObj = env->CallObjectMethod(mCallbacksObj, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 682 | gCallbacksClassInfo.dispatchUnhandledKey, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 683 | inputWindowHandleObj, keyEventObj, policyFlags); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 684 | checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey"); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 685 | android_view_KeyEvent_recycle(env, keyEventObj); |
| 686 | env->DeleteLocalRef(keyEventObj); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 687 | |
| 688 | if (fallbackKeyEventObj) { |
| 689 | // Note: outFallbackKeyEvent may be the same object as keyEvent. |
| 690 | if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj, |
| 691 | outFallbackKeyEvent)) { |
| 692 | result = true; |
| 693 | } |
| 694 | android_view_KeyEvent_recycle(env, fallbackKeyEventObj); |
| 695 | env->DeleteLocalRef(fallbackKeyEventObj); |
| 696 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 697 | } else { |
| 698 | LOGE("Failed to obtain key event object for dispatchUnhandledKey."); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 699 | } |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 700 | env->DeleteLocalRef(inputWindowHandleObj); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 701 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 702 | return result; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 705 | void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) { |
| 706 | android_server_PowerManagerService_userActivity(eventTime, eventType); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 709 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 710 | bool NativeInputManager::checkInjectEventsPermissionNonReentrant( |
| 711 | int32_t injectorPid, int32_t injectorUid) { |
| 712 | JNIEnv* env = jniEnv(); |
| 713 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 714 | gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid); |
| 715 | checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 716 | return result; |
| 717 | } |
| 718 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 719 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 720 | // ---------------------------------------------------------------------------- |
| 721 | |
| 722 | static sp<NativeInputManager> gNativeInputManager; |
| 723 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 724 | static bool checkInputManagerUnitialized(JNIEnv* env) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 725 | if (gNativeInputManager == NULL) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 726 | LOGE("Input manager not initialized."); |
| 727 | jniThrowRuntimeException(env, "Input manager not initialized."); |
| 728 | return true; |
| 729 | } |
| 730 | return false; |
| 731 | } |
| 732 | |
| 733 | static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz, |
| 734 | jobject callbacks) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 735 | if (gNativeInputManager == NULL) { |
| 736 | gNativeInputManager = new NativeInputManager(callbacks); |
| 737 | } else { |
| 738 | LOGE("Input manager already initialized."); |
| 739 | jniThrowRuntimeException(env, "Input manager already initialized."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
| 743 | static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) { |
| 744 | if (checkInputManagerUnitialized(env)) { |
| 745 | return; |
| 746 | } |
| 747 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 748 | status_t result = gNativeInputManager->getInputManager()->start(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 749 | if (result) { |
| 750 | jniThrowRuntimeException(env, "Input manager could not be started."); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
| 755 | jint displayId, jint width, jint height) { |
| 756 | if (checkInputManagerUnitialized(env)) { |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | // XXX we could get this from the SurfaceFlinger directly instead of requiring it |
| 761 | // to be passed in like this, not sure which is better but leaving it like this |
| 762 | // keeps the window manager in direct control of when display transitions propagate down |
| 763 | // to the input dispatcher |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 764 | gNativeInputManager->setDisplaySize(displayId, width, height); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz, |
| 768 | jint displayId, jint orientation) { |
| 769 | if (checkInputManagerUnitialized(env)) { |
| 770 | return; |
| 771 | } |
| 772 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 773 | gNativeInputManager->setDisplayOrientation(displayId, orientation); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 777 | jint deviceId, jint sourceMask, jint scanCode) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 778 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 779 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 782 | return gNativeInputManager->getInputManager()->getReader()->getScanCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 783 | deviceId, uint32_t(sourceMask), scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 787 | jint deviceId, jint sourceMask, jint keyCode) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 788 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 789 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 792 | return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 793 | deviceId, uint32_t(sourceMask), keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 797 | jint deviceId, jint sourceMask, jint sw) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 798 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 799 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 802 | return gNativeInputManager->getInputManager()->getReader()->getSwitchState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 803 | deviceId, uint32_t(sourceMask), sw); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 807 | jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 808 | if (checkInputManagerUnitialized(env)) { |
| 809 | return JNI_FALSE; |
| 810 | } |
| 811 | |
| 812 | int32_t* codes = env->GetIntArrayElements(keyCodes, NULL); |
| 813 | uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL); |
| 814 | jsize numCodes = env->GetArrayLength(keyCodes); |
| 815 | jboolean result; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 816 | if (numCodes == env->GetArrayLength(keyCodes)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 817 | result = gNativeInputManager->getInputManager()->getReader()->hasKeys( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 818 | deviceId, uint32_t(sourceMask), numCodes, codes, flags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 819 | } else { |
| 820 | result = JNI_FALSE; |
| 821 | } |
| 822 | |
| 823 | env->ReleaseBooleanArrayElements(outFlags, flags, 0); |
| 824 | env->ReleaseIntArrayElements(keyCodes, codes, 0); |
| 825 | return result; |
| 826 | } |
| 827 | |
| 828 | static void throwInputChannelNotInitialized(JNIEnv* env) { |
| 829 | jniThrowException(env, "java/lang/IllegalStateException", |
| 830 | "inputChannel is not initialized"); |
| 831 | } |
| 832 | |
| 833 | static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env, |
| 834 | jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) { |
| 835 | LOGW("Input channel object '%s' was disposed without first being unregistered with " |
| 836 | "the input manager!", inputChannel->getName().string()); |
| 837 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 838 | if (gNativeInputManager != NULL) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 839 | gNativeInputManager->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 840 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 844 | jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 845 | if (checkInputManagerUnitialized(env)) { |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 850 | inputChannelObj); |
| 851 | if (inputChannel == NULL) { |
| 852 | throwInputChannelNotInitialized(env); |
| 853 | return; |
| 854 | } |
| 855 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 856 | sp<InputWindowHandle> inputWindowHandle = |
| 857 | android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 858 | |
| 859 | status_t status = gNativeInputManager->registerInputChannel( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 860 | env, inputChannel, inputWindowHandle, monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 861 | if (status) { |
| 862 | jniThrowRuntimeException(env, "Failed to register input channel. " |
| 863 | "Check logs for details."); |
| 864 | return; |
| 865 | } |
| 866 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 867 | if (! monitor) { |
| 868 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, |
| 869 | android_server_InputManager_handleInputChannelDisposed, NULL); |
| 870 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz, |
| 874 | jobject inputChannelObj) { |
| 875 | if (checkInputManagerUnitialized(env)) { |
| 876 | return; |
| 877 | } |
| 878 | |
| 879 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 880 | inputChannelObj); |
| 881 | if (inputChannel == NULL) { |
| 882 | throwInputChannelNotInitialized(env); |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL); |
| 887 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 888 | status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 889 | if (status) { |
| 890 | jniThrowRuntimeException(env, "Failed to unregister input channel. " |
| 891 | "Check logs for details."); |
| 892 | } |
| 893 | } |
| 894 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 895 | static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz, |
| 896 | jobject inputEventObj, jint injectorPid, jint injectorUid, |
| 897 | jint syncMode, jint timeoutMillis) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 898 | if (checkInputManagerUnitialized(env)) { |
| 899 | return INPUT_EVENT_INJECTION_FAILED; |
| 900 | } |
| 901 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 902 | if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) { |
| 903 | KeyEvent keyEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 904 | status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent); |
| 905 | if (status) { |
| 906 | jniThrowRuntimeException(env, "Could not read contents of KeyEvent object."); |
| 907 | return INPUT_EVENT_INJECTION_FAILED; |
| 908 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 909 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 910 | return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent( |
| 911 | & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 912 | } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) { |
| 913 | MotionEvent motionEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 914 | status_t status = android_view_MotionEvent_toNative(env, inputEventObj, & motionEvent); |
| 915 | if (status) { |
| 916 | jniThrowRuntimeException(env, "Could not read contents of MotionEvent object."); |
| 917 | return INPUT_EVENT_INJECTION_FAILED; |
| 918 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 919 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 920 | return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent( |
| 921 | & motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 922 | } else { |
| 923 | jniThrowRuntimeException(env, "Invalid input event type."); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 924 | return INPUT_EVENT_INJECTION_FAILED; |
| 925 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 928 | static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz, |
| 929 | jobjectArray windowObjArray) { |
| 930 | if (checkInputManagerUnitialized(env)) { |
| 931 | return; |
| 932 | } |
| 933 | |
| 934 | gNativeInputManager->setInputWindows(env, windowObjArray); |
| 935 | } |
| 936 | |
| 937 | static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz, |
| 938 | jobject applicationObj) { |
| 939 | if (checkInputManagerUnitialized(env)) { |
| 940 | return; |
| 941 | } |
| 942 | |
| 943 | gNativeInputManager->setFocusedApplication(env, applicationObj); |
| 944 | } |
| 945 | |
| 946 | static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env, |
| 947 | jclass clazz, jboolean enabled, jboolean frozen) { |
| 948 | if (checkInputManagerUnitialized(env)) { |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | gNativeInputManager->setInputDispatchMode(enabled, frozen); |
| 953 | } |
| 954 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 955 | static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env, |
| 956 | jclass clazz, jint deviceId) { |
| 957 | if (checkInputManagerUnitialized(env)) { |
| 958 | return NULL; |
| 959 | } |
| 960 | |
| 961 | InputDeviceInfo deviceInfo; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 962 | status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo( |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 963 | deviceId, & deviceInfo); |
| 964 | if (status) { |
| 965 | return NULL; |
| 966 | } |
| 967 | |
| 968 | jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor); |
| 969 | if (! deviceObj) { |
| 970 | return NULL; |
| 971 | } |
| 972 | |
| 973 | jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string()); |
| 974 | if (! deviceNameObj) { |
| 975 | return NULL; |
| 976 | } |
| 977 | |
| 978 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId()); |
| 979 | env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj); |
| 980 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources()); |
| 981 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType()); |
| 982 | |
| 983 | const KeyedVector<int, InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges(); |
| 984 | for (size_t i = 0; i < ranges.size(); i++) { |
| 985 | int rangeType = ranges.keyAt(i); |
| 986 | const InputDeviceInfo::MotionRange& range = ranges.valueAt(i); |
| 987 | env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange, |
| 988 | rangeType, range.min, range.max, range.flat, range.fuzz); |
| 989 | if (env->ExceptionCheck()) { |
| 990 | return NULL; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | return deviceObj; |
| 995 | } |
| 996 | |
| 997 | static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env, |
| 998 | jclass clazz) { |
| 999 | if (checkInputManagerUnitialized(env)) { |
| 1000 | return NULL; |
| 1001 | } |
| 1002 | |
| 1003 | Vector<int> deviceIds; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1004 | gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1005 | |
| 1006 | jintArray deviceIdsObj = env->NewIntArray(deviceIds.size()); |
| 1007 | if (! deviceIdsObj) { |
| 1008 | return NULL; |
| 1009 | } |
| 1010 | |
| 1011 | env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array()); |
| 1012 | return deviceIdsObj; |
| 1013 | } |
| 1014 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1015 | static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env, |
| 1016 | jclass clazz, jobject configObj) { |
| 1017 | if (checkInputManagerUnitialized(env)) { |
| 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | InputConfiguration config; |
| 1022 | gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config); |
| 1023 | |
| 1024 | env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen); |
| 1025 | env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard); |
| 1026 | env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation); |
| 1027 | } |
| 1028 | |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1029 | static jboolean android_server_InputManager_nativeTransferTouchFocus(JNIEnv* env, |
| 1030 | jclass clazz, jobject fromChannelObj, jobject toChannelObj) { |
| 1031 | if (checkInputManagerUnitialized(env)) { |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | sp<InputChannel> fromChannel = |
| 1036 | android_view_InputChannel_getInputChannel(env, fromChannelObj); |
| 1037 | sp<InputChannel> toChannel = |
| 1038 | android_view_InputChannel_getInputChannel(env, toChannelObj); |
| 1039 | |
| 1040 | if (fromChannel == NULL || toChannel == NULL) { |
| 1041 | return false; |
| 1042 | } |
| 1043 | |
| 1044 | return gNativeInputManager->getInputManager()->getDispatcher()-> |
| 1045 | transferTouchFocus(fromChannel, toChannel); |
| 1046 | } |
| 1047 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1048 | static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) { |
| 1049 | if (checkInputManagerUnitialized(env)) { |
| 1050 | return NULL; |
| 1051 | } |
| 1052 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1053 | String8 dump; |
| 1054 | gNativeInputManager->dump(dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1055 | return env->NewStringUTF(dump.string()); |
| 1056 | } |
| 1057 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1058 | // ---------------------------------------------------------------------------- |
| 1059 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1060 | static JNINativeMethod gInputManagerMethods[] = { |
| 1061 | /* name, signature, funcPtr */ |
| 1062 | { "nativeInit", "(Lcom/android/server/InputManager$Callbacks;)V", |
| 1063 | (void*) android_server_InputManager_nativeInit }, |
| 1064 | { "nativeStart", "()V", |
| 1065 | (void*) android_server_InputManager_nativeStart }, |
| 1066 | { "nativeSetDisplaySize", "(III)V", |
| 1067 | (void*) android_server_InputManager_nativeSetDisplaySize }, |
| 1068 | { "nativeSetDisplayOrientation", "(II)V", |
| 1069 | (void*) android_server_InputManager_nativeSetDisplayOrientation }, |
| 1070 | { "nativeGetScanCodeState", "(III)I", |
| 1071 | (void*) android_server_InputManager_nativeGetScanCodeState }, |
| 1072 | { "nativeGetKeyCodeState", "(III)I", |
| 1073 | (void*) android_server_InputManager_nativeGetKeyCodeState }, |
| 1074 | { "nativeGetSwitchState", "(III)I", |
| 1075 | (void*) android_server_InputManager_nativeGetSwitchState }, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1076 | { "nativeHasKeys", "(II[I[Z)Z", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1077 | (void*) android_server_InputManager_nativeHasKeys }, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 1078 | { "nativeRegisterInputChannel", |
| 1079 | "(Landroid/view/InputChannel;Lcom/android/server/InputWindowHandle;Z)V", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1080 | (void*) android_server_InputManager_nativeRegisterInputChannel }, |
| 1081 | { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V", |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1082 | (void*) android_server_InputManager_nativeUnregisterInputChannel }, |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1083 | { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIII)I", |
| 1084 | (void*) android_server_InputManager_nativeInjectInputEvent }, |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1085 | { "nativeSetInputWindows", "([Lcom/android/server/InputWindow;)V", |
| 1086 | (void*) android_server_InputManager_nativeSetInputWindows }, |
| 1087 | { "nativeSetFocusedApplication", "(Lcom/android/server/InputApplication;)V", |
| 1088 | (void*) android_server_InputManager_nativeSetFocusedApplication }, |
| 1089 | { "nativeSetInputDispatchMode", "(ZZ)V", |
| 1090 | (void*) android_server_InputManager_nativeSetInputDispatchMode }, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1091 | { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;", |
| 1092 | (void*) android_server_InputManager_nativeGetInputDevice }, |
| 1093 | { "nativeGetInputDeviceIds", "()[I", |
| 1094 | (void*) android_server_InputManager_nativeGetInputDeviceIds }, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1095 | { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V", |
| 1096 | (void*) android_server_InputManager_nativeGetInputConfiguration }, |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1097 | { "nativeTransferTouchFocus", "(Landroid/view/InputChannel;Landroid/view/InputChannel;)Z", |
| 1098 | (void*) android_server_InputManager_nativeTransferTouchFocus }, |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1099 | { "nativeDump", "()Ljava/lang/String;", |
| 1100 | (void*) android_server_InputManager_nativeDump }, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1101 | }; |
| 1102 | |
| 1103 | #define FIND_CLASS(var, className) \ |
| 1104 | var = env->FindClass(className); \ |
| 1105 | LOG_FATAL_IF(! var, "Unable to find class " className); \ |
| 1106 | var = jclass(env->NewGlobalRef(var)); |
| 1107 | |
| 1108 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1109 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 1110 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 1111 | |
| 1112 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 1113 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 1114 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 1115 | |
| 1116 | int register_android_server_InputManager(JNIEnv* env) { |
| 1117 | int res = jniRegisterNativeMethods(env, "com/android/server/InputManager", |
| 1118 | gInputManagerMethods, NELEM(gInputManagerMethods)); |
| 1119 | LOG_FATAL_IF(res < 0, "Unable to register native methods."); |
| 1120 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1121 | // Callbacks |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1122 | |
| 1123 | FIND_CLASS(gCallbacksClassInfo.clazz, "com/android/server/InputManager$Callbacks"); |
| 1124 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1125 | GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, gCallbacksClassInfo.clazz, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1126 | "notifyConfigurationChanged", "(J)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1127 | |
| 1128 | GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, gCallbacksClassInfo.clazz, |
| 1129 | "notifyLidSwitchChanged", "(JZ)V"); |
| 1130 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1131 | GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, gCallbacksClassInfo.clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 1132 | "notifyInputChannelBroken", "(Lcom/android/server/InputWindowHandle;)V"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1133 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1134 | GET_METHOD_ID(gCallbacksClassInfo.notifyANR, gCallbacksClassInfo.clazz, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 1135 | "notifyANR", |
| 1136 | "(Lcom/android/server/InputApplicationHandle;Lcom/android/server/InputWindowHandle;)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1137 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1138 | GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, gCallbacksClassInfo.clazz, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1139 | "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1140 | |
| 1141 | GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, gCallbacksClassInfo.clazz, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1142 | "interceptKeyBeforeDispatching", |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 1143 | "(Lcom/android/server/InputWindowHandle;Landroid/view/KeyEvent;I)Z"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1144 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1145 | GET_METHOD_ID(gCallbacksClassInfo.dispatchUnhandledKey, gCallbacksClassInfo.clazz, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1146 | "dispatchUnhandledKey", |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame^] | 1147 | "(Lcom/android/server/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;"); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1148 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1149 | GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, gCallbacksClassInfo.clazz, |
| 1150 | "checkInjectEventsPermission", "(II)Z"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1151 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1152 | GET_METHOD_ID(gCallbacksClassInfo.filterTouchEvents, gCallbacksClassInfo.clazz, |
| 1153 | "filterTouchEvents", "()Z"); |
| 1154 | |
| 1155 | GET_METHOD_ID(gCallbacksClassInfo.filterJumpyTouchEvents, gCallbacksClassInfo.clazz, |
| 1156 | "filterJumpyTouchEvents", "()Z"); |
| 1157 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1158 | GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz, |
| 1159 | "getExcludedDeviceNames", "()[Ljava/lang/String;"); |
| 1160 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 1161 | GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz, |
| 1162 | "getMaxEventsPerSecond", "()I"); |
| 1163 | |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1164 | GET_METHOD_ID(gCallbacksClassInfo.getPointerLayer, gCallbacksClassInfo.clazz, |
| 1165 | "getPointerLayer", "()I"); |
| 1166 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1167 | GET_METHOD_ID(gCallbacksClassInfo.getPointerIcon, gCallbacksClassInfo.clazz, |
| 1168 | "getPointerIcon", "()Lcom/android/server/InputManager$PointerIcon;"); |
| 1169 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1170 | // KeyEvent |
| 1171 | |
| 1172 | FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent"); |
| 1173 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1174 | // MotionEvent |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1175 | |
| 1176 | FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent"); |
| 1177 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1178 | // InputDevice |
| 1179 | |
| 1180 | FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice"); |
| 1181 | |
| 1182 | GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz, |
| 1183 | "<init>", "()V"); |
| 1184 | |
| 1185 | GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz, |
| 1186 | "addMotionRange", "(IFFFF)V"); |
| 1187 | |
| 1188 | GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz, |
| 1189 | "mId", "I"); |
| 1190 | |
| 1191 | GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz, |
| 1192 | "mName", "Ljava/lang/String;"); |
| 1193 | |
| 1194 | GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz, |
| 1195 | "mSources", "I"); |
| 1196 | |
| 1197 | GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz, |
| 1198 | "mKeyboardType", "I"); |
| 1199 | |
| 1200 | GET_FIELD_ID(gInputDeviceClassInfo.mMotionRanges, gInputDeviceClassInfo.clazz, |
| 1201 | "mMotionRanges", "[Landroid/view/InputDevice$MotionRange;"); |
| 1202 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1203 | // Configuration |
| 1204 | |
| 1205 | FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration"); |
| 1206 | |
| 1207 | GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz, |
| 1208 | "touchscreen", "I"); |
| 1209 | |
| 1210 | GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz, |
| 1211 | "keyboard", "I"); |
| 1212 | |
| 1213 | GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz, |
| 1214 | "navigation", "I"); |
| 1215 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1216 | // PointerIcon |
| 1217 | |
| 1218 | FIND_CLASS(gPointerIconClassInfo.clazz, "com/android/server/InputManager$PointerIcon"); |
| 1219 | |
| 1220 | GET_FIELD_ID(gPointerIconClassInfo.bitmap, gPointerIconClassInfo.clazz, |
| 1221 | "bitmap", "Landroid/graphics/Bitmap;"); |
| 1222 | |
| 1223 | GET_FIELD_ID(gPointerIconClassInfo.hotSpotX, gPointerIconClassInfo.clazz, |
| 1224 | "hotSpotX", "F"); |
| 1225 | |
| 1226 | GET_FIELD_ID(gPointerIconClassInfo.hotSpotY, gPointerIconClassInfo.clazz, |
| 1227 | "hotSpotY", "F"); |
| 1228 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1229 | return 0; |
| 1230 | } |
| 1231 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1232 | } /* namespace android */ |