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