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