blob: 77cec5d737ec23315543ac1cf8defa19f334cf18 [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
Dianne Hackborna924dc0d2011-02-17 14:22:17 -080017package com.android.server.wm;
Jeff Brown46b9ac02010-04-22 18:58:52 -070018
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;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080026import android.content.res.Resources;
27import android.content.res.TypedArray;
28import android.content.res.XmlResourceParser;
29import android.graphics.Bitmap;
30import android.graphics.drawable.BitmapDrawable;
31import android.graphics.drawable.Drawable;
Jeff Brown46b9ac02010-04-22 18:58:52 -070032import android.os.Environment;
Jeff Brown05dc66a2011-03-02 14:41:58 -080033import android.os.Looper;
34import android.os.MessageQueue;
Jeff Brownae9fc032010-08-18 15:51:08 -070035import android.os.SystemProperties;
Jeff Brown46b9ac02010-04-22 18:58:52 -070036import android.util.Slog;
37import android.util.Xml;
38import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070039import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070040import android.view.InputEvent;
Jeff Brown1f245102010-11-18 20:53:46 -080041import android.view.KeyEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -070042import android.view.Surface;
Jeff Brown83c09682010-12-23 17:50:18 -080043import android.view.WindowManager;
Jeff Brown46b9ac02010-04-22 18:58:52 -070044
Jeff Brown46b9ac02010-04-22 18:58:52 -070045import java.io.File;
Jeff Brown46b9ac02010-04-22 18:58:52 -070046import java.io.FileNotFoundException;
47import java.io.FileReader;
48import java.io.IOException;
Jeff Brown46b9ac02010-04-22 18:58:52 -070049import java.io.PrintWriter;
50import java.util.ArrayList;
51
52/*
53 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac02010-04-22 18:58:52 -070054 */
55public class InputManager {
56 static final String TAG = "InputManager";
57
Jeff Brownb6997262010-10-08 22:31:17 -070058 private static final boolean DEBUG = false;
59
Jeff Brown46b9ac02010-04-22 18:58:52 -070060 private final Callbacks mCallbacks;
61 private final Context mContext;
62 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -070063
Jeff Brown05dc66a2011-03-02 14:41:58 -080064 private static native void nativeInit(Callbacks callbacks, MessageQueue messageQueue);
Jeff Brown46b9ac02010-04-22 18:58:52 -070065 private static native void nativeStart();
66 private static native void nativeSetDisplaySize(int displayId, int width, int height);
67 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
68
Jeff Brown6d0fec22010-07-23 21:28:06 -070069 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070070 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070071 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070072 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070073 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070074 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070075 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
76 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070077 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -080078 InputWindowHandle inputWindowHandle, boolean monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -070079 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown6ec402b2010-07-28 15:48:59 -070080 private static native int nativeInjectInputEvent(InputEvent event,
81 int injectorPid, int injectorUid, int syncMode, int timeoutMillis);
Jeff Brown349703e2010-06-22 01:27:15 -070082 private static native void nativeSetInputWindows(InputWindow[] windows);
83 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -080084 private static native void nativeSetSystemUiVisibility(int visibility);
Jeff Brown349703e2010-06-22 01:27:15 -070085 private static native void nativeSetFocusedApplication(InputApplication application);
Jeff Brown8d608662010-08-30 03:02:23 -070086 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070087 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070088 private static native int[] nativeGetInputDeviceIds();
Jeff Browne6504122010-09-27 14:52:15 -070089 private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
90 InputChannel toChannel);
Jeff Browne33348b2010-07-15 23:54:05 -070091 private static native String nativeDump();
Jeff Brown46b9ac02010-04-22 18:58:52 -070092
Jeff Brown7fbdc842010-06-17 20:52:56 -070093 // Input event injection constants defined in InputDispatcher.h.
94 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
95 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
96 static final int INPUT_EVENT_INJECTION_FAILED = 2;
97 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
98
Jeff Brown6ec402b2010-07-28 15:48:59 -070099 // Input event injection synchronization modes defined in InputDispatcher.h
100 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
101 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
102 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
103
Jeff Brown6d0fec22010-07-23 21:28:06 -0700104 // Key states (may be returned by queries about the current state of a
105 // particular key code, scan code or switch).
106
107 /** The key state is unknown or the requested key itself is not supported. */
108 public static final int KEY_STATE_UNKNOWN = -1;
109
110 /** The key is up. /*/
111 public static final int KEY_STATE_UP = 0;
112
113 /** The key is down. */
114 public static final int KEY_STATE_DOWN = 1;
115
116 /** The key is down but is a virtual key press that is being emulated by the system. */
117 public static final int KEY_STATE_VIRTUAL = 2;
118
Jeff Browne33348b2010-07-15 23:54:05 -0700119 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700120 this.mContext = context;
121 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700122 this.mCallbacks = new Callbacks();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800123
124 Looper looper = windowManagerService.mH.getLooper();
125
Jeff Brown46b9ac02010-04-22 18:58:52 -0700126 Slog.i(TAG, "Initializing input manager");
Jeff Brown05dc66a2011-03-02 14:41:58 -0800127 nativeInit(mCallbacks, looper.getQueue());
Jeff Brown46b9ac02010-04-22 18:58:52 -0700128 }
129
130 public void start() {
131 Slog.i(TAG, "Starting input manager");
132 nativeStart();
133 }
134
135 public void setDisplaySize(int displayId, int width, int height) {
136 if (width <= 0 || height <= 0) {
137 throw new IllegalArgumentException("Invalid display id or dimensions.");
138 }
139
Jeff Brownb6997262010-10-08 22:31:17 -0700140 if (DEBUG) {
141 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
142 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700143 nativeSetDisplaySize(displayId, width, height);
144 }
145
146 public void setDisplayOrientation(int displayId, int rotation) {
147 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
148 throw new IllegalArgumentException("Invalid rotation.");
149 }
150
Jeff Brownb6997262010-10-08 22:31:17 -0700151 if (DEBUG) {
152 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
153 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700154 nativeSetDisplayOrientation(displayId, rotation);
155 }
156
157 public void getInputConfiguration(Configuration config) {
158 if (config == null) {
159 throw new IllegalArgumentException("config must not be null.");
160 }
161
Jeff Brown57c59372010-09-21 18:22:55 -0700162 nativeGetInputConfiguration(config);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700163 }
164
Jeff Brown6d0fec22010-07-23 21:28:06 -0700165 /**
166 * Gets the current state of a key or button by key code.
167 * @param deviceId The input device id, or -1 to consult all devices.
168 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
169 * consider all input sources. An input device is consulted if at least one of its
170 * non-class input source bits matches the specified source mask.
171 * @param keyCode The key code to check.
172 * @return The key state.
173 */
174 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
175 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700176 }
177
Jeff Brown6d0fec22010-07-23 21:28:06 -0700178 /**
179 * Gets the current state of a key or button by scan code.
180 * @param deviceId The input device id, or -1 to consult all devices.
181 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
182 * consider all input sources. An input device is consulted if at least one of its
183 * non-class input source bits matches the specified source mask.
184 * @param scanCode The scan code to check.
185 * @return The key state.
186 */
187 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
188 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700189 }
190
Jeff Brown6d0fec22010-07-23 21:28:06 -0700191 /**
192 * Gets the current state of a switch by switch code.
193 * @param deviceId The input device id, or -1 to consult all devices.
194 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
195 * consider all input sources. An input device is consulted if at least one of its
196 * non-class input source bits matches the specified source mask.
197 * @param switchCode The switch code to check.
198 * @return The switch state.
199 */
200 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
201 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700202 }
203
Jeff Brown6d0fec22010-07-23 21:28:06 -0700204 /**
205 * Determines whether the specified key codes are supported by a particular device.
206 * @param deviceId The input device id, or -1 to consult all devices.
207 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
208 * consider all input sources. An input device is consulted if at least one of its
209 * non-class input source bits matches the specified source mask.
210 * @param keyCodes The array of key codes to check.
211 * @param keyExists An array at least as large as keyCodes whose entries will be set
212 * to true or false based on the presence or absence of support for the corresponding
213 * key codes.
214 * @return True if the lookup was successful, false otherwise.
215 */
216 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700217 if (keyCodes == null) {
218 throw new IllegalArgumentException("keyCodes must not be null.");
219 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700220 if (keyExists == null || keyExists.length < keyCodes.length) {
221 throw new IllegalArgumentException("keyExists must not be null and must be at "
222 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700223 }
224
Jeff Brown6d0fec22010-07-23 21:28:06 -0700225 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700226 }
227
Jeff Browna41ca772010-08-11 14:46:32 -0700228 /**
229 * Creates an input channel that will receive all input from the input dispatcher.
230 * @param inputChannelName The input channel name.
231 * @return The input channel.
232 */
233 public InputChannel monitorInput(String inputChannelName) {
234 if (inputChannelName == null) {
235 throw new IllegalArgumentException("inputChannelName must not be null.");
236 }
237
238 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
Jeff Brown928e0542011-01-10 11:17:36 -0800239 nativeRegisterInputChannel(inputChannels[0], null, true);
Jeff Browna41ca772010-08-11 14:46:32 -0700240 inputChannels[0].dispose(); // don't need to retain the Java object reference
241 return inputChannels[1];
242 }
243
244 /**
245 * Registers an input channel so that it can be used as an input event target.
246 * @param inputChannel The input channel to register.
Jeff Brown928e0542011-01-10 11:17:36 -0800247 * @param inputWindowHandle The handle of the input window associated with the
248 * input channel, or null if none.
Jeff Browna41ca772010-08-11 14:46:32 -0700249 */
Jeff Brown928e0542011-01-10 11:17:36 -0800250 public void registerInputChannel(InputChannel inputChannel,
251 InputWindowHandle inputWindowHandle) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700252 if (inputChannel == null) {
253 throw new IllegalArgumentException("inputChannel must not be null.");
254 }
255
Jeff Brown928e0542011-01-10 11:17:36 -0800256 nativeRegisterInputChannel(inputChannel, inputWindowHandle, 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
Jeff Brown349703e2010-06-22 01:27:15 -0700334 public void setInputDispatchMode(boolean enabled, boolean frozen) {
335 nativeSetInputDispatchMode(enabled, frozen);
336 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800337
338 public void setSystemUiVisibility(int visibility) {
339 nativeSetSystemUiVisibility(visibility);
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 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800364
Jeff Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-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 Brown46b9ac02010-04-22 18:58:52 -0700423
Jeff Brown46b9ac02010-04-22 18:58:52 -0700424 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700425 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800426 mWindowManagerService.mInputMonitor.notifyConfigurationChanged();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700427 }
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 Brown46b9ac02010-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 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800451
452 @SuppressWarnings("unused")
453 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
454 return mWindowManagerService.mInputMonitor.interceptMotionBeforeQueueingWhenScreenOff(
455 policyFlags);
456 }
457
Jeff Brown349703e2010-06-22 01:27:15 -0700458 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800459 public boolean interceptKeyBeforeDispatching(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800460 KeyEvent event, int policyFlags) {
461 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
462 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700463 }
464
465 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800466 public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800467 KeyEvent event, int policyFlags) {
468 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
469 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700470 }
471
472 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700473 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
474 return mContext.checkPermission(
475 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
476 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700477 }
478
479 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700480 public boolean filterTouchEvents() {
481 return mContext.getResources().getBoolean(
482 com.android.internal.R.bool.config_filterTouchEvents);
483 }
484
485 @SuppressWarnings("unused")
486 public boolean filterJumpyTouchEvents() {
487 return mContext.getResources().getBoolean(
488 com.android.internal.R.bool.config_filterJumpyTouchEvents);
489 }
Jeff Brownfe508922011-01-18 15:10:10 -0800490
491 @SuppressWarnings("unused")
492 public int getVirtualKeyQuietTimeMillis() {
493 return mContext.getResources().getInteger(
494 com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
495 }
496
Jeff Brown46b9ac02010-04-22 18:58:52 -0700497 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700498 public String[] getExcludedDeviceNames() {
499 ArrayList<String> names = new ArrayList<String>();
500
501 // Read partner-provided list of excluded input devices
502 XmlPullParser parser = null;
503 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
504 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
505 FileReader confreader = null;
506 try {
507 confreader = new FileReader(confFile);
508 parser = Xml.newPullParser();
509 parser.setInput(confreader);
510 XmlUtils.beginDocument(parser, "devices");
511
512 while (true) {
513 XmlUtils.nextElement(parser);
514 if (!"device".equals(parser.getName())) {
515 break;
516 }
517 String name = parser.getAttributeValue(null, "name");
518 if (name != null) {
519 names.add(name);
520 }
521 }
522 } catch (FileNotFoundException e) {
523 // It's ok if the file does not exist.
524 } catch (Exception e) {
525 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
526 } finally {
527 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
528 }
529
530 return names.toArray(new String[names.size()]);
531 }
Jeff Brownae9fc032010-08-18 15:51:08 -0700532
533 @SuppressWarnings("unused")
534 public int getMaxEventsPerSecond() {
535 int result = 0;
536 try {
537 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
538 } catch (NumberFormatException e) {
539 }
540 if (result < 1) {
Jeff Brown3d8c9bd2010-08-18 17:48:53 -0700541 result = 60;
Jeff Brownae9fc032010-08-18 15:51:08 -0700542 }
543 return result;
544 }
Jeff Brown83c09682010-12-23 17:50:18 -0800545
546 @SuppressWarnings("unused")
547 public int getPointerLayer() {
548 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800549 WindowManager.LayoutParams.TYPE_POINTER)
Jeff Brown83c09682010-12-23 17:50:18 -0800550 * WindowManagerService.TYPE_LAYER_MULTIPLIER
551 + WindowManagerService.TYPE_LAYER_OFFSET;
552 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800553
554 @SuppressWarnings("unused")
555 public PointerIcon getPointerIcon() {
556 return PointerIcon.load(mContext.getResources(),
Jeff Brown909733c2011-01-13 21:51:44 -0800557 com.android.internal.R.drawable.pointer_arrow_icon);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800558 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700559 }
560}