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