blob: 69bde41fc8e0d4eec3fc4405baf4f2e8a87e4aff [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;
26import android.os.Environment;
Jeff Brown05dc66a2011-03-02 14:41:58 -080027import android.os.Looper;
28import android.os.MessageQueue;
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 Brown1f245102010-11-18 20:53:46 -080035import android.view.KeyEvent;
Jeff Brown2352b972011-04-12 22:39:53 -070036import android.view.PointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070037import android.view.Surface;
Jeff Browna4547672011-03-02 21:38:11 -080038import android.view.ViewConfiguration;
Jeff Brown83c09682010-12-23 17:50:18 -080039import android.view.WindowManager;
Jeff Brown0029c662011-03-30 02:25:18 -070040import android.view.WindowManagerPolicy;
Jeff Brown46b9ac02010-04-22 18:58:52 -070041
Jeff Brown46b9ac02010-04-22 18:58:52 -070042import java.io.File;
Jeff Brown46b9ac02010-04-22 18:58:52 -070043import java.io.FileNotFoundException;
44import java.io.FileReader;
45import java.io.IOException;
Jeff Brown46b9ac02010-04-22 18:58:52 -070046import java.io.PrintWriter;
47import java.util.ArrayList;
48
49/*
50 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac02010-04-22 18:58:52 -070051 */
52public class InputManager {
53 static final String TAG = "InputManager";
54
Jeff Brownb6997262010-10-08 22:31:17 -070055 private static final boolean DEBUG = false;
56
Jeff Brown46b9ac02010-04-22 18:58:52 -070057 private final Callbacks mCallbacks;
58 private final Context mContext;
59 private final WindowManagerService mWindowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -070060
Jeff Brown2352b972011-04-12 22:39:53 -070061 private static native void nativeInit(Context context,
62 Callbacks callbacks, MessageQueue messageQueue);
Jeff Brown46b9ac02010-04-22 18:58:52 -070063 private static native void nativeStart();
64 private static native void nativeSetDisplaySize(int displayId, int width, int height);
65 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
66
Jeff Brown6d0fec22010-07-23 21:28:06 -070067 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070068 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070069 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070070 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070071 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070072 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070073 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
74 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070075 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -080076 InputWindowHandle inputWindowHandle, boolean monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -070077 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown0029c662011-03-30 02:25:18 -070078 private static native void nativeSetInputFilterEnabled(boolean enable);
Jeff Brown6ec402b2010-07-28 15:48:59 -070079 private static native int nativeInjectInputEvent(InputEvent event,
Jeff Brown0029c662011-03-30 02:25:18 -070080 int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
81 int policyFlags);
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 Brown0029c662011-03-30 02:25:18 -0700119 // State for the currently installed input filter.
120 final Object mInputFilterLock = new Object();
121 InputFilter mInputFilter;
122 InputFilterHost mInputFilterHost;
123
Jeff Browne33348b2010-07-15 23:54:05 -0700124 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700125 this.mContext = context;
126 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700127 this.mCallbacks = new Callbacks();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800128
129 Looper looper = windowManagerService.mH.getLooper();
130
Jeff Brown46b9ac02010-04-22 18:58:52 -0700131 Slog.i(TAG, "Initializing input manager");
Jeff Brown2352b972011-04-12 22:39:53 -0700132 nativeInit(mContext, mCallbacks, looper.getQueue());
Jeff Brown46b9ac02010-04-22 18:58:52 -0700133 }
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
Jeff Brownb6997262010-10-08 22:31:17 -0700145 if (DEBUG) {
146 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height);
147 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700148 nativeSetDisplaySize(displayId, width, height);
149 }
150
151 public void setDisplayOrientation(int displayId, int rotation) {
152 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
153 throw new IllegalArgumentException("Invalid rotation.");
154 }
155
Jeff Brownb6997262010-10-08 22:31:17 -0700156 if (DEBUG) {
157 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
158 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700159 nativeSetDisplayOrientation(displayId, rotation);
160 }
161
162 public void getInputConfiguration(Configuration config) {
163 if (config == null) {
164 throw new IllegalArgumentException("config must not be null.");
165 }
166
Jeff Brown57c59372010-09-21 18:22:55 -0700167 nativeGetInputConfiguration(config);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700168 }
169
Jeff Brown6d0fec22010-07-23 21:28:06 -0700170 /**
171 * Gets the current state of a key or button by key code.
172 * @param deviceId The input device id, or -1 to consult all devices.
173 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
174 * consider all input sources. An input device is consulted if at least one of its
175 * non-class input source bits matches the specified source mask.
176 * @param keyCode The key code to check.
177 * @return The key state.
178 */
179 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
180 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700181 }
182
Jeff Brown6d0fec22010-07-23 21:28:06 -0700183 /**
184 * Gets the current state of a key or button by scan code.
185 * @param deviceId The input device id, or -1 to consult all devices.
186 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
187 * consider all input sources. An input device is consulted if at least one of its
188 * non-class input source bits matches the specified source mask.
189 * @param scanCode The scan code to check.
190 * @return The key state.
191 */
192 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
193 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700194 }
195
Jeff Brown6d0fec22010-07-23 21:28:06 -0700196 /**
197 * Gets the current state of a switch by switch code.
198 * @param deviceId The input device id, or -1 to consult all devices.
199 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
200 * consider all input sources. An input device is consulted if at least one of its
201 * non-class input source bits matches the specified source mask.
202 * @param switchCode The switch code to check.
203 * @return The switch state.
204 */
205 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
206 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700207 }
208
Jeff Brown6d0fec22010-07-23 21:28:06 -0700209 /**
210 * Determines whether the specified key codes are supported by a particular device.
211 * @param deviceId The input device id, or -1 to consult all devices.
212 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
213 * consider all input sources. An input device is consulted if at least one of its
214 * non-class input source bits matches the specified source mask.
215 * @param keyCodes The array of key codes to check.
216 * @param keyExists An array at least as large as keyCodes whose entries will be set
217 * to true or false based on the presence or absence of support for the corresponding
218 * key codes.
219 * @return True if the lookup was successful, false otherwise.
220 */
221 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700222 if (keyCodes == null) {
223 throw new IllegalArgumentException("keyCodes must not be null.");
224 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700225 if (keyExists == null || keyExists.length < keyCodes.length) {
226 throw new IllegalArgumentException("keyExists must not be null and must be at "
227 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700228 }
229
Jeff Brown6d0fec22010-07-23 21:28:06 -0700230 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700231 }
232
Jeff Browna41ca772010-08-11 14:46:32 -0700233 /**
234 * Creates an input channel that will receive all input from the input dispatcher.
235 * @param inputChannelName The input channel name.
236 * @return The input channel.
237 */
238 public InputChannel monitorInput(String inputChannelName) {
239 if (inputChannelName == null) {
240 throw new IllegalArgumentException("inputChannelName must not be null.");
241 }
242
243 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
Jeff Brown928e0542011-01-10 11:17:36 -0800244 nativeRegisterInputChannel(inputChannels[0], null, true);
Jeff Browna41ca772010-08-11 14:46:32 -0700245 inputChannels[0].dispose(); // don't need to retain the Java object reference
246 return inputChannels[1];
247 }
248
249 /**
250 * Registers an input channel so that it can be used as an input event target.
251 * @param inputChannel The input channel to register.
Jeff Brown928e0542011-01-10 11:17:36 -0800252 * @param inputWindowHandle The handle of the input window associated with the
253 * input channel, or null if none.
Jeff Browna41ca772010-08-11 14:46:32 -0700254 */
Jeff Brown928e0542011-01-10 11:17:36 -0800255 public void registerInputChannel(InputChannel inputChannel,
256 InputWindowHandle inputWindowHandle) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700257 if (inputChannel == null) {
258 throw new IllegalArgumentException("inputChannel must not be null.");
259 }
260
Jeff Brown928e0542011-01-10 11:17:36 -0800261 nativeRegisterInputChannel(inputChannel, inputWindowHandle, false);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700262 }
263
Jeff Browna41ca772010-08-11 14:46:32 -0700264 /**
265 * Unregisters an input channel.
266 * @param inputChannel The input channel to unregister.
267 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700268 public void unregisterInputChannel(InputChannel inputChannel) {
269 if (inputChannel == null) {
270 throw new IllegalArgumentException("inputChannel must not be null.");
271 }
272
273 nativeUnregisterInputChannel(inputChannel);
274 }
Jeff Brown0029c662011-03-30 02:25:18 -0700275
276 /**
277 * Sets an input filter that will receive all input events before they are dispatched.
278 * The input filter may then reinterpret input events or inject new ones.
279 *
280 * To ensure consistency, the input dispatcher automatically drops all events
281 * in progress whenever an input filter is installed or uninstalled. After an input
282 * filter is uninstalled, it can no longer send input events unless it is reinstalled.
283 * Any events it attempts to send after it has been uninstalled will be dropped.
284 *
285 * @param filter The input filter, or null to remove the current filter.
286 */
287 public void setInputFilter(InputFilter filter) {
288 synchronized (mInputFilterLock) {
289 final InputFilter oldFilter = mInputFilter;
290 if (oldFilter == filter) {
291 return; // nothing to do
292 }
293
294 if (oldFilter != null) {
295 mInputFilter = null;
296 mInputFilterHost.disconnectLocked();
297 mInputFilterHost = null;
298 oldFilter.uninstall();
299 }
300
301 if (filter != null) {
302 mInputFilter = filter;
303 mInputFilterHost = new InputFilterHost();
304 filter.install(mInputFilterHost);
305 }
306
307 nativeSetInputFilterEnabled(filter != null);
308 }
309 }
310
Jeff Brown46b9ac02010-04-22 18:58:52 -0700311 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700312 * Injects an input event into the event system on behalf of an application.
313 * The synchronization mode determines whether the method blocks while waiting for
314 * input injection to proceed.
315 *
316 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
317 * is assumed always to be successful.
318 *
319 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
320 * dispatched so that the input dispatcher can determine whether input event injection will
321 * be permitted based on the current input focus. Does not wait for the input event to
322 * finish processing.
323 *
324 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
325 * be completely processed.
326 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700327 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700328 * @param injectorPid The pid of the injecting application.
329 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700330 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700331 * @param timeoutMillis The injection timeout in milliseconds.
332 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700333 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700334 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
335 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700336 if (event == null) {
337 throw new IllegalArgumentException("event must not be null");
338 }
339 if (injectorPid < 0 || injectorUid < 0) {
340 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
341 }
342 if (timeoutMillis <= 0) {
343 throw new IllegalArgumentException("timeoutMillis must be positive");
344 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700345
Jeff Brown0029c662011-03-30 02:25:18 -0700346 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis,
347 WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700348 }
Jeff Brown0029c662011-03-30 02:25:18 -0700349
Jeff Brown8d608662010-08-30 03:02:23 -0700350 /**
351 * Gets information about the input device with the specified id.
352 * @param id The device id.
353 * @return The input device or null if not found.
354 */
355 public InputDevice getInputDevice(int deviceId) {
356 return nativeGetInputDevice(deviceId);
357 }
358
359 /**
360 * Gets the ids of all input devices in the system.
361 * @return The input device ids.
362 */
363 public int[] getInputDeviceIds() {
364 return nativeGetInputDeviceIds();
365 }
366
Jeff Brown349703e2010-06-22 01:27:15 -0700367 public void setInputWindows(InputWindow[] windows) {
368 nativeSetInputWindows(windows);
369 }
370
371 public void setFocusedApplication(InputApplication application) {
372 nativeSetFocusedApplication(application);
373 }
374
Jeff Brown349703e2010-06-22 01:27:15 -0700375 public void setInputDispatchMode(boolean enabled, boolean frozen) {
376 nativeSetInputDispatchMode(enabled, frozen);
377 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800378
379 public void setSystemUiVisibility(int visibility) {
380 nativeSetSystemUiVisibility(visibility);
381 }
382
Jeff Browne6504122010-09-27 14:52:15 -0700383 /**
384 * Atomically transfers touch focus from one window to another as identified by
385 * their input channels. It is possible for multiple windows to have
386 * touch focus if they support split touch dispatch
387 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
388 * method only transfers touch focus of the specified window without affecting
389 * other windows that may also have touch focus at the same time.
390 * @param fromChannel The channel of a window that currently has touch focus.
391 * @param toChannel The channel of the window that should receive touch focus in
392 * place of the first.
393 * @return True if the transfer was successful. False if the window with the
394 * specified channel did not actually have touch focus at the time of the request.
395 */
396 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
397 if (fromChannel == null) {
398 throw new IllegalArgumentException("fromChannel must not be null.");
399 }
400 if (toChannel == null) {
401 throw new IllegalArgumentException("toChannel must not be null.");
402 }
403 return nativeTransferTouchFocus(fromChannel, toChannel);
404 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800405
Jeff Brown46b9ac02010-04-22 18:58:52 -0700406 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700407 String dumpStr = nativeDump();
408 if (dumpStr != null) {
409 pw.println(dumpStr);
410 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700411 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800412
Jeff Brown0029c662011-03-30 02:25:18 -0700413 private final class InputFilterHost implements InputFilter.Host {
414 private boolean mDisconnected;
415
416 public void disconnectLocked() {
417 mDisconnected = true;
418 }
419
420 public void sendInputEvent(InputEvent event, int policyFlags) {
421 if (event == null) {
422 throw new IllegalArgumentException("event must not be null");
423 }
424
425 synchronized (mInputFilterLock) {
426 if (!mDisconnected) {
427 nativeInjectInputEvent(event, 0, 0, INPUT_EVENT_INJECTION_SYNC_NONE, 0,
428 policyFlags | WindowManagerPolicy.FLAG_FILTERED);
429 }
430 }
431 }
432 }
433
Jeff Brown46b9ac02010-04-22 18:58:52 -0700434 /*
435 * Callbacks from native.
436 */
Jeff Brown0029c662011-03-30 02:25:18 -0700437 private final class Callbacks {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700438 static final String TAG = "InputManager-Callbacks";
439
440 private static final boolean DEBUG_VIRTUAL_KEYS = false;
441 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700442 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac02010-04-22 18:58:52 -0700443
Jeff Brown46b9ac02010-04-22 18:58:52 -0700444 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700445 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800446 mWindowManagerService.mInputMonitor.notifyConfigurationChanged();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700447 }
448
449 @SuppressWarnings("unused")
450 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700451 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700452 }
453
454 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800455 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
456 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputWindowHandle);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700457 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700458
459 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800460 public long notifyANR(InputApplicationHandle inputApplicationHandle,
461 InputWindowHandle inputWindowHandle) {
462 return mWindowManagerService.mInputMonitor.notifyANR(
463 inputApplicationHandle, inputWindowHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700464 }
Jeff Brown0029c662011-03-30 02:25:18 -0700465
466 @SuppressWarnings("unused")
467 final boolean filterInputEvent(InputEvent event, int policyFlags) {
468 synchronized (mInputFilterLock) {
469 if (mInputFilter != null) {
470 mInputFilter.filterInputEvent(event, policyFlags);
471 return false;
472 }
473 }
474 event.recycle();
475 return true;
476 }
477
Jeff Brown349703e2010-06-22 01:27:15 -0700478 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800479 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700480 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Brown1f245102010-11-18 20:53:46 -0800481 event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700482 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800483
484 @SuppressWarnings("unused")
485 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
486 return mWindowManagerService.mInputMonitor.interceptMotionBeforeQueueingWhenScreenOff(
487 policyFlags);
488 }
489
Jeff Brown349703e2010-06-22 01:27:15 -0700490 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800491 public boolean interceptKeyBeforeDispatching(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800492 KeyEvent event, int policyFlags) {
493 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
494 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700495 }
496
497 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800498 public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800499 KeyEvent event, int policyFlags) {
500 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
501 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700502 }
503
504 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700505 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
506 return mContext.checkPermission(
507 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
508 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700509 }
510
511 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700512 public boolean filterTouchEvents() {
513 return mContext.getResources().getBoolean(
514 com.android.internal.R.bool.config_filterTouchEvents);
515 }
516
517 @SuppressWarnings("unused")
518 public boolean filterJumpyTouchEvents() {
519 return mContext.getResources().getBoolean(
520 com.android.internal.R.bool.config_filterJumpyTouchEvents);
521 }
Jeff Brownfe508922011-01-18 15:10:10 -0800522
523 @SuppressWarnings("unused")
524 public int getVirtualKeyQuietTimeMillis() {
525 return mContext.getResources().getInteger(
526 com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
527 }
528
Jeff Brown46b9ac02010-04-22 18:58:52 -0700529 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700530 public String[] getExcludedDeviceNames() {
531 ArrayList<String> names = new ArrayList<String>();
532
533 // Read partner-provided list of excluded input devices
534 XmlPullParser parser = null;
535 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
536 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
537 FileReader confreader = null;
538 try {
539 confreader = new FileReader(confFile);
540 parser = Xml.newPullParser();
541 parser.setInput(confreader);
542 XmlUtils.beginDocument(parser, "devices");
543
544 while (true) {
545 XmlUtils.nextElement(parser);
546 if (!"device".equals(parser.getName())) {
547 break;
548 }
549 String name = parser.getAttributeValue(null, "name");
550 if (name != null) {
551 names.add(name);
552 }
553 }
554 } catch (FileNotFoundException e) {
555 // It's ok if the file does not exist.
556 } catch (Exception e) {
557 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
558 } finally {
559 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
560 }
561
562 return names.toArray(new String[names.size()]);
563 }
Jeff Browna4547672011-03-02 21:38:11 -0800564
565 @SuppressWarnings("unused")
566 public int getKeyRepeatTimeout() {
567 return ViewConfiguration.getKeyRepeatTimeout();
568 }
569
570 @SuppressWarnings("unused")
571 public int getKeyRepeatDelay() {
572 return ViewConfiguration.getKeyRepeatDelay();
573 }
574
Jeff Brownae9fc032010-08-18 15:51:08 -0700575 @SuppressWarnings("unused")
576 public int getMaxEventsPerSecond() {
577 int result = 0;
578 try {
579 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
580 } catch (NumberFormatException e) {
581 }
582 if (result < 1) {
makarand.karvekar88dd6e62011-03-02 17:11:14 -0600583 result = 55;
Jeff Brownae9fc032010-08-18 15:51:08 -0700584 }
585 return result;
586 }
Jeff Brown83c09682010-12-23 17:50:18 -0800587
588 @SuppressWarnings("unused")
589 public int getPointerLayer() {
590 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800591 WindowManager.LayoutParams.TYPE_POINTER)
Jeff Brown83c09682010-12-23 17:50:18 -0800592 * WindowManagerService.TYPE_LAYER_MULTIPLIER
593 + WindowManagerService.TYPE_LAYER_OFFSET;
594 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800595
596 @SuppressWarnings("unused")
597 public PointerIcon getPointerIcon() {
Jeff Brown2352b972011-04-12 22:39:53 -0700598 return PointerIcon.getDefaultIcon(mContext);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800599 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700600 }
601}