blob: f330d40a80f633430a6dcd471a79dee77144a7af [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.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070051 */
52public class InputManager {
53 static final String TAG = "InputManager";
54
55 private final Callbacks mCallbacks;
56 private final Context mContext;
57 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070058
59 private int mTouchScreenConfig;
60 private int mKeyboardConfig;
61 private int mNavigationConfig;
62
63 private static native void nativeInit(Callbacks callbacks);
64 private static native void nativeStart();
65 private static native void nativeSetDisplaySize(int displayId, int width, int height);
66 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
67
Jeff Brown6d0fec22010-07-23 21:28:06 -070068 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070069 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070070 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070071 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070072 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070073 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070074 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
75 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070076 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
77 boolean monitor);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070078 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070079 private static native int nativeInjectInputEvent(InputEvent event,
80 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070081 private static native void nativeSetInputWindows(InputWindow[] windows);
82 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
83 private static native void nativeSetFocusedApplication(InputApplication application);
84 private static native void nativePreemptInputDispatch();
Jeff Browne33348b2010-07-15 23:54:05 -070085 private static native String nativeDump();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070086
Jeff Brown7fbdc842010-06-17 20:52:56 -070087 // Input event injection constants defined in InputDispatcher.h.
88 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
89 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
90 static final int INPUT_EVENT_INJECTION_FAILED = 2;
91 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
92
Jeff Brown6ec402b2010-07-28 15:48:59 -070093 // Input event injection synchronization modes defined in InputDispatcher.h
94 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
95 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
96 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
97
Jeff Brown6d0fec22010-07-23 21:28:06 -070098 // Key states (may be returned by queries about the current state of a
99 // particular key code, scan code or switch).
100
101 /** The key state is unknown or the requested key itself is not supported. */
102 public static final int KEY_STATE_UNKNOWN = -1;
103
104 /** The key is up. /*/
105 public static final int KEY_STATE_UP = 0;
106
107 /** The key is down. */
108 public static final int KEY_STATE_DOWN = 1;
109
110 /** The key is down but is a virtual key press that is being emulated by the system. */
111 public static final int KEY_STATE_VIRTUAL = 2;
112
Jeff Browne33348b2010-07-15 23:54:05 -0700113 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700114 this.mContext = context;
115 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700116
117 this.mCallbacks = new Callbacks();
118
119 mTouchScreenConfig = Configuration.TOUCHSCREEN_NOTOUCH;
120 mKeyboardConfig = Configuration.KEYBOARD_NOKEYS;
121 mNavigationConfig = Configuration.NAVIGATION_NONAV;
122
123 init();
124 }
125
126 private void init() {
127 Slog.i(TAG, "Initializing input manager");
128 nativeInit(mCallbacks);
129 }
130
131 public void start() {
132 Slog.i(TAG, "Starting input manager");
133 nativeStart();
134 }
135
136 public void setDisplaySize(int displayId, int width, int height) {
137 if (width <= 0 || height <= 0) {
138 throw new IllegalArgumentException("Invalid display id or dimensions.");
139 }
140
141 Slog.i(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
142 nativeSetDisplaySize(displayId, width, height);
143 }
144
145 public void setDisplayOrientation(int displayId, int rotation) {
146 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
147 throw new IllegalArgumentException("Invalid rotation.");
148 }
149
150 Slog.i(TAG, "Setting display #" + displayId + " orientation to " + rotation);
151 nativeSetDisplayOrientation(displayId, rotation);
152 }
153
154 public void getInputConfiguration(Configuration config) {
155 if (config == null) {
156 throw new IllegalArgumentException("config must not be null.");
157 }
158
159 config.touchscreen = mTouchScreenConfig;
160 config.keyboard = mKeyboardConfig;
161 config.navigation = mNavigationConfig;
162 }
163
Jeff Brown6d0fec22010-07-23 21:28:06 -0700164 /**
165 * Gets the current state of a key or button by key code.
166 * @param deviceId The input device id, or -1 to consult all devices.
167 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
168 * consider all input sources. An input device is consulted if at least one of its
169 * non-class input source bits matches the specified source mask.
170 * @param keyCode The key code to check.
171 * @return The key state.
172 */
173 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
174 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700175 }
176
Jeff Brown6d0fec22010-07-23 21:28:06 -0700177 /**
178 * Gets the current state of a key or button by scan code.
179 * @param deviceId The input device id, or -1 to consult all devices.
180 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
181 * consider all input sources. An input device is consulted if at least one of its
182 * non-class input source bits matches the specified source mask.
183 * @param scanCode The scan code to check.
184 * @return The key state.
185 */
186 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
187 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700188 }
189
Jeff Brown6d0fec22010-07-23 21:28:06 -0700190 /**
191 * Gets the current state of a switch by switch code.
192 * @param deviceId The input device id, or -1 to consult all devices.
193 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
194 * consider all input sources. An input device is consulted if at least one of its
195 * non-class input source bits matches the specified source mask.
196 * @param switchCode The switch code to check.
197 * @return The switch state.
198 */
199 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
200 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700201 }
202
Jeff Brown6d0fec22010-07-23 21:28:06 -0700203 /**
204 * Determines whether the specified key codes are supported by a particular device.
205 * @param deviceId The input device id, or -1 to consult all devices.
206 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
207 * consider all input sources. An input device is consulted if at least one of its
208 * non-class input source bits matches the specified source mask.
209 * @param keyCodes The array of key codes to check.
210 * @param keyExists An array at least as large as keyCodes whose entries will be set
211 * to true or false based on the presence or absence of support for the corresponding
212 * key codes.
213 * @return True if the lookup was successful, false otherwise.
214 */
215 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700216 if (keyCodes == null) {
217 throw new IllegalArgumentException("keyCodes must not be null.");
218 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700219 if (keyExists == null || keyExists.length < keyCodes.length) {
220 throw new IllegalArgumentException("keyExists must not be null and must be at "
221 + "least as large as keyCodes.");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700222 }
223
Jeff Brown6d0fec22010-07-23 21:28:06 -0700224 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700225 }
226
Jeff Browna41ca772010-08-11 14:46:32 -0700227 /**
228 * Creates an input channel that will receive all input from the input dispatcher.
229 * @param inputChannelName The input channel name.
230 * @return The input channel.
231 */
232 public InputChannel monitorInput(String inputChannelName) {
233 if (inputChannelName == null) {
234 throw new IllegalArgumentException("inputChannelName must not be null.");
235 }
236
237 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
238 nativeRegisterInputChannel(inputChannels[0], true);
239 inputChannels[0].dispose(); // don't need to retain the Java object reference
240 return inputChannels[1];
241 }
242
243 /**
244 * Registers an input channel so that it can be used as an input event target.
245 * @param inputChannel The input channel to register.
246 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700247 public void registerInputChannel(InputChannel inputChannel) {
248 if (inputChannel == null) {
249 throw new IllegalArgumentException("inputChannel must not be null.");
250 }
251
Jeff Browna41ca772010-08-11 14:46:32 -0700252 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700253 }
254
Jeff Browna41ca772010-08-11 14:46:32 -0700255 /**
256 * Unregisters an input channel.
257 * @param inputChannel The input channel to unregister.
258 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700259 public void unregisterInputChannel(InputChannel inputChannel) {
260 if (inputChannel == null) {
261 throw new IllegalArgumentException("inputChannel must not be null.");
262 }
263
264 nativeUnregisterInputChannel(inputChannel);
265 }
266
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700267 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700268 * Injects an input event into the event system on behalf of an application.
269 * The synchronization mode determines whether the method blocks while waiting for
270 * input injection to proceed.
271 *
272 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
273 * is assumed always to be successful.
274 *
275 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
276 * dispatched so that the input dispatcher can determine whether input event injection will
277 * be permitted based on the current input focus. Does not wait for the input event to
278 * finish processing.
279 *
280 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
281 * be completely processed.
282 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700283 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700284 * @param injectorPid The pid of the injecting application.
285 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700286 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700287 * @param timeoutMillis The injection timeout in milliseconds.
288 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700289 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700290 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
291 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700292 if (event == null) {
293 throw new IllegalArgumentException("event must not be null");
294 }
295 if (injectorPid < 0 || injectorUid < 0) {
296 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
297 }
298 if (timeoutMillis <= 0) {
299 throw new IllegalArgumentException("timeoutMillis must be positive");
300 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700301
302 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700303 }
304
Jeff Brown349703e2010-06-22 01:27:15 -0700305 public void setInputWindows(InputWindow[] windows) {
306 nativeSetInputWindows(windows);
307 }
308
309 public void setFocusedApplication(InputApplication application) {
310 nativeSetFocusedApplication(application);
311 }
312
313 public void preemptInputDispatch() {
314 nativePreemptInputDispatch();
315 }
316
317 public void setInputDispatchMode(boolean enabled, boolean frozen) {
318 nativeSetInputDispatchMode(enabled, frozen);
319 }
320
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700321 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700322 String dumpStr = nativeDump();
323 if (dumpStr != null) {
324 pw.println(dumpStr);
325 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700326 }
327
328 private static final class VirtualKeyDefinition {
329 public int scanCode;
330
331 // configured position data, specified in display coords
332 public int centerX;
333 public int centerY;
334 public int width;
335 public int height;
336 }
337
338 /*
339 * Callbacks from native.
340 */
341 private class Callbacks {
342 static final String TAG = "InputManager-Callbacks";
343
344 private static final boolean DEBUG_VIRTUAL_KEYS = false;
345 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
346
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700347 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700348 public void virtualKeyDownFeedback() {
349 mWindowManagerService.mInputMonitor.virtualKeyDownFeedback();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700350 }
351
352 @SuppressWarnings("unused")
353 public void notifyConfigurationChanged(long whenNanos,
354 int touchScreenConfig, int keyboardConfig, int navigationConfig) {
355 mTouchScreenConfig = touchScreenConfig;
356 mKeyboardConfig = keyboardConfig;
357 mNavigationConfig = navigationConfig;
358
359 mWindowManagerService.sendNewConfiguration();
360 }
361
362 @SuppressWarnings("unused")
363 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700364 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700365 }
366
367 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700368 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700369 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700370 }
371
372 @SuppressWarnings("unused")
373 public long notifyInputChannelANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700374 return mWindowManagerService.mInputMonitor.notifyInputChannelANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700375 }
376
377 @SuppressWarnings("unused")
378 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700379 mWindowManagerService.mInputMonitor.notifyInputChannelRecoveredFromANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700380 }
381
382 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700383 public long notifyANR(Object token) {
384 return mWindowManagerService.mInputMonitor.notifyANR(token);
385 }
386
387 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700388 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
389 int policyFlags, boolean isScreenOn) {
390 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
391 whenNanos, keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700392 }
393
394 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700395 public boolean interceptKeyBeforeDispatching(InputChannel focus, int action,
396 int flags, int keyCode, int metaState, int repeatCount, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -0700397 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(focus,
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700398 action, flags, keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700399 }
400
401 @SuppressWarnings("unused")
402 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
403 return mContext.checkPermission(
404 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
405 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700406 }
407
408 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700409 public void notifyAppSwitchComing() {
Jeff Brown349703e2010-06-22 01:27:15 -0700410 mWindowManagerService.mInputMonitor.notifyAppSwitchComing();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700411 }
412
413 @SuppressWarnings("unused")
414 public boolean filterTouchEvents() {
415 return mContext.getResources().getBoolean(
416 com.android.internal.R.bool.config_filterTouchEvents);
417 }
418
419 @SuppressWarnings("unused")
420 public boolean filterJumpyTouchEvents() {
421 return mContext.getResources().getBoolean(
422 com.android.internal.R.bool.config_filterJumpyTouchEvents);
423 }
424
425 @SuppressWarnings("unused")
426 public VirtualKeyDefinition[] getVirtualKeyDefinitions(String deviceName) {
427 ArrayList<VirtualKeyDefinition> keys = new ArrayList<VirtualKeyDefinition>();
428
429 try {
430 FileInputStream fis = new FileInputStream(
431 "/sys/board_properties/virtualkeys." + deviceName);
432 InputStreamReader isr = new InputStreamReader(fis);
433 BufferedReader br = new BufferedReader(isr, 2048);
434 String str = br.readLine();
435 if (str != null) {
436 String[] it = str.split(":");
437 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
438 final int N = it.length-6;
439 for (int i=0; i<=N; i+=6) {
440 if (!"0x01".equals(it[i])) {
441 Slog.w(TAG, "Unknown virtual key type at elem #" + i
442 + ": " + it[i]);
443 continue;
444 }
445 try {
446 VirtualKeyDefinition key = new VirtualKeyDefinition();
447 key.scanCode = Integer.parseInt(it[i+1]);
448 key.centerX = Integer.parseInt(it[i+2]);
449 key.centerY = Integer.parseInt(it[i+3]);
450 key.width = Integer.parseInt(it[i+4]);
451 key.height = Integer.parseInt(it[i+5]);
452 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
453 + key.scanCode + ": center=" + key.centerX + ","
454 + key.centerY + " size=" + key.width + "x"
455 + key.height);
456 keys.add(key);
457 } catch (NumberFormatException e) {
458 Slog.w(TAG, "Bad number at region " + i + " in: "
459 + str, e);
460 }
461 }
462 }
463 br.close();
464 } catch (FileNotFoundException e) {
465 Slog.i(TAG, "No virtual keys found");
466 } catch (IOException e) {
467 Slog.w(TAG, "Error reading virtual keys", e);
468 }
469
470 return keys.toArray(new VirtualKeyDefinition[keys.size()]);
471 }
472
473 @SuppressWarnings("unused")
474 public String[] getExcludedDeviceNames() {
475 ArrayList<String> names = new ArrayList<String>();
476
477 // Read partner-provided list of excluded input devices
478 XmlPullParser parser = null;
479 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
480 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
481 FileReader confreader = null;
482 try {
483 confreader = new FileReader(confFile);
484 parser = Xml.newPullParser();
485 parser.setInput(confreader);
486 XmlUtils.beginDocument(parser, "devices");
487
488 while (true) {
489 XmlUtils.nextElement(parser);
490 if (!"device".equals(parser.getName())) {
491 break;
492 }
493 String name = parser.getAttributeValue(null, "name");
494 if (name != null) {
495 names.add(name);
496 }
497 }
498 } catch (FileNotFoundException e) {
499 // It's ok if the file does not exist.
500 } catch (Exception e) {
501 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
502 } finally {
503 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
504 }
505
506 return names.toArray(new String[names.size()]);
507 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700508
509 @SuppressWarnings("unused")
510 public int getMaxEventsPerSecond() {
511 int result = 0;
512 try {
513 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
514 } catch (NumberFormatException e) {
515 }
516 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700517 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700518 }
519 return result;
520 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700521 }
522}