blob: 29ca9a4b3cfb65abc5707d419c0764c89736ce55 [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 Brown46b9ac0a2010-04-22 18:58:52 -070033import android.view.Surface;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070034
35import java.io.BufferedReader;
36import java.io.File;
37import java.io.FileInputStream;
38import java.io.FileNotFoundException;
39import java.io.FileReader;
40import java.io.IOException;
41import java.io.InputStreamReader;
42import java.io.PrintWriter;
43import java.util.ArrayList;
Jeff Brown8d608662010-08-30 03:02:23 -070044import java.util.Properties;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070045
46/*
47 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070048 */
49public class InputManager {
50 static final String TAG = "InputManager";
51
52 private final Callbacks mCallbacks;
53 private final Context mContext;
54 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070055
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070056 private static native void nativeInit(Callbacks callbacks);
57 private static native void nativeStart();
58 private static native void nativeSetDisplaySize(int displayId, int width, int height);
59 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
60
Jeff Brown6d0fec22010-07-23 21:28:06 -070061 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070062 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070063 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070064 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070065 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070066 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070067 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
68 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070069 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
70 boolean monitor);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070071 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070072 private static native int nativeInjectInputEvent(InputEvent event,
73 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070074 private static native void nativeSetInputWindows(InputWindow[] windows);
75 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
76 private static native void nativeSetFocusedApplication(InputApplication application);
Jeff Brown8d608662010-08-30 03:02:23 -070077 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070078 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070079 private static native int[] nativeGetInputDeviceIds();
Jeff Browne33348b2010-07-15 23:54:05 -070080 private static native String nativeDump();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070081
Jeff Brown7fbdc842010-06-17 20:52:56 -070082 // Input event injection constants defined in InputDispatcher.h.
83 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
84 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
85 static final int INPUT_EVENT_INJECTION_FAILED = 2;
86 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
87
Jeff Brown6ec402b2010-07-28 15:48:59 -070088 // Input event injection synchronization modes defined in InputDispatcher.h
89 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
90 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
91 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
92
Jeff Brown6d0fec22010-07-23 21:28:06 -070093 // Key states (may be returned by queries about the current state of a
94 // particular key code, scan code or switch).
95
96 /** The key state is unknown or the requested key itself is not supported. */
97 public static final int KEY_STATE_UNKNOWN = -1;
98
99 /** The key is up. /*/
100 public static final int KEY_STATE_UP = 0;
101
102 /** The key is down. */
103 public static final int KEY_STATE_DOWN = 1;
104
105 /** The key is down but is a virtual key press that is being emulated by the system. */
106 public static final int KEY_STATE_VIRTUAL = 2;
107
Jeff Browne33348b2010-07-15 23:54:05 -0700108 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700109 this.mContext = context;
110 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700111
112 this.mCallbacks = new Callbacks();
113
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700114 init();
115 }
116
117 private void init() {
118 Slog.i(TAG, "Initializing input manager");
119 nativeInit(mCallbacks);
120 }
121
122 public void start() {
123 Slog.i(TAG, "Starting input manager");
124 nativeStart();
125 }
126
127 public void setDisplaySize(int displayId, int width, int height) {
128 if (width <= 0 || height <= 0) {
129 throw new IllegalArgumentException("Invalid display id or dimensions.");
130 }
131
132 Slog.i(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
133 nativeSetDisplaySize(displayId, width, height);
134 }
135
136 public void setDisplayOrientation(int displayId, int rotation) {
137 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
138 throw new IllegalArgumentException("Invalid rotation.");
139 }
140
141 Slog.i(TAG, "Setting display #" + displayId + " orientation to " + rotation);
142 nativeSetDisplayOrientation(displayId, rotation);
143 }
144
145 public void getInputConfiguration(Configuration config) {
146 if (config == null) {
147 throw new IllegalArgumentException("config must not be null.");
148 }
149
Jeff Brown57c59372010-09-21 18:22:55 -0700150 nativeGetInputConfiguration(config);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700151 }
152
Jeff Brown6d0fec22010-07-23 21:28:06 -0700153 /**
154 * Gets the current state of a key or button by key code.
155 * @param deviceId The input device id, or -1 to consult all devices.
156 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
157 * consider all input sources. An input device is consulted if at least one of its
158 * non-class input source bits matches the specified source mask.
159 * @param keyCode The key code to check.
160 * @return The key state.
161 */
162 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
163 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700164 }
165
Jeff Brown6d0fec22010-07-23 21:28:06 -0700166 /**
167 * Gets the current state of a key or button by scan 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 scanCode The scan code to check.
173 * @return The key state.
174 */
175 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
176 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700177 }
178
Jeff Brown6d0fec22010-07-23 21:28:06 -0700179 /**
180 * Gets the current state of a switch by switch 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 switchCode The switch code to check.
186 * @return The switch state.
187 */
188 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
189 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700190 }
191
Jeff Brown6d0fec22010-07-23 21:28:06 -0700192 /**
193 * Determines whether the specified key codes are supported by a particular device.
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 keyCodes The array of key codes to check.
199 * @param keyExists An array at least as large as keyCodes whose entries will be set
200 * to true or false based on the presence or absence of support for the corresponding
201 * key codes.
202 * @return True if the lookup was successful, false otherwise.
203 */
204 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700205 if (keyCodes == null) {
206 throw new IllegalArgumentException("keyCodes must not be null.");
207 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700208 if (keyExists == null || keyExists.length < keyCodes.length) {
209 throw new IllegalArgumentException("keyExists must not be null and must be at "
210 + "least as large as keyCodes.");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700211 }
212
Jeff Brown6d0fec22010-07-23 21:28:06 -0700213 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700214 }
215
Jeff Browna41ca772010-08-11 14:46:32 -0700216 /**
217 * Creates an input channel that will receive all input from the input dispatcher.
218 * @param inputChannelName The input channel name.
219 * @return The input channel.
220 */
221 public InputChannel monitorInput(String inputChannelName) {
222 if (inputChannelName == null) {
223 throw new IllegalArgumentException("inputChannelName must not be null.");
224 }
225
226 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
227 nativeRegisterInputChannel(inputChannels[0], true);
228 inputChannels[0].dispose(); // don't need to retain the Java object reference
229 return inputChannels[1];
230 }
231
232 /**
233 * Registers an input channel so that it can be used as an input event target.
234 * @param inputChannel The input channel to register.
235 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700236 public void registerInputChannel(InputChannel inputChannel) {
237 if (inputChannel == null) {
238 throw new IllegalArgumentException("inputChannel must not be null.");
239 }
240
Jeff Browna41ca772010-08-11 14:46:32 -0700241 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700242 }
243
Jeff Browna41ca772010-08-11 14:46:32 -0700244 /**
245 * Unregisters an input channel.
246 * @param inputChannel The input channel to unregister.
247 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700248 public void unregisterInputChannel(InputChannel inputChannel) {
249 if (inputChannel == null) {
250 throw new IllegalArgumentException("inputChannel must not be null.");
251 }
252
253 nativeUnregisterInputChannel(inputChannel);
254 }
255
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700256 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700257 * Injects an input event into the event system on behalf of an application.
258 * The synchronization mode determines whether the method blocks while waiting for
259 * input injection to proceed.
260 *
261 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
262 * is assumed always to be successful.
263 *
264 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
265 * dispatched so that the input dispatcher can determine whether input event injection will
266 * be permitted based on the current input focus. Does not wait for the input event to
267 * finish processing.
268 *
269 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
270 * be completely processed.
271 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700272 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700273 * @param injectorPid The pid of the injecting application.
274 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700275 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700276 * @param timeoutMillis The injection timeout in milliseconds.
277 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700278 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700279 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
280 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700281 if (event == null) {
282 throw new IllegalArgumentException("event must not be null");
283 }
284 if (injectorPid < 0 || injectorUid < 0) {
285 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
286 }
287 if (timeoutMillis <= 0) {
288 throw new IllegalArgumentException("timeoutMillis must be positive");
289 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700290
291 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700292 }
293
Jeff Brown8d608662010-08-30 03:02:23 -0700294 /**
295 * Gets information about the input device with the specified id.
296 * @param id The device id.
297 * @return The input device or null if not found.
298 */
299 public InputDevice getInputDevice(int deviceId) {
300 return nativeGetInputDevice(deviceId);
301 }
302
303 /**
304 * Gets the ids of all input devices in the system.
305 * @return The input device ids.
306 */
307 public int[] getInputDeviceIds() {
308 return nativeGetInputDeviceIds();
309 }
310
Jeff Brown349703e2010-06-22 01:27:15 -0700311 public void setInputWindows(InputWindow[] windows) {
312 nativeSetInputWindows(windows);
313 }
314
315 public void setFocusedApplication(InputApplication application) {
316 nativeSetFocusedApplication(application);
317 }
318
Jeff Brown349703e2010-06-22 01:27:15 -0700319 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
Jeff Brown8d608662010-08-30 03:02:23 -0700340 private static final class InputDeviceCalibration {
341 public String[] keys;
342 public String[] values;
343 }
344
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700345 /*
346 * Callbacks from native.
347 */
348 private class Callbacks {
349 static final String TAG = "InputManager-Callbacks";
350
351 private static final boolean DEBUG_VIRTUAL_KEYS = false;
352 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700353 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700354
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700355 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700356 public void virtualKeyDownFeedback() {
357 mWindowManagerService.mInputMonitor.virtualKeyDownFeedback();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700358 }
359
360 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700361 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700362 mWindowManagerService.sendNewConfiguration();
363 }
364
365 @SuppressWarnings("unused")
366 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700367 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700368 }
369
370 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700371 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700372 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700373 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700374
375 @SuppressWarnings("unused")
Jeff Brown519e0242010-09-15 15:18:56 -0700376 public long notifyANR(Object token, InputChannel inputChannel) {
377 return mWindowManagerService.mInputMonitor.notifyANR(token, inputChannel);
Jeff Brown349703e2010-06-22 01:27:15 -0700378 }
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 Brown46b9ac0a2010-04-22 18:58:52 -0700399 }
400
401 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700402 public boolean filterTouchEvents() {
403 return mContext.getResources().getBoolean(
404 com.android.internal.R.bool.config_filterTouchEvents);
405 }
406
407 @SuppressWarnings("unused")
408 public boolean filterJumpyTouchEvents() {
409 return mContext.getResources().getBoolean(
410 com.android.internal.R.bool.config_filterJumpyTouchEvents);
411 }
412
413 @SuppressWarnings("unused")
414 public VirtualKeyDefinition[] getVirtualKeyDefinitions(String deviceName) {
415 ArrayList<VirtualKeyDefinition> keys = new ArrayList<VirtualKeyDefinition>();
416
417 try {
418 FileInputStream fis = new FileInputStream(
419 "/sys/board_properties/virtualkeys." + deviceName);
420 InputStreamReader isr = new InputStreamReader(fis);
421 BufferedReader br = new BufferedReader(isr, 2048);
422 String str = br.readLine();
423 if (str != null) {
424 String[] it = str.split(":");
425 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
426 final int N = it.length-6;
427 for (int i=0; i<=N; i+=6) {
428 if (!"0x01".equals(it[i])) {
Jeff Brown8d608662010-08-30 03:02:23 -0700429 Slog.w(TAG, "Unknown virtual key type at elem #"
430 + i + ": " + it[i] + " for device " + deviceName);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700431 continue;
432 }
433 try {
434 VirtualKeyDefinition key = new VirtualKeyDefinition();
435 key.scanCode = Integer.parseInt(it[i+1]);
436 key.centerX = Integer.parseInt(it[i+2]);
437 key.centerY = Integer.parseInt(it[i+3]);
438 key.width = Integer.parseInt(it[i+4]);
439 key.height = Integer.parseInt(it[i+5]);
440 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
441 + key.scanCode + ": center=" + key.centerX + ","
442 + key.centerY + " size=" + key.width + "x"
443 + key.height);
444 keys.add(key);
445 } catch (NumberFormatException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700446 Slog.w(TAG, "Bad number in virtual key definition at region "
447 + i + " in: " + str + " for device " + deviceName, e);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700448 }
449 }
450 }
451 br.close();
452 } catch (FileNotFoundException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700453 Slog.i(TAG, "No virtual keys found for device " + deviceName + ".");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700454 } catch (IOException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700455 Slog.w(TAG, "Error reading virtual keys for device " + deviceName + ".", e);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700456 }
457
458 return keys.toArray(new VirtualKeyDefinition[keys.size()]);
459 }
460
461 @SuppressWarnings("unused")
Jeff Brown8d608662010-08-30 03:02:23 -0700462 public InputDeviceCalibration getInputDeviceCalibration(String deviceName) {
463 // Calibration is specified as a sequence of colon-delimited key value pairs.
464 Properties properties = new Properties();
465 File calibrationFile = new File(Environment.getRootDirectory(),
466 CALIBRATION_DIR_PATH + deviceName + ".idc");
467 if (calibrationFile.exists()) {
468 try {
469 properties.load(new FileInputStream(calibrationFile));
470 } catch (IOException ex) {
471 Slog.w(TAG, "Error reading input device calibration properties for device "
472 + deviceName + " from " + calibrationFile + ".", ex);
473 }
474 } else {
475 Slog.i(TAG, "No input device calibration properties found for device "
476 + deviceName + ".");
477 return null;
478 }
479
480 InputDeviceCalibration calibration = new InputDeviceCalibration();
481 calibration.keys = properties.keySet().toArray(new String[properties.size()]);
482 calibration.values = properties.values().toArray(new String[properties.size()]);
483 return calibration;
484 }
485
486 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700487 public String[] getExcludedDeviceNames() {
488 ArrayList<String> names = new ArrayList<String>();
489
490 // Read partner-provided list of excluded input devices
491 XmlPullParser parser = null;
492 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
493 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
494 FileReader confreader = null;
495 try {
496 confreader = new FileReader(confFile);
497 parser = Xml.newPullParser();
498 parser.setInput(confreader);
499 XmlUtils.beginDocument(parser, "devices");
500
501 while (true) {
502 XmlUtils.nextElement(parser);
503 if (!"device".equals(parser.getName())) {
504 break;
505 }
506 String name = parser.getAttributeValue(null, "name");
507 if (name != null) {
508 names.add(name);
509 }
510 }
511 } catch (FileNotFoundException e) {
512 // It's ok if the file does not exist.
513 } catch (Exception e) {
514 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
515 } finally {
516 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
517 }
518
519 return names.toArray(new String[names.size()]);
520 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700521
522 @SuppressWarnings("unused")
523 public int getMaxEventsPerSecond() {
524 int result = 0;
525 try {
526 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
527 } catch (NumberFormatException e) {
528 }
529 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700530 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700531 }
532 return result;
533 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700534 }
535}