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