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