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