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