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