blob: 314dd8a70a8a3aed7618c80d5318d67a1197955b [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 Brownae9fc032010-08-18 15:51:08 -070029import android.os.SystemProperties;
Jeff Brown46b9ac02010-04-22 18:58:52 -070030import android.util.Slog;
31import android.util.Xml;
32import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070033import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070034import android.view.InputEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -070035import android.view.KeyEvent;
36import android.view.MotionEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -070037import android.view.Surface;
38import android.view.WindowManagerPolicy;
39
40import java.io.BufferedReader;
41import java.io.File;
42import java.io.FileInputStream;
43import java.io.FileNotFoundException;
44import java.io.FileReader;
45import java.io.IOException;
46import java.io.InputStreamReader;
47import java.io.PrintWriter;
48import java.util.ArrayList;
Jeff Brown8d608662010-08-30 03:02:23 -070049import java.util.Properties;
Jeff Brown46b9ac02010-04-22 18:58:52 -070050
51/*
52 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac02010-04-22 18:58:52 -070053 */
54public class InputManager {
55 static final String TAG = "InputManager";
56
57 private final Callbacks mCallbacks;
58 private final Context mContext;
59 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -070060
61 private int mTouchScreenConfig;
62 private int mKeyboardConfig;
63 private int mNavigationConfig;
64
65 private static native void nativeInit(Callbacks callbacks);
66 private static native void nativeStart();
67 private static native void nativeSetDisplaySize(int displayId, int width, int height);
68 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
69
Jeff Brown6d0fec22010-07-23 21:28:06 -070070 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070071 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070072 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070073 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070074 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070075 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070076 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
77 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070078 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
79 boolean monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -070080 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070081 private static native int nativeInjectInputEvent(InputEvent event,
82 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070083 private static native void nativeSetInputWindows(InputWindow[] windows);
84 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
85 private static native void nativeSetFocusedApplication(InputApplication application);
86 private static native void nativePreemptInputDispatch();
Jeff Brown8d608662010-08-30 03:02:23 -070087 private static native InputDevice nativeGetInputDevice(int deviceId);
88 private static native int[] nativeGetInputDeviceIds();
Jeff Browne33348b2010-07-15 23:54:05 -070089 private static native String nativeDump();
Jeff Brown46b9ac02010-04-22 18:58:52 -070090
Jeff Brown7fbdc842010-06-17 20:52:56 -070091 // Input event injection constants defined in InputDispatcher.h.
92 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
93 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
94 static final int INPUT_EVENT_INJECTION_FAILED = 2;
95 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
96
Jeff Brown6ec402b2010-07-28 15:48:59 -070097 // Input event injection synchronization modes defined in InputDispatcher.h
98 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
99 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
100 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
101
Jeff Brown6d0fec22010-07-23 21:28:06 -0700102 // Key states (may be returned by queries about the current state of a
103 // particular key code, scan code or switch).
104
105 /** The key state is unknown or the requested key itself is not supported. */
106 public static final int KEY_STATE_UNKNOWN = -1;
107
108 /** The key is up. /*/
109 public static final int KEY_STATE_UP = 0;
110
111 /** The key is down. */
112 public static final int KEY_STATE_DOWN = 1;
113
114 /** The key is down but is a virtual key press that is being emulated by the system. */
115 public static final int KEY_STATE_VIRTUAL = 2;
116
Jeff Browne33348b2010-07-15 23:54:05 -0700117 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700118 this.mContext = context;
119 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700120
121 this.mCallbacks = new Callbacks();
122
123 mTouchScreenConfig = Configuration.TOUCHSCREEN_NOTOUCH;
124 mKeyboardConfig = Configuration.KEYBOARD_NOKEYS;
125 mNavigationConfig = Configuration.NAVIGATION_NONAV;
126
127 init();
128 }
129
130 private void init() {
131 Slog.i(TAG, "Initializing input manager");
132 nativeInit(mCallbacks);
133 }
134
135 public void start() {
136 Slog.i(TAG, "Starting input manager");
137 nativeStart();
138 }
139
140 public void setDisplaySize(int displayId, int width, int height) {
141 if (width <= 0 || height <= 0) {
142 throw new IllegalArgumentException("Invalid display id or dimensions.");
143 }
144
145 Slog.i(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
146 nativeSetDisplaySize(displayId, width, height);
147 }
148
149 public void setDisplayOrientation(int displayId, int rotation) {
150 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
151 throw new IllegalArgumentException("Invalid rotation.");
152 }
153
154 Slog.i(TAG, "Setting display #" + displayId + " orientation to " + rotation);
155 nativeSetDisplayOrientation(displayId, rotation);
156 }
157
158 public void getInputConfiguration(Configuration config) {
159 if (config == null) {
160 throw new IllegalArgumentException("config must not be null.");
161 }
162
163 config.touchscreen = mTouchScreenConfig;
164 config.keyboard = mKeyboardConfig;
165 config.navigation = mNavigationConfig;
166 }
167
Jeff Brown6d0fec22010-07-23 21:28:06 -0700168 /**
169 * Gets the current state of a key or button by key code.
170 * @param deviceId The input device id, or -1 to consult all devices.
171 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
172 * consider all input sources. An input device is consulted if at least one of its
173 * non-class input source bits matches the specified source mask.
174 * @param keyCode The key code to check.
175 * @return The key state.
176 */
177 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
178 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700179 }
180
Jeff Brown6d0fec22010-07-23 21:28:06 -0700181 /**
182 * Gets the current state of a key or button by scan code.
183 * @param deviceId The input device id, or -1 to consult all devices.
184 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
185 * consider all input sources. An input device is consulted if at least one of its
186 * non-class input source bits matches the specified source mask.
187 * @param scanCode The scan code to check.
188 * @return The key state.
189 */
190 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
191 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700192 }
193
Jeff Brown6d0fec22010-07-23 21:28:06 -0700194 /**
195 * Gets the current state of a switch by switch code.
196 * @param deviceId The input device id, or -1 to consult all devices.
197 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
198 * consider all input sources. An input device is consulted if at least one of its
199 * non-class input source bits matches the specified source mask.
200 * @param switchCode The switch code to check.
201 * @return The switch state.
202 */
203 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
204 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700205 }
206
Jeff Brown6d0fec22010-07-23 21:28:06 -0700207 /**
208 * Determines whether the specified key codes are supported by a particular device.
209 * @param deviceId The input device id, or -1 to consult all devices.
210 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
211 * consider all input sources. An input device is consulted if at least one of its
212 * non-class input source bits matches the specified source mask.
213 * @param keyCodes The array of key codes to check.
214 * @param keyExists An array at least as large as keyCodes whose entries will be set
215 * to true or false based on the presence or absence of support for the corresponding
216 * key codes.
217 * @return True if the lookup was successful, false otherwise.
218 */
219 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700220 if (keyCodes == null) {
221 throw new IllegalArgumentException("keyCodes must not be null.");
222 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700223 if (keyExists == null || keyExists.length < keyCodes.length) {
224 throw new IllegalArgumentException("keyExists must not be null and must be at "
225 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700226 }
227
Jeff Brown6d0fec22010-07-23 21:28:06 -0700228 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700229 }
230
Jeff Browna41ca772010-08-11 14:46:32 -0700231 /**
232 * Creates an input channel that will receive all input from the input dispatcher.
233 * @param inputChannelName The input channel name.
234 * @return The input channel.
235 */
236 public InputChannel monitorInput(String inputChannelName) {
237 if (inputChannelName == null) {
238 throw new IllegalArgumentException("inputChannelName must not be null.");
239 }
240
241 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
242 nativeRegisterInputChannel(inputChannels[0], true);
243 inputChannels[0].dispose(); // don't need to retain the Java object reference
244 return inputChannels[1];
245 }
246
247 /**
248 * Registers an input channel so that it can be used as an input event target.
249 * @param inputChannel The input channel to register.
250 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700251 public void registerInputChannel(InputChannel inputChannel) {
252 if (inputChannel == null) {
253 throw new IllegalArgumentException("inputChannel must not be null.");
254 }
255
Jeff Browna41ca772010-08-11 14:46:32 -0700256 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700257 }
258
Jeff Browna41ca772010-08-11 14:46:32 -0700259 /**
260 * Unregisters an input channel.
261 * @param inputChannel The input channel to unregister.
262 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700263 public void unregisterInputChannel(InputChannel inputChannel) {
264 if (inputChannel == null) {
265 throw new IllegalArgumentException("inputChannel must not be null.");
266 }
267
268 nativeUnregisterInputChannel(inputChannel);
269 }
270
Jeff Brown46b9ac02010-04-22 18:58:52 -0700271 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700272 * Injects an input event into the event system on behalf of an application.
273 * The synchronization mode determines whether the method blocks while waiting for
274 * input injection to proceed.
275 *
276 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
277 * is assumed always to be successful.
278 *
279 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
280 * dispatched so that the input dispatcher can determine whether input event injection will
281 * be permitted based on the current input focus. Does not wait for the input event to
282 * finish processing.
283 *
284 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
285 * be completely processed.
286 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700287 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700288 * @param injectorPid The pid of the injecting application.
289 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700290 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700291 * @param timeoutMillis The injection timeout in milliseconds.
292 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700293 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700294 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
295 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700296 if (event == null) {
297 throw new IllegalArgumentException("event must not be null");
298 }
299 if (injectorPid < 0 || injectorUid < 0) {
300 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
301 }
302 if (timeoutMillis <= 0) {
303 throw new IllegalArgumentException("timeoutMillis must be positive");
304 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700305
306 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700307 }
308
Jeff Brown8d608662010-08-30 03:02:23 -0700309 /**
310 * Gets information about the input device with the specified id.
311 * @param id The device id.
312 * @return The input device or null if not found.
313 */
314 public InputDevice getInputDevice(int deviceId) {
315 return nativeGetInputDevice(deviceId);
316 }
317
318 /**
319 * Gets the ids of all input devices in the system.
320 * @return The input device ids.
321 */
322 public int[] getInputDeviceIds() {
323 return nativeGetInputDeviceIds();
324 }
325
Jeff Brown349703e2010-06-22 01:27:15 -0700326 public void setInputWindows(InputWindow[] windows) {
327 nativeSetInputWindows(windows);
328 }
329
330 public void setFocusedApplication(InputApplication application) {
331 nativeSetFocusedApplication(application);
332 }
333
334 public void preemptInputDispatch() {
335 nativePreemptInputDispatch();
336 }
337
338 public void setInputDispatchMode(boolean enabled, boolean frozen) {
339 nativeSetInputDispatchMode(enabled, frozen);
340 }
341
Jeff Brown46b9ac02010-04-22 18:58:52 -0700342 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700343 String dumpStr = nativeDump();
344 if (dumpStr != null) {
345 pw.println(dumpStr);
346 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700347 }
348
349 private static final class VirtualKeyDefinition {
350 public int scanCode;
351
352 // configured position data, specified in display coords
353 public int centerX;
354 public int centerY;
355 public int width;
356 public int height;
357 }
358
Jeff Brown8d608662010-08-30 03:02:23 -0700359 private static final class InputDeviceCalibration {
360 public String[] keys;
361 public String[] values;
362 }
363
Jeff Brown46b9ac02010-04-22 18:58:52 -0700364 /*
365 * Callbacks from native.
366 */
367 private class Callbacks {
368 static final String TAG = "InputManager-Callbacks";
369
370 private static final boolean DEBUG_VIRTUAL_KEYS = false;
371 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700372 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac02010-04-22 18:58:52 -0700373
Jeff Brown46b9ac02010-04-22 18:58:52 -0700374 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700375 public void virtualKeyDownFeedback() {
376 mWindowManagerService.mInputMonitor.virtualKeyDownFeedback();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700377 }
378
379 @SuppressWarnings("unused")
380 public void notifyConfigurationChanged(long whenNanos,
381 int touchScreenConfig, int keyboardConfig, int navigationConfig) {
382 mTouchScreenConfig = touchScreenConfig;
383 mKeyboardConfig = keyboardConfig;
384 mNavigationConfig = navigationConfig;
385
386 mWindowManagerService.sendNewConfiguration();
387 }
388
389 @SuppressWarnings("unused")
390 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700391 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700392 }
393
394 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700395 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700396 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700397 }
398
399 @SuppressWarnings("unused")
400 public long notifyInputChannelANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700401 return mWindowManagerService.mInputMonitor.notifyInputChannelANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700402 }
403
404 @SuppressWarnings("unused")
405 public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700406 mWindowManagerService.mInputMonitor.notifyInputChannelRecoveredFromANR(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700407 }
408
409 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700410 public long notifyANR(Object token) {
411 return mWindowManagerService.mInputMonitor.notifyANR(token);
412 }
413
414 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700415 public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
416 int policyFlags, boolean isScreenOn) {
417 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
418 whenNanos, keyCode, down, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700419 }
420
421 @SuppressWarnings("unused")
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700422 public boolean interceptKeyBeforeDispatching(InputChannel focus, int action,
423 int flags, int keyCode, int metaState, int repeatCount, int policyFlags) {
Jeff Brown349703e2010-06-22 01:27:15 -0700424 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(focus,
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700425 action, flags, keyCode, metaState, repeatCount, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700426 }
427
428 @SuppressWarnings("unused")
429 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
430 return mContext.checkPermission(
431 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
432 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700433 }
434
435 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700436 public void notifyAppSwitchComing() {
Jeff Brown349703e2010-06-22 01:27:15 -0700437 mWindowManagerService.mInputMonitor.notifyAppSwitchComing();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700438 }
439
440 @SuppressWarnings("unused")
441 public boolean filterTouchEvents() {
442 return mContext.getResources().getBoolean(
443 com.android.internal.R.bool.config_filterTouchEvents);
444 }
445
446 @SuppressWarnings("unused")
447 public boolean filterJumpyTouchEvents() {
448 return mContext.getResources().getBoolean(
449 com.android.internal.R.bool.config_filterJumpyTouchEvents);
450 }
451
452 @SuppressWarnings("unused")
453 public VirtualKeyDefinition[] getVirtualKeyDefinitions(String deviceName) {
454 ArrayList<VirtualKeyDefinition> keys = new ArrayList<VirtualKeyDefinition>();
455
456 try {
457 FileInputStream fis = new FileInputStream(
458 "/sys/board_properties/virtualkeys." + deviceName);
459 InputStreamReader isr = new InputStreamReader(fis);
460 BufferedReader br = new BufferedReader(isr, 2048);
461 String str = br.readLine();
462 if (str != null) {
463 String[] it = str.split(":");
464 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "***** VIRTUAL KEYS: " + it);
465 final int N = it.length-6;
466 for (int i=0; i<=N; i+=6) {
467 if (!"0x01".equals(it[i])) {
Jeff Brown8d608662010-08-30 03:02:23 -0700468 Slog.w(TAG, "Unknown virtual key type at elem #"
469 + i + ": " + it[i] + " for device " + deviceName);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700470 continue;
471 }
472 try {
473 VirtualKeyDefinition key = new VirtualKeyDefinition();
474 key.scanCode = Integer.parseInt(it[i+1]);
475 key.centerX = Integer.parseInt(it[i+2]);
476 key.centerY = Integer.parseInt(it[i+3]);
477 key.width = Integer.parseInt(it[i+4]);
478 key.height = Integer.parseInt(it[i+5]);
479 if (DEBUG_VIRTUAL_KEYS) Slog.v(TAG, "Virtual key "
480 + key.scanCode + ": center=" + key.centerX + ","
481 + key.centerY + " size=" + key.width + "x"
482 + key.height);
483 keys.add(key);
484 } catch (NumberFormatException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700485 Slog.w(TAG, "Bad number in virtual key definition at region "
486 + i + " in: " + str + " for device " + deviceName, e);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700487 }
488 }
489 }
490 br.close();
491 } catch (FileNotFoundException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700492 Slog.i(TAG, "No virtual keys found for device " + deviceName + ".");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700493 } catch (IOException e) {
Jeff Brown8d608662010-08-30 03:02:23 -0700494 Slog.w(TAG, "Error reading virtual keys for device " + deviceName + ".", e);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700495 }
496
497 return keys.toArray(new VirtualKeyDefinition[keys.size()]);
498 }
499
500 @SuppressWarnings("unused")
Jeff Brown8d608662010-08-30 03:02:23 -0700501 public InputDeviceCalibration getInputDeviceCalibration(String deviceName) {
502 // Calibration is specified as a sequence of colon-delimited key value pairs.
503 Properties properties = new Properties();
504 File calibrationFile = new File(Environment.getRootDirectory(),
505 CALIBRATION_DIR_PATH + deviceName + ".idc");
506 if (calibrationFile.exists()) {
507 try {
508 properties.load(new FileInputStream(calibrationFile));
509 } catch (IOException ex) {
510 Slog.w(TAG, "Error reading input device calibration properties for device "
511 + deviceName + " from " + calibrationFile + ".", ex);
512 }
513 } else {
514 Slog.i(TAG, "No input device calibration properties found for device "
515 + deviceName + ".");
516 return null;
517 }
518
519 InputDeviceCalibration calibration = new InputDeviceCalibration();
520 calibration.keys = properties.keySet().toArray(new String[properties.size()]);
521 calibration.values = properties.values().toArray(new String[properties.size()]);
522 return calibration;
523 }
524
525 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700526 public String[] getExcludedDeviceNames() {
527 ArrayList<String> names = new ArrayList<String>();
528
529 // Read partner-provided list of excluded input devices
530 XmlPullParser parser = null;
531 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
532 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
533 FileReader confreader = null;
534 try {
535 confreader = new FileReader(confFile);
536 parser = Xml.newPullParser();
537 parser.setInput(confreader);
538 XmlUtils.beginDocument(parser, "devices");
539
540 while (true) {
541 XmlUtils.nextElement(parser);
542 if (!"device".equals(parser.getName())) {
543 break;
544 }
545 String name = parser.getAttributeValue(null, "name");
546 if (name != null) {
547 names.add(name);
548 }
549 }
550 } catch (FileNotFoundException e) {
551 // It's ok if the file does not exist.
552 } catch (Exception e) {
553 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
554 } finally {
555 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
556 }
557
558 return names.toArray(new String[names.size()]);
559 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700560
561 @SuppressWarnings("unused")
562 public int getMaxEventsPerSecond() {
563 int result = 0;
564 try {
565 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
566 } catch (NumberFormatException e) {
567 }
568 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700569 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700570 }
571 return result;
572 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700573 }
574}