blob: c2c799b4e0a01cbfe626e506df910a031c46c455 [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 Brown46b9ac0a2010-04-22 18:58:52 -070029import android.util.Slog;
30import android.util.Xml;
31import android.view.InputChannel;
Jeff Brown6ec402b2010-07-28 15:48:59 -070032import android.view.InputEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070033import android.view.KeyEvent;
34import android.view.MotionEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070035import android.view.Surface;
36import android.view.WindowManagerPolicy;
37
38import java.io.BufferedReader;
39import java.io.File;
40import java.io.FileInputStream;
41import java.io.FileNotFoundException;
42import java.io.FileReader;
43import java.io.IOException;
44import java.io.InputStreamReader;
45import java.io.PrintWriter;
46import java.util.ArrayList;
47
48/*
49 * Wraps the C++ InputManager and provides its callbacks.
50 *
51 * XXX Tempted to promote this to a first-class service, ie. InputManagerService, to
52 * improve separation of concerns with respect to the window manager.
53 */
54public class InputManager {
55 static final String TAG = "InputManager";
56
57 private final Callbacks mCallbacks;
58 private final Context mContext;
59 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070060
61 private int mTouchScreenConfig;
62 private int mKeyboardConfig;
63 private int mNavigationConfig;
64
65 private static native void nativeInit(Callbacks callbacks);
66 private static native void nativeStart();
67 private static native void nativeSetDisplaySize(int displayId, int width, int height);
68 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
69
Jeff Brown6d0fec22010-07-23 21:28:06 -070070 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070071 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070072 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070073 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070074 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070075 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070076 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
77 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070078 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
79 boolean monitor);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070080 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070081 private static native int nativeInjectInputEvent(InputEvent event,
82 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070083 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 Browne33348b2010-07-15 23:54:05 -070087 private static native String nativeDump();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070088
Jeff Brown7fbdc842010-06-17 20:52:56 -070089 // 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 Brown6ec402b2010-07-28 15:48:59 -070095 // Input event injection synchronization modes defined in InputDispatcher.h
96 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
97 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
98 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
99
Jeff Brown6d0fec22010-07-23 21:28:06 -0700100 // Key states (may be returned by queries about the current state of a
101 // particular key code, scan code or switch).
102
103 /** The key state is unknown or the requested key itself is not supported. */
104 public static final int KEY_STATE_UNKNOWN = -1;
105
106 /** The key is up. /*/
107 public static final int KEY_STATE_UP = 0;
108
109 /** The key is down. */
110 public static final int KEY_STATE_DOWN = 1;
111
112 /** The key is down but is a virtual key press that is being emulated by the system. */
113 public static final int KEY_STATE_VIRTUAL = 2;
114
Jeff Browne33348b2010-07-15 23:54:05 -0700115 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700116 this.mContext = context;
117 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700118
119 this.mCallbacks = new Callbacks();
120
121 mTouchScreenConfig = Configuration.TOUCHSCREEN_NOTOUCH;
122 mKeyboardConfig = Configuration.KEYBOARD_NOKEYS;
123 mNavigationConfig = Configuration.NAVIGATION_NONAV;
124
125 init();
126 }
127
128 private void init() {
129 Slog.i(TAG, "Initializing input manager");
130 nativeInit(mCallbacks);
131 }
132
133 public void start() {
134 Slog.i(TAG, "Starting input manager");
135 nativeStart();
136 }
137
138 public void setDisplaySize(int displayId, int width, int height) {
139 if (width <= 0 || height <= 0) {
140 throw new IllegalArgumentException("Invalid display id or dimensions.");
141 }
142
143 Slog.i(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
144 nativeSetDisplaySize(displayId, width, height);
145 }
146
147 public void setDisplayOrientation(int displayId, int rotation) {
148 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
149 throw new IllegalArgumentException("Invalid rotation.");
150 }
151
152 Slog.i(TAG, "Setting display #" + displayId + " orientation to " + rotation);
153 nativeSetDisplayOrientation(displayId, rotation);
154 }
155
156 public void getInputConfiguration(Configuration config) {
157 if (config == null) {
158 throw new IllegalArgumentException("config must not be null.");
159 }
160
161 config.touchscreen = mTouchScreenConfig;
162 config.keyboard = mKeyboardConfig;
163 config.navigation = mNavigationConfig;
164 }
165
Jeff Brown6d0fec22010-07-23 21:28:06 -0700166 /**
167 * Gets the current state of a key or button by key code.
168 * @param deviceId The input device id, or -1 to consult all devices.
169 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
170 * consider all input sources. An input device is consulted if at least one of its
171 * non-class input source bits matches the specified source mask.
172 * @param keyCode The key code to check.
173 * @return The key state.
174 */
175 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
176 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700177 }
178
Jeff Brown6d0fec22010-07-23 21:28:06 -0700179 /**
180 * Gets the current state of a key or button by scan code.
181 * @param deviceId The input device id, or -1 to consult all devices.
182 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
183 * consider all input sources. An input device is consulted if at least one of its
184 * non-class input source bits matches the specified source mask.
185 * @param scanCode The scan code to check.
186 * @return The key state.
187 */
188 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
189 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700190 }
191
Jeff Brown6d0fec22010-07-23 21:28:06 -0700192 /**
193 * Gets the current state of a switch by switch code.
194 * @param deviceId The input device id, or -1 to consult all devices.
195 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
196 * consider all input sources. An input device is consulted if at least one of its
197 * non-class input source bits matches the specified source mask.
198 * @param switchCode The switch code to check.
199 * @return The switch state.
200 */
201 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
202 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700203 }
204
Jeff Brown6d0fec22010-07-23 21:28:06 -0700205 /**
206 * Determines whether the specified key codes are supported by a particular device.
207 * @param deviceId The input device id, or -1 to consult all devices.
208 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
209 * consider all input sources. An input device is consulted if at least one of its
210 * non-class input source bits matches the specified source mask.
211 * @param keyCodes The array of key codes to check.
212 * @param keyExists An array at least as large as keyCodes whose entries will be set
213 * to true or false based on the presence or absence of support for the corresponding
214 * key codes.
215 * @return True if the lookup was successful, false otherwise.
216 */
217 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700218 if (keyCodes == null) {
219 throw new IllegalArgumentException("keyCodes must not be null.");
220 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700221 if (keyExists == null || keyExists.length < keyCodes.length) {
222 throw new IllegalArgumentException("keyExists must not be null and must be at "
223 + "least as large as keyCodes.");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700224 }
225
Jeff Brown6d0fec22010-07-23 21:28:06 -0700226 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700227 }
228
Jeff Browna41ca772010-08-11 14:46:32 -0700229 /**
230 * Creates an input channel that will receive all input from the input dispatcher.
231 * @param inputChannelName The input channel name.
232 * @return The input channel.
233 */
234 public InputChannel monitorInput(String inputChannelName) {
235 if (inputChannelName == null) {
236 throw new IllegalArgumentException("inputChannelName must not be null.");
237 }
238
239 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
240 nativeRegisterInputChannel(inputChannels[0], true);
241 inputChannels[0].dispose(); // don't need to retain the Java object reference
242 return inputChannels[1];
243 }
244
245 /**
246 * Registers an input channel so that it can be used as an input event target.
247 * @param inputChannel The input channel to register.
248 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700249 public void registerInputChannel(InputChannel inputChannel) {
250 if (inputChannel == null) {
251 throw new IllegalArgumentException("inputChannel must not be null.");
252 }
253
Jeff Browna41ca772010-08-11 14:46:32 -0700254 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700255 }
256
Jeff Browna41ca772010-08-11 14:46:32 -0700257 /**
258 * Unregisters an input channel.
259 * @param inputChannel The input channel to unregister.
260 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700261 public void unregisterInputChannel(InputChannel inputChannel) {
262 if (inputChannel == null) {
263 throw new IllegalArgumentException("inputChannel must not be null.");
264 }
265
266 nativeUnregisterInputChannel(inputChannel);
267 }
268
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700269 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700270 * Injects an input event into the event system on behalf of an application.
271 * The synchronization mode determines whether the method blocks while waiting for
272 * input injection to proceed.
273 *
274 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
275 * is assumed always to be successful.
276 *
277 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
278 * dispatched so that the input dispatcher can determine whether input event injection will
279 * be permitted based on the current input focus. Does not wait for the input event to
280 * finish processing.
281 *
282 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
283 * be completely processed.
284 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700285 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700286 * @param injectorPid The pid of the injecting application.
287 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700288 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700289 * @param timeoutMillis The injection timeout in milliseconds.
290 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700291 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700292 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
293 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700294 if (event == null) {
295 throw new IllegalArgumentException("event must not be null");
296 }
297 if (injectorPid < 0 || injectorUid < 0) {
298 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
299 }
300 if (timeoutMillis <= 0) {
301 throw new IllegalArgumentException("timeoutMillis must be positive");
302 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700303
304 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700305 }
306
Jeff Brown349703e2010-06-22 01:27:15 -0700307 public void setInputWindows(InputWindow[] windows) {
308 nativeSetInputWindows(windows);
309 }
310
311 public void setFocusedApplication(InputApplication application) {
312 nativeSetFocusedApplication(application);
313 }
314
315 public void preemptInputDispatch() {
316 nativePreemptInputDispatch();
317 }
318
319 public void setInputDispatchMode(boolean enabled, boolean frozen) {
320 nativeSetInputDispatchMode(enabled, frozen);
321 }
322
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700323 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700324 String dumpStr = nativeDump();
325 if (dumpStr != null) {
326 pw.println(dumpStr);
327 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700328 }
329
330 private static final class VirtualKeyDefinition {
331 public int scanCode;
332
333 // configured position data, specified in display coords
334 public int centerX;
335 public int centerY;
336 public int width;
337 public int height;
338 }
339
340 /*
341 * Callbacks from native.
342 */
343 private class Callbacks {
344 static final String TAG = "InputManager-Callbacks";
345
346 private static final boolean DEBUG_VIRTUAL_KEYS = false;
347 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
348
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700349 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700350 public void virtualKeyDownFeedback() {
351 mWindowManagerService.mInputMonitor.virtualKeyDownFeedback();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700352 }
353
354 @SuppressWarnings("unused")
355 public void notifyConfigurationChanged(long whenNanos,
356 int touchScreenConfig, int keyboardConfig, int navigationConfig) {
357 mTouchScreenConfig = touchScreenConfig;
358 mKeyboardConfig = keyboardConfig;
359 mNavigationConfig = navigationConfig;
360
361 mWindowManagerService.sendNewConfiguration();
362 }
363
364 @SuppressWarnings("unused")
365 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700366 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700367 }
368
369 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700370 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700371 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700372 }
373
374 @SuppressWarnings("unused")
375 public long notifyInputChannelANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700376 return mWindowManagerService.mInputMonitor.notifyInputChannelANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700377 }
378
379 @SuppressWarnings("unused")
380 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700381 mWindowManagerService.mInputMonitor.notifyInputChannelRecoveredFromANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700382 }
383
384 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700385 public long notifyANR(Object token) {
386 return mWindowManagerService.mInputMonitor.notifyANR(token);
387 }
388
389 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700390 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
391 int policyFlags, boolean isScreenOn) {
392 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
393 whenNanos, keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700394 }
395
396 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700397 public boolean interceptKeyBeforeDispatching(InputChannel focus, int action,
398 int flags, int keyCode, int metaState, int repeatCount, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -0700399 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(focus,
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700400 action, flags, keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700401 }
402
403 @SuppressWarnings("unused")
404 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
405 return mContext.checkPermission(
406 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
407 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700408 }
409
410 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700411 public void notifyAppSwitchComing() {
Jeff Brown349703e2010-06-22 01:27:15 -0700412 mWindowManagerService.mInputMonitor.notifyAppSwitchComing();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700413 }
414
415 @SuppressWarnings("unused")
416 public boolean filterTouchEvents() {
417 return mContext.getResources().getBoolean(
418 com.android.internal.R.bool.config_filterTouchEvents);
419 }
420
421 @SuppressWarnings("unused")
422 public boolean filterJumpyTouchEvents() {
423 return mContext.getResources().getBoolean(
424 com.android.internal.R.bool.config_filterJumpyTouchEvents);
425 }
426
427 @SuppressWarnings("unused")
428 public VirtualKeyDefinition[] getVirtualKeyDefinitions(String deviceName) {
429 ArrayList<VirtualKeyDefinition> keys = new ArrayList<VirtualKeyDefinition>();
430
431 try {
432 FileInputStream fis = new FileInputStream(
433 "/sys/board_properties/virtualkeys." + deviceName);
434 InputStreamReader isr = new InputStreamReader(fis);
435 BufferedReader br = new BufferedReader(isr, 2048);
436 String str = br.readLine();
437 if (str != null) {
438 String[] it = str.split(":");
439 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
440 final int N = it.length-6;
441 for (int i=0; i<=N; i+=6) {
442 if (!"0x01".equals(it[i])) {
443 Slog.w(TAG, "Unknown virtual key type at elem #" + i
444 + ": " + it[i]);
445 continue;
446 }
447 try {
448 VirtualKeyDefinition key = new VirtualKeyDefinition();
449 key.scanCode = Integer.parseInt(it[i+1]);
450 key.centerX = Integer.parseInt(it[i+2]);
451 key.centerY = Integer.parseInt(it[i+3]);
452 key.width = Integer.parseInt(it[i+4]);
453 key.height = Integer.parseInt(it[i+5]);
454 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
455 + key.scanCode + ": center=" + key.centerX + ","
456 + key.centerY + " size=" + key.width + "x"
457 + key.height);
458 keys.add(key);
459 } catch (NumberFormatException e) {
460 Slog.w(TAG, "Bad number at region " + i + " in: "
461 + str, e);
462 }
463 }
464 }
465 br.close();
466 } catch (FileNotFoundException e) {
467 Slog.i(TAG, "No virtual keys found");
468 } catch (IOException e) {
469 Slog.w(TAG, "Error reading virtual keys", e);
470 }
471
472 return keys.toArray(new VirtualKeyDefinition[keys.size()]);
473 }
474
475 @SuppressWarnings("unused")
476 public String[] getExcludedDeviceNames() {
477 ArrayList<String> names = new ArrayList<String>();
478
479 // Read partner-provided list of excluded input devices
480 XmlPullParser parser = null;
481 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
482 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
483 FileReader confreader = null;
484 try {
485 confreader = new FileReader(confFile);
486 parser = Xml.newPullParser();
487 parser.setInput(confreader);
488 XmlUtils.beginDocument(parser, "devices");
489
490 while (true) {
491 XmlUtils.nextElement(parser);
492 if (!"device".equals(parser.getName())) {
493 break;
494 }
495 String name = parser.getAttributeValue(null, "name");
496 if (name != null) {
497 names.add(name);
498 }
499 }
500 } catch (FileNotFoundException e) {
501 // It's ok if the file does not exist.
502 } catch (Exception e) {
503 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
504 } finally {
505 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
506 }
507
508 return names.toArray(new String[names.size()]);
509 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700510 }
511}