| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import com.android.internal.util.XmlUtils; |
| Jeff Brown | 46b9ac0a | 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 | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 25 | import android.content.res.Configuration; |
| 26 | import android.os.Environment; |
| Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 27 | import android.os.SystemProperties; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 28 | import android.util.Slog; |
| 29 | import android.util.Xml; |
| 30 | import android.view.InputChannel; |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 31 | import android.view.InputDevice; |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 32 | import android.view.InputEvent; |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 34 | import android.view.Surface; |
| Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 35 | import android.view.WindowManager; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 36 | |
| 37 | import java.io.BufferedReader; |
| 38 | import java.io.File; |
| 39 | import java.io.FileInputStream; |
| 40 | import java.io.FileNotFoundException; |
| 41 | import java.io.FileReader; |
| 42 | import java.io.IOException; |
| 43 | import java.io.InputStreamReader; |
| 44 | import java.io.PrintWriter; |
| 45 | import java.util.ArrayList; |
| 46 | |
| 47 | /* |
| 48 | * Wraps the C++ InputManager and provides its callbacks. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 49 | */ |
| 50 | public class InputManager { |
| 51 | static final String TAG = "InputManager"; |
| 52 | |
| Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 53 | private static final boolean DEBUG = false; |
| 54 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 55 | private final Callbacks mCallbacks; |
| 56 | private final Context mContext; |
| 57 | private final WindowManagerService mWindowManagerService; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 58 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 59 | private static native void nativeInit(Callbacks callbacks); |
| 60 | private static native void nativeStart(); |
| 61 | private static native void nativeSetDisplaySize(int displayId, int width, int height); |
| 62 | private static native void nativeSetDisplayOrientation(int displayId, int rotation); |
| 63 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 64 | private static native int nativeGetScanCodeState(int deviceId, int sourceMask, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 65 | int scanCode); |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 66 | private static native int nativeGetKeyCodeState(int deviceId, int sourceMask, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 67 | int keyCode); |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 68 | private static native int nativeGetSwitchState(int deviceId, int sourceMask, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 69 | int sw); |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 70 | private static native boolean nativeHasKeys(int deviceId, int sourceMask, |
| 71 | int[] keyCodes, boolean[] keyExists); |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 72 | private static native void nativeRegisterInputChannel(InputChannel inputChannel, |
| 73 | boolean monitor); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 74 | private static native void nativeUnregisterInputChannel(InputChannel inputChannel); |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 75 | private static native int nativeInjectInputEvent(InputEvent event, |
| 76 | int injectorPid, int injectorUid, int syncMode, int timeoutMillis); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 77 | private static native void nativeSetInputWindows(InputWindow[] windows); |
| 78 | private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen); |
| 79 | private static native void nativeSetFocusedApplication(InputApplication application); |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 80 | private static native InputDevice nativeGetInputDevice(int deviceId); |
| Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 81 | private static native void nativeGetInputConfiguration(Configuration configuration); |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 82 | private static native int[] nativeGetInputDeviceIds(); |
| Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 83 | private static native boolean nativeTransferTouchFocus(InputChannel fromChannel, |
| 84 | InputChannel toChannel); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 85 | private static native String nativeDump(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 86 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 87 | // Input event injection constants defined in InputDispatcher.h. |
| 88 | static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0; |
| 89 | static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1; |
| 90 | static final int INPUT_EVENT_INJECTION_FAILED = 2; |
| 91 | static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3; |
| 92 | |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 93 | // Input event injection synchronization modes defined in InputDispatcher.h |
| 94 | static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0; |
| 95 | static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1; |
| 96 | static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2; |
| 97 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 98 | // Key states (may be returned by queries about the current state of a |
| 99 | // particular key code, scan code or switch). |
| 100 | |
| 101 | /** The key state is unknown or the requested key itself is not supported. */ |
| 102 | public static final int KEY_STATE_UNKNOWN = -1; |
| 103 | |
| 104 | /** The key is up. /*/ |
| 105 | public static final int KEY_STATE_UP = 0; |
| 106 | |
| 107 | /** The key is down. */ |
| 108 | public static final int KEY_STATE_DOWN = 1; |
| 109 | |
| 110 | /** The key is down but is a virtual key press that is being emulated by the system. */ |
| 111 | public static final int KEY_STATE_VIRTUAL = 2; |
| 112 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 113 | public InputManager(Context context, WindowManagerService windowManagerService) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 114 | this.mContext = context; |
| 115 | this.mWindowManagerService = windowManagerService; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 116 | |
| 117 | this.mCallbacks = new Callbacks(); |
| 118 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 119 | init(); |
| 120 | } |
| 121 | |
| 122 | private void init() { |
| 123 | Slog.i(TAG, "Initializing input manager"); |
| 124 | nativeInit(mCallbacks); |
| 125 | } |
| 126 | |
| 127 | public void start() { |
| 128 | Slog.i(TAG, "Starting input manager"); |
| 129 | nativeStart(); |
| 130 | } |
| 131 | |
| 132 | public void setDisplaySize(int displayId, int width, int height) { |
| 133 | if (width <= 0 || height <= 0) { |
| 134 | throw new IllegalArgumentException("Invalid display id or dimensions."); |
| 135 | } |
| 136 | |
| Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 137 | if (DEBUG) { |
| 138 | Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height); |
| 139 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 140 | nativeSetDisplaySize(displayId, width, height); |
| 141 | } |
| 142 | |
| 143 | public void setDisplayOrientation(int displayId, int rotation) { |
| 144 | if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) { |
| 145 | throw new IllegalArgumentException("Invalid rotation."); |
| 146 | } |
| 147 | |
| Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 148 | if (DEBUG) { |
| 149 | Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation); |
| 150 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 151 | nativeSetDisplayOrientation(displayId, rotation); |
| 152 | } |
| 153 | |
| 154 | public void getInputConfiguration(Configuration config) { |
| 155 | if (config == null) { |
| 156 | throw new IllegalArgumentException("config must not be null."); |
| 157 | } |
| 158 | |
| Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 159 | nativeGetInputConfiguration(config); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Gets the current state of a key or button by key code. |
| 164 | * @param deviceId The input device id, or -1 to consult all devices. |
| 165 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 166 | * consider all input sources. An input device is consulted if at least one of its |
| 167 | * non-class input source bits matches the specified source mask. |
| 168 | * @param keyCode The key code to check. |
| 169 | * @return The key state. |
| 170 | */ |
| 171 | public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) { |
| 172 | return nativeGetKeyCodeState(deviceId, sourceMask, keyCode); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Gets the current state of a key or button by scan code. |
| 177 | * @param deviceId The input device id, or -1 to consult all devices. |
| 178 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 179 | * consider all input sources. An input device is consulted if at least one of its |
| 180 | * non-class input source bits matches the specified source mask. |
| 181 | * @param scanCode The scan code to check. |
| 182 | * @return The key state. |
| 183 | */ |
| 184 | public int getScanCodeState(int deviceId, int sourceMask, int scanCode) { |
| 185 | return nativeGetScanCodeState(deviceId, sourceMask, scanCode); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Gets the current state of a switch by switch code. |
| 190 | * @param deviceId The input device id, or -1 to consult all devices. |
| 191 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 192 | * consider all input sources. An input device is consulted if at least one of its |
| 193 | * non-class input source bits matches the specified source mask. |
| 194 | * @param switchCode The switch code to check. |
| 195 | * @return The switch state. |
| 196 | */ |
| 197 | public int getSwitchState(int deviceId, int sourceMask, int switchCode) { |
| 198 | return nativeGetSwitchState(deviceId, sourceMask, switchCode); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 201 | /** |
| 202 | * Determines whether the specified key codes are supported by a particular device. |
| 203 | * @param deviceId The input device id, or -1 to consult all devices. |
| 204 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 205 | * consider all input sources. An input device is consulted if at least one of its |
| 206 | * non-class input source bits matches the specified source mask. |
| 207 | * @param keyCodes The array of key codes to check. |
| 208 | * @param keyExists An array at least as large as keyCodes whose entries will be set |
| 209 | * to true or false based on the presence or absence of support for the corresponding |
| 210 | * key codes. |
| 211 | * @return True if the lookup was successful, false otherwise. |
| 212 | */ |
| 213 | public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 214 | if (keyCodes == null) { |
| 215 | throw new IllegalArgumentException("keyCodes must not be null."); |
| 216 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 217 | if (keyExists == null || keyExists.length < keyCodes.length) { |
| 218 | throw new IllegalArgumentException("keyExists must not be null and must be at " |
| 219 | + "least as large as keyCodes."); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 222 | return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 225 | /** |
| 226 | * Creates an input channel that will receive all input from the input dispatcher. |
| 227 | * @param inputChannelName The input channel name. |
| 228 | * @return The input channel. |
| 229 | */ |
| 230 | public InputChannel monitorInput(String inputChannelName) { |
| 231 | if (inputChannelName == null) { |
| 232 | throw new IllegalArgumentException("inputChannelName must not be null."); |
| 233 | } |
| 234 | |
| 235 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName); |
| 236 | nativeRegisterInputChannel(inputChannels[0], true); |
| 237 | inputChannels[0].dispose(); // don't need to retain the Java object reference |
| 238 | return inputChannels[1]; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Registers an input channel so that it can be used as an input event target. |
| 243 | * @param inputChannel The input channel to register. |
| 244 | */ |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 245 | public void registerInputChannel(InputChannel inputChannel) { |
| 246 | if (inputChannel == null) { |
| 247 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 248 | } |
| 249 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 250 | nativeRegisterInputChannel(inputChannel, false); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 253 | /** |
| 254 | * Unregisters an input channel. |
| 255 | * @param inputChannel The input channel to unregister. |
| 256 | */ |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 257 | public void unregisterInputChannel(InputChannel inputChannel) { |
| 258 | if (inputChannel == null) { |
| 259 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 260 | } |
| 261 | |
| 262 | nativeUnregisterInputChannel(inputChannel); |
| 263 | } |
| 264 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 265 | /** |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 266 | * Injects an input event into the event system on behalf of an application. |
| 267 | * The synchronization mode determines whether the method blocks while waiting for |
| 268 | * input injection to proceed. |
| 269 | * |
| 270 | * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and |
| 271 | * is assumed always to be successful. |
| 272 | * |
| 273 | * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be |
| 274 | * dispatched so that the input dispatcher can determine whether input event injection will |
| 275 | * be permitted based on the current input focus. Does not wait for the input event to |
| 276 | * finish processing. |
| 277 | * |
| 278 | * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to |
| 279 | * be completely processed. |
| 280 | * |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 281 | * @param event The event to inject. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 282 | * @param injectorPid The pid of the injecting application. |
| 283 | * @param injectorUid The uid of the injecting application. |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 284 | * @param syncMode The synchronization mode. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 285 | * @param timeoutMillis The injection timeout in milliseconds. |
| 286 | * @return One of the INPUT_EVENT_INJECTION_XXX constants. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 287 | */ |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 288 | public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid, |
| 289 | int syncMode, int timeoutMillis) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 290 | if (event == null) { |
| 291 | throw new IllegalArgumentException("event must not be null"); |
| 292 | } |
| 293 | if (injectorPid < 0 || injectorUid < 0) { |
| 294 | throw new IllegalArgumentException("injectorPid and injectorUid must not be negative."); |
| 295 | } |
| 296 | if (timeoutMillis <= 0) { |
| 297 | throw new IllegalArgumentException("timeoutMillis must be positive"); |
| 298 | } |
| Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 299 | |
| 300 | return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 303 | /** |
| 304 | * Gets information about the input device with the specified id. |
| 305 | * @param id The device id. |
| 306 | * @return The input device or null if not found. |
| 307 | */ |
| 308 | public InputDevice getInputDevice(int deviceId) { |
| 309 | return nativeGetInputDevice(deviceId); |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Gets the ids of all input devices in the system. |
| 314 | * @return The input device ids. |
| 315 | */ |
| 316 | public int[] getInputDeviceIds() { |
| 317 | return nativeGetInputDeviceIds(); |
| 318 | } |
| 319 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 320 | public void setInputWindows(InputWindow[] windows) { |
| 321 | nativeSetInputWindows(windows); |
| 322 | } |
| 323 | |
| 324 | public void setFocusedApplication(InputApplication application) { |
| 325 | nativeSetFocusedApplication(application); |
| 326 | } |
| 327 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 328 | public void setInputDispatchMode(boolean enabled, boolean frozen) { |
| 329 | nativeSetInputDispatchMode(enabled, frozen); |
| 330 | } |
| 331 | |
| Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 332 | /** |
| 333 | * Atomically transfers touch focus from one window to another as identified by |
| 334 | * their input channels. It is possible for multiple windows to have |
| 335 | * touch focus if they support split touch dispatch |
| 336 | * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this |
| 337 | * method only transfers touch focus of the specified window without affecting |
| 338 | * other windows that may also have touch focus at the same time. |
| 339 | * @param fromChannel The channel of a window that currently has touch focus. |
| 340 | * @param toChannel The channel of the window that should receive touch focus in |
| 341 | * place of the first. |
| 342 | * @return True if the transfer was successful. False if the window with the |
| 343 | * specified channel did not actually have touch focus at the time of the request. |
| 344 | */ |
| 345 | public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) { |
| 346 | if (fromChannel == null) { |
| 347 | throw new IllegalArgumentException("fromChannel must not be null."); |
| 348 | } |
| 349 | if (toChannel == null) { |
| 350 | throw new IllegalArgumentException("toChannel must not be null."); |
| 351 | } |
| 352 | return nativeTransferTouchFocus(fromChannel, toChannel); |
| 353 | } |
| 354 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 355 | public void dump(PrintWriter pw) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 356 | String dumpStr = nativeDump(); |
| 357 | if (dumpStr != null) { |
| 358 | pw.println(dumpStr); |
| 359 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 362 | /* |
| 363 | * Callbacks from native. |
| 364 | */ |
| 365 | private class Callbacks { |
| 366 | static final String TAG = "InputManager-Callbacks"; |
| 367 | |
| 368 | private static final boolean DEBUG_VIRTUAL_KEYS = false; |
| 369 | private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml"; |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 370 | private static final String CALIBRATION_DIR_PATH = "usr/idc/"; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 371 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 372 | @SuppressWarnings("unused") |
| Jeff Brown | 57c5937 | 2010-09-21 18:22:55 -0700 | [diff] [blame] | 373 | public void notifyConfigurationChanged(long whenNanos) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 374 | mWindowManagerService.sendNewConfiguration(); |
| 375 | } |
| 376 | |
| 377 | @SuppressWarnings("unused") |
| 378 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 379 | mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | @SuppressWarnings("unused") |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 383 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 384 | mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 385 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 386 | |
| 387 | @SuppressWarnings("unused") |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 388 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 389 | return mWindowManagerService.mInputMonitor.notifyANR(token, inputChannel); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | @SuppressWarnings("unused") |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 393 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 394 | return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing( |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 395 | event, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @SuppressWarnings("unused") |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 399 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 400 | KeyEvent event, int policyFlags) { |
| 401 | return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching( |
| 402 | focus, event, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | @SuppressWarnings("unused") |
| Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 406 | public KeyEvent dispatchUnhandledKey(InputChannel focus, |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 407 | KeyEvent event, int policyFlags) { |
| 408 | return mWindowManagerService.mInputMonitor.dispatchUnhandledKey( |
| 409 | focus, event, policyFlags); |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | @SuppressWarnings("unused") |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 413 | public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) { |
| 414 | return mContext.checkPermission( |
| 415 | android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid) |
| 416 | == PackageManager.PERMISSION_GRANTED; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | @SuppressWarnings("unused") |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 420 | public boolean filterTouchEvents() { |
| 421 | return mContext.getResources().getBoolean( |
| 422 | com.android.internal.R.bool.config_filterTouchEvents); |
| 423 | } |
| 424 | |
| 425 | @SuppressWarnings("unused") |
| 426 | public boolean filterJumpyTouchEvents() { |
| 427 | return mContext.getResources().getBoolean( |
| 428 | com.android.internal.R.bool.config_filterJumpyTouchEvents); |
| 429 | } |
| 430 | |
| 431 | @SuppressWarnings("unused") |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 432 | public String[] getExcludedDeviceNames() { |
| 433 | ArrayList<String> names = new ArrayList<String>(); |
| 434 | |
| 435 | // Read partner-provided list of excluded input devices |
| 436 | XmlPullParser parser = null; |
| 437 | // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". |
| 438 | File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH); |
| 439 | FileReader confreader = null; |
| 440 | try { |
| 441 | confreader = new FileReader(confFile); |
| 442 | parser = Xml.newPullParser(); |
| 443 | parser.setInput(confreader); |
| 444 | XmlUtils.beginDocument(parser, "devices"); |
| 445 | |
| 446 | while (true) { |
| 447 | XmlUtils.nextElement(parser); |
| 448 | if (!"device".equals(parser.getName())) { |
| 449 | break; |
| 450 | } |
| 451 | String name = parser.getAttributeValue(null, "name"); |
| 452 | if (name != null) { |
| 453 | names.add(name); |
| 454 | } |
| 455 | } |
| 456 | } catch (FileNotFoundException e) { |
| 457 | // It's ok if the file does not exist. |
| 458 | } catch (Exception e) { |
| 459 | Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e); |
| 460 | } finally { |
| 461 | try { if (confreader != null) confreader.close(); } catch (IOException e) { } |
| 462 | } |
| 463 | |
| 464 | return names.toArray(new String[names.size()]); |
| 465 | } |
| Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 466 | |
| 467 | @SuppressWarnings("unused") |
| 468 | public int getMaxEventsPerSecond() { |
| 469 | int result = 0; |
| 470 | try { |
| 471 | result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec")); |
| 472 | } catch (NumberFormatException e) { |
| 473 | } |
| 474 | if (result < 1) { |
| Jeff Brown | 3d8c9bd | 2010-08-18 17:48:53 -0700 | [diff] [blame] | 475 | result = 60; |
| Jeff Brown | ae9fc03 | 2010-08-18 15:51:08 -0700 | [diff] [blame] | 476 | } |
| 477 | return result; |
| 478 | } |
| Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 479 | |
| 480 | @SuppressWarnings("unused") |
| 481 | public int getPointerLayer() { |
| 482 | return mWindowManagerService.mPolicy.windowTypeToLayerLw( |
| 483 | WindowManager.LayoutParams.TYPE_DRAG) |
| 484 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 485 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 486 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 487 | } |
| 488 | } |