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