blob: 5c2048bd81f44a7c887517243c9d156c328cf0ca [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,
Jeff Brown928e0542011-01-10 11:17:36 -080080 InputWindowHandle inputWindowHandle, 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);
Jeff Brown928e0542011-01-10 11:17:36 -0800243 nativeRegisterInputChannel(inputChannels[0], null, true);
Jeff Browna41ca772010-08-11 14:46:32 -0700244 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.
Jeff Brown928e0542011-01-10 11:17:36 -0800251 * @param inputWindowHandle The handle of the input window associated with the
252 * input channel, or null if none.
Jeff Browna41ca772010-08-11 14:46:32 -0700253 */
Jeff Brown928e0542011-01-10 11:17:36 -0800254 public void registerInputChannel(InputChannel inputChannel,
255 InputWindowHandle inputWindowHandle) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700256 if (inputChannel == null) {
257 throw new IllegalArgumentException("inputChannel must not be null.");
258 }
259
Jeff Brown928e0542011-01-10 11:17:36 -0800260 nativeRegisterInputChannel(inputChannel, inputWindowHandle, false);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700261 }
262
Jeff Browna41ca772010-08-11 14:46:32 -0700263 /**
264 * Unregisters an input channel.
265 * @param inputChannel The input channel to unregister.
266 */
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700267 public void unregisterInputChannel(InputChannel inputChannel) {
268 if (inputChannel == null) {
269 throw new IllegalArgumentException("inputChannel must not be null.");
270 }
271
272 nativeUnregisterInputChannel(inputChannel);
273 }
274
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700275 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700276 * Injects an input event into the event system on behalf of an application.
277 * The synchronization mode determines whether the method blocks while waiting for
278 * input injection to proceed.
279 *
280 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
281 * is assumed always to be successful.
282 *
283 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
284 * dispatched so that the input dispatcher can determine whether input event injection will
285 * be permitted based on the current input focus. Does not wait for the input event to
286 * finish processing.
287 *
288 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
289 * be completely processed.
290 *
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700291 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700292 * @param injectorPid The pid of the injecting application.
293 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700294 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700295 * @param timeoutMillis The injection timeout in milliseconds.
296 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700297 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700298 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
299 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700300 if (event == null) {
301 throw new IllegalArgumentException("event must not be null");
302 }
303 if (injectorPid < 0 || injectorUid < 0) {
304 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
305 }
306 if (timeoutMillis <= 0) {
307 throw new IllegalArgumentException("timeoutMillis must be positive");
308 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700309
310 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700311 }
312
Jeff Brown8d608662010-08-30 03:02:23 -0700313 /**
314 * Gets information about the input device with the specified id.
315 * @param id The device id.
316 * @return The input device or null if not found.
317 */
318 public InputDevice getInputDevice(int deviceId) {
319 return nativeGetInputDevice(deviceId);
320 }
321
322 /**
323 * Gets the ids of all input devices in the system.
324 * @return The input device ids.
325 */
326 public int[] getInputDeviceIds() {
327 return nativeGetInputDeviceIds();
328 }
329
Jeff Brown349703e2010-06-22 01:27:15 -0700330 public void setInputWindows(InputWindow[] windows) {
331 nativeSetInputWindows(windows);
332 }
333
334 public void setFocusedApplication(InputApplication application) {
335 nativeSetFocusedApplication(application);
336 }
337
Jeff Brown349703e2010-06-22 01:27:15 -0700338 public void setInputDispatchMode(boolean enabled, boolean frozen) {
339 nativeSetInputDispatchMode(enabled, frozen);
340 }
341
Jeff Browne6504122010-09-27 14:52:15 -0700342 /**
343 * Atomically transfers touch focus from one window to another as identified by
344 * their input channels. It is possible for multiple windows to have
345 * touch focus if they support split touch dispatch
346 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
347 * method only transfers touch focus of the specified window without affecting
348 * other windows that may also have touch focus at the same time.
349 * @param fromChannel The channel of a window that currently has touch focus.
350 * @param toChannel The channel of the window that should receive touch focus in
351 * place of the first.
352 * @return True if the transfer was successful. False if the window with the
353 * specified channel did not actually have touch focus at the time of the request.
354 */
355 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
356 if (fromChannel == null) {
357 throw new IllegalArgumentException("fromChannel must not be null.");
358 }
359 if (toChannel == null) {
360 throw new IllegalArgumentException("toChannel must not be null.");
361 }
362 return nativeTransferTouchFocus(fromChannel, toChannel);
363 }
364
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700365 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700366 String dumpStr = nativeDump();
367 if (dumpStr != null) {
368 pw.println(dumpStr);
369 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700370 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800371
372 private static final class PointerIcon {
373 public Bitmap bitmap;
374 public float hotSpotX;
375 public float hotSpotY;
376
377 public static PointerIcon load(Resources resources, int resourceId) {
378 PointerIcon icon = new PointerIcon();
379
380 XmlResourceParser parser = resources.getXml(resourceId);
381 final int bitmapRes;
382 try {
383 XmlUtils.beginDocument(parser, "pointer-icon");
384
385 TypedArray a = resources.obtainAttributes(
386 parser, com.android.internal.R.styleable.PointerIcon);
387 bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
388 icon.hotSpotX = a.getFloat(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
389 icon.hotSpotY = a.getFloat(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
390 a.recycle();
391 } catch (Exception ex) {
392 Slog.e(TAG, "Exception parsing pointer icon resource.", ex);
393 return null;
394 } finally {
395 parser.close();
396 }
397
398 if (bitmapRes == 0) {
399 Slog.e(TAG, "<pointer-icon> is missing bitmap attribute");
400 return null;
401 }
402
403 Drawable drawable = resources.getDrawable(bitmapRes);
404 if (!(drawable instanceof BitmapDrawable)) {
405 Slog.e(TAG, "<pointer-icon> bitmap attribute must refer to a bitmap drawable");
406 return null;
407 }
408
409 icon.bitmap = ((BitmapDrawable)drawable).getBitmap();
410 return icon;
411 }
412 }
413
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700414 /*
415 * Callbacks from native.
416 */
417 private class Callbacks {
418 static final String TAG = "InputManager-Callbacks";
419
420 private static final boolean DEBUG_VIRTUAL_KEYS = false;
421 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700422 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700423
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700424 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700425 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700426 mWindowManagerService.sendNewConfiguration();
427 }
428
429 @SuppressWarnings("unused")
430 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700431 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700432 }
433
434 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800435 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
436 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputWindowHandle);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700437 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700438
439 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800440 public long notifyANR(InputApplicationHandle inputApplicationHandle,
441 InputWindowHandle inputWindowHandle) {
442 return mWindowManagerService.mInputMonitor.notifyANR(
443 inputApplicationHandle, inputWindowHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700444 }
445
446 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800447 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700448 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Brown1f245102010-11-18 20:53:46 -0800449 event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700450 }
451
452 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800453 public boolean interceptKeyBeforeDispatching(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800454 KeyEvent event, int policyFlags) {
455 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
456 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700457 }
458
459 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800460 public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800461 KeyEvent event, int policyFlags) {
462 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
463 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700464 }
465
466 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700467 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
468 return mContext.checkPermission(
469 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
470 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700471 }
472
473 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700474 public boolean filterTouchEvents() {
475 return mContext.getResources().getBoolean(
476 com.android.internal.R.bool.config_filterTouchEvents);
477 }
478
479 @SuppressWarnings("unused")
480 public boolean filterJumpyTouchEvents() {
481 return mContext.getResources().getBoolean(
482 com.android.internal.R.bool.config_filterJumpyTouchEvents);
483 }
484
485 @SuppressWarnings("unused")
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700486 public String[] getExcludedDeviceNames() {
487 ArrayList<String> names = new ArrayList<String>();
488
489 // Read partner-provided list of excluded input devices
490 XmlPullParser parser = null;
491 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
492 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
493 FileReader confreader = null;
494 try {
495 confreader = new FileReader(confFile);
496 parser = Xml.newPullParser();
497 parser.setInput(confreader);
498 XmlUtils.beginDocument(parser, "devices");
499
500 while (true) {
501 XmlUtils.nextElement(parser);
502 if (!"device".equals(parser.getName())) {
503 break;
504 }
505 String name = parser.getAttributeValue(null, "name");
506 if (name != null) {
507 names.add(name);
508 }
509 }
510 } catch (FileNotFoundException e) {
511 // It's ok if the file does not exist.
512 } catch (Exception e) {
513 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
514 } finally {
515 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
516 }
517
518 return names.toArray(new String[names.size()]);
519 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700520
521 @SuppressWarnings("unused")
522 public int getMaxEventsPerSecond() {
523 int result = 0;
524 try {
525 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
526 } catch (NumberFormatException e) {
527 }
528 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700529 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700530 }
531 return result;
532 }
Jeff Brown83c09682010-12-23 17:50:18 -0800533
534 @SuppressWarnings("unused")
535 public int getPointerLayer() {
536 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800537 WindowManager.LayoutParams.TYPE_POINTER)
Jeff Brown83c09682010-12-23 17:50:18 -0800538 * WindowManagerService.TYPE_LAYER_MULTIPLIER
539 + WindowManagerService.TYPE_LAYER_OFFSET;
540 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800541
542 @SuppressWarnings("unused")
543 public PointerIcon getPointerIcon() {
544 return PointerIcon.load(mContext.getResources(),
545 com.android.internal.R.drawable.pointericon_default);
546 }
Jeff Brown46b9ac0a2010-04-22 18:58:52 -0700547 }
548}