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