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