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