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