blob: ba39c577d6108e33f1d769b52c2eddeebefc2396 [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
Jeff Brownb6997262010-10-08 22:31:17 -070052 private static final boolean DEBUG = false;
53
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070054 private final Callbacks mCallbacks;
55 private final Context mContext;
56 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070057
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070058 private static native void nativeInit(Callbacks callbacks);
59 private static native void nativeStart();
60 private static native void nativeSetDisplaySize(int displayId, int width, int height);
61 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
62
Jeff Brown6d0fec22010-07-23 21:28:06 -070063 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070064 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070065 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070066 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070067 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070068 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070069 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
70 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070071 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
72 boolean monitor);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070073 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070074 private static native int nativeInjectInputEvent(InputEvent event,
75 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070076 private static native void nativeSetInputWindows(InputWindow[] windows);
77 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
78 private static native void nativeSetFocusedApplication(InputApplication application);
Jeff Brown8d608662010-08-30 03:02:23 -070079 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070080 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070081 private static native int[] nativeGetInputDeviceIds();
Jeff Browne33348b2010-07-15 23:54:05 -070082 private static native String nativeDump();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070083
Jeff Brown7fbdc842010-06-17 20:52:56 -070084 // Input event injection constants defined in InputDispatcher.h.
85 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
86 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
87 static final int INPUT_EVENT_INJECTION_FAILED = 2;
88 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
89
Jeff Brown6ec402b2010-07-28 15:48:59 -070090 // Input event injection synchronization modes defined in InputDispatcher.h
91 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
92 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
93 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
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
Jeff Browne33348b2010-07-15 23:54:05 -0700110 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700111 this.mContext = context;
112 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700113
114 this.mCallbacks = new Callbacks();
115
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700116 init();
117 }
118
119 private void init() {
120 Slog.i(TAG, "Initializing input manager");
121 nativeInit(mCallbacks);
122 }
123
124 public void start() {
125 Slog.i(TAG, "Starting input manager");
126 nativeStart();
127 }
128
129 public void setDisplaySize(int displayId, int width, int height) {
130 if (width <= 0 || height <= 0) {
131 throw new IllegalArgumentException("Invalid display id or dimensions.");
132 }
133
Jeff Brownb6997262010-10-08 22:31:17 -0700134 if (DEBUG) {
135 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
136 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700137 nativeSetDisplaySize(displayId, width, height);
138 }
139
140 public void setDisplayOrientation(int displayId, int rotation) {
141 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
142 throw new IllegalArgumentException("Invalid rotation.");
143 }
144
Jeff Brownb6997262010-10-08 22:31:17 -0700145 if (DEBUG) {
146 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
147 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700148 nativeSetDisplayOrientation(displayId, rotation);
149 }
150
151 public void getInputConfiguration(Configuration config) {
152 if (config == null) {
153 throw new IllegalArgumentException("config must not be null.");
154 }
155
Jeff Brown57c59372010-09-21 18:22:55 -0700156 nativeGetInputConfiguration(config);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700157 }
158
Jeff Brown6d0fec22010-07-23 21:28:06 -0700159 /**
160 * Gets the current state of a key or button by key code.
161 * @param deviceId The input device id, or -1 to consult all devices.
162 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
163 * consider all input sources. An input device is consulted if at least one of its
164 * non-class input source bits matches the specified source mask.
165 * @param keyCode The key code to check.
166 * @return The key state.
167 */
168 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
169 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700170 }
171
Jeff Brown6d0fec22010-07-23 21:28:06 -0700172 /**
173 * Gets the current state of a key or button by scan code.
174 * @param deviceId The input device id, or -1 to consult all devices.
175 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
176 * consider all input sources. An input device is consulted if at least one of its
177 * non-class input source bits matches the specified source mask.
178 * @param scanCode The scan code to check.
179 * @return The key state.
180 */
181 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
182 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700183 }
184
Jeff Brown6d0fec22010-07-23 21:28:06 -0700185 /**
186 * Gets the current state of a switch by switch code.
187 * @param deviceId The input device id, or -1 to consult all devices.
188 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
189 * consider all input sources. An input device is consulted if at least one of its
190 * non-class input source bits matches the specified source mask.
191 * @param switchCode The switch code to check.
192 * @return The switch state.
193 */
194 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
195 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700196 }
197
Jeff Brown6d0fec22010-07-23 21:28:06 -0700198 /**
199 * Determines whether the specified key codes are supported by a particular device.
200 * @param deviceId The input device id, or -1 to consult all devices.
201 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
202 * consider all input sources. An input device is consulted if at least one of its
203 * non-class input source bits matches the specified source mask.
204 * @param keyCodes The array of key codes to check.
205 * @param keyExists An array at least as large as keyCodes whose entries will be set
206 * to true or false based on the presence or absence of support for the corresponding
207 * key codes.
208 * @return True if the lookup was successful, false otherwise.
209 */
210 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700211 if (keyCodes == null) {
212 throw new IllegalArgumentException("keyCodes must not be null.");
213 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700214 if (keyExists == null || keyExists.length < keyCodes.length) {
215 throw new IllegalArgumentException("keyExists must not be null and must be at "
216 + "least as large as keyCodes.");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700217 }
218
Jeff Brown6d0fec22010-07-23 21:28:06 -0700219 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700220 }
221
Jeff Browna41ca772010-08-11 14:46:32 -0700222 /**
223 * Creates an input channel that will receive all input from the input dispatcher.
224 * @param inputChannelName The input channel name.
225 * @return The input channel.
226 */
227 public InputChannel monitorInput(String inputChannelName) {
228 if (inputChannelName == null) {
229 throw new IllegalArgumentException("inputChannelName must not be null.");
230 }
231
232 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
233 nativeRegisterInputChannel(inputChannels[0], true);
234 inputChannels[0].dispose(); // don't need to retain the Java object reference
235 return inputChannels[1];
236 }
237
238 /**
239 * Registers an input channel so that it can be used as an input event target.
240 * @param inputChannel The input channel to register.
241 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700242 public void registerInputChannel(InputChannel inputChannel) {
243 if (inputChannel == null) {
244 throw new IllegalArgumentException("inputChannel must not be null.");
245 }
246
Jeff Browna41ca772010-08-11 14:46:32 -0700247 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700248 }
249
Jeff Browna41ca772010-08-11 14:46:32 -0700250 /**
251 * Unregisters an input channel.
252 * @param inputChannel The input channel to unregister.
253 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700254 public void unregisterInputChannel(InputChannel inputChannel) {
255 if (inputChannel == null) {
256 throw new IllegalArgumentException("inputChannel must not be null.");
257 }
258
259 nativeUnregisterInputChannel(inputChannel);
260 }
261
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700262 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700263 * Injects an input event into the event system on behalf of an application.
264 * The synchronization mode determines whether the method blocks while waiting for
265 * input injection to proceed.
266 *
267 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
268 * is assumed always to be successful.
269 *
270 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
271 * dispatched so that the input dispatcher can determine whether input event injection will
272 * be permitted based on the current input focus. Does not wait for the input event to
273 * finish processing.
274 *
275 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
276 * be completely processed.
277 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700278 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700279 * @param injectorPid The pid of the injecting application.
280 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700281 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700282 * @param timeoutMillis The injection timeout in milliseconds.
283 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700284 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700285 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
286 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700287 if (event == null) {
288 throw new IllegalArgumentException("event must not be null");
289 }
290 if (injectorPid < 0 || injectorUid < 0) {
291 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
292 }
293 if (timeoutMillis <= 0) {
294 throw new IllegalArgumentException("timeoutMillis must be positive");
295 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700296
297 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700298 }
299
Jeff Brown8d608662010-08-30 03:02:23 -0700300 /**
301 * Gets information about the input device with the specified id.
302 * @param id The device id.
303 * @return The input device or null if not found.
304 */
305 public InputDevice getInputDevice(int deviceId) {
306 return nativeGetInputDevice(deviceId);
307 }
308
309 /**
310 * Gets the ids of all input devices in the system.
311 * @return The input device ids.
312 */
313 public int[] getInputDeviceIds() {
314 return nativeGetInputDeviceIds();
315 }
316
Jeff Brown349703e2010-06-22 01:27:15 -0700317 public void setInputWindows(InputWindow[] windows) {
318 nativeSetInputWindows(windows);
319 }
320
321 public void setFocusedApplication(InputApplication application) {
322 nativeSetFocusedApplication(application);
323 }
324
Jeff Brown349703e2010-06-22 01:27:15 -0700325 public void setInputDispatchMode(boolean enabled, boolean frozen) {
326 nativeSetInputDispatchMode(enabled, frozen);
327 }
328
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700329 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700330 String dumpStr = nativeDump();
331 if (dumpStr != null) {
332 pw.println(dumpStr);
333 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700334 }
335
336 private static final class VirtualKeyDefinition {
337 public int scanCode;
338
339 // configured position data, specified in display coords
340 public int centerX;
341 public int centerY;
342 public int width;
343 public int height;
344 }
345
Jeff Brown8d608662010-08-30 03:02:23 -0700346 private static final class InputDeviceCalibration {
347 public String[] keys;
348 public String[] values;
349 }
350
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700351 /*
352 * Callbacks from native.
353 */
354 private class Callbacks {
355 static final String TAG = "InputManager-Callbacks";
356
357 private static final boolean DEBUG_VIRTUAL_KEYS = false;
358 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700359 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700360
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700361 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700362 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700363 mWindowManagerService.sendNewConfiguration();
364 }
365
366 @SuppressWarnings("unused")
367 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700368 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700369 }
370
371 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700372 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700373 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700374 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700375
376 @SuppressWarnings("unused")
Jeff Brown519e0242010-09-15 15:18:56 -0700377 public long notifyANR(Object token, InputChannel inputChannel) {
378 return mWindowManagerService.mInputMonitor.notifyANR(token, inputChannel);
Jeff Brown349703e2010-06-22 01:27:15 -0700379 }
380
381 @SuppressWarnings("unused")
Jeff Browneb9f7a02010-10-29 21:50:21 -0700382 public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags,
383 int keyCode, int scanCode, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700384 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Browneb9f7a02010-10-29 21:50:21 -0700385 whenNanos, action, flags, keyCode, scanCode, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700386 }
387
388 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700389 public boolean interceptKeyBeforeDispatching(InputChannel focus, int action,
Jeff Browneb9f7a02010-10-29 21:50:21 -0700390 int flags, int keyCode, int scanCode, int metaState, int repeatCount,
391 int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -0700392 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(focus,
Jeff Browneb9f7a02010-10-29 21:50:21 -0700393 action, flags, keyCode, scanCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700394 }
395
396 @SuppressWarnings("unused")
397 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
398 return mContext.checkPermission(
399 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
400 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700401 }
402
403 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700404 public boolean filterTouchEvents() {
405 return mContext.getResources().getBoolean(
406 com.android.internal.R.bool.config_filterTouchEvents);
407 }
408
409 @SuppressWarnings("unused")
410 public boolean filterJumpyTouchEvents() {
411 return mContext.getResources().getBoolean(
412 com.android.internal.R.bool.config_filterJumpyTouchEvents);
413 }
Jeff Brown6f71d0f2010-10-24 14:39:33 -0700414
415 @SuppressWarnings("unused")
416 public int getVirtualKeyQuietTimeMillis() {
417 return mContext.getResources().getInteger(
418 com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
419 }
420
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700421 @SuppressWarnings("unused")
422 public VirtualKeyDefinition[] getVirtualKeyDefinitions(String deviceName) {
423 ArrayList<VirtualKeyDefinition> keys = new ArrayList<VirtualKeyDefinition>();
424
425 try {
426 FileInputStream fis = new FileInputStream(
427 "/sys/board_properties/virtualkeys." + deviceName);
428 InputStreamReader isr = new InputStreamReader(fis);
429 BufferedReader br = new BufferedReader(isr, 2048);
430 String str = br.readLine();
431 if (str != null) {
432 String[] it = str.split(":");
433 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
434 final int N = it.length-6;
435 for (int i=0; i<=N; i+=6) {
436 if (!"0x01".equals(it[i])) {
Jeff Brown8d608662010-08-30 03:02:23 -0700437 Slog.w(TAG, "Unknown virtual key type at elem #"
438 + i + ": " + it[i] + " for device " + deviceName);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700439 continue;
440 }
441 try {
442 VirtualKeyDefinition key = new VirtualKeyDefinition();
443 key.scanCode = Integer.parseInt(it[i+1]);
444 key.centerX = Integer.parseInt(it[i+2]);
445 key.centerY = Integer.parseInt(it[i+3]);
446 key.width = Integer.parseInt(it[i+4]);
447 key.height = Integer.parseInt(it[i+5]);
448 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
449 + key.scanCode + ": center=" + key.centerX + ","
450 + key.centerY + " size=" + key.width + "x"
451 + key.height);
452 keys.add(key);
453 } catch (NumberFormatException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700454 Slog.w(TAG, "Bad number in virtual key definition at region "
455 + i + " in: " + str + " for device " + deviceName, e);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700456 }
457 }
458 }
459 br.close();
460 } catch (FileNotFoundException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700461 Slog.i(TAG, "No virtual keys found for device " + deviceName + ".");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700462 } catch (IOException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700463 Slog.w(TAG, "Error reading virtual keys for device " + deviceName + ".", e);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700464 }
465
466 return keys.toArray(new VirtualKeyDefinition[keys.size()]);
467 }
468
469 @SuppressWarnings("unused")
Jeff Brown8d608662010-08-30 03:02:23 -0700470 public InputDeviceCalibration getInputDeviceCalibration(String deviceName) {
471 // Calibration is specified as a sequence of colon-delimited key value pairs.
472 Properties properties = new Properties();
473 File calibrationFile = new File(Environment.getRootDirectory(),
474 CALIBRATION_DIR_PATH + deviceName + ".idc");
475 if (calibrationFile.exists()) {
476 try {
477 properties.load(new FileInputStream(calibrationFile));
478 } catch (IOException ex) {
479 Slog.w(TAG, "Error reading input device calibration properties for device "
480 + deviceName + " from " + calibrationFile + ".", ex);
481 }
482 } else {
483 Slog.i(TAG, "No input device calibration properties found for device "
484 + deviceName + ".");
485 return null;
486 }
487
488 InputDeviceCalibration calibration = new InputDeviceCalibration();
489 calibration.keys = properties.keySet().toArray(new String[properties.size()]);
490 calibration.values = properties.values().toArray(new String[properties.size()]);
491 return calibration;
492 }
493
494 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700495 public String[] getExcludedDeviceNames() {
496 ArrayList<String> names = new ArrayList<String>();
497
498 // Read partner-provided list of excluded input devices
499 XmlPullParser parser = null;
500 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
501 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
502 FileReader confreader = null;
503 try {
504 confreader = new FileReader(confFile);
505 parser = Xml.newPullParser();
506 parser.setInput(confreader);
507 XmlUtils.beginDocument(parser, "devices");
508
509 while (true) {
510 XmlUtils.nextElement(parser);
511 if (!"device".equals(parser.getName())) {
512 break;
513 }
514 String name = parser.getAttributeValue(null, "name");
515 if (name != null) {
516 names.add(name);
517 }
518 }
519 } catch (FileNotFoundException e) {
520 // It's ok if the file does not exist.
521 } catch (Exception e) {
522 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
523 } finally {
524 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
525 }
526
527 return names.toArray(new String[names.size()]);
528 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700529
530 @SuppressWarnings("unused")
531 public int getMaxEventsPerSecond() {
532 int result = 0;
533 try {
534 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
535 } catch (NumberFormatException e) {
536 }
537 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700538 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700539 }
540 return result;
541 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700542 }
543}