blob: 9a1d0170a139661a9c828920bc918ebf8d637268 [file] [log] [blame]
Jeff Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-04-22 18:58:52 -070025import android.content.res.Configuration;
26import android.os.Environment;
27import android.os.LocalPowerManager;
28import android.os.PowerManager;
Jeff Brown46b9ac02010-04-22 18:58:52 -070029import android.util.Slog;
30import android.util.Xml;
31import android.view.InputChannel;
Jeff Brown46b9ac02010-04-22 18:58:52 -070032import android.view.KeyEvent;
33import android.view.MotionEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -070034import android.view.Surface;
35import android.view.WindowManagerPolicy;
36
37import java.io.BufferedReader;
38import java.io.File;
39import java.io.FileInputStream;
40import java.io.FileNotFoundException;
41import java.io.FileReader;
42import java.io.IOException;
43import java.io.InputStreamReader;
44import java.io.PrintWriter;
45import 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 */
53public 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 Brown46b9ac02010-04-22 18:58:52 -070059
60 private int mTouchScreenConfig;
61 private int mKeyboardConfig;
62 private int mNavigationConfig;
63
64 private static native void nativeInit(Callbacks callbacks);
65 private static native void nativeStart();
66 private static native void nativeSetDisplaySize(int displayId, int width, int height);
67 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
68
Jeff Brown6d0fec22010-07-23 21:28:06 -070069 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070070 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070071 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070072 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070073 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070074 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070075 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
76 int[] keyCodes, boolean[] keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -070077 private static native void nativeRegisterInputChannel(InputChannel inputChannel);
78 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brownc5ed5912010-07-14 18:48:53 -070079 private static native int nativeInjectKeyEvent(KeyEvent event,
Jeff Brown7fbdc842010-06-17 20:52:56 -070080 int injectorPid, int injectorUid, boolean sync, int timeoutMillis);
Jeff Brownc5ed5912010-07-14 18:48:53 -070081 private static native int nativeInjectMotionEvent(MotionEvent event,
Jeff Brown7fbdc842010-06-17 20:52:56 -070082 int injectorPid, int injectorUid, boolean sync, 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 Brown46b9ac02010-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 Brown6d0fec22010-07-23 21:28:06 -070095 // Key states (may be returned by queries about the current state of a
96 // particular key code, scan code or switch).
97
98 /** The key state is unknown or the requested key itself is not supported. */
99 public static final int KEY_STATE_UNKNOWN = -1;
100
101 /** The key is up. /*/
102 public static final int KEY_STATE_UP = 0;
103
104 /** The key is down. */
105 public static final int KEY_STATE_DOWN = 1;
106
107 /** The key is down but is a virtual key press that is being emulated by the system. */
108 public static final int KEY_STATE_VIRTUAL = 2;
109
110
Jeff Browne33348b2010-07-15 23:54:05 -0700111 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700112 this.mContext = context;
113 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700114
115 this.mCallbacks = new Callbacks();
116
117 mTouchScreenConfig = Configuration.TOUCHSCREEN_NOTOUCH;
118 mKeyboardConfig = Configuration.KEYBOARD_NOKEYS;
119 mNavigationConfig = Configuration.NAVIGATION_NONAV;
120
121 init();
122 }
123
124 private void init() {
125 Slog.i(TAG, "Initializing input manager");
126 nativeInit(mCallbacks);
127 }
128
129 public void start() {
130 Slog.i(TAG, "Starting input manager");
131 nativeStart();
132 }
133
134 public void setDisplaySize(int displayId, int width, int height) {
135 if (width <= 0 || height <= 0) {
136 throw new IllegalArgumentException("Invalid display id or dimensions.");
137 }
138
139 Slog.i(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
140 nativeSetDisplaySize(displayId, width, height);
141 }
142
143 public void setDisplayOrientation(int displayId, int rotation) {
144 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
145 throw new IllegalArgumentException("Invalid rotation.");
146 }
147
148 Slog.i(TAG, "Setting display #" + displayId + " orientation to " + rotation);
149 nativeSetDisplayOrientation(displayId, rotation);
150 }
151
152 public void getInputConfiguration(Configuration config) {
153 if (config == null) {
154 throw new IllegalArgumentException("config must not be null.");
155 }
156
157 config.touchscreen = mTouchScreenConfig;
158 config.keyboard = mKeyboardConfig;
159 config.navigation = mNavigationConfig;
160 }
161
Jeff Brown6d0fec22010-07-23 21:28:06 -0700162 /**
163 * Gets the current state of a key or button by key code.
164 * @param deviceId The input device id, or -1 to consult all devices.
165 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
166 * consider all input sources. An input device is consulted if at least one of its
167 * non-class input source bits matches the specified source mask.
168 * @param keyCode The key code to check.
169 * @return The key state.
170 */
171 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
172 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700173 }
174
Jeff Brown6d0fec22010-07-23 21:28:06 -0700175 /**
176 * Gets the current state of a key or button by scan code.
177 * @param deviceId The input device id, or -1 to consult all devices.
178 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
179 * consider all input sources. An input device is consulted if at least one of its
180 * non-class input source bits matches the specified source mask.
181 * @param scanCode The scan code to check.
182 * @return The key state.
183 */
184 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
185 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700186 }
187
Jeff Brown6d0fec22010-07-23 21:28:06 -0700188 /**
189 * Gets the current state of a switch by switch code.
190 * @param deviceId The input device id, or -1 to consult all devices.
191 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
192 * consider all input sources. An input device is consulted if at least one of its
193 * non-class input source bits matches the specified source mask.
194 * @param switchCode The switch code to check.
195 * @return The switch state.
196 */
197 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
198 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700199 }
200
Jeff Brown6d0fec22010-07-23 21:28:06 -0700201 /**
202 * Determines whether the specified key codes are supported by a particular device.
203 * @param deviceId The input device id, or -1 to consult all devices.
204 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
205 * consider all input sources. An input device is consulted if at least one of its
206 * non-class input source bits matches the specified source mask.
207 * @param keyCodes The array of key codes to check.
208 * @param keyExists An array at least as large as keyCodes whose entries will be set
209 * to true or false based on the presence or absence of support for the corresponding
210 * key codes.
211 * @return True if the lookup was successful, false otherwise.
212 */
213 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700214 if (keyCodes == null) {
215 throw new IllegalArgumentException("keyCodes must not be null.");
216 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700217 if (keyExists == null || keyExists.length < keyCodes.length) {
218 throw new IllegalArgumentException("keyExists must not be null and must be at "
219 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700220 }
221
Jeff Brown6d0fec22010-07-23 21:28:06 -0700222 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700223 }
224
225 public void registerInputChannel(InputChannel inputChannel) {
226 if (inputChannel == null) {
227 throw new IllegalArgumentException("inputChannel must not be null.");
228 }
229
230 nativeRegisterInputChannel(inputChannel);
231 }
232
233 public void unregisterInputChannel(InputChannel inputChannel) {
234 if (inputChannel == null) {
235 throw new IllegalArgumentException("inputChannel must not be null.");
236 }
237
238 nativeUnregisterInputChannel(inputChannel);
239 }
240
Jeff Brown46b9ac02010-04-22 18:58:52 -0700241 /**
242 * Injects a key event into the event system on behalf of an application.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700243 * This method may block even if sync is false because it must wait for previous events
244 * to be dispatched before it can determine whether input event injection will be
245 * permitted based on the current input focus.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700246 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700247 * @param injectorPid The pid of the injecting application.
248 * @param injectorUid The uid of the injecting application.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700249 * @param sync If true, waits for the event to be completed before returning.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700250 * @param timeoutMillis The injection timeout in milliseconds.
251 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700252 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700253 public int injectKeyEvent(KeyEvent event, int injectorPid, int injectorUid,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700254 boolean sync, int timeoutMillis) {
255 if (event == null) {
256 throw new IllegalArgumentException("event must not be null");
257 }
258 if (injectorPid < 0 || injectorUid < 0) {
259 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
260 }
261 if (timeoutMillis <= 0) {
262 throw new IllegalArgumentException("timeoutMillis must be positive");
263 }
264
Jeff Brownc5ed5912010-07-14 18:48:53 -0700265 return nativeInjectKeyEvent(event, injectorPid, injectorUid,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700266 sync, timeoutMillis);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700267 }
268
269 /**
270 * Injects a motion event into the event system on behalf of an application.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700271 * This method may block even if sync is false because it must wait for previous events
272 * to be dispatched before it can determine whether input event injection will be
273 * permitted based on the current input focus.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700274 * @param event The event to inject.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700275 * @param sync If true, waits for the event to be completed before returning.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700276 * @param injectorPid The pid of the injecting application.
277 * @param injectorUid The uid of the injecting application.
278 * @param sync If true, waits for the event to be completed before returning.
279 * @param timeoutMillis The injection timeout in milliseconds.
280 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700281 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700282 public int injectMotionEvent(MotionEvent event, int injectorPid, int injectorUid,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700283 boolean sync, int timeoutMillis) {
284 if (event == null) {
285 throw new IllegalArgumentException("event must not be null");
286 }
287 if (injectorPid < 0 || injectorUid < 0) {
288 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
289 }
290 if (timeoutMillis <= 0) {
291 throw new IllegalArgumentException("timeoutMillis must be positive");
292 }
293
Jeff Brownc5ed5912010-07-14 18:48:53 -0700294 return nativeInjectMotionEvent(event, injectorPid, injectorUid,
Jeff Brown7fbdc842010-06-17 20:52:56 -0700295 sync, timeoutMillis);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700296 }
297
Jeff Brown349703e2010-06-22 01:27:15 -0700298 public void setInputWindows(InputWindow[] windows) {
299 nativeSetInputWindows(windows);
300 }
301
302 public void setFocusedApplication(InputApplication application) {
303 nativeSetFocusedApplication(application);
304 }
305
306 public void preemptInputDispatch() {
307 nativePreemptInputDispatch();
308 }
309
310 public void setInputDispatchMode(boolean enabled, boolean frozen) {
311 nativeSetInputDispatchMode(enabled, frozen);
312 }
313
Jeff Brown46b9ac02010-04-22 18:58:52 -0700314 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700315 String dumpStr = nativeDump();
316 if (dumpStr != null) {
317 pw.println(dumpStr);
318 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700319 }
320
321 private static final class VirtualKeyDefinition {
322 public int scanCode;
323
324 // configured position data, specified in display coords
325 public int centerX;
326 public int centerY;
327 public int width;
328 public int height;
329 }
330
331 /*
332 * Callbacks from native.
333 */
334 private class Callbacks {
335 static final String TAG = "InputManager-Callbacks";
336
337 private static final boolean DEBUG_VIRTUAL_KEYS = false;
338 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
339
Jeff Brown46b9ac02010-04-22 18:58:52 -0700340 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700341 public void virtualKeyDownFeedback() {
342 mWindowManagerService.mInputMonitor.virtualKeyDownFeedback();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700343 }
344
345 @SuppressWarnings("unused")
346 public void notifyConfigurationChanged(long whenNanos,
347 int touchScreenConfig, int keyboardConfig, int navigationConfig) {
348 mTouchScreenConfig = touchScreenConfig;
349 mKeyboardConfig = keyboardConfig;
350 mNavigationConfig = navigationConfig;
351
352 mWindowManagerService.sendNewConfiguration();
353 }
354
355 @SuppressWarnings("unused")
356 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700357 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700358 }
359
360 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700361 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700362 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700363 }
364
365 @SuppressWarnings("unused")
366 public long notifyInputChannelANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700367 return mWindowManagerService.mInputMonitor.notifyInputChannelANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700368 }
369
370 @SuppressWarnings("unused")
371 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700372 mWindowManagerService.mInputMonitor.notifyInputChannelRecoveredFromANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700373 }
374
375 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700376 public long notifyANR(Object token) {
377 return mWindowManagerService.mInputMonitor.notifyANR(token);
378 }
379
380 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700381 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
382 int policyFlags, boolean isScreenOn) {
383 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
384 whenNanos, keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700385 }
386
387 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700388 public boolean interceptKeyBeforeDispatching(InputChannel focus, int action,
389 int flags, int keyCode, int metaState, int repeatCount, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -0700390 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(focus,
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700391 action, flags, keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700392 }
393
394 @SuppressWarnings("unused")
395 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
396 return mContext.checkPermission(
397 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
398 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700399 }
400
401 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700402 public void notifyAppSwitchComing() {
Jeff Brown349703e2010-06-22 01:27:15 -0700403 mWindowManagerService.mInputMonitor.notifyAppSwitchComing();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700404 }
405
406 @SuppressWarnings("unused")
407 public boolean filterTouchEvents() {
408 return mContext.getResources().getBoolean(
409 com.android.internal.R.bool.config_filterTouchEvents);
410 }
411
412 @SuppressWarnings("unused")
413 public boolean filterJumpyTouchEvents() {
414 return mContext.getResources().getBoolean(
415 com.android.internal.R.bool.config_filterJumpyTouchEvents);
416 }
417
418 @SuppressWarnings("unused")
419 public VirtualKeyDefinition[] getVirtualKeyDefinitions(String deviceName) {
420 ArrayList<VirtualKeyDefinition> keys = new ArrayList<VirtualKeyDefinition>();
421
422 try {
423 FileInputStream fis = new FileInputStream(
424 "/sys/board_properties/virtualkeys." + deviceName);
425 InputStreamReader isr = new InputStreamReader(fis);
426 BufferedReader br = new BufferedReader(isr, 2048);
427 String str = br.readLine();
428 if (str != null) {
429 String[] it = str.split(":");
430 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
431 final int N = it.length-6;
432 for (int i=0; i<=N; i+=6) {
433 if (!"0x01".equals(it[i])) {
434 Slog.w(TAG, "Unknown virtual key type at elem #" + i
435 + ": " + it[i]);
436 continue;
437 }
438 try {
439 VirtualKeyDefinition key = new VirtualKeyDefinition();
440 key.scanCode = Integer.parseInt(it[i+1]);
441 key.centerX = Integer.parseInt(it[i+2]);
442 key.centerY = Integer.parseInt(it[i+3]);
443 key.width = Integer.parseInt(it[i+4]);
444 key.height = Integer.parseInt(it[i+5]);
445 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
446 + key.scanCode + ": center=" + key.centerX + ","
447 + key.centerY + " size=" + key.width + "x"
448 + key.height);
449 keys.add(key);
450 } catch (NumberFormatException e) {
451 Slog.w(TAG, "Bad number at region " + i + " in: "
452 + str, e);
453 }
454 }
455 }
456 br.close();
457 } catch (FileNotFoundException e) {
458 Slog.i(TAG, "No virtual keys found");
459 } catch (IOException e) {
460 Slog.w(TAG, "Error reading virtual keys", e);
461 }
462
463 return keys.toArray(new VirtualKeyDefinition[keys.size()]);
464 }
465
466 @SuppressWarnings("unused")
467 public String[] getExcludedDeviceNames() {
468 ArrayList<String> names = new ArrayList<String>();
469
470 // Read partner-provided list of excluded input devices
471 XmlPullParser parser = null;
472 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
473 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
474 FileReader confreader = null;
475 try {
476 confreader = new FileReader(confFile);
477 parser = Xml.newPullParser();
478 parser.setInput(confreader);
479 XmlUtils.beginDocument(parser, "devices");
480
481 while (true) {
482 XmlUtils.nextElement(parser);
483 if (!"device".equals(parser.getName())) {
484 break;
485 }
486 String name = parser.getAttributeValue(null, "name");
487 if (name != null) {
488 names.add(name);
489 }
490 }
491 } catch (FileNotFoundException e) {
492 // It's ok if the file does not exist.
493 } catch (Exception e) {
494 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
495 } finally {
496 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
497 }
498
499 return names.toArray(new String[names.size()]);
500 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700501 }
502}