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