blob: c8b18c8d0a7379f87430921ab001e68e4a22fb51 [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 Brown89ef0722011-08-10 16:25:21 -070020import com.android.server.Watchdog;
Jeff Brown46b9ac02010-04-22 18:58:52 -070021
22import org.xmlpull.v1.XmlPullParser;
23
24import android.content.Context;
Jeff Brown349703e2010-06-22 01:27:15 -070025import android.content.pm.PackageManager;
Jeff Brown46b9ac02010-04-22 18:58:52 -070026import android.content.res.Configuration;
Jeff Brown1a84fd12011-06-02 01:26:32 -070027import android.database.ContentObserver;
Jeff Brown46b9ac02010-04-22 18:58:52 -070028import android.os.Environment;
Jeff Brown05dc66a2011-03-02 14:41:58 -080029import android.os.Looper;
30import android.os.MessageQueue;
Jeff Brownae9fc032010-08-18 15:51:08 -070031import android.os.SystemProperties;
Jeff Brown1a84fd12011-06-02 01:26:32 -070032import android.provider.Settings;
33import android.provider.Settings.SettingNotFoundException;
Jeff Brown46b9ac02010-04-22 18:58:52 -070034import android.util.Slog;
35import android.util.Xml;
36import android.view.InputChannel;
Jeff Brown8d608662010-08-30 03:02:23 -070037import android.view.InputDevice;
Jeff Brown6ec402b2010-07-28 15:48:59 -070038import android.view.InputEvent;
Jeff Brown1f245102010-11-18 20:53:46 -080039import android.view.KeyEvent;
Jeff Brown2352b972011-04-12 22:39:53 -070040import android.view.PointerIcon;
Jeff Brown46b9ac02010-04-22 18:58:52 -070041import android.view.Surface;
Jeff Browna4547672011-03-02 21:38:11 -080042import android.view.ViewConfiguration;
Jeff Brown83c09682010-12-23 17:50:18 -080043import android.view.WindowManager;
Jeff Brown0029c662011-03-30 02:25:18 -070044import android.view.WindowManagerPolicy;
Jeff Brown46b9ac02010-04-22 18:58:52 -070045
Jeff Brown46b9ac02010-04-22 18:58:52 -070046import java.io.File;
Jeff Brown46b9ac02010-04-22 18:58:52 -070047import java.io.FileNotFoundException;
48import java.io.FileReader;
49import java.io.IOException;
Jeff Brown46b9ac02010-04-22 18:58:52 -070050import java.io.PrintWriter;
51import java.util.ArrayList;
52
53/*
54 * Wraps the C++ InputManager and provides its callbacks.
Jeff Brown46b9ac02010-04-22 18:58:52 -070055 */
Jeff Brown89ef0722011-08-10 16:25:21 -070056public class InputManager implements Watchdog.Monitor {
Jeff Brown46b9ac02010-04-22 18:58:52 -070057 static final String TAG = "InputManager";
58
Jeff Brownb6997262010-10-08 22:31:17 -070059 private static final boolean DEBUG = false;
60
Jeff Brown46b9ac02010-04-22 18:58:52 -070061 private final Callbacks mCallbacks;
62 private final Context mContext;
63 private final WindowManagerService mWindowManagerService;
Jeff Brown1a84fd12011-06-02 01:26:32 -070064
Jeff Brown2352b972011-04-12 22:39:53 -070065 private static native void nativeInit(Context context,
66 Callbacks callbacks, MessageQueue messageQueue);
Jeff Brown46b9ac02010-04-22 18:58:52 -070067 private static native void nativeStart();
Jeff Brownbc68a592011-07-25 12:58:12 -070068 private static native void nativeSetDisplaySize(int displayId, int width, int height,
69 int externalWidth, int externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -070070 private static native void nativeSetDisplayOrientation(int displayId, int rotation);
71
Jeff Brown6d0fec22010-07-23 21:28:06 -070072 private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070073 int scanCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070074 private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070075 int keyCode);
Jeff Brown6d0fec22010-07-23 21:28:06 -070076 private static native int nativeGetSwitchState(int deviceId, int sourceMask,
Jeff Brown46b9ac02010-04-22 18:58:52 -070077 int sw);
Jeff Brown6d0fec22010-07-23 21:28:06 -070078 private static native boolean nativeHasKeys(int deviceId, int sourceMask,
79 int[] keyCodes, boolean[] keyExists);
Jeff Browna41ca772010-08-11 14:46:32 -070080 private static native void nativeRegisterInputChannel(InputChannel inputChannel,
Jeff Brown928e0542011-01-10 11:17:36 -080081 InputWindowHandle inputWindowHandle, boolean monitor);
Jeff Brown46b9ac02010-04-22 18:58:52 -070082 private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
Jeff Brown0029c662011-03-30 02:25:18 -070083 private static native void nativeSetInputFilterEnabled(boolean enable);
Jeff Brown6ec402b2010-07-28 15:48:59 -070084 private static native int nativeInjectInputEvent(InputEvent event,
Jeff Brown0029c662011-03-30 02:25:18 -070085 int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
86 int policyFlags);
Jeff Brown9302c872011-07-13 22:51:29 -070087 private static native void nativeSetInputWindows(InputWindowHandle[] windowHandles);
Jeff Brown349703e2010-06-22 01:27:15 -070088 private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
Jeff Brown05dc66a2011-03-02 14:41:58 -080089 private static native void nativeSetSystemUiVisibility(int visibility);
Jeff Brown9302c872011-07-13 22:51:29 -070090 private static native void nativeSetFocusedApplication(InputApplicationHandle application);
Jeff Brown8d608662010-08-30 03:02:23 -070091 private static native InputDevice nativeGetInputDevice(int deviceId);
Jeff Brown57c59372010-09-21 18:22:55 -070092 private static native void nativeGetInputConfiguration(Configuration configuration);
Jeff Brown8d608662010-08-30 03:02:23 -070093 private static native int[] nativeGetInputDeviceIds();
Jeff Browne6504122010-09-27 14:52:15 -070094 private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
95 InputChannel toChannel);
Jeff Brown1a84fd12011-06-02 01:26:32 -070096 private static native void nativeSetPointerSpeed(int speed);
Jeff Browne33348b2010-07-15 23:54:05 -070097 private static native String nativeDump();
Jeff Brown89ef0722011-08-10 16:25:21 -070098 private static native void nativeMonitor();
Jeff Brown46b9ac02010-04-22 18:58:52 -070099
Jeff Brown7fbdc842010-06-17 20:52:56 -0700100 // Input event injection constants defined in InputDispatcher.h.
101 static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
102 static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
103 static final int INPUT_EVENT_INJECTION_FAILED = 2;
104 static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
105
Jeff Brown6ec402b2010-07-28 15:48:59 -0700106 // Input event injection synchronization modes defined in InputDispatcher.h
107 static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
108 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
109 static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
110
Jeff Brown6d0fec22010-07-23 21:28:06 -0700111 // Key states (may be returned by queries about the current state of a
112 // particular key code, scan code or switch).
113
114 /** The key state is unknown or the requested key itself is not supported. */
115 public static final int KEY_STATE_UNKNOWN = -1;
116
117 /** The key is up. /*/
118 public static final int KEY_STATE_UP = 0;
119
120 /** The key is down. */
121 public static final int KEY_STATE_DOWN = 1;
122
123 /** The key is down but is a virtual key press that is being emulated by the system. */
124 public static final int KEY_STATE_VIRTUAL = 2;
125
Jeff Brown0029c662011-03-30 02:25:18 -0700126 // State for the currently installed input filter.
127 final Object mInputFilterLock = new Object();
128 InputFilter mInputFilter;
129 InputFilterHost mInputFilterHost;
130
Jeff Browne33348b2010-07-15 23:54:05 -0700131 public InputManager(Context context, WindowManagerService windowManagerService) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700132 this.mContext = context;
133 this.mWindowManagerService = windowManagerService;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700134 this.mCallbacks = new Callbacks();
Jeff Brown05dc66a2011-03-02 14:41:58 -0800135
136 Looper looper = windowManagerService.mH.getLooper();
137
Jeff Brown46b9ac02010-04-22 18:58:52 -0700138 Slog.i(TAG, "Initializing input manager");
Jeff Brown2352b972011-04-12 22:39:53 -0700139 nativeInit(mContext, mCallbacks, looper.getQueue());
Jeff Brown89ef0722011-08-10 16:25:21 -0700140
141 // Add ourself to the Watchdog monitors.
142 Watchdog.getInstance().addMonitor(this);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700143 }
Jeff Brown1a84fd12011-06-02 01:26:32 -0700144
Jeff Brown46b9ac02010-04-22 18:58:52 -0700145 public void start() {
146 Slog.i(TAG, "Starting input manager");
147 nativeStart();
Jeff Brown1a84fd12011-06-02 01:26:32 -0700148
149 registerPointerSpeedSettingObserver();
150 updatePointerSpeedFromSettings();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700151 }
152
Jeff Brownbc68a592011-07-25 12:58:12 -0700153 public void setDisplaySize(int displayId, int width, int height,
154 int externalWidth, int externalHeight) {
155 if (width <= 0 || height <= 0 || externalWidth <= 0 || externalHeight <= 0) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700156 throw new IllegalArgumentException("Invalid display id or dimensions.");
157 }
158
Jeff Brownb6997262010-10-08 22:31:17 -0700159 if (DEBUG) {
Jeff Brownbc68a592011-07-25 12:58:12 -0700160 Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height
161 + " external size " + externalWidth + "x" + externalHeight);
Jeff Brownb6997262010-10-08 22:31:17 -0700162 }
Jeff Brownbc68a592011-07-25 12:58:12 -0700163 nativeSetDisplaySize(displayId, width, height, externalWidth, externalHeight);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700164 }
165
166 public void setDisplayOrientation(int displayId, int rotation) {
167 if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
168 throw new IllegalArgumentException("Invalid rotation.");
169 }
170
Jeff Brownb6997262010-10-08 22:31:17 -0700171 if (DEBUG) {
172 Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
173 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700174 nativeSetDisplayOrientation(displayId, rotation);
175 }
176
177 public void getInputConfiguration(Configuration config) {
178 if (config == null) {
179 throw new IllegalArgumentException("config must not be null.");
180 }
181
Jeff Brown57c59372010-09-21 18:22:55 -0700182 nativeGetInputConfiguration(config);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700183 }
184
Jeff Brown6d0fec22010-07-23 21:28:06 -0700185 /**
186 * Gets the current state of a key or button by key code.
187 * @param deviceId The input device id, or -1 to consult all devices.
188 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
189 * consider all input sources. An input device is consulted if at least one of its
190 * non-class input source bits matches the specified source mask.
191 * @param keyCode The key code to check.
192 * @return The key state.
193 */
194 public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
195 return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700196 }
197
Jeff Brown6d0fec22010-07-23 21:28:06 -0700198 /**
199 * Gets the current state of a key or button by scan code.
200 * @param deviceId The input device id, or -1 to consult all devices.
201 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
202 * consider all input sources. An input device is consulted if at least one of its
203 * non-class input source bits matches the specified source mask.
204 * @param scanCode The scan code to check.
205 * @return The key state.
206 */
207 public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
208 return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700209 }
210
Jeff Brown6d0fec22010-07-23 21:28:06 -0700211 /**
212 * Gets the current state of a switch by switch code.
213 * @param deviceId The input device id, or -1 to consult all devices.
214 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
215 * consider all input sources. An input device is consulted if at least one of its
216 * non-class input source bits matches the specified source mask.
217 * @param switchCode The switch code to check.
218 * @return The switch state.
219 */
220 public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
221 return nativeGetSwitchState(deviceId, sourceMask, switchCode);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700222 }
223
Jeff Brown6d0fec22010-07-23 21:28:06 -0700224 /**
225 * Determines whether the specified key codes are supported by a particular device.
226 * @param deviceId The input device id, or -1 to consult all devices.
227 * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
228 * consider all input sources. An input device is consulted if at least one of its
229 * non-class input source bits matches the specified source mask.
230 * @param keyCodes The array of key codes to check.
231 * @param keyExists An array at least as large as keyCodes whose entries will be set
232 * to true or false based on the presence or absence of support for the corresponding
233 * key codes.
234 * @return True if the lookup was successful, false otherwise.
235 */
236 public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700237 if (keyCodes == null) {
238 throw new IllegalArgumentException("keyCodes must not be null.");
239 }
Jeff Brown6d0fec22010-07-23 21:28:06 -0700240 if (keyExists == null || keyExists.length < keyCodes.length) {
241 throw new IllegalArgumentException("keyExists must not be null and must be at "
242 + "least as large as keyCodes.");
Jeff Brown46b9ac02010-04-22 18:58:52 -0700243 }
244
Jeff Brown6d0fec22010-07-23 21:28:06 -0700245 return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700246 }
247
Jeff Browna41ca772010-08-11 14:46:32 -0700248 /**
249 * Creates an input channel that will receive all input from the input dispatcher.
250 * @param inputChannelName The input channel name.
251 * @return The input channel.
252 */
253 public InputChannel monitorInput(String inputChannelName) {
254 if (inputChannelName == null) {
255 throw new IllegalArgumentException("inputChannelName must not be null.");
256 }
257
258 InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
Jeff Brown928e0542011-01-10 11:17:36 -0800259 nativeRegisterInputChannel(inputChannels[0], null, true);
Jeff Browna41ca772010-08-11 14:46:32 -0700260 inputChannels[0].dispose(); // don't need to retain the Java object reference
261 return inputChannels[1];
262 }
263
264 /**
265 * Registers an input channel so that it can be used as an input event target.
266 * @param inputChannel The input channel to register.
Jeff Brown928e0542011-01-10 11:17:36 -0800267 * @param inputWindowHandle The handle of the input window associated with the
268 * input channel, or null if none.
Jeff Browna41ca772010-08-11 14:46:32 -0700269 */
Jeff Brown928e0542011-01-10 11:17:36 -0800270 public void registerInputChannel(InputChannel inputChannel,
271 InputWindowHandle inputWindowHandle) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700272 if (inputChannel == null) {
273 throw new IllegalArgumentException("inputChannel must not be null.");
274 }
275
Jeff Brown928e0542011-01-10 11:17:36 -0800276 nativeRegisterInputChannel(inputChannel, inputWindowHandle, false);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700277 }
278
Jeff Browna41ca772010-08-11 14:46:32 -0700279 /**
280 * Unregisters an input channel.
281 * @param inputChannel The input channel to unregister.
282 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700283 public void unregisterInputChannel(InputChannel inputChannel) {
284 if (inputChannel == null) {
285 throw new IllegalArgumentException("inputChannel must not be null.");
286 }
287
288 nativeUnregisterInputChannel(inputChannel);
289 }
Jeff Brown0029c662011-03-30 02:25:18 -0700290
291 /**
292 * Sets an input filter that will receive all input events before they are dispatched.
293 * The input filter may then reinterpret input events or inject new ones.
294 *
295 * To ensure consistency, the input dispatcher automatically drops all events
296 * in progress whenever an input filter is installed or uninstalled. After an input
297 * filter is uninstalled, it can no longer send input events unless it is reinstalled.
298 * Any events it attempts to send after it has been uninstalled will be dropped.
299 *
300 * @param filter The input filter, or null to remove the current filter.
301 */
302 public void setInputFilter(InputFilter filter) {
303 synchronized (mInputFilterLock) {
304 final InputFilter oldFilter = mInputFilter;
305 if (oldFilter == filter) {
306 return; // nothing to do
307 }
308
309 if (oldFilter != null) {
310 mInputFilter = null;
311 mInputFilterHost.disconnectLocked();
312 mInputFilterHost = null;
313 oldFilter.uninstall();
314 }
315
316 if (filter != null) {
317 mInputFilter = filter;
318 mInputFilterHost = new InputFilterHost();
319 filter.install(mInputFilterHost);
320 }
321
322 nativeSetInputFilterEnabled(filter != null);
323 }
324 }
325
Jeff Brown46b9ac02010-04-22 18:58:52 -0700326 /**
Jeff Brown6ec402b2010-07-28 15:48:59 -0700327 * Injects an input event into the event system on behalf of an application.
328 * The synchronization mode determines whether the method blocks while waiting for
329 * input injection to proceed.
330 *
331 * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks. Injection is asynchronous and
332 * is assumed always to be successful.
333 *
334 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
335 * dispatched so that the input dispatcher can determine whether input event injection will
336 * be permitted based on the current input focus. Does not wait for the input event to
337 * finish processing.
338 *
339 * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
340 * be completely processed.
341 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700342 * @param event The event to inject.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700343 * @param injectorPid The pid of the injecting application.
344 * @param injectorUid The uid of the injecting application.
Jeff Brown6ec402b2010-07-28 15:48:59 -0700345 * @param syncMode The synchronization mode.
Jeff Brown7fbdc842010-06-17 20:52:56 -0700346 * @param timeoutMillis The injection timeout in milliseconds.
347 * @return One of the INPUT_EVENT_INJECTION_XXX constants.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700348 */
Jeff Brown6ec402b2010-07-28 15:48:59 -0700349 public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
350 int syncMode, int timeoutMillis) {
Jeff Brown7fbdc842010-06-17 20:52:56 -0700351 if (event == null) {
352 throw new IllegalArgumentException("event must not be null");
353 }
354 if (injectorPid < 0 || injectorUid < 0) {
355 throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
356 }
357 if (timeoutMillis <= 0) {
358 throw new IllegalArgumentException("timeoutMillis must be positive");
359 }
Jeff Brown6ec402b2010-07-28 15:48:59 -0700360
Jeff Brown0029c662011-03-30 02:25:18 -0700361 return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis,
362 WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700363 }
Jeff Brown0029c662011-03-30 02:25:18 -0700364
Jeff Brown8d608662010-08-30 03:02:23 -0700365 /**
366 * Gets information about the input device with the specified id.
367 * @param id The device id.
368 * @return The input device or null if not found.
369 */
370 public InputDevice getInputDevice(int deviceId) {
371 return nativeGetInputDevice(deviceId);
372 }
373
374 /**
375 * Gets the ids of all input devices in the system.
376 * @return The input device ids.
377 */
378 public int[] getInputDeviceIds() {
379 return nativeGetInputDeviceIds();
380 }
381
Jeff Brown9302c872011-07-13 22:51:29 -0700382 public void setInputWindows(InputWindowHandle[] windowHandles) {
383 nativeSetInputWindows(windowHandles);
Jeff Brown349703e2010-06-22 01:27:15 -0700384 }
385
Jeff Brown9302c872011-07-13 22:51:29 -0700386 public void setFocusedApplication(InputApplicationHandle application) {
Jeff Brown349703e2010-06-22 01:27:15 -0700387 nativeSetFocusedApplication(application);
388 }
389
Jeff Brown349703e2010-06-22 01:27:15 -0700390 public void setInputDispatchMode(boolean enabled, boolean frozen) {
391 nativeSetInputDispatchMode(enabled, frozen);
392 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800393
394 public void setSystemUiVisibility(int visibility) {
395 nativeSetSystemUiVisibility(visibility);
396 }
397
Jeff Browne6504122010-09-27 14:52:15 -0700398 /**
399 * Atomically transfers touch focus from one window to another as identified by
400 * their input channels. It is possible for multiple windows to have
401 * touch focus if they support split touch dispatch
402 * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
403 * method only transfers touch focus of the specified window without affecting
404 * other windows that may also have touch focus at the same time.
405 * @param fromChannel The channel of a window that currently has touch focus.
406 * @param toChannel The channel of the window that should receive touch focus in
407 * place of the first.
408 * @return True if the transfer was successful. False if the window with the
409 * specified channel did not actually have touch focus at the time of the request.
410 */
411 public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
412 if (fromChannel == null) {
413 throw new IllegalArgumentException("fromChannel must not be null.");
414 }
415 if (toChannel == null) {
416 throw new IllegalArgumentException("toChannel must not be null.");
417 }
418 return nativeTransferTouchFocus(fromChannel, toChannel);
419 }
Jeff Brown05dc66a2011-03-02 14:41:58 -0800420
Jeff Brown1a84fd12011-06-02 01:26:32 -0700421 /**
422 * Set the pointer speed.
423 * @param speed The pointer speed as a value between -7 (slowest) and 7 (fastest)
424 * where 0 is the default speed.
425 */
426 public void setPointerSpeed(int speed) {
427 speed = Math.min(Math.max(speed, -7), 7);
428 nativeSetPointerSpeed(speed);
429 }
430
431 public void updatePointerSpeedFromSettings() {
432 int speed = getPointerSpeedSetting(0);
433 setPointerSpeed(speed);
434 }
435
436 private void registerPointerSpeedSettingObserver() {
437 mContext.getContentResolver().registerContentObserver(
438 Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
439 new ContentObserver(mWindowManagerService.mH) {
440 @Override
441 public void onChange(boolean selfChange) {
442 updatePointerSpeedFromSettings();
443 }
444 });
445 }
446
447 private int getPointerSpeedSetting(int defaultValue) {
448 int speed = defaultValue;
449 try {
450 speed = Settings.System.getInt(mContext.getContentResolver(),
451 Settings.System.POINTER_SPEED);
452 } catch (SettingNotFoundException snfe) {
453 }
454 return speed;
455 }
456
Jeff Brown46b9ac02010-04-22 18:58:52 -0700457 public void dump(PrintWriter pw) {
Jeff Browne33348b2010-07-15 23:54:05 -0700458 String dumpStr = nativeDump();
459 if (dumpStr != null) {
460 pw.println(dumpStr);
461 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700462 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800463
Jeff Brown89ef0722011-08-10 16:25:21 -0700464 // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
465 public void monitor() {
466 synchronized (mInputFilterLock) { }
467 nativeMonitor();
468 }
469
Jeff Brown0029c662011-03-30 02:25:18 -0700470 private final class InputFilterHost implements InputFilter.Host {
471 private boolean mDisconnected;
472
473 public void disconnectLocked() {
474 mDisconnected = true;
475 }
476
477 public void sendInputEvent(InputEvent event, int policyFlags) {
478 if (event == null) {
479 throw new IllegalArgumentException("event must not be null");
480 }
481
482 synchronized (mInputFilterLock) {
483 if (!mDisconnected) {
484 nativeInjectInputEvent(event, 0, 0, INPUT_EVENT_INJECTION_SYNC_NONE, 0,
485 policyFlags | WindowManagerPolicy.FLAG_FILTERED);
486 }
487 }
488 }
489 }
490
Jeff Brown46b9ac02010-04-22 18:58:52 -0700491 /*
492 * Callbacks from native.
493 */
Jeff Brown0029c662011-03-30 02:25:18 -0700494 private final class Callbacks {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700495 static final String TAG = "InputManager-Callbacks";
496
497 private static final boolean DEBUG_VIRTUAL_KEYS = false;
498 private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
Jeff Brown8d608662010-08-30 03:02:23 -0700499 private static final String CALIBRATION_DIR_PATH = "usr/idc/";
Jeff Brown46b9ac02010-04-22 18:58:52 -0700500
Jeff Brown46b9ac02010-04-22 18:58:52 -0700501 @SuppressWarnings("unused")
Jeff Brown57c59372010-09-21 18:22:55 -0700502 public void notifyConfigurationChanged(long whenNanos) {
Jeff Brownb09abc12011-01-13 21:08:27 -0800503 mWindowManagerService.mInputMonitor.notifyConfigurationChanged();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700504 }
505
506 @SuppressWarnings("unused")
507 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700508 mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700509 }
510
511 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800512 public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
513 mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputWindowHandle);
Jeff Brown7fbdc842010-06-17 20:52:56 -0700514 }
Jeff Brown7fbdc842010-06-17 20:52:56 -0700515
516 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800517 public long notifyANR(InputApplicationHandle inputApplicationHandle,
518 InputWindowHandle inputWindowHandle) {
519 return mWindowManagerService.mInputMonitor.notifyANR(
520 inputApplicationHandle, inputWindowHandle);
Jeff Brown349703e2010-06-22 01:27:15 -0700521 }
Jeff Brown0029c662011-03-30 02:25:18 -0700522
523 @SuppressWarnings("unused")
524 final boolean filterInputEvent(InputEvent event, int policyFlags) {
525 synchronized (mInputFilterLock) {
526 if (mInputFilter != null) {
527 mInputFilter.filterInputEvent(event, policyFlags);
528 return false;
529 }
530 }
531 event.recycle();
532 return true;
533 }
534
Jeff Brown349703e2010-06-22 01:27:15 -0700535 @SuppressWarnings("unused")
Jeff Brown1f245102010-11-18 20:53:46 -0800536 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -0700537 return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
Jeff Brown1f245102010-11-18 20:53:46 -0800538 event, policyFlags, isScreenOn);
Jeff Brown349703e2010-06-22 01:27:15 -0700539 }
Jeff Brown56194eb2011-03-02 19:23:13 -0800540
541 @SuppressWarnings("unused")
542 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
543 return mWindowManagerService.mInputMonitor.interceptMotionBeforeQueueingWhenScreenOff(
544 policyFlags);
545 }
546
Jeff Brown349703e2010-06-22 01:27:15 -0700547 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800548 public boolean interceptKeyBeforeDispatching(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800549 KeyEvent event, int policyFlags) {
550 return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
551 focus, event, policyFlags);
Jeff Brown349703e2010-06-22 01:27:15 -0700552 }
553
554 @SuppressWarnings("unused")
Jeff Brown928e0542011-01-10 11:17:36 -0800555 public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
Jeff Brown1f245102010-11-18 20:53:46 -0800556 KeyEvent event, int policyFlags) {
557 return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
558 focus, event, policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -0700559 }
560
561 @SuppressWarnings("unused")
Jeff Brown349703e2010-06-22 01:27:15 -0700562 public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
563 return mContext.checkPermission(
564 android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
565 == PackageManager.PERMISSION_GRANTED;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700566 }
Jeff Brownfe508922011-01-18 15:10:10 -0800567
568 @SuppressWarnings("unused")
569 public int getVirtualKeyQuietTimeMillis() {
570 return mContext.getResources().getInteger(
571 com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
572 }
573
Jeff Brown46b9ac02010-04-22 18:58:52 -0700574 @SuppressWarnings("unused")
Jeff Brown46b9ac02010-04-22 18:58:52 -0700575 public String[] getExcludedDeviceNames() {
576 ArrayList<String> names = new ArrayList<String>();
577
578 // Read partner-provided list of excluded input devices
579 XmlPullParser parser = null;
580 // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
581 File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
582 FileReader confreader = null;
583 try {
584 confreader = new FileReader(confFile);
585 parser = Xml.newPullParser();
586 parser.setInput(confreader);
587 XmlUtils.beginDocument(parser, "devices");
588
589 while (true) {
590 XmlUtils.nextElement(parser);
591 if (!"device".equals(parser.getName())) {
592 break;
593 }
594 String name = parser.getAttributeValue(null, "name");
595 if (name != null) {
596 names.add(name);
597 }
598 }
599 } catch (FileNotFoundException e) {
600 // It's ok if the file does not exist.
601 } catch (Exception e) {
602 Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
603 } finally {
604 try { if (confreader != null) confreader.close(); } catch (IOException e) { }
605 }
606
607 return names.toArray(new String[names.size()]);
608 }
Jeff Browna4547672011-03-02 21:38:11 -0800609
610 @SuppressWarnings("unused")
611 public int getKeyRepeatTimeout() {
612 return ViewConfiguration.getKeyRepeatTimeout();
613 }
614
615 @SuppressWarnings("unused")
616 public int getKeyRepeatDelay() {
617 return ViewConfiguration.getKeyRepeatDelay();
618 }
619
Jeff Brownae9fc032010-08-18 15:51:08 -0700620 @SuppressWarnings("unused")
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700621 public int getHoverTapTimeout() {
622 return ViewConfiguration.getHoverTapTimeout();
623 }
624
625 @SuppressWarnings("unused")
626 public int getHoverTapSlop() {
627 return ViewConfiguration.getHoverTapSlop();
Jeff Brown214eaf42011-05-26 19:17:02 -0700628 }
629
630 @SuppressWarnings("unused")
631 public int getDoubleTapTimeout() {
632 return ViewConfiguration.getDoubleTapTimeout();
633 }
634
635 @SuppressWarnings("unused")
636 public int getLongPressTimeout() {
637 return ViewConfiguration.getLongPressTimeout();
638 }
639
640 @SuppressWarnings("unused")
Jeff Brownae9fc032010-08-18 15:51:08 -0700641 public int getMaxEventsPerSecond() {
642 int result = 0;
643 try {
644 result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
645 } catch (NumberFormatException e) {
646 }
647 if (result < 1) {
makarand.karvekar88dd6e62011-03-02 17:11:14 -0600648 result = 55;
Jeff Brownae9fc032010-08-18 15:51:08 -0700649 }
650 return result;
651 }
Jeff Brown83c09682010-12-23 17:50:18 -0800652
653 @SuppressWarnings("unused")
654 public int getPointerLayer() {
655 return mWindowManagerService.mPolicy.windowTypeToLayerLw(
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800656 WindowManager.LayoutParams.TYPE_POINTER)
Jeff Brown83c09682010-12-23 17:50:18 -0800657 * WindowManagerService.TYPE_LAYER_MULTIPLIER
658 + WindowManagerService.TYPE_LAYER_OFFSET;
659 }
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800660
661 @SuppressWarnings("unused")
662 public PointerIcon getPointerIcon() {
Jeff Brown2352b972011-04-12 22:39:53 -0700663 return PointerIcon.getDefaultIcon(mContext);
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800664 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700665 }
666}