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