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 | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 27 | #include "JNIHelp.h" |
| 28 | #include "jni.h" |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 29 | #include <limits.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 30 | #include <android_runtime/AndroidRuntime.h> |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 31 | #include <ui/InputReader.h> |
| 32 | #include <ui/InputDispatcher.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 33 | #include <ui/InputManager.h> |
| 34 | #include <ui/InputTransport.h> |
| 35 | #include <utils/Log.h> |
| 36 | #include <utils/threads.h> |
| 37 | #include "../../core/jni/android_view_KeyEvent.h" |
| 38 | #include "../../core/jni/android_view_MotionEvent.h" |
| 39 | #include "../../core/jni/android_view_InputChannel.h" |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 40 | #include "com_android_server_PowerManagerService.h" |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 41 | |
| 42 | namespace android { |
| 43 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 44 | // ---------------------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 45 | |
| 46 | static struct { |
| 47 | jclass clazz; |
| 48 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 49 | jmethodID notifyConfigurationChanged; |
| 50 | jmethodID notifyLidSwitchChanged; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 51 | jmethodID notifyInputChannelBroken; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 52 | jmethodID notifyANR; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 53 | jmethodID interceptKeyBeforeQueueing; |
| 54 | jmethodID interceptKeyBeforeDispatching; |
| 55 | jmethodID checkInjectEventsPermission; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 56 | jmethodID filterTouchEvents; |
| 57 | jmethodID filterJumpyTouchEvents; |
| 58 | jmethodID getVirtualKeyDefinitions; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 59 | jmethodID getInputDeviceCalibration; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 60 | jmethodID getExcludedDeviceNames; |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 61 | jmethodID getMaxEventsPerSecond; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 62 | } gCallbacksClassInfo; |
| 63 | |
| 64 | static struct { |
| 65 | jclass clazz; |
| 66 | |
| 67 | jfieldID scanCode; |
| 68 | jfieldID centerX; |
| 69 | jfieldID centerY; |
| 70 | jfieldID width; |
| 71 | jfieldID height; |
| 72 | } gVirtualKeyDefinitionClassInfo; |
| 73 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 74 | static struct { |
| 75 | jclass clazz; |
| 76 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 77 | jfieldID keys; |
| 78 | jfieldID values; |
| 79 | } gInputDeviceCalibrationClassInfo; |
| 80 | |
| 81 | static struct { |
| 82 | jclass clazz; |
| 83 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 84 | jfieldID inputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 85 | jfieldID name; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 86 | jfieldID layoutParamsFlags; |
| 87 | jfieldID layoutParamsType; |
| 88 | jfieldID dispatchingTimeoutNanos; |
| 89 | jfieldID frameLeft; |
| 90 | jfieldID frameTop; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 91 | jfieldID frameRight; |
| 92 | jfieldID frameBottom; |
| 93 | jfieldID visibleFrameLeft; |
| 94 | jfieldID visibleFrameTop; |
| 95 | jfieldID visibleFrameRight; |
| 96 | jfieldID visibleFrameBottom; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 97 | jfieldID touchableAreaLeft; |
| 98 | jfieldID touchableAreaTop; |
| 99 | jfieldID touchableAreaRight; |
| 100 | jfieldID touchableAreaBottom; |
| 101 | jfieldID visible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 102 | jfieldID canReceiveKeys; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 103 | jfieldID hasFocus; |
| 104 | jfieldID hasWallpaper; |
| 105 | jfieldID paused; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 106 | jfieldID layer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 107 | jfieldID ownerPid; |
| 108 | jfieldID ownerUid; |
| 109 | } gInputWindowClassInfo; |
| 110 | |
| 111 | static struct { |
| 112 | jclass clazz; |
| 113 | |
| 114 | jfieldID name; |
| 115 | jfieldID dispatchingTimeoutNanos; |
| 116 | jfieldID token; |
| 117 | } gInputApplicationClassInfo; |
| 118 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 119 | static struct { |
| 120 | jclass clazz; |
| 121 | } gKeyEventClassInfo; |
| 122 | |
| 123 | static struct { |
| 124 | jclass clazz; |
| 125 | } gMotionEventClassInfo; |
| 126 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 127 | static struct { |
| 128 | jclass clazz; |
| 129 | |
| 130 | jmethodID ctor; |
| 131 | jmethodID addMotionRange; |
| 132 | |
| 133 | jfieldID mId; |
| 134 | jfieldID mName; |
| 135 | jfieldID mSources; |
| 136 | jfieldID mKeyboardType; |
| 137 | jfieldID mMotionRanges; |
| 138 | } gInputDeviceClassInfo; |
| 139 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 140 | static struct { |
| 141 | jclass clazz; |
| 142 | |
| 143 | jfieldID touchscreen; |
| 144 | jfieldID keyboard; |
| 145 | jfieldID navigation; |
| 146 | } gConfigurationClassInfo; |
| 147 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 148 | // ---------------------------------------------------------------------------- |
| 149 | |
| 150 | static inline nsecs_t now() { |
| 151 | return systemTime(SYSTEM_TIME_MONOTONIC); |
| 152 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 153 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 154 | // ---------------------------------------------------------------------------- |
| 155 | |
| 156 | class NativeInputManager : public virtual RefBase, |
| 157 | public virtual InputReaderPolicyInterface, |
| 158 | public virtual InputDispatcherPolicyInterface { |
| 159 | protected: |
| 160 | virtual ~NativeInputManager(); |
| 161 | |
| 162 | public: |
| 163 | NativeInputManager(jobject callbacksObj); |
| 164 | |
| 165 | inline sp<InputManager> getInputManager() const { return mInputManager; } |
| 166 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 167 | void dump(String8& dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 168 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 169 | void setDisplaySize(int32_t displayId, int32_t width, int32_t height); |
| 170 | void setDisplayOrientation(int32_t displayId, int32_t orientation); |
| 171 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 172 | status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel, |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 173 | jweak inputChannelObjWeak, bool monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 174 | status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel); |
| 175 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 176 | void setInputWindows(JNIEnv* env, jobjectArray windowObjArray); |
| 177 | void setFocusedApplication(JNIEnv* env, jobject applicationObj); |
| 178 | void setInputDispatchMode(bool enabled, bool frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 179 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 180 | /* --- InputReaderPolicyInterface implementation --- */ |
| 181 | |
| 182 | virtual bool getDisplayInfo(int32_t displayId, |
| 183 | int32_t* width, int32_t* height, int32_t* orientation); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 184 | virtual bool filterTouchEvents(); |
| 185 | virtual bool filterJumpyTouchEvents(); |
| 186 | virtual void getVirtualKeyDefinitions(const String8& deviceName, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 187 | Vector<VirtualKeyDefinition>& outVirtualKeyDefinitions); |
| 188 | virtual void getInputDeviceCalibration(const String8& deviceName, |
| 189 | InputDeviceCalibration& outCalibration); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 190 | virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames); |
| 191 | |
| 192 | /* --- InputDispatcherPolicyInterface implementation --- */ |
| 193 | |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 194 | virtual void notifySwitch(nsecs_t when, int32_t switchCode, int32_t switchValue, |
| 195 | uint32_t policyFlags); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 196 | virtual void notifyConfigurationChanged(nsecs_t when); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 197 | virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
| 198 | const sp<InputChannel>& inputChannel); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 199 | virtual void notifyInputChannelBroken(const sp<InputChannel>& inputChannel); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 200 | virtual nsecs_t getKeyRepeatTimeout(); |
Jeff Brown | b21fb10 | 2010-09-07 10:44:57 -0700 | [diff] [blame] | 201 | virtual nsecs_t getKeyRepeatDelay(); |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 202 | virtual int32_t getMaxEventsPerSecond(); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 203 | virtual void interceptKeyBeforeQueueing(nsecs_t when, int32_t deviceId, |
| 204 | int32_t action, int32_t& flags, int32_t keyCode, int32_t scanCode, |
| 205 | uint32_t& policyFlags); |
| 206 | virtual void interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 207 | virtual bool interceptKeyBeforeDispatching(const sp<InputChannel>& inputChannel, |
| 208 | const KeyEvent* keyEvent, uint32_t policyFlags); |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 209 | virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 210 | virtual bool checkInjectEventsPermissionNonReentrant( |
| 211 | int32_t injectorPid, int32_t injectorUid); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 212 | |
| 213 | private: |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 214 | class ApplicationToken : public InputApplicationHandle { |
| 215 | jweak mTokenObjWeak; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 216 | |
| 217 | public: |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 218 | ApplicationToken(jweak tokenObjWeak) : |
| 219 | mTokenObjWeak(tokenObjWeak) { } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 220 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 221 | virtual ~ApplicationToken() { |
| 222 | JNIEnv* env = NativeInputManager::jniEnv(); |
| 223 | env->DeleteWeakGlobalRef(mTokenObjWeak); |
| 224 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 225 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 226 | inline jweak getTokenObj() { return mTokenObjWeak; } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 229 | sp<InputManager> mInputManager; |
| 230 | |
| 231 | jobject mCallbacksObj; |
| 232 | |
| 233 | // Cached filtering policies. |
| 234 | int32_t mFilterTouchEvents; |
| 235 | int32_t mFilterJumpyTouchEvents; |
| 236 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 237 | // Cached throttling policy. |
| 238 | int32_t mMaxEventsPerSecond; |
| 239 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 240 | // Cached display state. (lock mDisplayLock) |
| 241 | Mutex mDisplayLock; |
| 242 | int32_t mDisplayWidth, mDisplayHeight; |
| 243 | int32_t mDisplayOrientation; |
| 244 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 245 | // Power manager interactions. |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 246 | bool isScreenOn(); |
| 247 | bool isScreenBright(); |
| 248 | |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 249 | // Weak references to all currently registered input channels by connection pointer. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 250 | Mutex mInputChannelRegistryLock; |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 251 | KeyedVector<InputChannel*, jweak> mInputChannelObjWeakTable; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 252 | |
| 253 | jobject getInputChannelObjLocal(JNIEnv* env, const sp<InputChannel>& inputChannel); |
| 254 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 255 | static bool populateWindow(JNIEnv* env, jobject windowObj, InputWindow& outWindow); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 256 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 257 | static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 258 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 259 | static inline JNIEnv* jniEnv() { |
| 260 | return AndroidRuntime::getJNIEnv(); |
| 261 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | // ---------------------------------------------------------------------------- |
| 265 | |
| 266 | NativeInputManager::NativeInputManager(jobject callbacksObj) : |
| 267 | mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1), |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 268 | mMaxEventsPerSecond(-1), |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 269 | mDisplayWidth(-1), mDisplayHeight(-1), mDisplayOrientation(ROTATION_0) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 270 | JNIEnv* env = jniEnv(); |
| 271 | |
| 272 | mCallbacksObj = env->NewGlobalRef(callbacksObj); |
| 273 | |
| 274 | sp<EventHub> eventHub = new EventHub(); |
| 275 | mInputManager = new InputManager(eventHub, this, this); |
| 276 | } |
| 277 | |
| 278 | NativeInputManager::~NativeInputManager() { |
| 279 | JNIEnv* env = jniEnv(); |
| 280 | |
| 281 | env->DeleteGlobalRef(mCallbacksObj); |
| 282 | } |
| 283 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 284 | void NativeInputManager::dump(String8& dump) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 285 | mInputManager->getReader()->dump(dump); |
| 286 | dump.append("\n"); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 287 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 288 | mInputManager->getDispatcher()->dump(dump); |
| 289 | dump.append("\n"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 292 | bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 293 | if (env->ExceptionCheck()) { |
| 294 | LOGE("An exception was thrown by callback '%s'.", methodName); |
| 295 | LOGE_EX(env); |
| 296 | env->ExceptionClear(); |
| 297 | return true; |
| 298 | } |
| 299 | return false; |
| 300 | } |
| 301 | |
| 302 | void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_t height) { |
| 303 | if (displayId == 0) { |
| 304 | AutoMutex _l(mDisplayLock); |
| 305 | |
| 306 | mDisplayWidth = width; |
| 307 | mDisplayHeight = height; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) { |
| 312 | if (displayId == 0) { |
| 313 | AutoMutex _l(mDisplayLock); |
| 314 | |
| 315 | mDisplayOrientation = orientation; |
| 316 | } |
| 317 | } |
| 318 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 319 | status_t NativeInputManager::registerInputChannel(JNIEnv* env, |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 320 | const sp<InputChannel>& inputChannel, jobject inputChannelObj, bool monitor) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 321 | jweak inputChannelObjWeak = env->NewWeakGlobalRef(inputChannelObj); |
| 322 | if (! inputChannelObjWeak) { |
| 323 | LOGE("Could not create weak reference for input channel."); |
| 324 | LOGE_EX(env); |
| 325 | return NO_MEMORY; |
| 326 | } |
| 327 | |
| 328 | status_t status; |
| 329 | { |
| 330 | AutoMutex _l(mInputChannelRegistryLock); |
| 331 | |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 332 | ssize_t index = mInputChannelObjWeakTable.indexOfKey(inputChannel.get()); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 333 | if (index >= 0) { |
| 334 | LOGE("Input channel object '%s' has already been registered", |
| 335 | inputChannel->getName().string()); |
| 336 | status = INVALID_OPERATION; |
| 337 | goto DeleteWeakRef; |
| 338 | } |
| 339 | |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 340 | mInputChannelObjWeakTable.add(inputChannel.get(), inputChannelObjWeak); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 343 | status = mInputManager->getDispatcher()->registerInputChannel(inputChannel, monitor); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 344 | if (! status) { |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 345 | // Success. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 346 | return OK; |
| 347 | } |
| 348 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 349 | // Failed! |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 350 | { |
| 351 | AutoMutex _l(mInputChannelRegistryLock); |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 352 | mInputChannelObjWeakTable.removeItem(inputChannel.get()); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | DeleteWeakRef: |
| 356 | env->DeleteWeakGlobalRef(inputChannelObjWeak); |
| 357 | return status; |
| 358 | } |
| 359 | |
| 360 | status_t NativeInputManager::unregisterInputChannel(JNIEnv* env, |
| 361 | const sp<InputChannel>& inputChannel) { |
| 362 | jweak inputChannelObjWeak; |
| 363 | { |
| 364 | AutoMutex _l(mInputChannelRegistryLock); |
| 365 | |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 366 | ssize_t index = mInputChannelObjWeakTable.indexOfKey(inputChannel.get()); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 367 | if (index < 0) { |
| 368 | LOGE("Input channel object '%s' is not currently registered", |
| 369 | inputChannel->getName().string()); |
| 370 | return INVALID_OPERATION; |
| 371 | } |
| 372 | |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 373 | inputChannelObjWeak = mInputChannelObjWeakTable.valueAt(index); |
| 374 | mInputChannelObjWeakTable.removeItemsAt(index); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | env->DeleteWeakGlobalRef(inputChannelObjWeak); |
| 378 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 379 | return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | jobject NativeInputManager::getInputChannelObjLocal(JNIEnv* env, |
| 383 | const sp<InputChannel>& inputChannel) { |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 384 | InputChannel* inputChannelPtr = inputChannel.get(); |
| 385 | if (! inputChannelPtr) { |
| 386 | return NULL; |
| 387 | } |
| 388 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 389 | { |
| 390 | AutoMutex _l(mInputChannelRegistryLock); |
| 391 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 392 | ssize_t index = mInputChannelObjWeakTable.indexOfKey(inputChannelPtr); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 393 | if (index < 0) { |
| 394 | return NULL; |
| 395 | } |
| 396 | |
Jeff Brown | 2cbecea | 2010-08-17 15:59:26 -0700 | [diff] [blame] | 397 | jweak inputChannelObjWeak = mInputChannelObjWeakTable.valueAt(index); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 398 | return env->NewLocalRef(inputChannelObjWeak); |
| 399 | } |
| 400 | } |
| 401 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 402 | bool NativeInputManager::getDisplayInfo(int32_t displayId, |
| 403 | int32_t* width, int32_t* height, int32_t* orientation) { |
| 404 | bool result = false; |
| 405 | if (displayId == 0) { |
| 406 | AutoMutex _l(mDisplayLock); |
| 407 | |
| 408 | if (mDisplayWidth > 0) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 409 | if (width) { |
| 410 | *width = mDisplayWidth; |
| 411 | } |
| 412 | if (height) { |
| 413 | *height = mDisplayHeight; |
| 414 | } |
| 415 | if (orientation) { |
| 416 | *orientation = mDisplayOrientation; |
| 417 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 418 | result = true; |
| 419 | } |
| 420 | } |
| 421 | return result; |
| 422 | } |
| 423 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 424 | bool NativeInputManager::filterTouchEvents() { |
| 425 | if (mFilterTouchEvents < 0) { |
| 426 | JNIEnv* env = jniEnv(); |
| 427 | |
| 428 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 429 | gCallbacksClassInfo.filterTouchEvents); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 430 | if (checkAndClearExceptionFromCallback(env, "filterTouchEvents")) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 431 | result = false; |
| 432 | } |
| 433 | |
| 434 | mFilterTouchEvents = result ? 1 : 0; |
| 435 | } |
| 436 | return mFilterTouchEvents; |
| 437 | } |
| 438 | |
| 439 | bool NativeInputManager::filterJumpyTouchEvents() { |
| 440 | if (mFilterJumpyTouchEvents < 0) { |
| 441 | JNIEnv* env = jniEnv(); |
| 442 | |
| 443 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 444 | gCallbacksClassInfo.filterJumpyTouchEvents); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 445 | if (checkAndClearExceptionFromCallback(env, "filterJumpyTouchEvents")) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 446 | result = false; |
| 447 | } |
| 448 | |
| 449 | mFilterJumpyTouchEvents = result ? 1 : 0; |
| 450 | } |
| 451 | return mFilterJumpyTouchEvents; |
| 452 | } |
| 453 | |
| 454 | void NativeInputManager::getVirtualKeyDefinitions(const String8& deviceName, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 455 | Vector<VirtualKeyDefinition>& outVirtualKeyDefinitions) { |
| 456 | outVirtualKeyDefinitions.clear(); |
| 457 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 458 | JNIEnv* env = jniEnv(); |
| 459 | |
| 460 | jstring deviceNameStr = env->NewStringUTF(deviceName.string()); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 461 | if (! checkAndClearExceptionFromCallback(env, "getVirtualKeyDefinitions")) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 462 | jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj, |
| 463 | gCallbacksClassInfo.getVirtualKeyDefinitions, deviceNameStr)); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 464 | if (! checkAndClearExceptionFromCallback(env, "getVirtualKeyDefinitions") && result) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 465 | jsize length = env->GetArrayLength(result); |
| 466 | for (jsize i = 0; i < length; i++) { |
| 467 | jobject item = env->GetObjectArrayElement(result, i); |
| 468 | |
| 469 | outVirtualKeyDefinitions.add(); |
| 470 | outVirtualKeyDefinitions.editTop().scanCode = |
| 471 | int32_t(env->GetIntField(item, gVirtualKeyDefinitionClassInfo.scanCode)); |
| 472 | outVirtualKeyDefinitions.editTop().centerX = |
| 473 | int32_t(env->GetIntField(item, gVirtualKeyDefinitionClassInfo.centerX)); |
| 474 | outVirtualKeyDefinitions.editTop().centerY = |
| 475 | int32_t(env->GetIntField(item, gVirtualKeyDefinitionClassInfo.centerY)); |
| 476 | outVirtualKeyDefinitions.editTop().width = |
| 477 | int32_t(env->GetIntField(item, gVirtualKeyDefinitionClassInfo.width)); |
| 478 | outVirtualKeyDefinitions.editTop().height = |
| 479 | int32_t(env->GetIntField(item, gVirtualKeyDefinitionClassInfo.height)); |
| 480 | |
| 481 | env->DeleteLocalRef(item); |
| 482 | } |
| 483 | env->DeleteLocalRef(result); |
| 484 | } |
| 485 | env->DeleteLocalRef(deviceNameStr); |
| 486 | } |
| 487 | } |
| 488 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 489 | void NativeInputManager::getInputDeviceCalibration(const String8& deviceName, |
| 490 | InputDeviceCalibration& outCalibration) { |
| 491 | outCalibration.clear(); |
| 492 | |
| 493 | JNIEnv* env = jniEnv(); |
| 494 | |
| 495 | jstring deviceNameStr = env->NewStringUTF(deviceName.string()); |
| 496 | if (! checkAndClearExceptionFromCallback(env, "getInputDeviceCalibration")) { |
| 497 | jobject result = env->CallObjectMethod(mCallbacksObj, |
| 498 | gCallbacksClassInfo.getInputDeviceCalibration, deviceNameStr); |
| 499 | if (! checkAndClearExceptionFromCallback(env, "getInputDeviceCalibration") && result) { |
| 500 | jobjectArray keys = jobjectArray(env->GetObjectField(result, |
| 501 | gInputDeviceCalibrationClassInfo.keys)); |
| 502 | jobjectArray values = jobjectArray(env->GetObjectField(result, |
| 503 | gInputDeviceCalibrationClassInfo.values)); |
| 504 | |
| 505 | jsize length = env->GetArrayLength(keys); |
| 506 | for (jsize i = 0; i < length; i++) { |
| 507 | jstring keyStr = jstring(env->GetObjectArrayElement(keys, i)); |
| 508 | jstring valueStr = jstring(env->GetObjectArrayElement(values, i)); |
| 509 | |
| 510 | const char* keyChars = env->GetStringUTFChars(keyStr, NULL); |
| 511 | String8 key(keyChars); |
| 512 | env->ReleaseStringUTFChars(keyStr, keyChars); |
| 513 | |
| 514 | const char* valueChars = env->GetStringUTFChars(valueStr, NULL); |
| 515 | String8 value(valueChars); |
| 516 | env->ReleaseStringUTFChars(valueStr, valueChars); |
| 517 | |
| 518 | outCalibration.addProperty(key, value); |
| 519 | |
| 520 | env->DeleteLocalRef(keyStr); |
| 521 | env->DeleteLocalRef(valueStr); |
| 522 | } |
| 523 | env->DeleteLocalRef(keys); |
| 524 | env->DeleteLocalRef(values); |
| 525 | env->DeleteLocalRef(result); |
| 526 | } |
| 527 | env->DeleteLocalRef(deviceNameStr); |
| 528 | } |
| 529 | } |
| 530 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 531 | void NativeInputManager::getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 532 | outExcludedDeviceNames.clear(); |
| 533 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 534 | JNIEnv* env = jniEnv(); |
| 535 | |
| 536 | jobjectArray result = jobjectArray(env->CallObjectMethod(mCallbacksObj, |
| 537 | gCallbacksClassInfo.getExcludedDeviceNames)); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 538 | if (! checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && result) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 539 | jsize length = env->GetArrayLength(result); |
| 540 | for (jsize i = 0; i < length; i++) { |
| 541 | jstring item = jstring(env->GetObjectArrayElement(result, i)); |
| 542 | |
| 543 | const char* deviceNameChars = env->GetStringUTFChars(item, NULL); |
| 544 | outExcludedDeviceNames.add(String8(deviceNameChars)); |
| 545 | env->ReleaseStringUTFChars(item, deviceNameChars); |
| 546 | |
| 547 | env->DeleteLocalRef(item); |
| 548 | } |
| 549 | env->DeleteLocalRef(result); |
| 550 | } |
| 551 | } |
| 552 | |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 553 | void NativeInputManager::notifySwitch(nsecs_t when, int32_t switchCode, |
| 554 | int32_t switchValue, uint32_t policyFlags) { |
| 555 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 556 | LOGD("notifySwitch - when=%lld, switchCode=%d, switchValue=%d, policyFlags=0x%x", |
| 557 | when, switchCode, switchValue, policyFlags); |
| 558 | #endif |
| 559 | |
| 560 | JNIEnv* env = jniEnv(); |
| 561 | |
| 562 | switch (switchCode) { |
| 563 | case SW_LID: |
| 564 | env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyLidSwitchChanged, |
| 565 | when, switchValue == 0); |
| 566 | checkAndClearExceptionFromCallback(env, "notifyLidSwitchChanged"); |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 571 | void NativeInputManager::notifyConfigurationChanged(nsecs_t when) { |
| 572 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 573 | LOGD("notifyConfigurationChanged - when=%lld", when); |
| 574 | #endif |
| 575 | |
| 576 | JNIEnv* env = jniEnv(); |
| 577 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 578 | env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyConfigurationChanged, when); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 579 | checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged"); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 582 | nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle, |
| 583 | const sp<InputChannel>& inputChannel) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 584 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 585 | LOGD("notifyANR"); |
| 586 | #endif |
| 587 | |
| 588 | JNIEnv* env = jniEnv(); |
| 589 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 590 | jobject tokenObjLocal; |
| 591 | if (inputApplicationHandle.get()) { |
| 592 | ApplicationToken* token = static_cast<ApplicationToken*>(inputApplicationHandle.get()); |
| 593 | jweak tokenObjWeak = token->getTokenObj(); |
| 594 | tokenObjLocal = env->NewLocalRef(tokenObjWeak); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 595 | } else { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 596 | tokenObjLocal = NULL; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Jeff Brown | 54a1825 | 2010-09-16 14:07:33 -0700 | [diff] [blame] | 599 | jobject inputChannelObjLocal = getInputChannelObjLocal(env, inputChannel); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 600 | jlong newTimeout = env->CallLongMethod(mCallbacksObj, |
| 601 | gCallbacksClassInfo.notifyANR, tokenObjLocal, inputChannelObjLocal); |
| 602 | if (checkAndClearExceptionFromCallback(env, "notifyANR")) { |
| 603 | newTimeout = 0; // abort dispatch |
| 604 | } else { |
| 605 | assert(newTimeout >= 0); |
| 606 | } |
| 607 | |
| 608 | env->DeleteLocalRef(tokenObjLocal); |
| 609 | env->DeleteLocalRef(inputChannelObjLocal); |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 610 | return newTimeout; |
| 611 | } |
| 612 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 613 | void NativeInputManager::notifyInputChannelBroken(const sp<InputChannel>& inputChannel) { |
| 614 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 615 | LOGD("notifyInputChannelBroken - inputChannel='%s'", inputChannel->getName().string()); |
| 616 | #endif |
| 617 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 618 | JNIEnv* env = jniEnv(); |
| 619 | |
| 620 | jobject inputChannelObjLocal = getInputChannelObjLocal(env, inputChannel); |
| 621 | if (inputChannelObjLocal) { |
| 622 | env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyInputChannelBroken, |
| 623 | inputChannelObjLocal); |
| 624 | checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken"); |
| 625 | |
| 626 | env->DeleteLocalRef(inputChannelObjLocal); |
| 627 | } |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 630 | nsecs_t NativeInputManager::getKeyRepeatTimeout() { |
| 631 | if (! isScreenOn()) { |
| 632 | // Disable key repeat when the screen is off. |
| 633 | return -1; |
| 634 | } else { |
| 635 | // TODO use ViewConfiguration.getLongPressTimeout() |
| 636 | return milliseconds_to_nanoseconds(500); |
| 637 | } |
| 638 | } |
| 639 | |
Jeff Brown | b21fb10 | 2010-09-07 10:44:57 -0700 | [diff] [blame] | 640 | nsecs_t NativeInputManager::getKeyRepeatDelay() { |
| 641 | return milliseconds_to_nanoseconds(50); |
| 642 | } |
| 643 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 644 | int32_t NativeInputManager::getMaxEventsPerSecond() { |
| 645 | if (mMaxEventsPerSecond < 0) { |
| 646 | JNIEnv* env = jniEnv(); |
| 647 | |
| 648 | jint result = env->CallIntMethod(mCallbacksObj, |
| 649 | gCallbacksClassInfo.getMaxEventsPerSecond); |
| 650 | if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) { |
Jeff Brown | 3d8c9bd | 2010-08-18 17:48:53 -0700 | [diff] [blame] | 651 | result = 60; |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | mMaxEventsPerSecond = result; |
| 655 | } |
| 656 | return mMaxEventsPerSecond; |
| 657 | } |
| 658 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 659 | void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 660 | Vector<InputWindow> windows; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 661 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 662 | jsize length = env->GetArrayLength(windowObjArray); |
| 663 | for (jsize i = 0; i < length; i++) { |
| 664 | jobject inputTargetObj = env->GetObjectArrayElement(windowObjArray, i); |
| 665 | if (! inputTargetObj) { |
| 666 | break; // found null element indicating end of used portion of the array |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 669 | windows.push(); |
| 670 | InputWindow& window = windows.editTop(); |
| 671 | bool valid = populateWindow(env, inputTargetObj, window); |
| 672 | if (! valid) { |
| 673 | windows.pop(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 676 | env->DeleteLocalRef(inputTargetObj); |
| 677 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 678 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 679 | mInputManager->getDispatcher()->setInputWindows(windows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | bool NativeInputManager::populateWindow(JNIEnv* env, jobject windowObj, |
| 683 | InputWindow& outWindow) { |
| 684 | bool valid = false; |
| 685 | |
| 686 | jobject inputChannelObj = env->GetObjectField(windowObj, |
| 687 | gInputWindowClassInfo.inputChannel); |
| 688 | if (inputChannelObj) { |
| 689 | sp<InputChannel> inputChannel = |
| 690 | android_view_InputChannel_getInputChannel(env, inputChannelObj); |
| 691 | if (inputChannel != NULL) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 692 | jstring name = jstring(env->GetObjectField(windowObj, |
| 693 | gInputWindowClassInfo.name)); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 694 | jint layoutParamsFlags = env->GetIntField(windowObj, |
| 695 | gInputWindowClassInfo.layoutParamsFlags); |
| 696 | jint layoutParamsType = env->GetIntField(windowObj, |
| 697 | gInputWindowClassInfo.layoutParamsType); |
| 698 | jlong dispatchingTimeoutNanos = env->GetLongField(windowObj, |
| 699 | gInputWindowClassInfo.dispatchingTimeoutNanos); |
| 700 | jint frameLeft = env->GetIntField(windowObj, |
| 701 | gInputWindowClassInfo.frameLeft); |
| 702 | jint frameTop = env->GetIntField(windowObj, |
| 703 | gInputWindowClassInfo.frameTop); |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 704 | jint frameRight = env->GetIntField(windowObj, |
| 705 | gInputWindowClassInfo.frameRight); |
| 706 | jint frameBottom = env->GetIntField(windowObj, |
| 707 | gInputWindowClassInfo.frameBottom); |
| 708 | jint visibleFrameLeft = env->GetIntField(windowObj, |
| 709 | gInputWindowClassInfo.visibleFrameLeft); |
| 710 | jint visibleFrameTop = env->GetIntField(windowObj, |
| 711 | gInputWindowClassInfo.visibleFrameTop); |
| 712 | jint visibleFrameRight = env->GetIntField(windowObj, |
| 713 | gInputWindowClassInfo.visibleFrameRight); |
| 714 | jint visibleFrameBottom = env->GetIntField(windowObj, |
| 715 | gInputWindowClassInfo.visibleFrameBottom); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 716 | jint touchableAreaLeft = env->GetIntField(windowObj, |
| 717 | gInputWindowClassInfo.touchableAreaLeft); |
| 718 | jint touchableAreaTop = env->GetIntField(windowObj, |
| 719 | gInputWindowClassInfo.touchableAreaTop); |
| 720 | jint touchableAreaRight = env->GetIntField(windowObj, |
| 721 | gInputWindowClassInfo.touchableAreaRight); |
| 722 | jint touchableAreaBottom = env->GetIntField(windowObj, |
| 723 | gInputWindowClassInfo.touchableAreaBottom); |
| 724 | jboolean visible = env->GetBooleanField(windowObj, |
| 725 | gInputWindowClassInfo.visible); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 726 | jboolean canReceiveKeys = env->GetBooleanField(windowObj, |
| 727 | gInputWindowClassInfo.canReceiveKeys); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 728 | jboolean hasFocus = env->GetBooleanField(windowObj, |
| 729 | gInputWindowClassInfo.hasFocus); |
| 730 | jboolean hasWallpaper = env->GetBooleanField(windowObj, |
| 731 | gInputWindowClassInfo.hasWallpaper); |
| 732 | jboolean paused = env->GetBooleanField(windowObj, |
| 733 | gInputWindowClassInfo.paused); |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 734 | jint layer = env->GetIntField(windowObj, |
| 735 | gInputWindowClassInfo.layer); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 736 | jint ownerPid = env->GetIntField(windowObj, |
| 737 | gInputWindowClassInfo.ownerPid); |
| 738 | jint ownerUid = env->GetIntField(windowObj, |
| 739 | gInputWindowClassInfo.ownerUid); |
| 740 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 741 | const char* nameStr = env->GetStringUTFChars(name, NULL); |
| 742 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 743 | outWindow.inputChannel = inputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 744 | outWindow.name.setTo(nameStr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 745 | outWindow.layoutParamsFlags = layoutParamsFlags; |
| 746 | outWindow.layoutParamsType = layoutParamsType; |
| 747 | outWindow.dispatchingTimeout = dispatchingTimeoutNanos; |
| 748 | outWindow.frameLeft = frameLeft; |
| 749 | outWindow.frameTop = frameTop; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 750 | outWindow.frameRight = frameRight; |
| 751 | outWindow.frameBottom = frameBottom; |
| 752 | outWindow.visibleFrameLeft = visibleFrameLeft; |
| 753 | outWindow.visibleFrameTop = visibleFrameTop; |
| 754 | outWindow.visibleFrameRight = visibleFrameRight; |
| 755 | outWindow.visibleFrameBottom = visibleFrameBottom; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 756 | outWindow.touchableAreaLeft = touchableAreaLeft; |
| 757 | outWindow.touchableAreaTop = touchableAreaTop; |
| 758 | outWindow.touchableAreaRight = touchableAreaRight; |
| 759 | outWindow.touchableAreaBottom = touchableAreaBottom; |
| 760 | outWindow.visible = visible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 761 | outWindow.canReceiveKeys = canReceiveKeys; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 762 | outWindow.hasFocus = hasFocus; |
| 763 | outWindow.hasWallpaper = hasWallpaper; |
| 764 | outWindow.paused = paused; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 765 | outWindow.layer = layer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 766 | outWindow.ownerPid = ownerPid; |
| 767 | outWindow.ownerUid = ownerUid; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 768 | |
| 769 | env->ReleaseStringUTFChars(name, nameStr); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 770 | valid = true; |
| 771 | } else { |
| 772 | LOGW("Dropping input target because its input channel is not initialized."); |
| 773 | } |
| 774 | |
| 775 | env->DeleteLocalRef(inputChannelObj); |
| 776 | } else { |
| 777 | LOGW("Dropping input target because the input channel object was null."); |
| 778 | } |
| 779 | return valid; |
| 780 | } |
| 781 | |
| 782 | void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationObj) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 783 | if (applicationObj) { |
| 784 | jstring nameObj = jstring(env->GetObjectField(applicationObj, |
| 785 | gInputApplicationClassInfo.name)); |
| 786 | jlong dispatchingTimeoutNanos = env->GetLongField(applicationObj, |
| 787 | gInputApplicationClassInfo.dispatchingTimeoutNanos); |
| 788 | jobject tokenObj = env->GetObjectField(applicationObj, |
| 789 | gInputApplicationClassInfo.token); |
| 790 | jweak tokenObjWeak = env->NewWeakGlobalRef(tokenObj); |
| 791 | if (! tokenObjWeak) { |
| 792 | LOGE("Could not create weak reference for application token."); |
| 793 | LOGE_EX(env); |
| 794 | env->ExceptionClear(); |
| 795 | } |
| 796 | env->DeleteLocalRef(tokenObj); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 797 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 798 | String8 name; |
| 799 | if (nameObj) { |
| 800 | const char* nameStr = env->GetStringUTFChars(nameObj, NULL); |
| 801 | name.setTo(nameStr); |
| 802 | env->ReleaseStringUTFChars(nameObj, nameStr); |
| 803 | env->DeleteLocalRef(nameObj); |
| 804 | } else { |
| 805 | LOGE("InputApplication.name should not be null."); |
| 806 | name.setTo("unknown"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 809 | InputApplication application; |
| 810 | application.name = name; |
| 811 | application.dispatchingTimeout = dispatchingTimeoutNanos; |
| 812 | application.handle = new ApplicationToken(tokenObjWeak); |
| 813 | mInputManager->getDispatcher()->setFocusedApplication(& application); |
| 814 | } else { |
| 815 | mInputManager->getDispatcher()->setFocusedApplication(NULL); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
| 819 | void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 820 | mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 823 | bool NativeInputManager::isScreenOn() { |
| 824 | return android_server_PowerManagerService_isScreenOn(); |
| 825 | } |
| 826 | |
| 827 | bool NativeInputManager::isScreenBright() { |
| 828 | return android_server_PowerManagerService_isScreenBright(); |
| 829 | } |
| 830 | |
| 831 | void NativeInputManager::interceptKeyBeforeQueueing(nsecs_t when, |
| 832 | int32_t deviceId, int32_t action, int32_t &flags, |
| 833 | int32_t keyCode, int32_t scanCode, uint32_t& policyFlags) { |
| 834 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 835 | LOGD("interceptKeyBeforeQueueing - when=%lld, deviceId=%d, action=%d, flags=%d, " |
| 836 | "keyCode=%d, scanCode=%d, policyFlags=0x%x", |
| 837 | when, deviceId, action, flags, keyCode, scanCode, policyFlags); |
| 838 | #endif |
| 839 | |
| 840 | if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) { |
| 841 | policyFlags |= POLICY_FLAG_VIRTUAL; |
| 842 | flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 845 | // Policy: |
| 846 | // - Ignore untrusted events and pass them along. |
| 847 | // - Ask the window manager what to do with normal events and trusted injected events. |
| 848 | // - For normal events wake and brighten the screen if currently off or dim. |
| 849 | if ((policyFlags & POLICY_FLAG_TRUSTED)) { |
| 850 | const int32_t WM_ACTION_PASS_TO_USER = 1; |
| 851 | const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2; |
| 852 | const int32_t WM_ACTION_GO_TO_SLEEP = 4; |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 853 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 854 | bool isScreenOn = this->isScreenOn(); |
| 855 | bool isScreenBright = this->isScreenBright(); |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 856 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 857 | JNIEnv* env = jniEnv(); |
| 858 | jint wmActions = env->CallIntMethod(mCallbacksObj, |
| 859 | gCallbacksClassInfo.interceptKeyBeforeQueueing, |
| 860 | when, keyCode, action == AKEY_EVENT_ACTION_DOWN, policyFlags, isScreenOn); |
| 861 | if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) { |
| 862 | wmActions = 0; |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 865 | if (!(flags & POLICY_FLAG_INJECTED)) { |
| 866 | if (!isScreenOn) { |
| 867 | policyFlags |= POLICY_FLAG_WOKE_HERE; |
| 868 | flags |= AKEY_EVENT_FLAG_WOKE_HERE; |
| 869 | } |
| 870 | |
| 871 | if (!isScreenBright) { |
| 872 | policyFlags |= POLICY_FLAG_BRIGHT_HERE; |
| 873 | } |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | if (wmActions & WM_ACTION_GO_TO_SLEEP) { |
| 877 | android_server_PowerManagerService_goToSleep(when); |
| 878 | } |
| 879 | |
| 880 | if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) { |
| 881 | android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT); |
| 882 | } |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 883 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 884 | if (wmActions & WM_ACTION_PASS_TO_USER) { |
| 885 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 886 | } |
| 887 | } else { |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 888 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | void NativeInputManager::interceptGenericBeforeQueueing(nsecs_t when, uint32_t& policyFlags) { |
| 893 | #if DEBUG_INPUT_DISPATCHER_POLICY |
| 894 | LOGD("interceptGenericBeforeQueueing - when=%lld, policyFlags=0x%x", when, policyFlags); |
| 895 | #endif |
| 896 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 897 | // Policy: |
| 898 | // - Ignore untrusted events and pass them along. |
| 899 | // - No special filtering for injected events required at this time. |
| 900 | // - Filter normal events based on screen state. |
| 901 | // - For normal events brighten (but do not wake) the screen if currently dim. |
| 902 | if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) { |
| 903 | if (isScreenOn()) { |
| 904 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 905 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 906 | if (!isScreenBright()) { |
| 907 | policyFlags |= POLICY_FLAG_BRIGHT_HERE; |
| 908 | } |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 909 | } |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 910 | } else { |
| 911 | policyFlags |= POLICY_FLAG_PASS_TO_USER; |
Jeff Brown | b931a1b | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
| 915 | bool NativeInputManager::interceptKeyBeforeDispatching(const sp<InputChannel>& inputChannel, |
| 916 | const KeyEvent* keyEvent, uint32_t policyFlags) { |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 917 | // Policy: |
| 918 | // - Ignore untrusted events and pass them along. |
| 919 | // - Filter normal events and trusted injected events through the window manager policy to |
| 920 | // handle the HOME key and the like. |
| 921 | if (policyFlags & POLICY_FLAG_TRUSTED) { |
| 922 | JNIEnv* env = jniEnv(); |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 923 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 924 | // Note: inputChannel may be null. |
| 925 | jobject inputChannelObj = getInputChannelObjLocal(env, inputChannel); |
| 926 | jboolean consumed = env->CallBooleanMethod(mCallbacksObj, |
| 927 | gCallbacksClassInfo.interceptKeyBeforeDispatching, |
| 928 | inputChannelObj, keyEvent->getAction(), keyEvent->getFlags(), |
| 929 | keyEvent->getKeyCode(), keyEvent->getMetaState(), |
| 930 | keyEvent->getRepeatCount(), policyFlags); |
| 931 | bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching"); |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 932 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame^] | 933 | env->DeleteLocalRef(inputChannelObj); |
| 934 | return consumed && ! error; |
| 935 | } else { |
| 936 | return false; |
| 937 | } |
Jeff Brown | d009787 | 2010-06-30 14:41:59 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Jeff Brown | 01ce2e9 | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 940 | void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) { |
| 941 | android_server_PowerManagerService_userActivity(eventTime, eventType); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 944 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 945 | bool NativeInputManager::checkInjectEventsPermissionNonReentrant( |
| 946 | int32_t injectorPid, int32_t injectorUid) { |
| 947 | JNIEnv* env = jniEnv(); |
| 948 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 949 | gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid); |
| 950 | checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 951 | return result; |
| 952 | } |
| 953 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 954 | // ---------------------------------------------------------------------------- |
| 955 | |
| 956 | static sp<NativeInputManager> gNativeInputManager; |
| 957 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 958 | static bool checkInputManagerUnitialized(JNIEnv* env) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 959 | if (gNativeInputManager == NULL) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 960 | LOGE("Input manager not initialized."); |
| 961 | jniThrowRuntimeException(env, "Input manager not initialized."); |
| 962 | return true; |
| 963 | } |
| 964 | return false; |
| 965 | } |
| 966 | |
| 967 | static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz, |
| 968 | jobject callbacks) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 969 | if (gNativeInputManager == NULL) { |
| 970 | gNativeInputManager = new NativeInputManager(callbacks); |
| 971 | } else { |
| 972 | LOGE("Input manager already initialized."); |
| 973 | jniThrowRuntimeException(env, "Input manager already initialized."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
| 977 | static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) { |
| 978 | if (checkInputManagerUnitialized(env)) { |
| 979 | return; |
| 980 | } |
| 981 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 982 | status_t result = gNativeInputManager->getInputManager()->start(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 983 | if (result) { |
| 984 | jniThrowRuntimeException(env, "Input manager could not be started."); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
| 989 | jint displayId, jint width, jint height) { |
| 990 | if (checkInputManagerUnitialized(env)) { |
| 991 | return; |
| 992 | } |
| 993 | |
| 994 | // XXX we could get this from the SurfaceFlinger directly instead of requiring it |
| 995 | // to be passed in like this, not sure which is better but leaving it like this |
| 996 | // keeps the window manager in direct control of when display transitions propagate down |
| 997 | // to the input dispatcher |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 998 | gNativeInputManager->setDisplaySize(displayId, width, height); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz, |
| 1002 | jint displayId, jint orientation) { |
| 1003 | if (checkInputManagerUnitialized(env)) { |
| 1004 | return; |
| 1005 | } |
| 1006 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1007 | gNativeInputManager->setDisplayOrientation(displayId, orientation); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1011 | jint deviceId, jint sourceMask, jint scanCode) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1012 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1013 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1016 | return gNativeInputManager->getInputManager()->getReader()->getScanCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1017 | deviceId, uint32_t(sourceMask), scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1021 | jint deviceId, jint sourceMask, jint keyCode) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1022 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1023 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1026 | return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1027 | deviceId, uint32_t(sourceMask), keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1031 | jint deviceId, jint sourceMask, jint sw) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1032 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1033 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1036 | return gNativeInputManager->getInputManager()->getReader()->getSwitchState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1037 | deviceId, uint32_t(sourceMask), sw); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1041 | jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1042 | if (checkInputManagerUnitialized(env)) { |
| 1043 | return JNI_FALSE; |
| 1044 | } |
| 1045 | |
| 1046 | int32_t* codes = env->GetIntArrayElements(keyCodes, NULL); |
| 1047 | uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL); |
| 1048 | jsize numCodes = env->GetArrayLength(keyCodes); |
| 1049 | jboolean result; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1050 | if (numCodes == env->GetArrayLength(keyCodes)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1051 | result = gNativeInputManager->getInputManager()->getReader()->hasKeys( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1052 | deviceId, uint32_t(sourceMask), numCodes, codes, flags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1053 | } else { |
| 1054 | result = JNI_FALSE; |
| 1055 | } |
| 1056 | |
| 1057 | env->ReleaseBooleanArrayElements(outFlags, flags, 0); |
| 1058 | env->ReleaseIntArrayElements(keyCodes, codes, 0); |
| 1059 | return result; |
| 1060 | } |
| 1061 | |
| 1062 | static void throwInputChannelNotInitialized(JNIEnv* env) { |
| 1063 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1064 | "inputChannel is not initialized"); |
| 1065 | } |
| 1066 | |
| 1067 | static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env, |
| 1068 | jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) { |
| 1069 | LOGW("Input channel object '%s' was disposed without first being unregistered with " |
| 1070 | "the input manager!", inputChannel->getName().string()); |
| 1071 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1072 | if (gNativeInputManager != NULL) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1073 | gNativeInputManager->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1074 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz, |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1078 | jobject inputChannelObj, jboolean monitor) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1079 | if (checkInputManagerUnitialized(env)) { |
| 1080 | return; |
| 1081 | } |
| 1082 | |
| 1083 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1084 | inputChannelObj); |
| 1085 | if (inputChannel == NULL) { |
| 1086 | throwInputChannelNotInitialized(env); |
| 1087 | return; |
| 1088 | } |
| 1089 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1090 | |
| 1091 | status_t status = gNativeInputManager->registerInputChannel( |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1092 | env, inputChannel, inputChannelObj, monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1093 | if (status) { |
| 1094 | jniThrowRuntimeException(env, "Failed to register input channel. " |
| 1095 | "Check logs for details."); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1099 | if (! monitor) { |
| 1100 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, |
| 1101 | android_server_InputManager_handleInputChannelDisposed, NULL); |
| 1102 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz, |
| 1106 | jobject inputChannelObj) { |
| 1107 | if (checkInputManagerUnitialized(env)) { |
| 1108 | return; |
| 1109 | } |
| 1110 | |
| 1111 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1112 | inputChannelObj); |
| 1113 | if (inputChannel == NULL) { |
| 1114 | throwInputChannelNotInitialized(env); |
| 1115 | return; |
| 1116 | } |
| 1117 | |
| 1118 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL); |
| 1119 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1120 | status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1121 | if (status) { |
| 1122 | jniThrowRuntimeException(env, "Failed to unregister input channel. " |
| 1123 | "Check logs for details."); |
| 1124 | } |
| 1125 | } |
| 1126 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1127 | static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz, |
| 1128 | jobject inputEventObj, jint injectorPid, jint injectorUid, |
| 1129 | jint syncMode, jint timeoutMillis) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1130 | if (checkInputManagerUnitialized(env)) { |
| 1131 | return INPUT_EVENT_INJECTION_FAILED; |
| 1132 | } |
| 1133 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1134 | if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) { |
| 1135 | KeyEvent keyEvent; |
| 1136 | android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1137 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1138 | return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent( |
| 1139 | & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1140 | } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) { |
| 1141 | MotionEvent motionEvent; |
| 1142 | android_view_MotionEvent_toNative(env, inputEventObj, & motionEvent); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1143 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1144 | return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent( |
| 1145 | & motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1146 | } else { |
| 1147 | jniThrowRuntimeException(env, "Invalid input event type."); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1148 | return INPUT_EVENT_INJECTION_FAILED; |
| 1149 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1152 | static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz, |
| 1153 | jobjectArray windowObjArray) { |
| 1154 | if (checkInputManagerUnitialized(env)) { |
| 1155 | return; |
| 1156 | } |
| 1157 | |
| 1158 | gNativeInputManager->setInputWindows(env, windowObjArray); |
| 1159 | } |
| 1160 | |
| 1161 | static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz, |
| 1162 | jobject applicationObj) { |
| 1163 | if (checkInputManagerUnitialized(env)) { |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | gNativeInputManager->setFocusedApplication(env, applicationObj); |
| 1168 | } |
| 1169 | |
| 1170 | static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env, |
| 1171 | jclass clazz, jboolean enabled, jboolean frozen) { |
| 1172 | if (checkInputManagerUnitialized(env)) { |
| 1173 | return; |
| 1174 | } |
| 1175 | |
| 1176 | gNativeInputManager->setInputDispatchMode(enabled, frozen); |
| 1177 | } |
| 1178 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1179 | static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env, |
| 1180 | jclass clazz, jint deviceId) { |
| 1181 | if (checkInputManagerUnitialized(env)) { |
| 1182 | return NULL; |
| 1183 | } |
| 1184 | |
| 1185 | InputDeviceInfo deviceInfo; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1186 | status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo( |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1187 | deviceId, & deviceInfo); |
| 1188 | if (status) { |
| 1189 | return NULL; |
| 1190 | } |
| 1191 | |
| 1192 | jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor); |
| 1193 | if (! deviceObj) { |
| 1194 | return NULL; |
| 1195 | } |
| 1196 | |
| 1197 | jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string()); |
| 1198 | if (! deviceNameObj) { |
| 1199 | return NULL; |
| 1200 | } |
| 1201 | |
| 1202 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId()); |
| 1203 | env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj); |
| 1204 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources()); |
| 1205 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType()); |
| 1206 | |
| 1207 | const KeyedVector<int, InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges(); |
| 1208 | for (size_t i = 0; i < ranges.size(); i++) { |
| 1209 | int rangeType = ranges.keyAt(i); |
| 1210 | const InputDeviceInfo::MotionRange& range = ranges.valueAt(i); |
| 1211 | env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange, |
| 1212 | rangeType, range.min, range.max, range.flat, range.fuzz); |
| 1213 | if (env->ExceptionCheck()) { |
| 1214 | return NULL; |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | return deviceObj; |
| 1219 | } |
| 1220 | |
| 1221 | static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env, |
| 1222 | jclass clazz) { |
| 1223 | if (checkInputManagerUnitialized(env)) { |
| 1224 | return NULL; |
| 1225 | } |
| 1226 | |
| 1227 | Vector<int> deviceIds; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1228 | gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1229 | |
| 1230 | jintArray deviceIdsObj = env->NewIntArray(deviceIds.size()); |
| 1231 | if (! deviceIdsObj) { |
| 1232 | return NULL; |
| 1233 | } |
| 1234 | |
| 1235 | env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array()); |
| 1236 | return deviceIdsObj; |
| 1237 | } |
| 1238 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1239 | static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env, |
| 1240 | jclass clazz, jobject configObj) { |
| 1241 | if (checkInputManagerUnitialized(env)) { |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | InputConfiguration config; |
| 1246 | gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config); |
| 1247 | |
| 1248 | env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen); |
| 1249 | env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard); |
| 1250 | env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation); |
| 1251 | } |
| 1252 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1253 | static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) { |
| 1254 | if (checkInputManagerUnitialized(env)) { |
| 1255 | return NULL; |
| 1256 | } |
| 1257 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1258 | String8 dump; |
| 1259 | gNativeInputManager->dump(dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1260 | return env->NewStringUTF(dump.string()); |
| 1261 | } |
| 1262 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1263 | // ---------------------------------------------------------------------------- |
| 1264 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1265 | static JNINativeMethod gInputManagerMethods[] = { |
| 1266 | /* name, signature, funcPtr */ |
| 1267 | { "nativeInit", "(Lcom/android/server/InputManager$Callbacks;)V", |
| 1268 | (void*) android_server_InputManager_nativeInit }, |
| 1269 | { "nativeStart", "()V", |
| 1270 | (void*) android_server_InputManager_nativeStart }, |
| 1271 | { "nativeSetDisplaySize", "(III)V", |
| 1272 | (void*) android_server_InputManager_nativeSetDisplaySize }, |
| 1273 | { "nativeSetDisplayOrientation", "(II)V", |
| 1274 | (void*) android_server_InputManager_nativeSetDisplayOrientation }, |
| 1275 | { "nativeGetScanCodeState", "(III)I", |
| 1276 | (void*) android_server_InputManager_nativeGetScanCodeState }, |
| 1277 | { "nativeGetKeyCodeState", "(III)I", |
| 1278 | (void*) android_server_InputManager_nativeGetKeyCodeState }, |
| 1279 | { "nativeGetSwitchState", "(III)I", |
| 1280 | (void*) android_server_InputManager_nativeGetSwitchState }, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1281 | { "nativeHasKeys", "(II[I[Z)Z", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1282 | (void*) android_server_InputManager_nativeHasKeys }, |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1283 | { "nativeRegisterInputChannel", "(Landroid/view/InputChannel;Z)V", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1284 | (void*) android_server_InputManager_nativeRegisterInputChannel }, |
| 1285 | { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V", |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1286 | (void*) android_server_InputManager_nativeUnregisterInputChannel }, |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1287 | { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIII)I", |
| 1288 | (void*) android_server_InputManager_nativeInjectInputEvent }, |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1289 | { "nativeSetInputWindows", "([Lcom/android/server/InputWindow;)V", |
| 1290 | (void*) android_server_InputManager_nativeSetInputWindows }, |
| 1291 | { "nativeSetFocusedApplication", "(Lcom/android/server/InputApplication;)V", |
| 1292 | (void*) android_server_InputManager_nativeSetFocusedApplication }, |
| 1293 | { "nativeSetInputDispatchMode", "(ZZ)V", |
| 1294 | (void*) android_server_InputManager_nativeSetInputDispatchMode }, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1295 | { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;", |
| 1296 | (void*) android_server_InputManager_nativeGetInputDevice }, |
| 1297 | { "nativeGetInputDeviceIds", "()[I", |
| 1298 | (void*) android_server_InputManager_nativeGetInputDeviceIds }, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1299 | { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V", |
| 1300 | (void*) android_server_InputManager_nativeGetInputConfiguration }, |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1301 | { "nativeDump", "()Ljava/lang/String;", |
| 1302 | (void*) android_server_InputManager_nativeDump }, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1303 | }; |
| 1304 | |
| 1305 | #define FIND_CLASS(var, className) \ |
| 1306 | var = env->FindClass(className); \ |
| 1307 | LOG_FATAL_IF(! var, "Unable to find class " className); \ |
| 1308 | var = jclass(env->NewGlobalRef(var)); |
| 1309 | |
| 1310 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1311 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 1312 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 1313 | |
| 1314 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 1315 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 1316 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 1317 | |
| 1318 | int register_android_server_InputManager(JNIEnv* env) { |
| 1319 | int res = jniRegisterNativeMethods(env, "com/android/server/InputManager", |
| 1320 | gInputManagerMethods, NELEM(gInputManagerMethods)); |
| 1321 | LOG_FATAL_IF(res < 0, "Unable to register native methods."); |
| 1322 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1323 | // Callbacks |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1324 | |
| 1325 | FIND_CLASS(gCallbacksClassInfo.clazz, "com/android/server/InputManager$Callbacks"); |
| 1326 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1327 | GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, gCallbacksClassInfo.clazz, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1328 | "notifyConfigurationChanged", "(J)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1329 | |
| 1330 | GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, gCallbacksClassInfo.clazz, |
| 1331 | "notifyLidSwitchChanged", "(JZ)V"); |
| 1332 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1333 | GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, gCallbacksClassInfo.clazz, |
| 1334 | "notifyInputChannelBroken", "(Landroid/view/InputChannel;)V"); |
| 1335 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1336 | GET_METHOD_ID(gCallbacksClassInfo.notifyANR, gCallbacksClassInfo.clazz, |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1337 | "notifyANR", "(Ljava/lang/Object;Landroid/view/InputChannel;)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1338 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1339 | GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, gCallbacksClassInfo.clazz, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1340 | "interceptKeyBeforeQueueing", "(JIZIZ)I"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1341 | |
| 1342 | GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, gCallbacksClassInfo.clazz, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1343 | "interceptKeyBeforeDispatching", "(Landroid/view/InputChannel;IIIIII)Z"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1344 | |
| 1345 | GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, gCallbacksClassInfo.clazz, |
| 1346 | "checkInjectEventsPermission", "(II)Z"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1347 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1348 | GET_METHOD_ID(gCallbacksClassInfo.filterTouchEvents, gCallbacksClassInfo.clazz, |
| 1349 | "filterTouchEvents", "()Z"); |
| 1350 | |
| 1351 | GET_METHOD_ID(gCallbacksClassInfo.filterJumpyTouchEvents, gCallbacksClassInfo.clazz, |
| 1352 | "filterJumpyTouchEvents", "()Z"); |
| 1353 | |
| 1354 | GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyDefinitions, gCallbacksClassInfo.clazz, |
| 1355 | "getVirtualKeyDefinitions", |
| 1356 | "(Ljava/lang/String;)[Lcom/android/server/InputManager$VirtualKeyDefinition;"); |
| 1357 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1358 | GET_METHOD_ID(gCallbacksClassInfo.getInputDeviceCalibration, gCallbacksClassInfo.clazz, |
| 1359 | "getInputDeviceCalibration", |
| 1360 | "(Ljava/lang/String;)Lcom/android/server/InputManager$InputDeviceCalibration;"); |
| 1361 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1362 | GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz, |
| 1363 | "getExcludedDeviceNames", "()[Ljava/lang/String;"); |
| 1364 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 1365 | GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz, |
| 1366 | "getMaxEventsPerSecond", "()I"); |
| 1367 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1368 | // VirtualKeyDefinition |
| 1369 | |
| 1370 | FIND_CLASS(gVirtualKeyDefinitionClassInfo.clazz, |
| 1371 | "com/android/server/InputManager$VirtualKeyDefinition"); |
| 1372 | |
| 1373 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.scanCode, gVirtualKeyDefinitionClassInfo.clazz, |
| 1374 | "scanCode", "I"); |
| 1375 | |
| 1376 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.centerX, gVirtualKeyDefinitionClassInfo.clazz, |
| 1377 | "centerX", "I"); |
| 1378 | |
| 1379 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.centerY, gVirtualKeyDefinitionClassInfo.clazz, |
| 1380 | "centerY", "I"); |
| 1381 | |
| 1382 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.width, gVirtualKeyDefinitionClassInfo.clazz, |
| 1383 | "width", "I"); |
| 1384 | |
| 1385 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.height, gVirtualKeyDefinitionClassInfo.clazz, |
| 1386 | "height", "I"); |
| 1387 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1388 | // InputDeviceCalibration |
| 1389 | |
| 1390 | FIND_CLASS(gInputDeviceCalibrationClassInfo.clazz, |
| 1391 | "com/android/server/InputManager$InputDeviceCalibration"); |
| 1392 | |
| 1393 | GET_FIELD_ID(gInputDeviceCalibrationClassInfo.keys, gInputDeviceCalibrationClassInfo.clazz, |
| 1394 | "keys", "[Ljava/lang/String;"); |
| 1395 | |
| 1396 | GET_FIELD_ID(gInputDeviceCalibrationClassInfo.values, gInputDeviceCalibrationClassInfo.clazz, |
| 1397 | "values", "[Ljava/lang/String;"); |
| 1398 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1399 | // InputWindow |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1400 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1401 | FIND_CLASS(gInputWindowClassInfo.clazz, "com/android/server/InputWindow"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1402 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1403 | GET_FIELD_ID(gInputWindowClassInfo.inputChannel, gInputWindowClassInfo.clazz, |
| 1404 | "inputChannel", "Landroid/view/InputChannel;"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1405 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1406 | GET_FIELD_ID(gInputWindowClassInfo.name, gInputWindowClassInfo.clazz, |
| 1407 | "name", "Ljava/lang/String;"); |
| 1408 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1409 | GET_FIELD_ID(gInputWindowClassInfo.layoutParamsFlags, gInputWindowClassInfo.clazz, |
| 1410 | "layoutParamsFlags", "I"); |
| 1411 | |
| 1412 | GET_FIELD_ID(gInputWindowClassInfo.layoutParamsType, gInputWindowClassInfo.clazz, |
| 1413 | "layoutParamsType", "I"); |
| 1414 | |
| 1415 | GET_FIELD_ID(gInputWindowClassInfo.dispatchingTimeoutNanos, gInputWindowClassInfo.clazz, |
| 1416 | "dispatchingTimeoutNanos", "J"); |
| 1417 | |
| 1418 | GET_FIELD_ID(gInputWindowClassInfo.frameLeft, gInputWindowClassInfo.clazz, |
| 1419 | "frameLeft", "I"); |
| 1420 | |
| 1421 | GET_FIELD_ID(gInputWindowClassInfo.frameTop, gInputWindowClassInfo.clazz, |
| 1422 | "frameTop", "I"); |
| 1423 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1424 | GET_FIELD_ID(gInputWindowClassInfo.frameRight, gInputWindowClassInfo.clazz, |
| 1425 | "frameRight", "I"); |
| 1426 | |
| 1427 | GET_FIELD_ID(gInputWindowClassInfo.frameBottom, gInputWindowClassInfo.clazz, |
| 1428 | "frameBottom", "I"); |
| 1429 | |
| 1430 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameLeft, gInputWindowClassInfo.clazz, |
| 1431 | "visibleFrameLeft", "I"); |
| 1432 | |
| 1433 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameTop, gInputWindowClassInfo.clazz, |
| 1434 | "visibleFrameTop", "I"); |
| 1435 | |
| 1436 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameRight, gInputWindowClassInfo.clazz, |
| 1437 | "visibleFrameRight", "I"); |
| 1438 | |
| 1439 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameBottom, gInputWindowClassInfo.clazz, |
| 1440 | "visibleFrameBottom", "I"); |
| 1441 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1442 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaLeft, gInputWindowClassInfo.clazz, |
| 1443 | "touchableAreaLeft", "I"); |
| 1444 | |
| 1445 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaTop, gInputWindowClassInfo.clazz, |
| 1446 | "touchableAreaTop", "I"); |
| 1447 | |
| 1448 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaRight, gInputWindowClassInfo.clazz, |
| 1449 | "touchableAreaRight", "I"); |
| 1450 | |
| 1451 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaBottom, gInputWindowClassInfo.clazz, |
| 1452 | "touchableAreaBottom", "I"); |
| 1453 | |
| 1454 | GET_FIELD_ID(gInputWindowClassInfo.visible, gInputWindowClassInfo.clazz, |
| 1455 | "visible", "Z"); |
| 1456 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1457 | GET_FIELD_ID(gInputWindowClassInfo.canReceiveKeys, gInputWindowClassInfo.clazz, |
| 1458 | "canReceiveKeys", "Z"); |
| 1459 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1460 | GET_FIELD_ID(gInputWindowClassInfo.hasFocus, gInputWindowClassInfo.clazz, |
| 1461 | "hasFocus", "Z"); |
| 1462 | |
| 1463 | GET_FIELD_ID(gInputWindowClassInfo.hasWallpaper, gInputWindowClassInfo.clazz, |
| 1464 | "hasWallpaper", "Z"); |
| 1465 | |
| 1466 | GET_FIELD_ID(gInputWindowClassInfo.paused, gInputWindowClassInfo.clazz, |
| 1467 | "paused", "Z"); |
| 1468 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1469 | GET_FIELD_ID(gInputWindowClassInfo.layer, gInputWindowClassInfo.clazz, |
| 1470 | "layer", "I"); |
| 1471 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1472 | GET_FIELD_ID(gInputWindowClassInfo.ownerPid, gInputWindowClassInfo.clazz, |
| 1473 | "ownerPid", "I"); |
| 1474 | |
| 1475 | GET_FIELD_ID(gInputWindowClassInfo.ownerUid, gInputWindowClassInfo.clazz, |
| 1476 | "ownerUid", "I"); |
| 1477 | |
| 1478 | // InputApplication |
| 1479 | |
| 1480 | FIND_CLASS(gInputApplicationClassInfo.clazz, "com/android/server/InputApplication"); |
| 1481 | |
| 1482 | GET_FIELD_ID(gInputApplicationClassInfo.name, gInputApplicationClassInfo.clazz, |
| 1483 | "name", "Ljava/lang/String;"); |
| 1484 | |
| 1485 | GET_FIELD_ID(gInputApplicationClassInfo.dispatchingTimeoutNanos, |
| 1486 | gInputApplicationClassInfo.clazz, |
| 1487 | "dispatchingTimeoutNanos", "J"); |
| 1488 | |
| 1489 | GET_FIELD_ID(gInputApplicationClassInfo.token, gInputApplicationClassInfo.clazz, |
| 1490 | "token", "Ljava/lang/Object;"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1491 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1492 | // KeyEvent |
| 1493 | |
| 1494 | FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent"); |
| 1495 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1496 | // MotionEvent |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1497 | |
| 1498 | FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent"); |
| 1499 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1500 | // InputDevice |
| 1501 | |
| 1502 | FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice"); |
| 1503 | |
| 1504 | GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz, |
| 1505 | "<init>", "()V"); |
| 1506 | |
| 1507 | GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz, |
| 1508 | "addMotionRange", "(IFFFF)V"); |
| 1509 | |
| 1510 | GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz, |
| 1511 | "mId", "I"); |
| 1512 | |
| 1513 | GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz, |
| 1514 | "mName", "Ljava/lang/String;"); |
| 1515 | |
| 1516 | GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz, |
| 1517 | "mSources", "I"); |
| 1518 | |
| 1519 | GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz, |
| 1520 | "mKeyboardType", "I"); |
| 1521 | |
| 1522 | GET_FIELD_ID(gInputDeviceClassInfo.mMotionRanges, gInputDeviceClassInfo.clazz, |
| 1523 | "mMotionRanges", "[Landroid/view/InputDevice$MotionRange;"); |
| 1524 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 1525 | // Configuration |
| 1526 | |
| 1527 | FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration"); |
| 1528 | |
| 1529 | GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz, |
| 1530 | "touchscreen", "I"); |
| 1531 | |
| 1532 | GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz, |
| 1533 | "keyboard", "I"); |
| 1534 | |
| 1535 | GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz, |
| 1536 | "navigation", "I"); |
| 1537 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1538 | return 0; |
| 1539 | } |
| 1540 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1541 | } /* namespace android */ |