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