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); |
| 210 | virtual void pokeUserActivity(nsecs_t eventTime, int32_t windowType, int32_t eventType); |
| 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 | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 976 | void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t windowType, int32_t eventType) { |
| 977 | if (windowType != InputWindow::TYPE_KEYGUARD) { |
| 978 | android_server_PowerManagerService_userActivity(eventTime, eventType); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 982 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 983 | bool NativeInputManager::checkInjectEventsPermissionNonReentrant( |
| 984 | int32_t injectorPid, int32_t injectorUid) { |
| 985 | JNIEnv* env = jniEnv(); |
| 986 | jboolean result = env->CallBooleanMethod(mCallbacksObj, |
| 987 | gCallbacksClassInfo.checkInjectEventsPermission, injectorPid, injectorUid); |
| 988 | checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 989 | return result; |
| 990 | } |
| 991 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 992 | // ---------------------------------------------------------------------------- |
| 993 | |
| 994 | static sp<NativeInputManager> gNativeInputManager; |
| 995 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 996 | static bool checkInputManagerUnitialized(JNIEnv* env) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 997 | if (gNativeInputManager == NULL) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 998 | LOGE("Input manager not initialized."); |
| 999 | jniThrowRuntimeException(env, "Input manager not initialized."); |
| 1000 | return true; |
| 1001 | } |
| 1002 | return false; |
| 1003 | } |
| 1004 | |
| 1005 | static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz, |
| 1006 | jobject callbacks) { |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1007 | if (gNativeInputManager == NULL) { |
| 1008 | gNativeInputManager = new NativeInputManager(callbacks); |
| 1009 | } else { |
| 1010 | LOGE("Input manager already initialized."); |
| 1011 | jniThrowRuntimeException(env, "Input manager already initialized."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) { |
| 1016 | if (checkInputManagerUnitialized(env)) { |
| 1017 | return; |
| 1018 | } |
| 1019 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1020 | status_t result = gNativeInputManager->getInputManager()->start(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1021 | if (result) { |
| 1022 | jniThrowRuntimeException(env, "Input manager could not be started."); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | static void android_server_InputManager_nativeSetDisplaySize(JNIEnv* env, jclass clazz, |
| 1027 | jint displayId, jint width, jint height) { |
| 1028 | if (checkInputManagerUnitialized(env)) { |
| 1029 | return; |
| 1030 | } |
| 1031 | |
| 1032 | // XXX we could get this from the SurfaceFlinger directly instead of requiring it |
| 1033 | // to be passed in like this, not sure which is better but leaving it like this |
| 1034 | // keeps the window manager in direct control of when display transitions propagate down |
| 1035 | // to the input dispatcher |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1036 | gNativeInputManager->setDisplaySize(displayId, width, height); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | static void android_server_InputManager_nativeSetDisplayOrientation(JNIEnv* env, jclass clazz, |
| 1040 | jint displayId, jint orientation) { |
| 1041 | if (checkInputManagerUnitialized(env)) { |
| 1042 | return; |
| 1043 | } |
| 1044 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1045 | gNativeInputManager->setDisplayOrientation(displayId, orientation); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static jint android_server_InputManager_nativeGetScanCodeState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1049 | jint deviceId, jint sourceMask, jint scanCode) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1050 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1051 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1054 | return gNativeInputManager->getInputManager()->getReader()->getScanCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1055 | deviceId, uint32_t(sourceMask), scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static jint android_server_InputManager_nativeGetKeyCodeState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1059 | jint deviceId, jint sourceMask, jint keyCode) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1060 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1061 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1064 | return gNativeInputManager->getInputManager()->getReader()->getKeyCodeState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1065 | deviceId, uint32_t(sourceMask), keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static jint android_server_InputManager_nativeGetSwitchState(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1069 | jint deviceId, jint sourceMask, jint sw) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1070 | if (checkInputManagerUnitialized(env)) { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1071 | return AKEY_STATE_UNKNOWN; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1074 | return gNativeInputManager->getInputManager()->getReader()->getSwitchState( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1075 | deviceId, uint32_t(sourceMask), sw); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | static jboolean android_server_InputManager_nativeHasKeys(JNIEnv* env, jclass clazz, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1079 | jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1080 | if (checkInputManagerUnitialized(env)) { |
| 1081 | return JNI_FALSE; |
| 1082 | } |
| 1083 | |
| 1084 | int32_t* codes = env->GetIntArrayElements(keyCodes, NULL); |
| 1085 | uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL); |
| 1086 | jsize numCodes = env->GetArrayLength(keyCodes); |
| 1087 | jboolean result; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1088 | if (numCodes == env->GetArrayLength(keyCodes)) { |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1089 | result = gNativeInputManager->getInputManager()->getReader()->hasKeys( |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1090 | deviceId, uint32_t(sourceMask), numCodes, codes, flags); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1091 | } else { |
| 1092 | result = JNI_FALSE; |
| 1093 | } |
| 1094 | |
| 1095 | env->ReleaseBooleanArrayElements(outFlags, flags, 0); |
| 1096 | env->ReleaseIntArrayElements(keyCodes, codes, 0); |
| 1097 | return result; |
| 1098 | } |
| 1099 | |
| 1100 | static void throwInputChannelNotInitialized(JNIEnv* env) { |
| 1101 | jniThrowException(env, "java/lang/IllegalStateException", |
| 1102 | "inputChannel is not initialized"); |
| 1103 | } |
| 1104 | |
| 1105 | static void android_server_InputManager_handleInputChannelDisposed(JNIEnv* env, |
| 1106 | jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) { |
| 1107 | LOGW("Input channel object '%s' was disposed without first being unregistered with " |
| 1108 | "the input manager!", inputChannel->getName().string()); |
| 1109 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1110 | if (gNativeInputManager != NULL) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1111 | gNativeInputManager->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1112 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | static void android_server_InputManager_nativeRegisterInputChannel(JNIEnv* env, jclass clazz, |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1116 | jobject inputChannelObj, jboolean monitor) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1117 | if (checkInputManagerUnitialized(env)) { |
| 1118 | return; |
| 1119 | } |
| 1120 | |
| 1121 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1122 | inputChannelObj); |
| 1123 | if (inputChannel == NULL) { |
| 1124 | throwInputChannelNotInitialized(env); |
| 1125 | return; |
| 1126 | } |
| 1127 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1128 | |
| 1129 | status_t status = gNativeInputManager->registerInputChannel( |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1130 | env, inputChannel, inputChannelObj, monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1131 | if (status) { |
| 1132 | jniThrowRuntimeException(env, "Failed to register input channel. " |
| 1133 | "Check logs for details."); |
| 1134 | return; |
| 1135 | } |
| 1136 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1137 | if (! monitor) { |
| 1138 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, |
| 1139 | android_server_InputManager_handleInputChannelDisposed, NULL); |
| 1140 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | static void android_server_InputManager_nativeUnregisterInputChannel(JNIEnv* env, jclass clazz, |
| 1144 | jobject inputChannelObj) { |
| 1145 | if (checkInputManagerUnitialized(env)) { |
| 1146 | return; |
| 1147 | } |
| 1148 | |
| 1149 | sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, |
| 1150 | inputChannelObj); |
| 1151 | if (inputChannel == NULL) { |
| 1152 | throwInputChannelNotInitialized(env); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL); |
| 1157 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1158 | status_t status = gNativeInputManager->unregisterInputChannel(env, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1159 | if (status) { |
| 1160 | jniThrowRuntimeException(env, "Failed to unregister input channel. " |
| 1161 | "Check logs for details."); |
| 1162 | } |
| 1163 | } |
| 1164 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1165 | static jint android_server_InputManager_nativeInjectInputEvent(JNIEnv* env, jclass clazz, |
| 1166 | jobject inputEventObj, jint injectorPid, jint injectorUid, |
| 1167 | jint syncMode, jint timeoutMillis) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1168 | if (checkInputManagerUnitialized(env)) { |
| 1169 | return INPUT_EVENT_INJECTION_FAILED; |
| 1170 | } |
| 1171 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1172 | if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) { |
| 1173 | KeyEvent keyEvent; |
| 1174 | android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1175 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1176 | return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent( |
| 1177 | & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1178 | } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) { |
| 1179 | MotionEvent motionEvent; |
| 1180 | android_view_MotionEvent_toNative(env, inputEventObj, & motionEvent); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1181 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1182 | return gNativeInputManager->getInputManager()->getDispatcher()->injectInputEvent( |
| 1183 | & motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1184 | } else { |
| 1185 | jniThrowRuntimeException(env, "Invalid input event type."); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1186 | return INPUT_EVENT_INJECTION_FAILED; |
| 1187 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1190 | static void android_server_InputManager_nativeSetInputWindows(JNIEnv* env, jclass clazz, |
| 1191 | jobjectArray windowObjArray) { |
| 1192 | if (checkInputManagerUnitialized(env)) { |
| 1193 | return; |
| 1194 | } |
| 1195 | |
| 1196 | gNativeInputManager->setInputWindows(env, windowObjArray); |
| 1197 | } |
| 1198 | |
| 1199 | static void android_server_InputManager_nativeSetFocusedApplication(JNIEnv* env, jclass clazz, |
| 1200 | jobject applicationObj) { |
| 1201 | if (checkInputManagerUnitialized(env)) { |
| 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | gNativeInputManager->setFocusedApplication(env, applicationObj); |
| 1206 | } |
| 1207 | |
| 1208 | static void android_server_InputManager_nativeSetInputDispatchMode(JNIEnv* env, |
| 1209 | jclass clazz, jboolean enabled, jboolean frozen) { |
| 1210 | if (checkInputManagerUnitialized(env)) { |
| 1211 | return; |
| 1212 | } |
| 1213 | |
| 1214 | gNativeInputManager->setInputDispatchMode(enabled, frozen); |
| 1215 | } |
| 1216 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1217 | static jobject android_server_InputManager_nativeGetInputDevice(JNIEnv* env, |
| 1218 | jclass clazz, jint deviceId) { |
| 1219 | if (checkInputManagerUnitialized(env)) { |
| 1220 | return NULL; |
| 1221 | } |
| 1222 | |
| 1223 | InputDeviceInfo deviceInfo; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1224 | status_t status = gNativeInputManager->getInputManager()->getReader()->getInputDeviceInfo( |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1225 | deviceId, & deviceInfo); |
| 1226 | if (status) { |
| 1227 | return NULL; |
| 1228 | } |
| 1229 | |
| 1230 | jobject deviceObj = env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor); |
| 1231 | if (! deviceObj) { |
| 1232 | return NULL; |
| 1233 | } |
| 1234 | |
| 1235 | jstring deviceNameObj = env->NewStringUTF(deviceInfo.getName().string()); |
| 1236 | if (! deviceNameObj) { |
| 1237 | return NULL; |
| 1238 | } |
| 1239 | |
| 1240 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mId, deviceInfo.getId()); |
| 1241 | env->SetObjectField(deviceObj, gInputDeviceClassInfo.mName, deviceNameObj); |
| 1242 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mSources, deviceInfo.getSources()); |
| 1243 | env->SetIntField(deviceObj, gInputDeviceClassInfo.mKeyboardType, deviceInfo.getKeyboardType()); |
| 1244 | |
| 1245 | const KeyedVector<int, InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges(); |
| 1246 | for (size_t i = 0; i < ranges.size(); i++) { |
| 1247 | int rangeType = ranges.keyAt(i); |
| 1248 | const InputDeviceInfo::MotionRange& range = ranges.valueAt(i); |
| 1249 | env->CallVoidMethod(deviceObj, gInputDeviceClassInfo.addMotionRange, |
| 1250 | rangeType, range.min, range.max, range.flat, range.fuzz); |
| 1251 | if (env->ExceptionCheck()) { |
| 1252 | return NULL; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | return deviceObj; |
| 1257 | } |
| 1258 | |
| 1259 | static jintArray android_server_InputManager_nativeGetInputDeviceIds(JNIEnv* env, |
| 1260 | jclass clazz) { |
| 1261 | if (checkInputManagerUnitialized(env)) { |
| 1262 | return NULL; |
| 1263 | } |
| 1264 | |
| 1265 | Vector<int> deviceIds; |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1266 | gNativeInputManager->getInputManager()->getReader()->getInputDeviceIds(deviceIds); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1267 | |
| 1268 | jintArray deviceIdsObj = env->NewIntArray(deviceIds.size()); |
| 1269 | if (! deviceIdsObj) { |
| 1270 | return NULL; |
| 1271 | } |
| 1272 | |
| 1273 | env->SetIntArrayRegion(deviceIdsObj, 0, deviceIds.size(), deviceIds.array()); |
| 1274 | return deviceIdsObj; |
| 1275 | } |
| 1276 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame^] | 1277 | static void android_server_InputManager_nativeGetInputConfiguration(JNIEnv* env, |
| 1278 | jclass clazz, jobject configObj) { |
| 1279 | if (checkInputManagerUnitialized(env)) { |
| 1280 | return; |
| 1281 | } |
| 1282 | |
| 1283 | InputConfiguration config; |
| 1284 | gNativeInputManager->getInputManager()->getReader()->getInputConfiguration(& config); |
| 1285 | |
| 1286 | env->SetIntField(configObj, gConfigurationClassInfo.touchscreen, config.touchScreen); |
| 1287 | env->SetIntField(configObj, gConfigurationClassInfo.keyboard, config.keyboard); |
| 1288 | env->SetIntField(configObj, gConfigurationClassInfo.navigation, config.navigation); |
| 1289 | } |
| 1290 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1291 | static jstring android_server_InputManager_nativeDump(JNIEnv* env, jclass clazz) { |
| 1292 | if (checkInputManagerUnitialized(env)) { |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1296 | String8 dump; |
| 1297 | gNativeInputManager->dump(dump); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1298 | return env->NewStringUTF(dump.string()); |
| 1299 | } |
| 1300 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1301 | // ---------------------------------------------------------------------------- |
| 1302 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1303 | static JNINativeMethod gInputManagerMethods[] = { |
| 1304 | /* name, signature, funcPtr */ |
| 1305 | { "nativeInit", "(Lcom/android/server/InputManager$Callbacks;)V", |
| 1306 | (void*) android_server_InputManager_nativeInit }, |
| 1307 | { "nativeStart", "()V", |
| 1308 | (void*) android_server_InputManager_nativeStart }, |
| 1309 | { "nativeSetDisplaySize", "(III)V", |
| 1310 | (void*) android_server_InputManager_nativeSetDisplaySize }, |
| 1311 | { "nativeSetDisplayOrientation", "(II)V", |
| 1312 | (void*) android_server_InputManager_nativeSetDisplayOrientation }, |
| 1313 | { "nativeGetScanCodeState", "(III)I", |
| 1314 | (void*) android_server_InputManager_nativeGetScanCodeState }, |
| 1315 | { "nativeGetKeyCodeState", "(III)I", |
| 1316 | (void*) android_server_InputManager_nativeGetKeyCodeState }, |
| 1317 | { "nativeGetSwitchState", "(III)I", |
| 1318 | (void*) android_server_InputManager_nativeGetSwitchState }, |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1319 | { "nativeHasKeys", "(II[I[Z)Z", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1320 | (void*) android_server_InputManager_nativeHasKeys }, |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 1321 | { "nativeRegisterInputChannel", "(Landroid/view/InputChannel;Z)V", |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1322 | (void*) android_server_InputManager_nativeRegisterInputChannel }, |
| 1323 | { "nativeUnregisterInputChannel", "(Landroid/view/InputChannel;)V", |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1324 | (void*) android_server_InputManager_nativeUnregisterInputChannel }, |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1325 | { "nativeInjectInputEvent", "(Landroid/view/InputEvent;IIII)I", |
| 1326 | (void*) android_server_InputManager_nativeInjectInputEvent }, |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1327 | { "nativeSetInputWindows", "([Lcom/android/server/InputWindow;)V", |
| 1328 | (void*) android_server_InputManager_nativeSetInputWindows }, |
| 1329 | { "nativeSetFocusedApplication", "(Lcom/android/server/InputApplication;)V", |
| 1330 | (void*) android_server_InputManager_nativeSetFocusedApplication }, |
| 1331 | { "nativeSetInputDispatchMode", "(ZZ)V", |
| 1332 | (void*) android_server_InputManager_nativeSetInputDispatchMode }, |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1333 | { "nativeGetInputDevice", "(I)Landroid/view/InputDevice;", |
| 1334 | (void*) android_server_InputManager_nativeGetInputDevice }, |
| 1335 | { "nativeGetInputDeviceIds", "()[I", |
| 1336 | (void*) android_server_InputManager_nativeGetInputDeviceIds }, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame^] | 1337 | { "nativeGetInputConfiguration", "(Landroid/content/res/Configuration;)V", |
| 1338 | (void*) android_server_InputManager_nativeGetInputConfiguration }, |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1339 | { "nativeDump", "()Ljava/lang/String;", |
| 1340 | (void*) android_server_InputManager_nativeDump }, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1341 | }; |
| 1342 | |
| 1343 | #define FIND_CLASS(var, className) \ |
| 1344 | var = env->FindClass(className); \ |
| 1345 | LOG_FATAL_IF(! var, "Unable to find class " className); \ |
| 1346 | var = jclass(env->NewGlobalRef(var)); |
| 1347 | |
| 1348 | #define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \ |
| 1349 | var = env->GetMethodID(clazz, methodName, methodDescriptor); \ |
| 1350 | LOG_FATAL_IF(! var, "Unable to find method " methodName); |
| 1351 | |
| 1352 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 1353 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 1354 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 1355 | |
| 1356 | int register_android_server_InputManager(JNIEnv* env) { |
| 1357 | int res = jniRegisterNativeMethods(env, "com/android/server/InputManager", |
| 1358 | gInputManagerMethods, NELEM(gInputManagerMethods)); |
| 1359 | LOG_FATAL_IF(res < 0, "Unable to register native methods."); |
| 1360 | |
Jeff Brown | 9c3cda0 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 1361 | // Callbacks |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1362 | |
| 1363 | FIND_CLASS(gCallbacksClassInfo.clazz, "com/android/server/InputManager$Callbacks"); |
| 1364 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1365 | GET_METHOD_ID(gCallbacksClassInfo.notifyConfigurationChanged, gCallbacksClassInfo.clazz, |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame^] | 1366 | "notifyConfigurationChanged", "(J)V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1367 | |
| 1368 | GET_METHOD_ID(gCallbacksClassInfo.notifyLidSwitchChanged, gCallbacksClassInfo.clazz, |
| 1369 | "notifyLidSwitchChanged", "(JZ)V"); |
| 1370 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1371 | GET_METHOD_ID(gCallbacksClassInfo.notifyInputChannelBroken, gCallbacksClassInfo.clazz, |
| 1372 | "notifyInputChannelBroken", "(Landroid/view/InputChannel;)V"); |
| 1373 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1374 | GET_METHOD_ID(gCallbacksClassInfo.notifyANR, gCallbacksClassInfo.clazz, |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1375 | "notifyANR", "(Ljava/lang/Object;Landroid/view/InputChannel;)J"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1376 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1377 | GET_METHOD_ID(gCallbacksClassInfo.virtualKeyDownFeedback, gCallbacksClassInfo.clazz, |
| 1378 | "virtualKeyDownFeedback", "()V"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1379 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1380 | GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeQueueing, gCallbacksClassInfo.clazz, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1381 | "interceptKeyBeforeQueueing", "(JIZIZ)I"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1382 | |
| 1383 | GET_METHOD_ID(gCallbacksClassInfo.interceptKeyBeforeDispatching, gCallbacksClassInfo.clazz, |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1384 | "interceptKeyBeforeDispatching", "(Landroid/view/InputChannel;IIIIII)Z"); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1385 | |
| 1386 | GET_METHOD_ID(gCallbacksClassInfo.checkInjectEventsPermission, gCallbacksClassInfo.clazz, |
| 1387 | "checkInjectEventsPermission", "(II)Z"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1388 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1389 | GET_METHOD_ID(gCallbacksClassInfo.filterTouchEvents, gCallbacksClassInfo.clazz, |
| 1390 | "filterTouchEvents", "()Z"); |
| 1391 | |
| 1392 | GET_METHOD_ID(gCallbacksClassInfo.filterJumpyTouchEvents, gCallbacksClassInfo.clazz, |
| 1393 | "filterJumpyTouchEvents", "()Z"); |
| 1394 | |
| 1395 | GET_METHOD_ID(gCallbacksClassInfo.getVirtualKeyDefinitions, gCallbacksClassInfo.clazz, |
| 1396 | "getVirtualKeyDefinitions", |
| 1397 | "(Ljava/lang/String;)[Lcom/android/server/InputManager$VirtualKeyDefinition;"); |
| 1398 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1399 | GET_METHOD_ID(gCallbacksClassInfo.getInputDeviceCalibration, gCallbacksClassInfo.clazz, |
| 1400 | "getInputDeviceCalibration", |
| 1401 | "(Ljava/lang/String;)Lcom/android/server/InputManager$InputDeviceCalibration;"); |
| 1402 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1403 | GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz, |
| 1404 | "getExcludedDeviceNames", "()[Ljava/lang/String;"); |
| 1405 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 1406 | GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz, |
| 1407 | "getMaxEventsPerSecond", "()I"); |
| 1408 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1409 | // VirtualKeyDefinition |
| 1410 | |
| 1411 | FIND_CLASS(gVirtualKeyDefinitionClassInfo.clazz, |
| 1412 | "com/android/server/InputManager$VirtualKeyDefinition"); |
| 1413 | |
| 1414 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.scanCode, gVirtualKeyDefinitionClassInfo.clazz, |
| 1415 | "scanCode", "I"); |
| 1416 | |
| 1417 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.centerX, gVirtualKeyDefinitionClassInfo.clazz, |
| 1418 | "centerX", "I"); |
| 1419 | |
| 1420 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.centerY, gVirtualKeyDefinitionClassInfo.clazz, |
| 1421 | "centerY", "I"); |
| 1422 | |
| 1423 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.width, gVirtualKeyDefinitionClassInfo.clazz, |
| 1424 | "width", "I"); |
| 1425 | |
| 1426 | GET_FIELD_ID(gVirtualKeyDefinitionClassInfo.height, gVirtualKeyDefinitionClassInfo.clazz, |
| 1427 | "height", "I"); |
| 1428 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1429 | // InputDeviceCalibration |
| 1430 | |
| 1431 | FIND_CLASS(gInputDeviceCalibrationClassInfo.clazz, |
| 1432 | "com/android/server/InputManager$InputDeviceCalibration"); |
| 1433 | |
| 1434 | GET_FIELD_ID(gInputDeviceCalibrationClassInfo.keys, gInputDeviceCalibrationClassInfo.clazz, |
| 1435 | "keys", "[Ljava/lang/String;"); |
| 1436 | |
| 1437 | GET_FIELD_ID(gInputDeviceCalibrationClassInfo.values, gInputDeviceCalibrationClassInfo.clazz, |
| 1438 | "values", "[Ljava/lang/String;"); |
| 1439 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1440 | // InputWindow |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1441 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1442 | FIND_CLASS(gInputWindowClassInfo.clazz, "com/android/server/InputWindow"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1443 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1444 | GET_FIELD_ID(gInputWindowClassInfo.inputChannel, gInputWindowClassInfo.clazz, |
| 1445 | "inputChannel", "Landroid/view/InputChannel;"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1446 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1447 | GET_FIELD_ID(gInputWindowClassInfo.name, gInputWindowClassInfo.clazz, |
| 1448 | "name", "Ljava/lang/String;"); |
| 1449 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1450 | GET_FIELD_ID(gInputWindowClassInfo.layoutParamsFlags, gInputWindowClassInfo.clazz, |
| 1451 | "layoutParamsFlags", "I"); |
| 1452 | |
| 1453 | GET_FIELD_ID(gInputWindowClassInfo.layoutParamsType, gInputWindowClassInfo.clazz, |
| 1454 | "layoutParamsType", "I"); |
| 1455 | |
| 1456 | GET_FIELD_ID(gInputWindowClassInfo.dispatchingTimeoutNanos, gInputWindowClassInfo.clazz, |
| 1457 | "dispatchingTimeoutNanos", "J"); |
| 1458 | |
| 1459 | GET_FIELD_ID(gInputWindowClassInfo.frameLeft, gInputWindowClassInfo.clazz, |
| 1460 | "frameLeft", "I"); |
| 1461 | |
| 1462 | GET_FIELD_ID(gInputWindowClassInfo.frameTop, gInputWindowClassInfo.clazz, |
| 1463 | "frameTop", "I"); |
| 1464 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1465 | GET_FIELD_ID(gInputWindowClassInfo.frameRight, gInputWindowClassInfo.clazz, |
| 1466 | "frameRight", "I"); |
| 1467 | |
| 1468 | GET_FIELD_ID(gInputWindowClassInfo.frameBottom, gInputWindowClassInfo.clazz, |
| 1469 | "frameBottom", "I"); |
| 1470 | |
| 1471 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameLeft, gInputWindowClassInfo.clazz, |
| 1472 | "visibleFrameLeft", "I"); |
| 1473 | |
| 1474 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameTop, gInputWindowClassInfo.clazz, |
| 1475 | "visibleFrameTop", "I"); |
| 1476 | |
| 1477 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameRight, gInputWindowClassInfo.clazz, |
| 1478 | "visibleFrameRight", "I"); |
| 1479 | |
| 1480 | GET_FIELD_ID(gInputWindowClassInfo.visibleFrameBottom, gInputWindowClassInfo.clazz, |
| 1481 | "visibleFrameBottom", "I"); |
| 1482 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1483 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaLeft, gInputWindowClassInfo.clazz, |
| 1484 | "touchableAreaLeft", "I"); |
| 1485 | |
| 1486 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaTop, gInputWindowClassInfo.clazz, |
| 1487 | "touchableAreaTop", "I"); |
| 1488 | |
| 1489 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaRight, gInputWindowClassInfo.clazz, |
| 1490 | "touchableAreaRight", "I"); |
| 1491 | |
| 1492 | GET_FIELD_ID(gInputWindowClassInfo.touchableAreaBottom, gInputWindowClassInfo.clazz, |
| 1493 | "touchableAreaBottom", "I"); |
| 1494 | |
| 1495 | GET_FIELD_ID(gInputWindowClassInfo.visible, gInputWindowClassInfo.clazz, |
| 1496 | "visible", "Z"); |
| 1497 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1498 | GET_FIELD_ID(gInputWindowClassInfo.canReceiveKeys, gInputWindowClassInfo.clazz, |
| 1499 | "canReceiveKeys", "Z"); |
| 1500 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1501 | GET_FIELD_ID(gInputWindowClassInfo.hasFocus, gInputWindowClassInfo.clazz, |
| 1502 | "hasFocus", "Z"); |
| 1503 | |
| 1504 | GET_FIELD_ID(gInputWindowClassInfo.hasWallpaper, gInputWindowClassInfo.clazz, |
| 1505 | "hasWallpaper", "Z"); |
| 1506 | |
| 1507 | GET_FIELD_ID(gInputWindowClassInfo.paused, gInputWindowClassInfo.clazz, |
| 1508 | "paused", "Z"); |
| 1509 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 1510 | GET_FIELD_ID(gInputWindowClassInfo.layer, gInputWindowClassInfo.clazz, |
| 1511 | "layer", "I"); |
| 1512 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1513 | GET_FIELD_ID(gInputWindowClassInfo.ownerPid, gInputWindowClassInfo.clazz, |
| 1514 | "ownerPid", "I"); |
| 1515 | |
| 1516 | GET_FIELD_ID(gInputWindowClassInfo.ownerUid, gInputWindowClassInfo.clazz, |
| 1517 | "ownerUid", "I"); |
| 1518 | |
| 1519 | // InputApplication |
| 1520 | |
| 1521 | FIND_CLASS(gInputApplicationClassInfo.clazz, "com/android/server/InputApplication"); |
| 1522 | |
| 1523 | GET_FIELD_ID(gInputApplicationClassInfo.name, gInputApplicationClassInfo.clazz, |
| 1524 | "name", "Ljava/lang/String;"); |
| 1525 | |
| 1526 | GET_FIELD_ID(gInputApplicationClassInfo.dispatchingTimeoutNanos, |
| 1527 | gInputApplicationClassInfo.clazz, |
| 1528 | "dispatchingTimeoutNanos", "J"); |
| 1529 | |
| 1530 | GET_FIELD_ID(gInputApplicationClassInfo.token, gInputApplicationClassInfo.clazz, |
| 1531 | "token", "Ljava/lang/Object;"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 1532 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1533 | // KeyEvent |
| 1534 | |
| 1535 | FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent"); |
| 1536 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1537 | // MotionEvent |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1538 | |
| 1539 | FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent"); |
| 1540 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 1541 | // InputDevice |
| 1542 | |
| 1543 | FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice"); |
| 1544 | |
| 1545 | GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz, |
| 1546 | "<init>", "()V"); |
| 1547 | |
| 1548 | GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz, |
| 1549 | "addMotionRange", "(IFFFF)V"); |
| 1550 | |
| 1551 | GET_FIELD_ID(gInputDeviceClassInfo.mId, gInputDeviceClassInfo.clazz, |
| 1552 | "mId", "I"); |
| 1553 | |
| 1554 | GET_FIELD_ID(gInputDeviceClassInfo.mName, gInputDeviceClassInfo.clazz, |
| 1555 | "mName", "Ljava/lang/String;"); |
| 1556 | |
| 1557 | GET_FIELD_ID(gInputDeviceClassInfo.mSources, gInputDeviceClassInfo.clazz, |
| 1558 | "mSources", "I"); |
| 1559 | |
| 1560 | GET_FIELD_ID(gInputDeviceClassInfo.mKeyboardType, gInputDeviceClassInfo.clazz, |
| 1561 | "mKeyboardType", "I"); |
| 1562 | |
| 1563 | GET_FIELD_ID(gInputDeviceClassInfo.mMotionRanges, gInputDeviceClassInfo.clazz, |
| 1564 | "mMotionRanges", "[Landroid/view/InputDevice$MotionRange;"); |
| 1565 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame^] | 1566 | // Configuration |
| 1567 | |
| 1568 | FIND_CLASS(gConfigurationClassInfo.clazz, "android/content/res/Configuration"); |
| 1569 | |
| 1570 | GET_FIELD_ID(gConfigurationClassInfo.touchscreen, gConfigurationClassInfo.clazz, |
| 1571 | "touchscreen", "I"); |
| 1572 | |
| 1573 | GET_FIELD_ID(gConfigurationClassInfo.keyboard, gConfigurationClassInfo.clazz, |
| 1574 | "keyboard", "I"); |
| 1575 | |
| 1576 | GET_FIELD_ID(gConfigurationClassInfo.navigation, gConfigurationClassInfo.clazz, |
| 1577 | "navigation", "I"); |
| 1578 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1579 | return 0; |
| 1580 | } |
| 1581 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1582 | } /* namespace android */ |