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