blob: b5becb5c4405a9b724655edf70864ad935d6cd90 [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;
Jeff Brownae9fc032010-08-18 15:51:08 -070027import android.os.SystemProperties;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070028import android.util.Slog;
29import android.util.Xml;
30import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070031import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070032import android.view.InputEvent;
Jeff Brown1f245102010-11-18 20:53:46 -080033import android.view.KeyEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070034import android.view.Surface;
Jeff Brown83c09682010-12-23 17:50:18 -080035import android.view.WindowManager;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070036
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.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070049 */
50public class InputManager {
51 static final String TAG = "InputManager";
52
Jeff Brownb6997262010-10-08 22:31:17 -070053 private static final boolean DEBUG = false;
54
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070055 private final Callbacks mCallbacks;
56 private final Context mContext;
57 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070058
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070059 private static native void nativeInit(Callbacks callbacks);
60 private static native void nativeStart();
61 private static native void nativeSetDisplaySize(int displayId, int width, int height);
62 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
63
Jeff Brown6d0fec22010-07-23 21:28:06 -070064 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070065 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070066 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070067 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070068 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070069 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070070 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
71 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070072 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
73 boolean monitor);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070074 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070075 private static native int nativeInjectInputEvent(InputEvent event,
76 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070077 private static native void nativeSetInputWindows(InputWindow[] windows);
78 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
79 private static native void nativeSetFocusedApplication(InputApplication application);
Jeff Brown8d608662010-08-30 03:02:23 -070080 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070081 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070082 private static native int[] nativeGetInputDeviceIds();
Jeff Browne6504122010-09-27 14:52:15 -070083 private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
84 InputChannel toChannel);
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
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700119 init();
120 }
121
122 private void init() {
123 Slog.i(TAG, "Initializing input manager");
124 nativeInit(mCallbacks);
125 }
126
127 public void start() {
128 Slog.i(TAG, "Starting input manager");
129 nativeStart();
130 }
131
132 public void setDisplaySize(int displayId, int width, int height) {
133 if (width <= 0 || height <= 0) {
134 throw new IllegalArgumentException("Invalid display id or dimensions.");
135 }
136
Jeff Brownb6997262010-10-08 22:31:17 -0700137 if (DEBUG) {
138 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
139 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700140 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
Jeff Brownb6997262010-10-08 22:31:17 -0700148 if (DEBUG) {
149 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
150 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700151 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
Jeff Brown57c59372010-09-21 18:22:55 -0700159 nativeGetInputConfiguration(config);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700160 }
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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-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 Brown46b9ac0a2010-04-22 18:58:52 -0700220 }
221
Jeff Brown6d0fec22010-07-23 21:28:06 -0700222 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700223 }
224
Jeff Browna41ca772010-08-11 14:46:32 -0700225 /**
226 * Creates an input channel that will receive all input from the input dispatcher.
227 * @param inputChannelName The input channel name.
228 * @return The input channel.
229 */
230 public InputChannel monitorInput(String inputChannelName) {
231 if (inputChannelName == null) {
232 throw new IllegalArgumentException("inputChannelName must not be null.");
233 }
234
235 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
236 nativeRegisterInputChannel(inputChannels[0], true);
237 inputChannels[0].dispose(); // don't need to retain the Java object reference
238 return inputChannels[1];
239 }
240
241 /**
242 * Registers an input channel so that it can be used as an input event target.
243 * @param inputChannel The input channel to register.
244 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700245 public void registerInputChannel(InputChannel inputChannel) {
246 if (inputChannel == null) {
247 throw new IllegalArgumentException("inputChannel must not be null.");
248 }
249
Jeff Browna41ca772010-08-11 14:46:32 -0700250 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700251 }
252
Jeff Browna41ca772010-08-11 14:46:32 -0700253 /**
254 * Unregisters an input channel.
255 * @param inputChannel The input channel to unregister.
256 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700257 public void unregisterInputChannel(InputChannel inputChannel) {
258 if (inputChannel == null) {
259 throw new IllegalArgumentException("inputChannel must not be null.");
260 }
261
262 nativeUnregisterInputChannel(inputChannel);
263 }
264
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700265 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700266 * Injects an input event into the event system on behalf of an application.
267 * The synchronization mode determines whether the method blocks while waiting for
268 * input injection to proceed.
269 *
270 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
271 * is assumed always to be successful.
272 *
273 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
274 * dispatched so that the input dispatcher can determine whether input event injection will
275 * be permitted based on the current input focus. Does not wait for the input event to
276 * finish processing.
277 *
278 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
279 * be completely processed.
280 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700281 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700282 * @param injectorPid The pid of the injecting application.
283 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700284 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700285 * @param timeoutMillis The injection timeout in milliseconds.
286 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700287 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700288 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
289 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700290 if (event == null) {
291 throw new IllegalArgumentException("event must not be null");
292 }
293 if (injectorPid < 0 || injectorUid < 0) {
294 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
295 }
296 if (timeoutMillis <= 0) {
297 throw new IllegalArgumentException("timeoutMillis must be positive");
298 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700299
300 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700301 }
302
Jeff Brown8d608662010-08-30 03:02:23 -0700303 /**
304 * Gets information about the input device with the specified id.
305 * @param id The device id.
306 * @return The input device or null if not found.
307 */
308 public InputDevice getInputDevice(int deviceId) {
309 return nativeGetInputDevice(deviceId);
310 }
311
312 /**
313 * Gets the ids of all input devices in the system.
314 * @return The input device ids.
315 */
316 public int[] getInputDeviceIds() {
317 return nativeGetInputDeviceIds();
318 }
319
Jeff Brown349703e2010-06-22 01:27:15 -0700320 public void setInputWindows(InputWindow[] windows) {
321 nativeSetInputWindows(windows);
322 }
323
324 public void setFocusedApplication(InputApplication application) {
325 nativeSetFocusedApplication(application);
326 }
327
Jeff Brown349703e2010-06-22 01:27:15 -0700328 public void setInputDispatchMode(boolean enabled, boolean frozen) {
329 nativeSetInputDispatchMode(enabled, frozen);
330 }
331
Jeff Browne6504122010-09-27 14:52:15 -0700332 /**
333 * Atomically transfers touch focus from one window to another as identified by
334 * their input channels. It is possible for multiple windows to have
335 * touch focus if they support split touch dispatch
336 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
337 * method only transfers touch focus of the specified window without affecting
338 * other windows that may also have touch focus at the same time.
339 * @param fromChannel The channel of a window that currently has touch focus.
340 * @param toChannel The channel of the window that should receive touch focus in
341 * place of the first.
342 * @return True if the transfer was successful. False if the window with the
343 * specified channel did not actually have touch focus at the time of the request.
344 */
345 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
346 if (fromChannel == null) {
347 throw new IllegalArgumentException("fromChannel must not be null.");
348 }
349 if (toChannel == null) {
350 throw new IllegalArgumentException("toChannel must not be null.");
351 }
352 return nativeTransferTouchFocus(fromChannel, toChannel);
353 }
354
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700355 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700356 String dumpStr = nativeDump();
357 if (dumpStr != null) {
358 pw.println(dumpStr);
359 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700360 }
361
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700362 /*
363 * Callbacks from native.
364 */
365 private class Callbacks {
366 static final String TAG = "InputManager-Callbacks";
367
368 private static final boolean DEBUG_VIRTUAL_KEYS = false;
369 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700370 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700371
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700372 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700373 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700374 mWindowManagerService.sendNewConfiguration();
375 }
376
377 @SuppressWarnings("unused")
378 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700379 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700380 }
381
382 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700383 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700384 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700385 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700386
387 @SuppressWarnings("unused")
Jeff Brown519e0242010-09-15 15:18:56 -0700388 public long notifyANR(Object token, InputChannel inputChannel) {
389 return mWindowManagerService.mInputMonitor.notifyANR(token, inputChannel);
Jeff Brown349703e2010-06-22 01:27:15 -0700390 }
391
392 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800393 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700394 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Brown1f245102010-11-18 20:53:46 -0800395 event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700396 }
397
398 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800399 public boolean interceptKeyBeforeDispatching(InputChannel focus,
400 KeyEvent event, int policyFlags) {
401 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
402 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700403 }
404
405 @SuppressWarnings("unused")
Jeff Brown49ed71d2010-12-06 17:13:33 -0800406 public KeyEvent dispatchUnhandledKey(InputChannel focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800407 KeyEvent event, int policyFlags) {
408 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
409 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700410 }
411
412 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700413 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
414 return mContext.checkPermission(
415 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
416 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700417 }
418
419 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700420 public boolean filterTouchEvents() {
421 return mContext.getResources().getBoolean(
422 com.android.internal.R.bool.config_filterTouchEvents);
423 }
424
425 @SuppressWarnings("unused")
426 public boolean filterJumpyTouchEvents() {
427 return mContext.getResources().getBoolean(
428 com.android.internal.R.bool.config_filterJumpyTouchEvents);
429 }
430
431 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700432 public String[] getExcludedDeviceNames() {
433 ArrayList<String> names = new ArrayList<String>();
434
435 // Read partner-provided list of excluded input devices
436 XmlPullParser parser = null;
437 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
438 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
439 FileReader confreader = null;
440 try {
441 confreader = new FileReader(confFile);
442 parser = Xml.newPullParser();
443 parser.setInput(confreader);
444 XmlUtils.beginDocument(parser, "devices");
445
446 while (true) {
447 XmlUtils.nextElement(parser);
448 if (!"device".equals(parser.getName())) {
449 break;
450 }
451 String name = parser.getAttributeValue(null, "name");
452 if (name != null) {
453 names.add(name);
454 }
455 }
456 } catch (FileNotFoundException e) {
457 // It's ok if the file does not exist.
458 } catch (Exception e) {
459 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
460 } finally {
461 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
462 }
463
464 return names.toArray(new String[names.size()]);
465 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700466
467 @SuppressWarnings("unused")
468 public int getMaxEventsPerSecond() {
469 int result = 0;
470 try {
471 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
472 } catch (NumberFormatException e) {
473 }
474 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700475 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700476 }
477 return result;
478 }
Jeff Brown83c09682010-12-23 17:50:18 -0800479
480 @SuppressWarnings("unused")
481 public int getPointerLayer() {
482 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
483 WindowManager.LayoutParams.TYPE_DRAG)
484 * WindowManagerService.TYPE_LAYER_MULTIPLIER
485 + WindowManagerService.TYPE_LAYER_OFFSET;
486 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 }
488}