blob: 410b8c259b002b36d42d9f838b2683936b720e0a [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;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080022import org.xmlpull.v1.XmlPullParserException;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070023
24import android.content.Context;
Jeff Brown349703e2010-06-22 01:27:15 -070025import android.content.pm.PackageManager;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070026import android.content.res.Configuration;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080027import android.content.res.Resources;
28import android.content.res.TypedArray;
29import android.content.res.XmlResourceParser;
30import android.graphics.Bitmap;
31import android.graphics.drawable.BitmapDrawable;
32import android.graphics.drawable.Drawable;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070033import android.os.Environment;
Jeff Brownae9fc032010-08-18 15:51:08 -070034import android.os.SystemProperties;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070035import android.util.Slog;
36import android.util.Xml;
37import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070038import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070039import android.view.InputEvent;
Jeff Brown1f245102010-11-18 20:53:46 -080040import android.view.KeyEvent;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070041import android.view.Surface;
Jeff Brown83c09682010-12-23 17:50:18 -080042import android.view.WindowManager;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070043
44import java.io.BufferedReader;
45import java.io.File;
46import java.io.FileInputStream;
47import java.io.FileNotFoundException;
48import java.io.FileReader;
49import java.io.IOException;
50import java.io.InputStreamReader;
51import java.io.PrintWriter;
52import java.util.ArrayList;
53
54/*
55 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070056 */
57public class InputManager {
58 static final String TAG = "InputManager";
59
Jeff Brownb6997262010-10-08 22:31:17 -070060 private static final boolean DEBUG = false;
61
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070062 private final Callbacks mCallbacks;
63 private final Context mContext;
64 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070065
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070066 private static native void nativeInit(Callbacks callbacks);
67 private static native void nativeStart();
68 private static native void nativeSetDisplaySize(int displayId, int width, int height);
69 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
70
Jeff Brown6d0fec22010-07-23 21:28:06 -070071 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070072 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070073 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070074 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070075 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070076 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070077 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
78 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070079 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
80 boolean monitor);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070081 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070082 private static native int nativeInjectInputEvent(InputEvent event,
83 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070084 private static native void nativeSetInputWindows(InputWindow[] windows);
85 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
86 private static native void nativeSetFocusedApplication(InputApplication application);
Jeff Brown8d608662010-08-30 03:02:23 -070087 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070088 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070089 private static native int[] nativeGetInputDeviceIds();
Jeff Browne6504122010-09-27 14:52:15 -070090 private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
91 InputChannel toChannel);
Jeff Browne33348b2010-07-15 23:54:05 -070092 private static native String nativeDump();
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070093
Jeff Brown7fbdc842010-06-17 20:52:56 -070094 // Input event injection constants defined in InputDispatcher.h.
95 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
96 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
97 static final int INPUT_EVENT_INJECTION_FAILED = 2;
98 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
99
Jeff Brown6ec402b2010-07-28 15:48:59 -0700100 // Input event injection synchronization modes defined in InputDispatcher.h
101 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
102 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
103 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
104
Jeff Brown6d0fec22010-07-23 21:28:06 -0700105 // Key states (may be returned by queries about the current state of a
106 // particular key code, scan code or switch).
107
108 /** The key state is unknown or the requested key itself is not supported. */
109 public static final int KEY_STATE_UNKNOWN = -1;
110
111 /** The key is up. /*/
112 public static final int KEY_STATE_UP = 0;
113
114 /** The key is down. */
115 public static final int KEY_STATE_DOWN = 1;
116
117 /** The key is down but is a virtual key press that is being emulated by the system. */
118 public static final int KEY_STATE_VIRTUAL = 2;
119
Jeff Browne33348b2010-07-15 23:54:05 -0700120 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700121 this.mContext = context;
122 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700123
124 this.mCallbacks = new Callbacks();
125
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700126 init();
127 }
128
129 private void init() {
130 Slog.i(TAG, "Initializing input manager");
131 nativeInit(mCallbacks);
132 }
133
134 public void start() {
135 Slog.i(TAG, "Starting input manager");
136 nativeStart();
137 }
138
139 public void setDisplaySize(int displayId, int width, int height) {
140 if (width <= 0 || height <= 0) {
141 throw new IllegalArgumentException("Invalid display id or dimensions.");
142 }
143
Jeff Brownb6997262010-10-08 22:31:17 -0700144 if (DEBUG) {
145 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
146 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700147 nativeSetDisplaySize(displayId, width, height);
148 }
149
150 public void setDisplayOrientation(int displayId, int rotation) {
151 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
152 throw new IllegalArgumentException("Invalid rotation.");
153 }
154
Jeff Brownb6997262010-10-08 22:31:17 -0700155 if (DEBUG) {
156 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
157 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700158 nativeSetDisplayOrientation(displayId, rotation);
159 }
160
161 public void getInputConfiguration(Configuration config) {
162 if (config == null) {
163 throw new IllegalArgumentException("config must not be null.");
164 }
165
Jeff Brown57c59372010-09-21 18:22:55 -0700166 nativeGetInputConfiguration(config);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700167 }
168
Jeff Brown6d0fec22010-07-23 21:28:06 -0700169 /**
170 * Gets the current state of a key or button by key code.
171 * @param deviceId The input device id, or -1 to consult all devices.
172 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
173 * consider all input sources. An input device is consulted if at least one of its
174 * non-class input source bits matches the specified source mask.
175 * @param keyCode The key code to check.
176 * @return The key state.
177 */
178 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
179 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700180 }
181
Jeff Brown6d0fec22010-07-23 21:28:06 -0700182 /**
183 * Gets the current state of a key or button by scan code.
184 * @param deviceId The input device id, or -1 to consult all devices.
185 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
186 * consider all input sources. An input device is consulted if at least one of its
187 * non-class input source bits matches the specified source mask.
188 * @param scanCode The scan code to check.
189 * @return The key state.
190 */
191 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
192 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700193 }
194
Jeff Brown6d0fec22010-07-23 21:28:06 -0700195 /**
196 * Gets the current state of a switch by switch code.
197 * @param deviceId The input device id, or -1 to consult all devices.
198 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
199 * consider all input sources. An input device is consulted if at least one of its
200 * non-class input source bits matches the specified source mask.
201 * @param switchCode The switch code to check.
202 * @return The switch state.
203 */
204 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
205 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700206 }
207
Jeff Brown6d0fec22010-07-23 21:28:06 -0700208 /**
209 * Determines whether the specified key codes are supported by a particular device.
210 * @param deviceId The input device id, or -1 to consult all devices.
211 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
212 * consider all input sources. An input device is consulted if at least one of its
213 * non-class input source bits matches the specified source mask.
214 * @param keyCodes The array of key codes to check.
215 * @param keyExists An array at least as large as keyCodes whose entries will be set
216 * to true or false based on the presence or absence of support for the corresponding
217 * key codes.
218 * @return True if the lookup was successful, false otherwise.
219 */
220 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700221 if (keyCodes == null) {
222 throw new IllegalArgumentException("keyCodes must not be null.");
223 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700224 if (keyExists == null || keyExists.length < keyCodes.length) {
225 throw new IllegalArgumentException("keyExists must not be null and must be at "
226 + "least as large as keyCodes.");
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700227 }
228
Jeff Brown6d0fec22010-07-23 21:28:06 -0700229 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700230 }
231
Jeff Browna41ca772010-08-11 14:46:32 -0700232 /**
233 * Creates an input channel that will receive all input from the input dispatcher.
234 * @param inputChannelName The input channel name.
235 * @return The input channel.
236 */
237 public InputChannel monitorInput(String inputChannelName) {
238 if (inputChannelName == null) {
239 throw new IllegalArgumentException("inputChannelName must not be null.");
240 }
241
242 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
243 nativeRegisterInputChannel(inputChannels[0], true);
244 inputChannels[0].dispose(); // don't need to retain the Java object reference
245 return inputChannels[1];
246 }
247
248 /**
249 * Registers an input channel so that it can be used as an input event target.
250 * @param inputChannel The input channel to register.
251 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700252 public void registerInputChannel(InputChannel inputChannel) {
253 if (inputChannel == null) {
254 throw new IllegalArgumentException("inputChannel must not be null.");
255 }
256
Jeff Browna41ca772010-08-11 14:46:32 -0700257 nativeRegisterInputChannel(inputChannel, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700258 }
259
Jeff Browna41ca772010-08-11 14:46:32 -0700260 /**
261 * Unregisters an input channel.
262 * @param inputChannel The input channel to unregister.
263 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700264 public void unregisterInputChannel(InputChannel inputChannel) {
265 if (inputChannel == null) {
266 throw new IllegalArgumentException("inputChannel must not be null.");
267 }
268
269 nativeUnregisterInputChannel(inputChannel);
270 }
271
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700272 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700273 * Injects an input event into the event system on behalf of an application.
274 * The synchronization mode determines whether the method blocks while waiting for
275 * input injection to proceed.
276 *
277 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
278 * is assumed always to be successful.
279 *
280 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
281 * dispatched so that the input dispatcher can determine whether input event injection will
282 * be permitted based on the current input focus. Does not wait for the input event to
283 * finish processing.
284 *
285 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
286 * be completely processed.
287 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700288 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700289 * @param injectorPid The pid of the injecting application.
290 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700291 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700292 * @param timeoutMillis The injection timeout in milliseconds.
293 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700294 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700295 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
296 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700297 if (event == null) {
298 throw new IllegalArgumentException("event must not be null");
299 }
300 if (injectorPid < 0 || injectorUid < 0) {
301 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
302 }
303 if (timeoutMillis <= 0) {
304 throw new IllegalArgumentException("timeoutMillis must be positive");
305 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700306
307 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700308 }
309
Jeff Brown8d608662010-08-30 03:02:23 -0700310 /**
311 * Gets information about the input device with the specified id.
312 * @param id The device id.
313 * @return The input device or null if not found.
314 */
315 public InputDevice getInputDevice(int deviceId) {
316 return nativeGetInputDevice(deviceId);
317 }
318
319 /**
320 * Gets the ids of all input devices in the system.
321 * @return The input device ids.
322 */
323 public int[] getInputDeviceIds() {
324 return nativeGetInputDeviceIds();
325 }
326
Jeff Brown349703e2010-06-22 01:27:15 -0700327 public void setInputWindows(InputWindow[] windows) {
328 nativeSetInputWindows(windows);
329 }
330
331 public void setFocusedApplication(InputApplication application) {
332 nativeSetFocusedApplication(application);
333 }
334
Jeff Brown349703e2010-06-22 01:27:15 -0700335 public void setInputDispatchMode(boolean enabled, boolean frozen) {
336 nativeSetInputDispatchMode(enabled, frozen);
337 }
338
Jeff Browne6504122010-09-27 14:52:15 -0700339 /**
340 * Atomically transfers touch focus from one window to another as identified by
341 * their input channels. It is possible for multiple windows to have
342 * touch focus if they support split touch dispatch
343 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
344 * method only transfers touch focus of the specified window without affecting
345 * other windows that may also have touch focus at the same time.
346 * @param fromChannel The channel of a window that currently has touch focus.
347 * @param toChannel The channel of the window that should receive touch focus in
348 * place of the first.
349 * @return True if the transfer was successful. False if the window with the
350 * specified channel did not actually have touch focus at the time of the request.
351 */
352 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
353 if (fromChannel == null) {
354 throw new IllegalArgumentException("fromChannel must not be null.");
355 }
356 if (toChannel == null) {
357 throw new IllegalArgumentException("toChannel must not be null.");
358 }
359 return nativeTransferTouchFocus(fromChannel, toChannel);
360 }
361
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700362 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700363 String dumpStr = nativeDump();
364 if (dumpStr != null) {
365 pw.println(dumpStr);
366 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700367 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800368
369 private static final class PointerIcon {
370 public Bitmap bitmap;
371 public float hotSpotX;
372 public float hotSpotY;
373
374 public static PointerIcon load(Resources resources, int resourceId) {
375 PointerIcon icon = new PointerIcon();
376
377 XmlResourceParser parser = resources.getXml(resourceId);
378 final int bitmapRes;
379 try {
380 XmlUtils.beginDocument(parser, "pointer-icon");
381
382 TypedArray a = resources.obtainAttributes(
383 parser, com.android.internal.R.styleable.PointerIcon);
384 bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
385 icon.hotSpotX = a.getFloat(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
386 icon.hotSpotY = a.getFloat(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
387 a.recycle();
388 } catch (Exception ex) {
389 Slog.e(TAG, "Exception parsing pointer icon resource.", ex);
390 return null;
391 } finally {
392 parser.close();
393 }
394
395 if (bitmapRes == 0) {
396 Slog.e(TAG, "<pointer-icon> is missing bitmap attribute");
397 return null;
398 }
399
400 Drawable drawable = resources.getDrawable(bitmapRes);
401 if (!(drawable instanceof BitmapDrawable)) {
402 Slog.e(TAG, "<pointer-icon> bitmap attribute must refer to a bitmap drawable");
403 return null;
404 }
405
406 icon.bitmap = ((BitmapDrawable)drawable).getBitmap();
407 return icon;
408 }
409 }
410
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700411 /*
412 * Callbacks from native.
413 */
414 private class Callbacks {
415 static final String TAG = "InputManager-Callbacks";
416
417 private static final boolean DEBUG_VIRTUAL_KEYS = false;
418 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700419 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700420
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700421 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700422 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700423 mWindowManagerService.sendNewConfiguration();
424 }
425
426 @SuppressWarnings("unused")
427 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700428 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700429 }
430
431 @SuppressWarnings("unused")
Jeff Brown7fbdc842010-06-17 20:52:56 -0700432 public void notifyInputChannelBroken(InputChannel inputChannel) {
Jeff Brown349703e2010-06-22 01:27:15 -0700433 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputChannel);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700434 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700435
436 @SuppressWarnings("unused")
Jeff Brown519e0242010-09-15 15:18:56 -0700437 public long notifyANR(Object token, InputChannel inputChannel) {
438 return mWindowManagerService.mInputMonitor.notifyANR(token, inputChannel);
Jeff Brown349703e2010-06-22 01:27:15 -0700439 }
440
441 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800442 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700443 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Brown1f245102010-11-18 20:53:46 -0800444 event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700445 }
446
447 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800448 public boolean interceptKeyBeforeDispatching(InputChannel focus,
449 KeyEvent event, int policyFlags) {
450 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
451 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700452 }
453
454 @SuppressWarnings("unused")
Jeff Brown49ed71d2010-12-06 17:13:33 -0800455 public KeyEvent dispatchUnhandledKey(InputChannel focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800456 KeyEvent event, int policyFlags) {
457 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
458 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700459 }
460
461 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700462 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
463 return mContext.checkPermission(
464 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
465 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700466 }
467
468 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700469 public boolean filterTouchEvents() {
470 return mContext.getResources().getBoolean(
471 com.android.internal.R.bool.config_filterTouchEvents);
472 }
473
474 @SuppressWarnings("unused")
475 public boolean filterJumpyTouchEvents() {
476 return mContext.getResources().getBoolean(
477 com.android.internal.R.bool.config_filterJumpyTouchEvents);
478 }
479
480 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700481 public String[] getExcludedDeviceNames() {
482 ArrayList<String> names = new ArrayList<String>();
483
484 // Read partner-provided list of excluded input devices
485 XmlPullParser parser = null;
486 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
487 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
488 FileReader confreader = null;
489 try {
490 confreader = new FileReader(confFile);
491 parser = Xml.newPullParser();
492 parser.setInput(confreader);
493 XmlUtils.beginDocument(parser, "devices");
494
495 while (true) {
496 XmlUtils.nextElement(parser);
497 if (!"device".equals(parser.getName())) {
498 break;
499 }
500 String name = parser.getAttributeValue(null, "name");
501 if (name != null) {
502 names.add(name);
503 }
504 }
505 } catch (FileNotFoundException e) {
506 // It's ok if the file does not exist.
507 } catch (Exception e) {
508 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
509 } finally {
510 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
511 }
512
513 return names.toArray(new String[names.size()]);
514 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700515
516 @SuppressWarnings("unused")
517 public int getMaxEventsPerSecond() {
518 int result = 0;
519 try {
520 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
521 } catch (NumberFormatException e) {
522 }
523 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700524 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700525 }
526 return result;
527 }
Jeff Brown83c09682010-12-23 17:50:18 -0800528
529 @SuppressWarnings("unused")
530 public int getPointerLayer() {
531 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800532 WindowManager.LayoutParams.TYPE_POINTER)
Jeff Brown83c09682010-12-23 17:50:18 -0800533 * WindowManagerService.TYPE_LAYER_MULTIPLIER
534 + WindowManagerService.TYPE_LAYER_OFFSET;
535 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800536
537 @SuppressWarnings("unused")
538 public PointerIcon getPointerIcon() {
539 return PointerIcon.load(mContext.getResources(),
540 com.android.internal.R.drawable.pointericon_default);
541 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700542 }
543}