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