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 | |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 18 | |
| 19 | import com.android.internal.util.XmlUtils; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 20 | |
| 21 | import org.xmlpull.v1.XmlPullParser; |
| 22 | |
| 23 | import android.content.Context; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 26 | import android.database.ContentObserver; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 27 | import android.os.Environment; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 28 | import android.os.Handler; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 29 | import android.os.Looper; |
| 30 | import android.os.MessageQueue; |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 31 | import android.os.SystemProperties; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 32 | import android.provider.Settings; |
| 33 | import android.provider.Settings.SettingNotFoundException; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 34 | import android.util.Slog; |
| 35 | import android.util.Xml; |
| 36 | import android.view.InputChannel; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 37 | import android.view.InputDevice; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 38 | import android.view.InputEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 39 | import android.view.KeyEvent; |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 40 | import android.view.PointerIcon; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 41 | import android.view.Surface; |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 42 | import android.view.ViewConfiguration; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 43 | import android.view.WindowManager; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 44 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 45 | import java.io.File; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 46 | import java.io.FileNotFoundException; |
| 47 | import java.io.FileReader; |
| 48 | import java.io.IOException; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 49 | import java.io.PrintWriter; |
| 50 | import java.util.ArrayList; |
| 51 | |
| 52 | /* |
| 53 | * Wraps the C++ InputManager and provides its callbacks. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 54 | */ |
| 55 | public class InputManager { |
| 56 | static final String TAG = "InputManager"; |
| 57 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 58 | private static final boolean DEBUG = false; |
| 59 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 60 | private final Callbacks mCallbacks; |
| 61 | private final Context mContext; |
| 62 | private final WindowManagerService mWindowManagerService; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 63 | |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 64 | private static native void nativeInit(Context context, |
| 65 | Callbacks callbacks, MessageQueue messageQueue); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 66 | private static native void nativeStart(); |
| 67 | private static native void nativeSetDisplaySize(int displayId, int width, int height); |
| 68 | private static native void nativeSetDisplayOrientation(int displayId, int rotation); |
| 69 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 70 | private static native int nativeGetScanCodeState(int deviceId, int sourceMask, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 71 | int scanCode); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 72 | private static native int nativeGetKeyCodeState(int deviceId, int sourceMask, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 73 | int keyCode); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 74 | private static native int nativeGetSwitchState(int deviceId, int sourceMask, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 75 | int sw); |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 76 | private static native boolean nativeHasKeys(int deviceId, int sourceMask, |
| 77 | int[] keyCodes, boolean[] keyExists); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 78 | private static native void nativeRegisterInputChannel(InputChannel inputChannel, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 79 | InputWindowHandle inputWindowHandle, boolean monitor); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 80 | private static native void nativeUnregisterInputChannel(InputChannel inputChannel); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 81 | private static native int nativeInjectInputEvent(InputEvent event, |
| 82 | int injectorPid, int injectorUid, int syncMode, int timeoutMillis); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 83 | private static native void nativeSetInputWindows(InputWindow[] windows); |
| 84 | private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 85 | private static native void nativeSetSystemUiVisibility(int visibility); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 86 | private static native void nativeSetFocusedApplication(InputApplication application); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 87 | private static native InputDevice nativeGetInputDevice(int deviceId); |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 88 | private static native void nativeGetInputConfiguration(Configuration configuration); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 89 | private static native int[] nativeGetInputDeviceIds(); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 90 | private static native boolean nativeTransferTouchFocus(InputChannel fromChannel, |
| 91 | InputChannel toChannel); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 92 | private static native void nativeSetPointerSpeed(int speed); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 93 | private static native String nativeDump(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 94 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 95 | // Input event injection constants defined in InputDispatcher.h. |
| 96 | static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0; |
| 97 | static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1; |
| 98 | static final int INPUT_EVENT_INJECTION_FAILED = 2; |
| 99 | static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3; |
| 100 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 101 | // Input event injection synchronization modes defined in InputDispatcher.h |
| 102 | static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0; |
| 103 | static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1; |
| 104 | static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2; |
| 105 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 106 | // Key states (may be returned by queries about the current state of a |
| 107 | // particular key code, scan code or switch). |
| 108 | |
| 109 | /** The key state is unknown or the requested key itself is not supported. */ |
| 110 | public static final int KEY_STATE_UNKNOWN = -1; |
| 111 | |
| 112 | /** The key is up. /*/ |
| 113 | public static final int KEY_STATE_UP = 0; |
| 114 | |
| 115 | /** The key is down. */ |
| 116 | public static final int KEY_STATE_DOWN = 1; |
| 117 | |
| 118 | /** The key is down but is a virtual key press that is being emulated by the system. */ |
| 119 | public static final int KEY_STATE_VIRTUAL = 2; |
| 120 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 121 | public InputManager(Context context, WindowManagerService windowManagerService) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 122 | this.mContext = context; |
| 123 | this.mWindowManagerService = windowManagerService; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 124 | this.mCallbacks = new Callbacks(); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 125 | |
| 126 | Looper looper = windowManagerService.mH.getLooper(); |
| 127 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 128 | Slog.i(TAG, "Initializing input manager"); |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 129 | nativeInit(mContext, mCallbacks, looper.getQueue()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 130 | } |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 131 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 132 | public void start() { |
| 133 | Slog.i(TAG, "Starting input manager"); |
| 134 | nativeStart(); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 135 | |
| 136 | registerPointerSpeedSettingObserver(); |
| 137 | updatePointerSpeedFromSettings(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | public void setDisplaySize(int displayId, int width, int height) { |
| 141 | if (width <= 0 || height <= 0) { |
| 142 | throw new IllegalArgumentException("Invalid display id or dimensions."); |
| 143 | } |
| 144 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 145 | if (DEBUG) { |
| 146 | Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height); |
| 147 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 148 | nativeSetDisplaySize(displayId, width, height); |
| 149 | } |
| 150 | |
| 151 | public void setDisplayOrientation(int displayId, int rotation) { |
| 152 | if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) { |
| 153 | throw new IllegalArgumentException("Invalid rotation."); |
| 154 | } |
| 155 | |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 156 | if (DEBUG) { |
| 157 | Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation); |
| 158 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 159 | nativeSetDisplayOrientation(displayId, rotation); |
| 160 | } |
| 161 | |
| 162 | public void getInputConfiguration(Configuration config) { |
| 163 | if (config == null) { |
| 164 | throw new IllegalArgumentException("config must not be null."); |
| 165 | } |
| 166 | |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 167 | nativeGetInputConfiguration(config); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 170 | /** |
| 171 | * Gets the current state of a key or button by key code. |
| 172 | * @param deviceId The input device id, or -1 to consult all devices. |
| 173 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 174 | * consider all input sources. An input device is consulted if at least one of its |
| 175 | * non-class input source bits matches the specified source mask. |
| 176 | * @param keyCode The key code to check. |
| 177 | * @return The key state. |
| 178 | */ |
| 179 | public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) { |
| 180 | return nativeGetKeyCodeState(deviceId, sourceMask, keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 183 | /** |
| 184 | * Gets the current state of a key or button by scan code. |
| 185 | * @param deviceId The input device id, or -1 to consult all devices. |
| 186 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 187 | * consider all input sources. An input device is consulted if at least one of its |
| 188 | * non-class input source bits matches the specified source mask. |
| 189 | * @param scanCode The scan code to check. |
| 190 | * @return The key state. |
| 191 | */ |
| 192 | public int getScanCodeState(int deviceId, int sourceMask, int scanCode) { |
| 193 | return nativeGetScanCodeState(deviceId, sourceMask, scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Gets the current state of a switch by switch code. |
| 198 | * @param deviceId The input device id, or -1 to consult all devices. |
| 199 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 200 | * consider all input sources. An input device is consulted if at least one of its |
| 201 | * non-class input source bits matches the specified source mask. |
| 202 | * @param switchCode The switch code to check. |
| 203 | * @return The switch state. |
| 204 | */ |
| 205 | public int getSwitchState(int deviceId, int sourceMask, int switchCode) { |
| 206 | return nativeGetSwitchState(deviceId, sourceMask, switchCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 209 | /** |
| 210 | * Determines whether the specified key codes are supported by a particular device. |
| 211 | * @param deviceId The input device id, or -1 to consult all devices. |
| 212 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 213 | * consider all input sources. An input device is consulted if at least one of its |
| 214 | * non-class input source bits matches the specified source mask. |
| 215 | * @param keyCodes The array of key codes to check. |
| 216 | * @param keyExists An array at least as large as keyCodes whose entries will be set |
| 217 | * to true or false based on the presence or absence of support for the corresponding |
| 218 | * key codes. |
| 219 | * @return True if the lookup was successful, false otherwise. |
| 220 | */ |
| 221 | public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 222 | if (keyCodes == null) { |
| 223 | throw new IllegalArgumentException("keyCodes must not be null."); |
| 224 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 225 | if (keyExists == null || keyExists.length < keyCodes.length) { |
| 226 | throw new IllegalArgumentException("keyExists must not be null and must be at " |
| 227 | + "least as large as keyCodes."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 230 | return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Creates an input channel that will receive all input from the input dispatcher. |
| 235 | * @param inputChannelName The input channel name. |
| 236 | * @return The input channel. |
| 237 | */ |
| 238 | public InputChannel monitorInput(String inputChannelName) { |
| 239 | if (inputChannelName == null) { |
| 240 | throw new IllegalArgumentException("inputChannelName must not be null."); |
| 241 | } |
| 242 | |
| 243 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 244 | nativeRegisterInputChannel(inputChannels[0], null, true); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 245 | inputChannels[0].dispose(); // don't need to retain the Java object reference |
| 246 | return inputChannels[1]; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Registers an input channel so that it can be used as an input event target. |
| 251 | * @param inputChannel The input channel to register. |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 252 | * @param inputWindowHandle The handle of the input window associated with the |
| 253 | * input channel, or null if none. |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 254 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 255 | public void registerInputChannel(InputChannel inputChannel, |
| 256 | InputWindowHandle inputWindowHandle) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 257 | if (inputChannel == null) { |
| 258 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 259 | } |
| 260 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 261 | nativeRegisterInputChannel(inputChannel, inputWindowHandle, false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 264 | /** |
| 265 | * Unregisters an input channel. |
| 266 | * @param inputChannel The input channel to unregister. |
| 267 | */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 268 | public void unregisterInputChannel(InputChannel inputChannel) { |
| 269 | if (inputChannel == null) { |
| 270 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 271 | } |
| 272 | |
| 273 | nativeUnregisterInputChannel(inputChannel); |
| 274 | } |
| 275 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 276 | /** |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 277 | * Injects an input event into the event system on behalf of an application. |
| 278 | * The synchronization mode determines whether the method blocks while waiting for |
| 279 | * input injection to proceed. |
| 280 | * |
| 281 | * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and |
| 282 | * is assumed always to be successful. |
| 283 | * |
| 284 | * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be |
| 285 | * dispatched so that the input dispatcher can determine whether input event injection will |
| 286 | * be permitted based on the current input focus. Does not wait for the input event to |
| 287 | * finish processing. |
| 288 | * |
| 289 | * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to |
| 290 | * be completely processed. |
| 291 | * |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 292 | * @param event The event to inject. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 293 | * @param injectorPid The pid of the injecting application. |
| 294 | * @param injectorUid The uid of the injecting application. |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 295 | * @param syncMode The synchronization mode. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 296 | * @param timeoutMillis The injection timeout in milliseconds. |
| 297 | * @return One of the INPUT_EVENT_INJECTION_XXX constants. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 298 | */ |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 299 | public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid, |
| 300 | int syncMode, int timeoutMillis) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 301 | if (event == null) { |
| 302 | throw new IllegalArgumentException("event must not be null"); |
| 303 | } |
| 304 | if (injectorPid < 0 || injectorUid < 0) { |
| 305 | throw new IllegalArgumentException("injectorPid and injectorUid must not be negative."); |
| 306 | } |
| 307 | if (timeoutMillis <= 0) { |
| 308 | throw new IllegalArgumentException("timeoutMillis must be positive"); |
| 309 | } |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 310 | |
| 311 | return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 314 | /** |
| 315 | * Gets information about the input device with the specified id. |
| 316 | * @param id The device id. |
| 317 | * @return The input device or null if not found. |
| 318 | */ |
| 319 | public InputDevice getInputDevice(int deviceId) { |
| 320 | return nativeGetInputDevice(deviceId); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * Gets the ids of all input devices in the system. |
| 325 | * @return The input device ids. |
| 326 | */ |
| 327 | public int[] getInputDeviceIds() { |
| 328 | return nativeGetInputDeviceIds(); |
| 329 | } |
| 330 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 331 | public void setInputWindows(InputWindow[] windows) { |
| 332 | nativeSetInputWindows(windows); |
| 333 | } |
| 334 | |
| 335 | public void setFocusedApplication(InputApplication application) { |
| 336 | nativeSetFocusedApplication(application); |
| 337 | } |
| 338 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 339 | public void setInputDispatchMode(boolean enabled, boolean frozen) { |
| 340 | nativeSetInputDispatchMode(enabled, frozen); |
| 341 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 342 | |
| 343 | public void setSystemUiVisibility(int visibility) { |
| 344 | nativeSetSystemUiVisibility(visibility); |
| 345 | } |
| 346 | |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 347 | /** |
| 348 | * Atomically transfers touch focus from one window to another as identified by |
| 349 | * their input channels. It is possible for multiple windows to have |
| 350 | * touch focus if they support split touch dispatch |
| 351 | * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this |
| 352 | * method only transfers touch focus of the specified window without affecting |
| 353 | * other windows that may also have touch focus at the same time. |
| 354 | * @param fromChannel The channel of a window that currently has touch focus. |
| 355 | * @param toChannel The channel of the window that should receive touch focus in |
| 356 | * place of the first. |
| 357 | * @return True if the transfer was successful. False if the window with the |
| 358 | * specified channel did not actually have touch focus at the time of the request. |
| 359 | */ |
| 360 | public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) { |
| 361 | if (fromChannel == null) { |
| 362 | throw new IllegalArgumentException("fromChannel must not be null."); |
| 363 | } |
| 364 | if (toChannel == null) { |
| 365 | throw new IllegalArgumentException("toChannel must not be null."); |
| 366 | } |
| 367 | return nativeTransferTouchFocus(fromChannel, toChannel); |
| 368 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 369 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame^] | 370 | /** |
| 371 | * Set the pointer speed. |
| 372 | * @param speed The pointer speed as a value between -7 (slowest) and 7 (fastest) |
| 373 | * where 0 is the default speed. |
| 374 | */ |
| 375 | public void setPointerSpeed(int speed) { |
| 376 | speed = Math.min(Math.max(speed, -7), 7); |
| 377 | nativeSetPointerSpeed(speed); |
| 378 | } |
| 379 | |
| 380 | public void updatePointerSpeedFromSettings() { |
| 381 | int speed = getPointerSpeedSetting(0); |
| 382 | setPointerSpeed(speed); |
| 383 | } |
| 384 | |
| 385 | private void registerPointerSpeedSettingObserver() { |
| 386 | mContext.getContentResolver().registerContentObserver( |
| 387 | Settings.System.getUriFor(Settings.System.POINTER_SPEED), true, |
| 388 | new ContentObserver(mWindowManagerService.mH) { |
| 389 | @Override |
| 390 | public void onChange(boolean selfChange) { |
| 391 | updatePointerSpeedFromSettings(); |
| 392 | } |
| 393 | }); |
| 394 | } |
| 395 | |
| 396 | private int getPointerSpeedSetting(int defaultValue) { |
| 397 | int speed = defaultValue; |
| 398 | try { |
| 399 | speed = Settings.System.getInt(mContext.getContentResolver(), |
| 400 | Settings.System.POINTER_SPEED); |
| 401 | } catch (SettingNotFoundException snfe) { |
| 402 | } |
| 403 | return speed; |
| 404 | } |
| 405 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 406 | public void dump(PrintWriter pw) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 407 | String dumpStr = nativeDump(); |
| 408 | if (dumpStr != null) { |
| 409 | pw.println(dumpStr); |
| 410 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 411 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 412 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 413 | /* |
| 414 | * Callbacks from native. |
| 415 | */ |
| 416 | private class Callbacks { |
| 417 | static final String TAG = "InputManager-Callbacks"; |
| 418 | |
| 419 | private static final boolean DEBUG_VIRTUAL_KEYS = false; |
| 420 | private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml"; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 421 | private static final String CALIBRATION_DIR_PATH = "usr/idc/"; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 422 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 423 | @SuppressWarnings("unused") |
Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 424 | public void notifyConfigurationChanged(long whenNanos) { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 425 | mWindowManagerService.mInputMonitor.notifyConfigurationChanged(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | @SuppressWarnings("unused") |
| 429 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 430 | mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | @SuppressWarnings("unused") |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 434 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 435 | mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputWindowHandle); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 436 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 437 | |
| 438 | @SuppressWarnings("unused") |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 439 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
| 440 | InputWindowHandle inputWindowHandle) { |
| 441 | return mWindowManagerService.mInputMonitor.notifyANR( |
| 442 | inputApplicationHandle, inputWindowHandle); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | @SuppressWarnings("unused") |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 446 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 447 | return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing( |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 448 | event, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 449 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 450 | |
| 451 | @SuppressWarnings("unused") |
| 452 | public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { |
| 453 | return mWindowManagerService.mInputMonitor.interceptMotionBeforeQueueingWhenScreenOff( |
| 454 | policyFlags); |
| 455 | } |
| 456 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 457 | @SuppressWarnings("unused") |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 458 | public boolean interceptKeyBeforeDispatching(InputWindowHandle focus, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 459 | KeyEvent event, int policyFlags) { |
| 460 | return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching( |
| 461 | focus, event, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | @SuppressWarnings("unused") |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 465 | public KeyEvent dispatchUnhandledKey(InputWindowHandle focus, |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 466 | KeyEvent event, int policyFlags) { |
| 467 | return mWindowManagerService.mInputMonitor.dispatchUnhandledKey( |
| 468 | focus, event, policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | @SuppressWarnings("unused") |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 472 | public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) { |
| 473 | return mContext.checkPermission( |
| 474 | android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid) |
| 475 | == PackageManager.PERMISSION_GRANTED; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @SuppressWarnings("unused") |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 479 | public boolean filterTouchEvents() { |
| 480 | return mContext.getResources().getBoolean( |
| 481 | com.android.internal.R.bool.config_filterTouchEvents); |
| 482 | } |
| 483 | |
| 484 | @SuppressWarnings("unused") |
| 485 | public boolean filterJumpyTouchEvents() { |
| 486 | return mContext.getResources().getBoolean( |
| 487 | com.android.internal.R.bool.config_filterJumpyTouchEvents); |
| 488 | } |
Jeff Brown | fe50892 | 2011-01-18 15:10:10 -0800 | [diff] [blame] | 489 | |
| 490 | @SuppressWarnings("unused") |
| 491 | public int getVirtualKeyQuietTimeMillis() { |
| 492 | return mContext.getResources().getInteger( |
| 493 | com.android.internal.R.integer.config_virtualKeyQuietTimeMillis); |
| 494 | } |
| 495 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 496 | @SuppressWarnings("unused") |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 497 | public String[] getExcludedDeviceNames() { |
| 498 | ArrayList<String> names = new ArrayList<String>(); |
| 499 | |
| 500 | // Read partner-provided list of excluded input devices |
| 501 | XmlPullParser parser = null; |
| 502 | // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". |
| 503 | File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH); |
| 504 | FileReader confreader = null; |
| 505 | try { |
| 506 | confreader = new FileReader(confFile); |
| 507 | parser = Xml.newPullParser(); |
| 508 | parser.setInput(confreader); |
| 509 | XmlUtils.beginDocument(parser, "devices"); |
| 510 | |
| 511 | while (true) { |
| 512 | XmlUtils.nextElement(parser); |
| 513 | if (!"device".equals(parser.getName())) { |
| 514 | break; |
| 515 | } |
| 516 | String name = parser.getAttributeValue(null, "name"); |
| 517 | if (name != null) { |
| 518 | names.add(name); |
| 519 | } |
| 520 | } |
| 521 | } catch (FileNotFoundException e) { |
| 522 | // It's ok if the file does not exist. |
| 523 | } catch (Exception e) { |
| 524 | Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e); |
| 525 | } finally { |
| 526 | try { if (confreader != null) confreader.close(); } catch (IOException e) { } |
| 527 | } |
| 528 | |
| 529 | return names.toArray(new String[names.size()]); |
| 530 | } |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 531 | |
| 532 | @SuppressWarnings("unused") |
| 533 | public int getKeyRepeatTimeout() { |
| 534 | return ViewConfiguration.getKeyRepeatTimeout(); |
| 535 | } |
| 536 | |
| 537 | @SuppressWarnings("unused") |
| 538 | public int getKeyRepeatDelay() { |
| 539 | return ViewConfiguration.getKeyRepeatDelay(); |
| 540 | } |
| 541 | |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 542 | @SuppressWarnings("unused") |
Jeff Brown | 214eaf4 | 2011-05-26 19:17:02 -0700 | [diff] [blame] | 543 | public int getTapTimeout() { |
| 544 | return ViewConfiguration.getTapTimeout(); |
| 545 | } |
| 546 | |
| 547 | @SuppressWarnings("unused") |
| 548 | public int getDoubleTapTimeout() { |
| 549 | return ViewConfiguration.getDoubleTapTimeout(); |
| 550 | } |
| 551 | |
| 552 | @SuppressWarnings("unused") |
| 553 | public int getLongPressTimeout() { |
| 554 | return ViewConfiguration.getLongPressTimeout(); |
| 555 | } |
| 556 | |
| 557 | @SuppressWarnings("unused") |
| 558 | public int getTouchSlop() { |
| 559 | return ViewConfiguration.get(mContext).getScaledTouchSlop(); |
| 560 | } |
| 561 | |
| 562 | @SuppressWarnings("unused") |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 563 | public int getMaxEventsPerSecond() { |
| 564 | int result = 0; |
| 565 | try { |
| 566 | result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec")); |
| 567 | } catch (NumberFormatException e) { |
| 568 | } |
| 569 | if (result < 1) { |
makarand.karvekar | 88dd6e6 | 2011-03-02 17:11:14 -0600 | [diff] [blame] | 570 | result = 55; |
Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 571 | } |
| 572 | return result; |
| 573 | } |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 574 | |
| 575 | @SuppressWarnings("unused") |
| 576 | public int getPointerLayer() { |
| 577 | return mWindowManagerService.mPolicy.windowTypeToLayerLw( |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 578 | WindowManager.LayoutParams.TYPE_POINTER) |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 579 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 580 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 581 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 582 | |
| 583 | @SuppressWarnings("unused") |
| 584 | public PointerIcon getPointerIcon() { |
Jeff Brown | 86ea1f5 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 585 | return PointerIcon.getDefaultIcon(mContext); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 586 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 587 | } |
| 588 | } |