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