| 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 | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 32 | import android.view.KeyEvent; |
| 33 | import android.view.MotionEvent; |
| Jeff Brown | 46b9ac0a | 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 | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 59 | private final PowerManager mPowerManager; |
| 60 | private final PowerManagerService mPowerManagerService; |
| 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 | |
| 71 | private static native int nativeGetScanCodeState(int deviceId, int deviceClasses, |
| 72 | int scanCode); |
| 73 | private static native int nativeGetKeyCodeState(int deviceId, int deviceClasses, |
| 74 | int keyCode); |
| 75 | private static native int nativeGetSwitchState(int deviceId, int deviceClasses, |
| 76 | int sw); |
| 77 | private static native boolean nativeHasKeys(int[] keyCodes, boolean[] keyExists); |
| 78 | private static native void nativeRegisterInputChannel(InputChannel inputChannel); |
| 79 | private static native void nativeUnregisterInputChannel(InputChannel inputChannel); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 80 | private static native int nativeInjectKeyEvent(KeyEvent event, int nature, |
| 81 | int injectorPid, int injectorUid, boolean sync, int timeoutMillis); |
| 82 | private static native int nativeInjectMotionEvent(MotionEvent event, int nature, |
| 83 | int injectorPid, int injectorUid, boolean sync, 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 | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 88 | |
| 89 | // Device class as defined by EventHub. |
| 90 | private static final int CLASS_KEYBOARD = 0x00000001; |
| 91 | private static final int CLASS_ALPHAKEY = 0x00000002; |
| 92 | private static final int CLASS_TOUCHSCREEN = 0x00000004; |
| 93 | private static final int CLASS_TRACKBALL = 0x00000008; |
| 94 | private static final int CLASS_TOUCHSCREEN_MT = 0x00000010; |
| 95 | private static final int CLASS_DPAD = 0x00000020; |
| 96 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 97 | // Input event injection constants defined in InputDispatcher.h. |
| 98 | static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0; |
| 99 | static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1; |
| 100 | static final int INPUT_EVENT_INJECTION_FAILED = 2; |
| 101 | static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3; |
| 102 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | public InputManager(Context context, |
| 104 | WindowManagerService windowManagerService, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 105 | PowerManager powerManager, |
| 106 | PowerManagerService powerManagerService) { |
| 107 | this.mContext = context; |
| 108 | this.mWindowManagerService = windowManagerService; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 109 | this.mPowerManager = powerManager; |
| 110 | this.mPowerManagerService = powerManagerService; |
| 111 | |
| 112 | this.mCallbacks = new Callbacks(); |
| 113 | |
| 114 | mTouchScreenConfig = Configuration.TOUCHSCREEN_NOTOUCH; |
| 115 | mKeyboardConfig = Configuration.KEYBOARD_NOKEYS; |
| 116 | mNavigationConfig = Configuration.NAVIGATION_NONAV; |
| 117 | |
| 118 | init(); |
| 119 | } |
| 120 | |
| 121 | private void init() { |
| 122 | Slog.i(TAG, "Initializing input manager"); |
| 123 | nativeInit(mCallbacks); |
| 124 | } |
| 125 | |
| 126 | public void start() { |
| 127 | Slog.i(TAG, "Starting input manager"); |
| 128 | nativeStart(); |
| 129 | } |
| 130 | |
| 131 | public void setDisplaySize(int displayId, int width, int height) { |
| 132 | if (width <= 0 || height <= 0) { |
| 133 | throw new IllegalArgumentException("Invalid display id or dimensions."); |
| 134 | } |
| 135 | |
| 136 | Slog.i(TAG, "Setting display #" + displayId + " size to " + width + "x" + height); |
| 137 | nativeSetDisplaySize(displayId, width, height); |
| 138 | } |
| 139 | |
| 140 | public void setDisplayOrientation(int displayId, int rotation) { |
| 141 | if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) { |
| 142 | throw new IllegalArgumentException("Invalid rotation."); |
| 143 | } |
| 144 | |
| 145 | Slog.i(TAG, "Setting display #" + displayId + " orientation to " + rotation); |
| 146 | nativeSetDisplayOrientation(displayId, rotation); |
| 147 | } |
| 148 | |
| 149 | public void getInputConfiguration(Configuration config) { |
| 150 | if (config == null) { |
| 151 | throw new IllegalArgumentException("config must not be null."); |
| 152 | } |
| 153 | |
| 154 | config.touchscreen = mTouchScreenConfig; |
| 155 | config.keyboard = mKeyboardConfig; |
| 156 | config.navigation = mNavigationConfig; |
| 157 | } |
| 158 | |
| 159 | public int getScancodeState(int code) { |
| 160 | return nativeGetScanCodeState(0, -1, code); |
| 161 | } |
| 162 | |
| 163 | public int getScancodeState(int deviceId, int code) { |
| 164 | return nativeGetScanCodeState(deviceId, -1, code); |
| 165 | } |
| 166 | |
| 167 | public int getTrackballScancodeState(int code) { |
| 168 | return nativeGetScanCodeState(-1, CLASS_TRACKBALL, code); |
| 169 | } |
| 170 | |
| 171 | public int getDPadScancodeState(int code) { |
| 172 | return nativeGetScanCodeState(-1, CLASS_DPAD, code); |
| 173 | } |
| 174 | |
| 175 | public int getKeycodeState(int code) { |
| 176 | return nativeGetKeyCodeState(0, -1, code); |
| 177 | } |
| 178 | |
| 179 | public int getKeycodeState(int deviceId, int code) { |
| 180 | return nativeGetKeyCodeState(deviceId, -1, code); |
| 181 | } |
| 182 | |
| 183 | public int getTrackballKeycodeState(int code) { |
| 184 | return nativeGetKeyCodeState(-1, CLASS_TRACKBALL, code); |
| 185 | } |
| 186 | |
| 187 | public int getDPadKeycodeState(int code) { |
| 188 | return nativeGetKeyCodeState(-1, CLASS_DPAD, code); |
| 189 | } |
| 190 | |
| 191 | public int getSwitchState(int sw) { |
| 192 | return nativeGetSwitchState(-1, -1, sw); |
| 193 | } |
| 194 | |
| 195 | public int getSwitchState(int deviceId, int sw) { |
| 196 | return nativeGetSwitchState(deviceId, -1, sw); |
| 197 | } |
| 198 | |
| 199 | public boolean hasKeys(int[] keyCodes, boolean[] keyExists) { |
| 200 | if (keyCodes == null) { |
| 201 | throw new IllegalArgumentException("keyCodes must not be null."); |
| 202 | } |
| 203 | if (keyExists == null) { |
| 204 | throw new IllegalArgumentException("keyExists must not be null."); |
| 205 | } |
| 206 | |
| 207 | return nativeHasKeys(keyCodes, keyExists); |
| 208 | } |
| 209 | |
| 210 | public void registerInputChannel(InputChannel inputChannel) { |
| 211 | if (inputChannel == null) { |
| 212 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 213 | } |
| 214 | |
| 215 | nativeRegisterInputChannel(inputChannel); |
| 216 | } |
| 217 | |
| 218 | public void unregisterInputChannel(InputChannel inputChannel) { |
| 219 | if (inputChannel == null) { |
| 220 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 221 | } |
| 222 | |
| 223 | nativeUnregisterInputChannel(inputChannel); |
| 224 | } |
| 225 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 226 | /** |
| 227 | * 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] | 228 | * This method may block even if sync is false because it must wait for previous events |
| 229 | * to be dispatched before it can determine whether input event injection will be |
| 230 | * permitted based on the current input focus. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 231 | * @param event The event to inject. |
| 232 | * @param nature The nature of the event. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 233 | * @param injectorPid The pid of the injecting application. |
| 234 | * @param injectorUid The uid of the injecting application. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 235 | * @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] | 236 | * @param timeoutMillis The injection timeout in milliseconds. |
| 237 | * @return One of the INPUT_EVENT_INJECTION_XXX constants. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 238 | */ |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 239 | public int injectKeyEvent(KeyEvent event, int nature, int injectorPid, int injectorUid, |
| 240 | boolean sync, int timeoutMillis) { |
| 241 | if (event == null) { |
| 242 | throw new IllegalArgumentException("event must not be null"); |
| 243 | } |
| 244 | if (injectorPid < 0 || injectorUid < 0) { |
| 245 | throw new IllegalArgumentException("injectorPid and injectorUid must not be negative."); |
| 246 | } |
| 247 | if (timeoutMillis <= 0) { |
| 248 | throw new IllegalArgumentException("timeoutMillis must be positive"); |
| 249 | } |
| 250 | |
| 251 | return nativeInjectKeyEvent(event, nature, injectorPid, injectorUid, |
| 252 | sync, timeoutMillis); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * 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] | 257 | * This method may block even if sync is false because it must wait for previous events |
| 258 | * to be dispatched before it can determine whether input event injection will be |
| 259 | * permitted based on the current input focus. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 260 | * @param event The event to inject. |
| 261 | * @param nature The nature of the event. |
| 262 | * @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] | 263 | * @param injectorPid The pid of the injecting application. |
| 264 | * @param injectorUid The uid of the injecting application. |
| 265 | * @param sync If true, waits for the event to be completed before returning. |
| 266 | * @param timeoutMillis The injection timeout in milliseconds. |
| 267 | * @return One of the INPUT_EVENT_INJECTION_XXX constants. |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 268 | */ |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 269 | public int injectMotionEvent(MotionEvent event, int nature, int injectorPid, int injectorUid, |
| 270 | boolean sync, int timeoutMillis) { |
| 271 | if (event == null) { |
| 272 | throw new IllegalArgumentException("event must not be null"); |
| 273 | } |
| 274 | if (injectorPid < 0 || injectorUid < 0) { |
| 275 | throw new IllegalArgumentException("injectorPid and injectorUid must not be negative."); |
| 276 | } |
| 277 | if (timeoutMillis <= 0) { |
| 278 | throw new IllegalArgumentException("timeoutMillis must be positive"); |
| 279 | } |
| 280 | |
| 281 | return nativeInjectMotionEvent(event, nature, injectorPid, injectorUid, |
| 282 | sync, timeoutMillis); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 285 | public void setInputWindows(InputWindow[] windows) { |
| 286 | nativeSetInputWindows(windows); |
| 287 | } |
| 288 | |
| 289 | public void setFocusedApplication(InputApplication application) { |
| 290 | nativeSetFocusedApplication(application); |
| 291 | } |
| 292 | |
| 293 | public void preemptInputDispatch() { |
| 294 | nativePreemptInputDispatch(); |
| 295 | } |
| 296 | |
| 297 | public void setInputDispatchMode(boolean enabled, boolean frozen) { |
| 298 | nativeSetInputDispatchMode(enabled, frozen); |
| 299 | } |
| 300 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 301 | public void dump(PrintWriter pw) { |
| 302 | // TODO |
| 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 | } |