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