Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 17 | package com.android.server.input; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 18 | |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 19 | import android.view.Display; |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 20 | import com.android.internal.os.SomeArgs; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 21 | import com.android.internal.R; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 22 | import com.android.internal.util.XmlUtils; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 23 | import com.android.server.DisplayThread; |
| 24 | import com.android.server.LocalServices; |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 25 | import com.android.server.Watchdog; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 26 | |
| 27 | import org.xmlpull.v1.XmlPullParser; |
| 28 | |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 29 | import android.Manifest; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 30 | import android.app.Notification; |
| 31 | import android.app.NotificationManager; |
| 32 | import android.app.PendingIntent; |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 33 | import android.bluetooth.BluetoothAdapter; |
| 34 | import android.bluetooth.BluetoothDevice; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 35 | import android.content.BroadcastReceiver; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 36 | import android.content.ComponentName; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 37 | import android.content.Context; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 38 | import android.content.Intent; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 39 | import android.content.IntentFilter; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 40 | import android.content.pm.ActivityInfo; |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 41 | import android.content.pm.ApplicationInfo; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 42 | import android.content.pm.PackageManager; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 43 | import android.content.pm.ResolveInfo; |
| 44 | import android.content.pm.PackageManager.NameNotFoundException; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 45 | import android.content.res.Resources; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 46 | import android.content.res.Resources.NotFoundException; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 47 | import android.content.res.TypedArray; |
| 48 | import android.content.res.XmlResourceParser; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 49 | import android.database.ContentObserver; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 50 | import android.hardware.display.DisplayViewport; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 51 | import android.hardware.input.IInputDevicesChangedListener; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 52 | import android.hardware.input.IInputManager; |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 53 | import android.hardware.input.InputDeviceIdentifier; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 54 | import android.hardware.input.InputManager; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 55 | import android.hardware.input.InputManagerInternal; |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 56 | import android.hardware.input.ITabletModeChangedListener; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 57 | import android.hardware.input.KeyboardLayout; |
Jason Gerecke | d6396d6 | 2014-01-27 18:30:37 -0800 | [diff] [blame] | 58 | import android.hardware.input.TouchCalibration; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 59 | import android.os.Binder; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 60 | import android.os.Bundle; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 61 | import android.os.Environment; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 62 | import android.os.Handler; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 63 | import android.os.IBinder; |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 64 | import android.os.Looper; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 65 | import android.os.Message; |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 66 | import android.os.MessageQueue; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 67 | import android.os.Process; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 68 | import android.os.RemoteException; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 69 | import android.os.UserHandle; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 70 | import android.provider.Settings; |
| 71 | import android.provider.Settings.SettingNotFoundException; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 72 | import android.util.Log; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 73 | import android.util.Slog; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 74 | import android.util.SparseArray; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 75 | import android.util.Xml; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 76 | import android.view.IInputFilter; |
| 77 | import android.view.IInputFilterHost; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 78 | import android.view.InputChannel; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 79 | import android.view.InputDevice; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 80 | import android.view.InputEvent; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 81 | import android.view.KeyEvent; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 82 | import android.view.PointerIcon; |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 83 | import android.view.Surface; |
Jeff Brown | a454767 | 2011-03-02 21:38:11 -0800 | [diff] [blame] | 84 | import android.view.ViewConfiguration; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 85 | import android.view.WindowManagerPolicy; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 86 | import android.widget.Toast; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 87 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 88 | import java.io.File; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 89 | import java.io.FileDescriptor; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 90 | import java.io.FileNotFoundException; |
| 91 | import java.io.FileReader; |
| 92 | import java.io.IOException; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 93 | import java.io.InputStreamReader; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 94 | import java.io.PrintWriter; |
| 95 | import java.util.ArrayList; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 96 | import java.util.HashMap; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 97 | import java.util.HashSet; |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 98 | import java.util.List; |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 99 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 100 | import libcore.io.Streams; |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 101 | import libcore.util.Objects; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * Wraps the C++ InputManager and provides its callbacks. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 105 | */ |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 106 | public class InputManagerService extends IInputManager.Stub |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 107 | implements Watchdog.Monitor { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | static final String TAG = "InputManager"; |
Jeff Brown | 1b9ba57 | 2012-05-21 10:54:18 -0700 | [diff] [blame] | 109 | static final boolean DEBUG = false; |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 110 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 111 | private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml"; |
| 112 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 113 | private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 114 | private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2; |
| 115 | private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3; |
| 116 | private static final int MSG_UPDATE_KEYBOARD_LAYOUTS = 4; |
| 117 | private static final int MSG_RELOAD_DEVICE_ALIASES = 5; |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 118 | private static final int MSG_DELIVER_TABLET_MODE_CHANGED = 6; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 119 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 120 | // Pointer to native input manager service object. |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 121 | private final long mPtr; |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 122 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 123 | private final Context mContext; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 124 | private final InputManagerHandler mHandler; |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 125 | |
| 126 | private WindowManagerCallbacks mWindowManagerCallbacks; |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 127 | private WiredAccessoryCallbacks mWiredAccessoryCallbacks; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 128 | private boolean mSystemReady; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 129 | private NotificationManager mNotificationManager; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 130 | |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 131 | private final Object mTabletModeLock = new Object(); |
| 132 | // List of currently registered tablet mode changed listeners by process id |
| 133 | private final SparseArray<TabletModeChangedListenerRecord> mTabletModeChangedListeners = |
| 134 | new SparseArray<>(); // guarded by mTabletModeLock |
| 135 | private final List<TabletModeChangedListenerRecord> mTempTabletModeChangedListenersToNotify = |
| 136 | new ArrayList<>(); |
| 137 | |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 138 | // Persistent data store. Must be locked each time during use. |
| 139 | private final PersistentDataStore mDataStore = new PersistentDataStore(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 140 | |
| 141 | // List of currently registered input devices changed listeners by process id. |
| 142 | private Object mInputDevicesLock = new Object(); |
| 143 | private boolean mInputDevicesChangedPending; // guarded by mInputDevicesLock |
| 144 | private InputDevice[] mInputDevices = new InputDevice[0]; |
| 145 | private final SparseArray<InputDevicesChangedListenerRecord> mInputDevicesChangedListeners = |
| 146 | new SparseArray<InputDevicesChangedListenerRecord>(); // guarded by mInputDevicesLock |
| 147 | private final ArrayList<InputDevicesChangedListenerRecord> |
| 148 | mTempInputDevicesChangedListenersToNotify = |
| 149 | new ArrayList<InputDevicesChangedListenerRecord>(); // handler thread only |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 150 | private final ArrayList<InputDevice> |
| 151 | mTempFullKeyboards = new ArrayList<InputDevice>(); // handler thread only |
| 152 | private boolean mKeyboardLayoutNotificationShown; |
| 153 | private PendingIntent mKeyboardLayoutIntent; |
| 154 | private Toast mSwitchedKeyboardLayoutToast; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 155 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 156 | // State for vibrator tokens. |
| 157 | private Object mVibratorLock = new Object(); |
| 158 | private HashMap<IBinder, VibratorToken> mVibratorTokens = |
| 159 | new HashMap<IBinder, VibratorToken>(); |
| 160 | private int mNextVibratorTokenValue; |
| 161 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 162 | // State for the currently installed input filter. |
| 163 | final Object mInputFilterLock = new Object(); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 164 | IInputFilter mInputFilter; // guarded by mInputFilterLock |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 165 | InputFilterHost mInputFilterHost; // guarded by mInputFilterLock |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 166 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 167 | private static native long nativeInit(InputManagerService service, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 168 | Context context, MessageQueue messageQueue); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 169 | private static native void nativeStart(long ptr); |
| 170 | private static native void nativeSetDisplayViewport(long ptr, boolean external, |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 171 | int displayId, int rotation, |
| 172 | int logicalLeft, int logicalTop, int logicalRight, int logicalBottom, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 173 | int physicalLeft, int physicalTop, int physicalRight, int physicalBottom, |
| 174 | int deviceWidth, int deviceHeight); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 175 | |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 176 | private static native int nativeGetScanCodeState(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 177 | int deviceId, int sourceMask, int scanCode); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 178 | private static native int nativeGetKeyCodeState(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 179 | int deviceId, int sourceMask, int keyCode); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 180 | private static native int nativeGetSwitchState(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 181 | int deviceId, int sourceMask, int sw); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 182 | private static native boolean nativeHasKeys(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 183 | int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 184 | private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel, |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 185 | InputWindowHandle inputWindowHandle, boolean monitor); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 186 | private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel); |
| 187 | private static native void nativeSetInputFilterEnabled(long ptr, boolean enable); |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 188 | private static native int nativeInjectInputEvent(long ptr, InputEvent event, int displayId, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 189 | int injectorPid, int injectorUid, int syncMode, int timeoutMillis, |
| 190 | int policyFlags); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 191 | private static native void nativeSetInputWindows(long ptr, InputWindowHandle[] windowHandles); |
| 192 | private static native void nativeSetInputDispatchMode(long ptr, boolean enabled, boolean frozen); |
| 193 | private static native void nativeSetSystemUiVisibility(long ptr, int visibility); |
| 194 | private static native void nativeSetFocusedApplication(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 195 | InputApplicationHandle application); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 196 | private static native boolean nativeTransferTouchFocus(long ptr, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 197 | InputChannel fromChannel, InputChannel toChannel); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 198 | private static native void nativeSetPointerSpeed(long ptr, int speed); |
| 199 | private static native void nativeSetShowTouches(long ptr, boolean enabled); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 200 | private static native void nativeSetInteractive(long ptr, boolean interactive); |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 201 | private static native void nativeReloadCalibration(long ptr); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 202 | private static native void nativeVibrate(long ptr, int deviceId, long[] pattern, |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 203 | int repeat, int token); |
Ashok Bhat | 7e2a9dc | 2014-01-02 19:43:30 +0000 | [diff] [blame] | 204 | private static native void nativeCancelVibrate(long ptr, int deviceId, int token); |
| 205 | private static native void nativeReloadKeyboardLayouts(long ptr); |
| 206 | private static native void nativeReloadDeviceAliases(long ptr); |
| 207 | private static native String nativeDump(long ptr); |
| 208 | private static native void nativeMonitor(long ptr); |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame^] | 209 | private static native void nativeSetPointerIconShape(long ptr, int iconId); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 210 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 211 | // Input event injection constants defined in InputDispatcher.h. |
| 212 | private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0; |
| 213 | private static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1; |
| 214 | private static final int INPUT_EVENT_INJECTION_FAILED = 2; |
| 215 | private static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3; |
| 216 | |
| 217 | // Maximum number of milliseconds to wait for input event injection. |
| 218 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| 219 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 220 | // Key states (may be returned by queries about the current state of a |
| 221 | // particular key code, scan code or switch). |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 222 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 223 | /** The key state is unknown or the requested key itself is not supported. */ |
| 224 | public static final int KEY_STATE_UNKNOWN = -1; |
| 225 | |
| 226 | /** The key is up. /*/ |
| 227 | public static final int KEY_STATE_UP = 0; |
| 228 | |
| 229 | /** The key is down. */ |
| 230 | public static final int KEY_STATE_DOWN = 1; |
| 231 | |
| 232 | /** The key is down but is a virtual key press that is being emulated by the system. */ |
| 233 | public static final int KEY_STATE_VIRTUAL = 2; |
| 234 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 235 | /** Scan code: Mouse / trackball button. */ |
| 236 | public static final int BTN_MOUSE = 0x110; |
| 237 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 238 | // Switch code values must match bionic/libc/kernel/common/linux/input.h |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 239 | /** Switch code: Lid switch. When set, lid is shut. */ |
| 240 | public static final int SW_LID = 0x00; |
| 241 | |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 242 | /** Switch code: Tablet mode switch. |
| 243 | * When set, the device is in tablet mode (i.e. no keyboard is connected). |
| 244 | */ |
| 245 | public static final int SW_TABLET_MODE = 0x01; |
| 246 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 247 | /** Switch code: Keypad slide. When set, keyboard is exposed. */ |
| 248 | public static final int SW_KEYPAD_SLIDE = 0x0a; |
| 249 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 250 | /** Switch code: Headphone. When set, headphone is inserted. */ |
| 251 | public static final int SW_HEADPHONE_INSERT = 0x02; |
| 252 | |
| 253 | /** Switch code: Microphone. When set, microphone is inserted. */ |
| 254 | public static final int SW_MICROPHONE_INSERT = 0x04; |
| 255 | |
Jon Eklund | 43cc8bb | 2014-07-28 16:07:24 -0500 | [diff] [blame] | 256 | /** Switch code: Line out. When set, Line out (hi-Z) is inserted. */ |
| 257 | public static final int SW_LINEOUT_INSERT = 0x06; |
| 258 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 259 | /** Switch code: Headphone/Microphone Jack. When set, something is inserted. */ |
| 260 | public static final int SW_JACK_PHYSICAL_INSERT = 0x07; |
| 261 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 262 | /** Switch code: Camera lens cover. When set the lens is covered. */ |
| 263 | public static final int SW_CAMERA_LENS_COVER = 0x09; |
| 264 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 265 | public static final int SW_LID_BIT = 1 << SW_LID; |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 266 | public static final int SW_TABLET_MODE_BIT = 1 << SW_TABLET_MODE; |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 267 | public static final int SW_KEYPAD_SLIDE_BIT = 1 << SW_KEYPAD_SLIDE; |
| 268 | public static final int SW_HEADPHONE_INSERT_BIT = 1 << SW_HEADPHONE_INSERT; |
| 269 | public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT; |
Jon Eklund | 43cc8bb | 2014-07-28 16:07:24 -0500 | [diff] [blame] | 270 | public static final int SW_LINEOUT_INSERT_BIT = 1 << SW_LINEOUT_INSERT; |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 271 | public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT; |
| 272 | public static final int SW_JACK_BITS = |
Jon Eklund | 43cc8bb | 2014-07-28 16:07:24 -0500 | [diff] [blame] | 273 | SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT | SW_LINEOUT_INSERT_BIT; |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 274 | public static final int SW_CAMERA_LENS_COVER_BIT = 1 << SW_CAMERA_LENS_COVER; |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 275 | |
| 276 | /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */ |
| 277 | final boolean mUseDevInputEventForAudioJack; |
| 278 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 279 | public InputManagerService(Context context) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 280 | this.mContext = context; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 281 | this.mHandler = new InputManagerHandler(DisplayThread.get().getLooper()); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 282 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 283 | mUseDevInputEventForAudioJack = |
| 284 | context.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack); |
| 285 | Slog.i(TAG, "Initializing input manager, mUseDevInputEventForAudioJack=" |
| 286 | + mUseDevInputEventForAudioJack); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 287 | mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue()); |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 288 | |
| 289 | LocalServices.addService(InputManagerInternal.class, new LocalService()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 290 | } |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 291 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 292 | public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks) { |
| 293 | mWindowManagerCallbacks = callbacks; |
| 294 | } |
| 295 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 296 | public void setWiredAccessoryCallbacks(WiredAccessoryCallbacks callbacks) { |
| 297 | mWiredAccessoryCallbacks = callbacks; |
| 298 | } |
| 299 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 300 | public void start() { |
| 301 | Slog.i(TAG, "Starting input manager"); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 302 | nativeStart(mPtr); |
| 303 | |
| 304 | // Add ourself to the Watchdog monitors. |
| 305 | Watchdog.getInstance().addMonitor(this); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 306 | |
| 307 | registerPointerSpeedSettingObserver(); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 308 | registerShowTouchesSettingObserver(); |
| 309 | |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 310 | mContext.registerReceiver(new BroadcastReceiver() { |
| 311 | @Override |
| 312 | public void onReceive(Context context, Intent intent) { |
| 313 | updatePointerSpeedFromSettings(); |
| 314 | updateShowTouchesFromSettings(); |
| 315 | } |
| 316 | }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); |
| 317 | |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 318 | updatePointerSpeedFromSettings(); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 319 | updateShowTouchesFromSettings(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 320 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 321 | |
Matthew Xie | 9631314 | 2012-06-29 16:57:31 -0700 | [diff] [blame] | 322 | // TODO(BT) Pass in paramter for bluetooth system |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 323 | public void systemRunning() { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 324 | if (DEBUG) { |
| 325 | Slog.d(TAG, "System ready."); |
| 326 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 327 | mNotificationManager = (NotificationManager)mContext.getSystemService( |
| 328 | Context.NOTIFICATION_SERVICE); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 329 | mSystemReady = true; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 330 | |
| 331 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 332 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 333 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
Jeff Brown | 69b0716 | 2013-11-07 00:30:16 -0800 | [diff] [blame] | 334 | filter.addAction(Intent.ACTION_PACKAGE_REPLACED); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 335 | filter.addDataScheme("package"); |
| 336 | mContext.registerReceiver(new BroadcastReceiver() { |
| 337 | @Override |
| 338 | public void onReceive(Context context, Intent intent) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 339 | updateKeyboardLayouts(); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 340 | } |
| 341 | }, filter, null, mHandler); |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 342 | |
| 343 | filter = new IntentFilter(BluetoothDevice.ACTION_ALIAS_CHANGED); |
| 344 | mContext.registerReceiver(new BroadcastReceiver() { |
| 345 | @Override |
| 346 | public void onReceive(Context context, Intent intent) { |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 347 | reloadDeviceAliases(); |
| 348 | } |
| 349 | }, filter, null, mHandler); |
| 350 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 351 | mHandler.sendEmptyMessage(MSG_RELOAD_DEVICE_ALIASES); |
| 352 | mHandler.sendEmptyMessage(MSG_UPDATE_KEYBOARD_LAYOUTS); |
Eric Laurent | 4a5eeb9 | 2014-05-06 10:49:04 -0700 | [diff] [blame] | 353 | |
| 354 | if (mWiredAccessoryCallbacks != null) { |
| 355 | mWiredAccessoryCallbacks.systemReady(); |
| 356 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | private void reloadKeyboardLayouts() { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 360 | if (DEBUG) { |
| 361 | Slog.d(TAG, "Reloading keyboard layouts."); |
| 362 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 363 | nativeReloadKeyboardLayouts(mPtr); |
| 364 | } |
| 365 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 366 | private void reloadDeviceAliases() { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 367 | if (DEBUG) { |
| 368 | Slog.d(TAG, "Reloading device names."); |
| 369 | } |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 370 | nativeReloadDeviceAliases(mPtr); |
| 371 | } |
| 372 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 373 | private void setDisplayViewportsInternal(DisplayViewport defaultViewport, |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 374 | DisplayViewport externalTouchViewport) { |
| 375 | if (defaultViewport.valid) { |
| 376 | setDisplayViewport(false, defaultViewport); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 377 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 378 | |
| 379 | if (externalTouchViewport.valid) { |
| 380 | setDisplayViewport(true, externalTouchViewport); |
| 381 | } else if (defaultViewport.valid) { |
| 382 | setDisplayViewport(true, defaultViewport); |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 383 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 384 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 385 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 386 | private void setDisplayViewport(boolean external, DisplayViewport viewport) { |
| 387 | nativeSetDisplayViewport(mPtr, external, |
| 388 | viewport.displayId, viewport.orientation, |
| 389 | viewport.logicalFrame.left, viewport.logicalFrame.top, |
| 390 | viewport.logicalFrame.right, viewport.logicalFrame.bottom, |
| 391 | viewport.physicalFrame.left, viewport.physicalFrame.top, |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 392 | viewport.physicalFrame.right, viewport.physicalFrame.bottom, |
| 393 | viewport.deviceWidth, viewport.deviceHeight); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 394 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 395 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 396 | /** |
| 397 | * Gets the current state of a key or button by key code. |
| 398 | * @param deviceId The input device id, or -1 to consult all devices. |
| 399 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 400 | * consider all input sources. An input device is consulted if at least one of its |
| 401 | * non-class input source bits matches the specified source mask. |
| 402 | * @param keyCode The key code to check. |
| 403 | * @return The key state. |
| 404 | */ |
| 405 | public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 406 | return nativeGetKeyCodeState(mPtr, deviceId, sourceMask, keyCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 407 | } |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 408 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 409 | /** |
| 410 | * Gets the current state of a key or button by scan code. |
| 411 | * @param deviceId The input device id, or -1 to consult all devices. |
| 412 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 413 | * consider all input sources. An input device is consulted if at least one of its |
| 414 | * non-class input source bits matches the specified source mask. |
| 415 | * @param scanCode The scan code to check. |
| 416 | * @return The key state. |
| 417 | */ |
| 418 | public int getScanCodeState(int deviceId, int sourceMask, int scanCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 419 | return nativeGetScanCodeState(mPtr, deviceId, sourceMask, scanCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 420 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 421 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 422 | /** |
| 423 | * Gets the current state of a switch by switch code. |
| 424 | * @param deviceId The input device id, or -1 to consult all devices. |
| 425 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 426 | * consider all input sources. An input device is consulted if at least one of its |
| 427 | * non-class input source bits matches the specified source mask. |
| 428 | * @param switchCode The switch code to check. |
| 429 | * @return The switch state. |
| 430 | */ |
| 431 | public int getSwitchState(int deviceId, int sourceMask, int switchCode) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 432 | return nativeGetSwitchState(mPtr, deviceId, sourceMask, switchCode); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 435 | /** |
| 436 | * Determines whether the specified key codes are supported by a particular device. |
| 437 | * @param deviceId The input device id, or -1 to consult all devices. |
| 438 | * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to |
| 439 | * consider all input sources. An input device is consulted if at least one of its |
| 440 | * non-class input source bits matches the specified source mask. |
| 441 | * @param keyCodes The array of key codes to check. |
| 442 | * @param keyExists An array at least as large as keyCodes whose entries will be set |
| 443 | * to true or false based on the presence or absence of support for the corresponding |
| 444 | * key codes. |
| 445 | * @return True if the lookup was successful, false otherwise. |
| 446 | */ |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 447 | @Override // Binder call |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 448 | public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 449 | if (keyCodes == null) { |
| 450 | throw new IllegalArgumentException("keyCodes must not be null."); |
| 451 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 452 | if (keyExists == null || keyExists.length < keyCodes.length) { |
| 453 | throw new IllegalArgumentException("keyExists must not be null and must be at " |
| 454 | + "least as large as keyCodes."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 455 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 456 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 457 | return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 458 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 459 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 460 | /** |
| 461 | * Creates an input channel that will receive all input from the input dispatcher. |
| 462 | * @param inputChannelName The input channel name. |
| 463 | * @return The input channel. |
| 464 | */ |
| 465 | public InputChannel monitorInput(String inputChannelName) { |
| 466 | if (inputChannelName == null) { |
| 467 | throw new IllegalArgumentException("inputChannelName must not be null."); |
| 468 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 469 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 470 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 471 | nativeRegisterInputChannel(mPtr, inputChannels[0], null, true); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 472 | inputChannels[0].dispose(); // don't need to retain the Java object reference |
| 473 | return inputChannels[1]; |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Registers an input channel so that it can be used as an input event target. |
| 478 | * @param inputChannel The input channel to register. |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 479 | * @param inputWindowHandle The handle of the input window associated with the |
| 480 | * input channel, or null if none. |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 481 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 482 | public void registerInputChannel(InputChannel inputChannel, |
| 483 | InputWindowHandle inputWindowHandle) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 484 | if (inputChannel == null) { |
| 485 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 486 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 487 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 488 | nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 489 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 490 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 491 | /** |
| 492 | * Unregisters an input channel. |
| 493 | * @param inputChannel The input channel to unregister. |
| 494 | */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 495 | public void unregisterInputChannel(InputChannel inputChannel) { |
| 496 | if (inputChannel == null) { |
| 497 | throw new IllegalArgumentException("inputChannel must not be null."); |
| 498 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 499 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 500 | nativeUnregisterInputChannel(mPtr, inputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 501 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * Sets an input filter that will receive all input events before they are dispatched. |
| 505 | * The input filter may then reinterpret input events or inject new ones. |
| 506 | * |
| 507 | * To ensure consistency, the input dispatcher automatically drops all events |
| 508 | * in progress whenever an input filter is installed or uninstalled. After an input |
| 509 | * filter is uninstalled, it can no longer send input events unless it is reinstalled. |
| 510 | * Any events it attempts to send after it has been uninstalled will be dropped. |
| 511 | * |
| 512 | * @param filter The input filter, or null to remove the current filter. |
| 513 | */ |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 514 | public void setInputFilter(IInputFilter filter) { |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 515 | synchronized (mInputFilterLock) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 516 | final IInputFilter oldFilter = mInputFilter; |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 517 | if (oldFilter == filter) { |
| 518 | return; // nothing to do |
| 519 | } |
| 520 | |
| 521 | if (oldFilter != null) { |
| 522 | mInputFilter = null; |
| 523 | mInputFilterHost.disconnectLocked(); |
| 524 | mInputFilterHost = null; |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 525 | try { |
| 526 | oldFilter.uninstall(); |
| 527 | } catch (RemoteException re) { |
| 528 | /* ignore */ |
| 529 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | if (filter != null) { |
| 533 | mInputFilter = filter; |
| 534 | mInputFilterHost = new InputFilterHost(); |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 535 | try { |
| 536 | filter.install(mInputFilterHost); |
| 537 | } catch (RemoteException re) { |
| 538 | /* ignore */ |
| 539 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 542 | nativeSetInputFilterEnabled(mPtr, filter != null); |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 546 | @Override // Binder call |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 547 | public boolean injectInputEvent(InputEvent event, int mode) { |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 548 | return injectInputEventInternal(event, Display.DEFAULT_DISPLAY, mode); |
| 549 | } |
| 550 | |
| 551 | private boolean injectInputEventInternal(InputEvent event, int displayId, int mode) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 552 | if (event == null) { |
| 553 | throw new IllegalArgumentException("event must not be null"); |
| 554 | } |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 555 | if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC |
| 556 | && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH |
| 557 | && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) { |
| 558 | throw new IllegalArgumentException("mode is invalid"); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 559 | } |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 560 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 561 | final int pid = Binder.getCallingPid(); |
| 562 | final int uid = Binder.getCallingUid(); |
| 563 | final long ident = Binder.clearCallingIdentity(); |
| 564 | final int result; |
| 565 | try { |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 566 | result = nativeInjectInputEvent(mPtr, event, displayId, pid, uid, mode, |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 567 | INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT); |
| 568 | } finally { |
| 569 | Binder.restoreCallingIdentity(ident); |
| 570 | } |
| 571 | switch (result) { |
| 572 | case INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 573 | Slog.w(TAG, "Input event injection from pid " + pid + " permission denied."); |
| 574 | throw new SecurityException( |
| 575 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 576 | case INPUT_EVENT_INJECTION_SUCCEEDED: |
| 577 | return true; |
| 578 | case INPUT_EVENT_INJECTION_TIMED_OUT: |
| 579 | Slog.w(TAG, "Input event injection from pid " + pid + " timed out."); |
| 580 | return false; |
| 581 | case INPUT_EVENT_INJECTION_FAILED: |
| 582 | default: |
| 583 | Slog.w(TAG, "Input event injection from pid " + pid + " failed."); |
| 584 | return false; |
| 585 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 586 | } |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 587 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 588 | /** |
| 589 | * Gets information about the input device with the specified id. |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 590 | * @param deviceId The device id. |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 591 | * @return The input device or null if not found. |
| 592 | */ |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 593 | @Override // Binder call |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 594 | public InputDevice getInputDevice(int deviceId) { |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 595 | synchronized (mInputDevicesLock) { |
| 596 | final int count = mInputDevices.length; |
| 597 | for (int i = 0; i < count; i++) { |
| 598 | final InputDevice inputDevice = mInputDevices[i]; |
| 599 | if (inputDevice.getId() == deviceId) { |
| 600 | return inputDevice; |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | return null; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 605 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 606 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 607 | /** |
| 608 | * Gets the ids of all input devices in the system. |
| 609 | * @return The input device ids. |
| 610 | */ |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 611 | @Override // Binder call |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 612 | public int[] getInputDeviceIds() { |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 613 | synchronized (mInputDevicesLock) { |
| 614 | final int count = mInputDevices.length; |
| 615 | int[] ids = new int[count]; |
| 616 | for (int i = 0; i < count; i++) { |
| 617 | ids[i] = mInputDevices[i].getId(); |
| 618 | } |
| 619 | return ids; |
| 620 | } |
| 621 | } |
| 622 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 623 | /** |
| 624 | * Gets all input devices in the system. |
| 625 | * @return The array of input devices. |
| 626 | */ |
| 627 | public InputDevice[] getInputDevices() { |
| 628 | synchronized (mInputDevicesLock) { |
| 629 | return mInputDevices; |
| 630 | } |
| 631 | } |
| 632 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 633 | @Override // Binder call |
| 634 | public void registerInputDevicesChangedListener(IInputDevicesChangedListener listener) { |
| 635 | if (listener == null) { |
| 636 | throw new IllegalArgumentException("listener must not be null"); |
| 637 | } |
| 638 | |
| 639 | synchronized (mInputDevicesLock) { |
| 640 | int callingPid = Binder.getCallingPid(); |
| 641 | if (mInputDevicesChangedListeners.get(callingPid) != null) { |
| 642 | throw new SecurityException("The calling process has already " |
| 643 | + "registered an InputDevicesChangedListener."); |
| 644 | } |
| 645 | |
| 646 | InputDevicesChangedListenerRecord record = |
| 647 | new InputDevicesChangedListenerRecord(callingPid, listener); |
| 648 | try { |
| 649 | IBinder binder = listener.asBinder(); |
| 650 | binder.linkToDeath(record, 0); |
| 651 | } catch (RemoteException ex) { |
| 652 | // give up |
| 653 | throw new RuntimeException(ex); |
| 654 | } |
| 655 | |
| 656 | mInputDevicesChangedListeners.put(callingPid, record); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | private void onInputDevicesChangedListenerDied(int pid) { |
| 661 | synchronized (mInputDevicesLock) { |
| 662 | mInputDevicesChangedListeners.remove(pid); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | // Must be called on handler. |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 667 | private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) { |
| 668 | // Scan for changes. |
| 669 | int numFullKeyboardsAdded = 0; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 670 | mTempInputDevicesChangedListenersToNotify.clear(); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 671 | mTempFullKeyboards.clear(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 672 | final int numListeners; |
| 673 | final int[] deviceIdAndGeneration; |
| 674 | synchronized (mInputDevicesLock) { |
| 675 | if (!mInputDevicesChangedPending) { |
| 676 | return; |
| 677 | } |
| 678 | mInputDevicesChangedPending = false; |
| 679 | |
| 680 | numListeners = mInputDevicesChangedListeners.size(); |
| 681 | for (int i = 0; i < numListeners; i++) { |
| 682 | mTempInputDevicesChangedListenersToNotify.add( |
| 683 | mInputDevicesChangedListeners.valueAt(i)); |
| 684 | } |
| 685 | |
| 686 | final int numDevices = mInputDevices.length; |
| 687 | deviceIdAndGeneration = new int[numDevices * 2]; |
| 688 | for (int i = 0; i < numDevices; i++) { |
| 689 | final InputDevice inputDevice = mInputDevices[i]; |
| 690 | deviceIdAndGeneration[i * 2] = inputDevice.getId(); |
| 691 | deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration(); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 692 | |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 693 | if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 694 | if (!containsInputDeviceWithDescriptor(oldInputDevices, |
| 695 | inputDevice.getDescriptor())) { |
| 696 | mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice); |
| 697 | } else { |
| 698 | mTempFullKeyboards.add(inputDevice); |
| 699 | } |
| 700 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 704 | // Notify listeners. |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 705 | for (int i = 0; i < numListeners; i++) { |
| 706 | mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged( |
| 707 | deviceIdAndGeneration); |
| 708 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 709 | mTempInputDevicesChangedListenersToNotify.clear(); |
| 710 | |
| 711 | // Check for missing keyboard layouts. |
| 712 | if (mNotificationManager != null) { |
| 713 | final int numFullKeyboards = mTempFullKeyboards.size(); |
| 714 | boolean missingLayoutForExternalKeyboard = false; |
| 715 | boolean missingLayoutForExternalKeyboardAdded = false; |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 716 | boolean multipleMissingLayoutsForExternalKeyboardsAdded = false; |
| 717 | InputDevice keyboardMissingLayout = null; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 718 | synchronized (mDataStore) { |
| 719 | for (int i = 0; i < numFullKeyboards; i++) { |
| 720 | final InputDevice inputDevice = mTempFullKeyboards.get(i); |
Michael Wright | 86aaca6 | 2014-09-08 18:54:45 -0700 | [diff] [blame] | 721 | final String layout = |
| 722 | getCurrentKeyboardLayoutForInputDevice(inputDevice.getIdentifier()); |
| 723 | if (layout == null) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 724 | missingLayoutForExternalKeyboard = true; |
| 725 | if (i < numFullKeyboardsAdded) { |
| 726 | missingLayoutForExternalKeyboardAdded = true; |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 727 | if (keyboardMissingLayout == null) { |
| 728 | keyboardMissingLayout = inputDevice; |
| 729 | } else { |
| 730 | multipleMissingLayoutsForExternalKeyboardsAdded = true; |
| 731 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | if (missingLayoutForExternalKeyboard) { |
| 737 | if (missingLayoutForExternalKeyboardAdded) { |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 738 | if (multipleMissingLayoutsForExternalKeyboardsAdded) { |
| 739 | // We have more than one keyboard missing a layout, so drop the |
| 740 | // user at the generic input methods page so they can pick which |
| 741 | // one to set. |
| 742 | showMissingKeyboardLayoutNotification(null); |
| 743 | } else { |
| 744 | showMissingKeyboardLayoutNotification(keyboardMissingLayout); |
| 745 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 746 | } |
| 747 | } else if (mKeyboardLayoutNotificationShown) { |
| 748 | hideMissingKeyboardLayoutNotification(); |
| 749 | } |
| 750 | } |
| 751 | mTempFullKeyboards.clear(); |
| 752 | } |
| 753 | |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 754 | @Override // Binder call & native callback |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 755 | public TouchCalibration getTouchCalibrationForInputDevice(String inputDeviceDescriptor, |
| 756 | int surfaceRotation) { |
Jason Gerecke | d6396d6 | 2014-01-27 18:30:37 -0800 | [diff] [blame] | 757 | if (inputDeviceDescriptor == null) { |
| 758 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 759 | } |
| 760 | |
| 761 | synchronized (mDataStore) { |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 762 | return mDataStore.getTouchCalibration(inputDeviceDescriptor, surfaceRotation); |
Jason Gerecke | d6396d6 | 2014-01-27 18:30:37 -0800 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
| 766 | @Override // Binder call |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 767 | public void setTouchCalibrationForInputDevice(String inputDeviceDescriptor, int surfaceRotation, |
Jason Gerecke | d6396d6 | 2014-01-27 18:30:37 -0800 | [diff] [blame] | 768 | TouchCalibration calibration) { |
| 769 | if (!checkCallingPermission(android.Manifest.permission.SET_INPUT_CALIBRATION, |
| 770 | "setTouchCalibrationForInputDevice()")) { |
| 771 | throw new SecurityException("Requires SET_INPUT_CALIBRATION permission"); |
| 772 | } |
| 773 | if (inputDeviceDescriptor == null) { |
| 774 | throw new IllegalArgumentException("inputDeviceDescriptor must not be null"); |
| 775 | } |
| 776 | if (calibration == null) { |
| 777 | throw new IllegalArgumentException("calibration must not be null"); |
| 778 | } |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 779 | if (surfaceRotation < Surface.ROTATION_0 || surfaceRotation > Surface.ROTATION_270) { |
| 780 | throw new IllegalArgumentException("surfaceRotation value out of bounds"); |
| 781 | } |
Jason Gerecke | d6396d6 | 2014-01-27 18:30:37 -0800 | [diff] [blame] | 782 | |
| 783 | synchronized (mDataStore) { |
| 784 | try { |
Jason Gerecke | d522074 | 2014-03-10 09:47:59 -0700 | [diff] [blame] | 785 | if (mDataStore.setTouchCalibration(inputDeviceDescriptor, surfaceRotation, |
| 786 | calibration)) { |
Jason Gerecke | 857aa7b | 2014-01-27 18:34:20 -0800 | [diff] [blame] | 787 | nativeReloadCalibration(mPtr); |
| 788 | } |
Jason Gerecke | d6396d6 | 2014-01-27 18:30:37 -0800 | [diff] [blame] | 789 | } finally { |
| 790 | mDataStore.saveIfNeeded(); |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 795 | @Override // Binder call |
| 796 | public void registerTabletModeChangedListener(ITabletModeChangedListener listener) { |
| 797 | if (!checkCallingPermission(android.Manifest.permission.TABLET_MODE_LISTENER, |
| 798 | "registerTabletModeChangedListener()")) { |
| 799 | throw new SecurityException("Requires TABLET_MODE_LISTENER permission"); |
| 800 | } |
| 801 | if (listener == null) { |
| 802 | throw new IllegalArgumentException("listener must not be null"); |
| 803 | } |
| 804 | |
| 805 | synchronized (mTabletModeLock) { |
| 806 | final int callingPid = Binder.getCallingPid(); |
| 807 | if (mTabletModeChangedListeners.get(callingPid) != null) { |
| 808 | throw new IllegalStateException("The calling process has already registered " |
| 809 | + "a TabletModeChangedListener."); |
| 810 | } |
| 811 | TabletModeChangedListenerRecord record = |
| 812 | new TabletModeChangedListenerRecord(callingPid, listener); |
| 813 | try { |
| 814 | IBinder binder = listener.asBinder(); |
| 815 | binder.linkToDeath(record, 0); |
| 816 | } catch (RemoteException ex) { |
| 817 | throw new RuntimeException(ex); |
| 818 | } |
| 819 | mTabletModeChangedListeners.put(callingPid, record); |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | private void onTabletModeChangedListenerDied(int pid) { |
| 824 | synchronized (mTabletModeLock) { |
| 825 | mTabletModeChangedListeners.remove(pid); |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | // Must be called on handler |
| 830 | private void deliverTabletModeChanged(long whenNanos, boolean inTabletMode) { |
| 831 | mTempTabletModeChangedListenersToNotify.clear(); |
| 832 | final int numListeners; |
| 833 | synchronized (mTabletModeLock) { |
| 834 | numListeners = mTabletModeChangedListeners.size(); |
| 835 | for (int i = 0; i < numListeners; i++) { |
| 836 | mTempTabletModeChangedListenersToNotify.add( |
| 837 | mTabletModeChangedListeners.valueAt(i)); |
| 838 | } |
| 839 | } |
| 840 | for (int i = 0; i < numListeners; i++) { |
| 841 | mTempTabletModeChangedListenersToNotify.get(i).notifyTabletModeChanged( |
| 842 | whenNanos, inTabletMode); |
| 843 | } |
| 844 | } |
| 845 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 846 | // Must be called on handler. |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 847 | private void showMissingKeyboardLayoutNotification(InputDevice device) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 848 | if (!mKeyboardLayoutNotificationShown) { |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 849 | final Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 850 | if (device != null) { |
| 851 | intent.putExtra(Settings.EXTRA_INPUT_DEVICE_IDENTIFIER, device.getIdentifier()); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 852 | } |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 853 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 854 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 855 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 856 | final PendingIntent keyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0, |
| 857 | intent, 0, null, UserHandle.CURRENT); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 858 | |
| 859 | Resources r = mContext.getResources(); |
| 860 | Notification notification = new Notification.Builder(mContext) |
| 861 | .setContentTitle(r.getString( |
| 862 | R.string.select_keyboard_layout_notification_title)) |
| 863 | .setContentText(r.getString( |
| 864 | R.string.select_keyboard_layout_notification_message)) |
Michael Wright | c93fbd1 | 2014-09-22 20:07:59 -0700 | [diff] [blame] | 865 | .setContentIntent(keyboardLayoutIntent) |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 866 | .setSmallIcon(R.drawable.ic_settings_language) |
| 867 | .setPriority(Notification.PRIORITY_LOW) |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 868 | .setColor(mContext.getColor( |
Selim Cinek | 255dd04 | 2014-08-19 22:29:02 +0200 | [diff] [blame] | 869 | com.android.internal.R.color.system_notification_accent_color)) |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 870 | .build(); |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 871 | mNotificationManager.notifyAsUser(null, |
| 872 | R.string.select_keyboard_layout_notification_title, |
| 873 | notification, UserHandle.ALL); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 874 | mKeyboardLayoutNotificationShown = true; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | // Must be called on handler. |
| 879 | private void hideMissingKeyboardLayoutNotification() { |
| 880 | if (mKeyboardLayoutNotificationShown) { |
| 881 | mKeyboardLayoutNotificationShown = false; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 882 | mNotificationManager.cancelAsUser(null, |
| 883 | R.string.select_keyboard_layout_notification_title, |
| 884 | UserHandle.ALL); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | // Must be called on handler. |
| 889 | private void updateKeyboardLayouts() { |
| 890 | // Scan all input devices state for keyboard layouts that have been uninstalled. |
| 891 | final HashSet<String> availableKeyboardLayouts = new HashSet<String>(); |
| 892 | visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { |
| 893 | @Override |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 894 | public void visitKeyboardLayout(Resources resources, String descriptor, String label, |
| 895 | String collection, int keyboardLayoutResId, int priority) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 896 | availableKeyboardLayouts.add(descriptor); |
| 897 | } |
| 898 | }); |
| 899 | synchronized (mDataStore) { |
| 900 | try { |
| 901 | mDataStore.removeUninstalledKeyboardLayouts(availableKeyboardLayouts); |
| 902 | } finally { |
| 903 | mDataStore.saveIfNeeded(); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | // Reload keyboard layouts. |
| 908 | reloadKeyboardLayouts(); |
| 909 | } |
| 910 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 911 | private static boolean containsInputDeviceWithDescriptor(InputDevice[] inputDevices, |
| 912 | String descriptor) { |
| 913 | final int numDevices = inputDevices.length; |
| 914 | for (int i = 0; i < numDevices; i++) { |
| 915 | final InputDevice inputDevice = inputDevices[i]; |
| 916 | if (inputDevice.getDescriptor().equals(descriptor)) { |
| 917 | return true; |
| 918 | } |
| 919 | } |
| 920 | return false; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 921 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 922 | |
| 923 | @Override // Binder call |
| 924 | public KeyboardLayout[] getKeyboardLayouts() { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 925 | final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>(); |
| 926 | visitAllKeyboardLayouts(new KeyboardLayoutVisitor() { |
| 927 | @Override |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 928 | public void visitKeyboardLayout(Resources resources, String descriptor, String label, |
| 929 | String collection, int keyboardLayoutResId, int priority) { |
| 930 | list.add(new KeyboardLayout(descriptor, label, collection, priority)); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 931 | } |
| 932 | }); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 933 | return list.toArray(new KeyboardLayout[list.size()]); |
| 934 | } |
| 935 | |
| 936 | @Override // Binder call |
| 937 | public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) { |
| 938 | if (keyboardLayoutDescriptor == null) { |
| 939 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 940 | } |
| 941 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 942 | final KeyboardLayout[] result = new KeyboardLayout[1]; |
| 943 | visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() { |
| 944 | @Override |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 945 | public void visitKeyboardLayout(Resources resources, String descriptor, |
| 946 | String label, String collection, int keyboardLayoutResId, int priority) { |
| 947 | result[0] = new KeyboardLayout(descriptor, label, collection, priority); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 948 | } |
| 949 | }); |
| 950 | if (result[0] == null) { |
| 951 | Log.w(TAG, "Could not get keyboard layout with descriptor '" |
| 952 | + keyboardLayoutDescriptor + "'."); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 953 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 954 | return result[0]; |
| 955 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 956 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 957 | private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 958 | final PackageManager pm = mContext.getPackageManager(); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 959 | Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS); |
| 960 | for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent, |
| 961 | PackageManager.GET_META_DATA)) { |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 962 | final ActivityInfo activityInfo = resolveInfo.activityInfo; |
| 963 | final int priority = resolveInfo.priority; |
| 964 | visitKeyboardLayoutsInPackage(pm, activityInfo, null, priority, visitor); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 968 | private void visitKeyboardLayout(String keyboardLayoutDescriptor, |
| 969 | KeyboardLayoutVisitor visitor) { |
| 970 | KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor); |
| 971 | if (d != null) { |
| 972 | final PackageManager pm = mContext.getPackageManager(); |
| 973 | try { |
| 974 | ActivityInfo receiver = pm.getReceiverInfo( |
| 975 | new ComponentName(d.packageName, d.receiverName), |
| 976 | PackageManager.GET_META_DATA); |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 977 | visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, 0, visitor); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 978 | } catch (NameNotFoundException ex) { |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 984 | String keyboardName, int requestedPriority, KeyboardLayoutVisitor visitor) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 985 | Bundle metaData = receiver.metaData; |
| 986 | if (metaData == null) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 987 | return; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS); |
| 991 | if (configResId == 0) { |
| 992 | Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS |
| 993 | + "' on receiver " + receiver.packageName + "/" + receiver.name); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 994 | return; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 997 | CharSequence receiverLabel = receiver.loadLabel(pm); |
| 998 | String collection = receiverLabel != null ? receiverLabel.toString() : ""; |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 999 | int priority; |
| 1000 | if ((receiver.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1001 | priority = requestedPriority; |
| 1002 | } else { |
| 1003 | priority = 0; |
| 1004 | } |
Jeff Brown | d9fec5d | 2012-05-17 16:01:54 -0700 | [diff] [blame] | 1005 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1006 | try { |
| 1007 | Resources resources = pm.getResourcesForApplication(receiver.applicationInfo); |
| 1008 | XmlResourceParser parser = resources.getXml(configResId); |
| 1009 | try { |
| 1010 | XmlUtils.beginDocument(parser, "keyboard-layouts"); |
| 1011 | |
| 1012 | for (;;) { |
| 1013 | XmlUtils.nextElement(parser); |
| 1014 | String element = parser.getName(); |
| 1015 | if (element == null) { |
| 1016 | break; |
| 1017 | } |
| 1018 | if (element.equals("keyboard-layout")) { |
| 1019 | TypedArray a = resources.obtainAttributes( |
| 1020 | parser, com.android.internal.R.styleable.KeyboardLayout); |
| 1021 | try { |
| 1022 | String name = a.getString( |
| 1023 | com.android.internal.R.styleable.KeyboardLayout_name); |
| 1024 | String label = a.getString( |
| 1025 | com.android.internal.R.styleable.KeyboardLayout_label); |
Jeff Brown | 2f09576 | 2012-05-10 21:29:33 -0700 | [diff] [blame] | 1026 | int keyboardLayoutResId = a.getResourceId( |
| 1027 | com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, |
| 1028 | 0); |
| 1029 | if (name == null || label == null || keyboardLayoutResId == 0) { |
| 1030 | Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1031 | + "attributes in keyboard layout " |
| 1032 | + "resource from receiver " |
| 1033 | + receiver.packageName + "/" + receiver.name); |
| 1034 | } else { |
| 1035 | String descriptor = KeyboardLayoutDescriptor.format( |
| 1036 | receiver.packageName, receiver.name, name); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1037 | if (keyboardName == null || name.equals(keyboardName)) { |
| 1038 | visitor.visitKeyboardLayout(resources, descriptor, |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 1039 | label, collection, keyboardLayoutResId, priority); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | } finally { |
| 1043 | a.recycle(); |
| 1044 | } |
| 1045 | } else { |
| 1046 | Log.w(TAG, "Skipping unrecognized element '" + element |
| 1047 | + "' in keyboard layout resource from receiver " |
| 1048 | + receiver.packageName + "/" + receiver.name); |
| 1049 | } |
| 1050 | } |
| 1051 | } finally { |
| 1052 | parser.close(); |
| 1053 | } |
| 1054 | } catch (Exception ex) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1055 | Log.w(TAG, "Could not parse keyboard layout resource from receiver " |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1056 | + receiver.packageName + "/" + receiver.name, ex); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1057 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1060 | /** |
| 1061 | * Builds a layout descriptor for the vendor/product. This returns the |
| 1062 | * descriptor for ids that aren't useful (such as the default 0, 0). |
| 1063 | */ |
| 1064 | private String getLayoutDescriptor(InputDeviceIdentifier identifier) { |
| 1065 | if (identifier == null || identifier.getDescriptor() == null) { |
| 1066 | throw new IllegalArgumentException("identifier and descriptor must not be null"); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1069 | if (identifier.getVendorId() == 0 && identifier.getProductId() == 0) { |
| 1070 | return identifier.getDescriptor(); |
| 1071 | } |
| 1072 | StringBuilder bob = new StringBuilder(); |
| 1073 | bob.append("vendor:").append(identifier.getVendorId()); |
| 1074 | bob.append(",product:").append(identifier.getProductId()); |
| 1075 | return bob.toString(); |
| 1076 | } |
| 1077 | |
| 1078 | @Override // Binder call |
| 1079 | public String getCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier) { |
| 1080 | |
| 1081 | String key = getLayoutDescriptor(identifier); |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 1082 | synchronized (mDataStore) { |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1083 | String layout = null; |
| 1084 | // try loading it using the layout descriptor if we have it |
| 1085 | layout = mDataStore.getCurrentKeyboardLayout(key); |
| 1086 | if (layout == null && !key.equals(identifier.getDescriptor())) { |
| 1087 | // if it doesn't exist fall back to the device descriptor |
| 1088 | layout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor()); |
| 1089 | } |
| 1090 | if (DEBUG) { |
| 1091 | Slog.d(TAG, "Loaded keyboard layout id for " + key + " and got " |
| 1092 | + layout); |
| 1093 | } |
| 1094 | return layout; |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 1095 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | @Override // Binder call |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1099 | public void setCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1100 | String keyboardLayoutDescriptor) { |
| 1101 | if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT, |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1102 | "setCurrentKeyboardLayoutForInputDevice()")) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1103 | throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission"); |
| 1104 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1105 | if (keyboardLayoutDescriptor == null) { |
| 1106 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 1107 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1108 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1109 | String key = getLayoutDescriptor(identifier); |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 1110 | synchronized (mDataStore) { |
| 1111 | try { |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1112 | if (mDataStore.setCurrentKeyboardLayout(key, keyboardLayoutDescriptor)) { |
| 1113 | if (DEBUG) { |
| 1114 | Slog.d(TAG, "Saved keyboard layout using " + key); |
| 1115 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1116 | mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS); |
| 1117 | } |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 1118 | } finally { |
| 1119 | mDataStore.saveIfNeeded(); |
| 1120 | } |
| 1121 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1122 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1123 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1124 | @Override // Binder call |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1125 | public String[] getKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier) { |
| 1126 | String key = getLayoutDescriptor(identifier); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1127 | synchronized (mDataStore) { |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1128 | String[] layouts = mDataStore.getKeyboardLayouts(key); |
| 1129 | if ((layouts == null || layouts.length == 0) |
| 1130 | && !key.equals(identifier.getDescriptor())) { |
| 1131 | layouts = mDataStore.getKeyboardLayouts(identifier.getDescriptor()); |
| 1132 | } |
| 1133 | return layouts; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | @Override // Binder call |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1138 | public void addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1139 | String keyboardLayoutDescriptor) { |
| 1140 | if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT, |
| 1141 | "addKeyboardLayoutForInputDevice()")) { |
| 1142 | throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission"); |
| 1143 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1144 | if (keyboardLayoutDescriptor == null) { |
| 1145 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 1146 | } |
| 1147 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1148 | String key = getLayoutDescriptor(identifier); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1149 | synchronized (mDataStore) { |
| 1150 | try { |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1151 | String oldLayout = mDataStore.getCurrentKeyboardLayout(key); |
| 1152 | if (oldLayout == null && !key.equals(identifier.getDescriptor())) { |
| 1153 | oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor()); |
| 1154 | } |
| 1155 | if (mDataStore.addKeyboardLayout(key, keyboardLayoutDescriptor) |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1156 | && !Objects.equal(oldLayout, |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1157 | mDataStore.getCurrentKeyboardLayout(key))) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1158 | mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS); |
| 1159 | } |
| 1160 | } finally { |
| 1161 | mDataStore.saveIfNeeded(); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1162 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | @Override // Binder call |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1167 | public void removeKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier, |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1168 | String keyboardLayoutDescriptor) { |
| 1169 | if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT, |
| 1170 | "removeKeyboardLayoutForInputDevice()")) { |
| 1171 | throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission"); |
| 1172 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1173 | if (keyboardLayoutDescriptor == null) { |
| 1174 | throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null"); |
| 1175 | } |
| 1176 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1177 | String key = getLayoutDescriptor(identifier); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1178 | synchronized (mDataStore) { |
| 1179 | try { |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1180 | String oldLayout = mDataStore.getCurrentKeyboardLayout(key); |
| 1181 | if (oldLayout == null && !key.equals(identifier.getDescriptor())) { |
| 1182 | oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor()); |
| 1183 | } |
| 1184 | boolean removed = mDataStore.removeKeyboardLayout(key, keyboardLayoutDescriptor); |
| 1185 | if (!key.equals(identifier.getDescriptor())) { |
| 1186 | // We need to remove from both places to ensure it is gone |
| 1187 | removed |= mDataStore.removeKeyboardLayout(identifier.getDescriptor(), |
| 1188 | keyboardLayoutDescriptor); |
| 1189 | } |
| 1190 | if (removed && !Objects.equal(oldLayout, |
| 1191 | mDataStore.getCurrentKeyboardLayout(key))) { |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1192 | mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS); |
| 1193 | } |
| 1194 | } finally { |
| 1195 | mDataStore.saveIfNeeded(); |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | public void switchKeyboardLayout(int deviceId, int direction) { |
| 1201 | mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, deviceId, direction).sendToTarget(); |
| 1202 | } |
| 1203 | |
| 1204 | // Must be called on handler. |
| 1205 | private void handleSwitchKeyboardLayout(int deviceId, int direction) { |
| 1206 | final InputDevice device = getInputDevice(deviceId); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1207 | if (device != null) { |
| 1208 | final boolean changed; |
| 1209 | final String keyboardLayoutDescriptor; |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1210 | |
| 1211 | String key = getLayoutDescriptor(device.getIdentifier()); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1212 | synchronized (mDataStore) { |
| 1213 | try { |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1214 | changed = mDataStore.switchKeyboardLayout(key, direction); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1215 | keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout( |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1216 | key); |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1217 | } finally { |
| 1218 | mDataStore.saveIfNeeded(); |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | if (changed) { |
| 1223 | if (mSwitchedKeyboardLayoutToast != null) { |
| 1224 | mSwitchedKeyboardLayoutToast.cancel(); |
| 1225 | mSwitchedKeyboardLayoutToast = null; |
| 1226 | } |
| 1227 | if (keyboardLayoutDescriptor != null) { |
| 1228 | KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor); |
| 1229 | if (keyboardLayout != null) { |
| 1230 | mSwitchedKeyboardLayoutToast = Toast.makeText( |
| 1231 | mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT); |
| 1232 | mSwitchedKeyboardLayoutToast.show(); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | reloadKeyboardLayouts(); |
| 1237 | } |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1238 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1241 | public void setInputWindows(InputWindowHandle[] windowHandles) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1242 | nativeSetInputWindows(mPtr, windowHandles); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1243 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1244 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 1245 | public void setFocusedApplication(InputApplicationHandle application) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1246 | nativeSetFocusedApplication(mPtr, application); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1247 | } |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1248 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1249 | public void setInputDispatchMode(boolean enabled, boolean frozen) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1250 | nativeSetInputDispatchMode(mPtr, enabled, frozen); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1251 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1252 | |
| 1253 | public void setSystemUiVisibility(int visibility) { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1254 | nativeSetSystemUiVisibility(mPtr, visibility); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1257 | /** |
| 1258 | * Atomically transfers touch focus from one window to another as identified by |
| 1259 | * their input channels. It is possible for multiple windows to have |
| 1260 | * touch focus if they support split touch dispatch |
| 1261 | * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this |
| 1262 | * method only transfers touch focus of the specified window without affecting |
| 1263 | * other windows that may also have touch focus at the same time. |
| 1264 | * @param fromChannel The channel of a window that currently has touch focus. |
| 1265 | * @param toChannel The channel of the window that should receive touch focus in |
| 1266 | * place of the first. |
| 1267 | * @return True if the transfer was successful. False if the window with the |
| 1268 | * specified channel did not actually have touch focus at the time of the request. |
| 1269 | */ |
| 1270 | public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) { |
| 1271 | if (fromChannel == null) { |
| 1272 | throw new IllegalArgumentException("fromChannel must not be null."); |
| 1273 | } |
| 1274 | if (toChannel == null) { |
| 1275 | throw new IllegalArgumentException("toChannel must not be null."); |
| 1276 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1277 | return nativeTransferTouchFocus(mPtr, fromChannel, toChannel); |
Jeff Brown | e650412 | 2010-09-27 14:52:15 -0700 | [diff] [blame] | 1278 | } |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 1279 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1280 | @Override // Binder call |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1281 | public void tryPointerSpeed(int speed) { |
| 1282 | if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED, |
| 1283 | "tryPointerSpeed()")) { |
| 1284 | throw new SecurityException("Requires SET_POINTER_SPEED permission"); |
| 1285 | } |
| 1286 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1287 | if (speed < InputManager.MIN_POINTER_SPEED || speed > InputManager.MAX_POINTER_SPEED) { |
| 1288 | throw new IllegalArgumentException("speed out of range"); |
| 1289 | } |
| 1290 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1291 | setPointerSpeedUnchecked(speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | public void updatePointerSpeedFromSettings() { |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1295 | int speed = getPointerSpeedSetting(); |
| 1296 | setPointerSpeedUnchecked(speed); |
| 1297 | } |
| 1298 | |
| 1299 | private void setPointerSpeedUnchecked(int speed) { |
| 1300 | speed = Math.min(Math.max(speed, InputManager.MIN_POINTER_SPEED), |
| 1301 | InputManager.MAX_POINTER_SPEED); |
| 1302 | nativeSetPointerSpeed(mPtr, speed); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | private void registerPointerSpeedSettingObserver() { |
| 1306 | mContext.getContentResolver().registerContentObserver( |
| 1307 | Settings.System.getUriFor(Settings.System.POINTER_SPEED), true, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1308 | new ContentObserver(mHandler) { |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1309 | @Override |
| 1310 | public void onChange(boolean selfChange) { |
| 1311 | updatePointerSpeedFromSettings(); |
| 1312 | } |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1313 | }, UserHandle.USER_ALL); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1316 | private int getPointerSpeedSetting() { |
| 1317 | int speed = InputManager.DEFAULT_POINTER_SPEED; |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1318 | try { |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1319 | speed = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 1320 | Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT); |
Jeff Brown | 1a84fd1 | 2011-06-02 01:26:32 -0700 | [diff] [blame] | 1321 | } catch (SettingNotFoundException snfe) { |
| 1322 | } |
| 1323 | return speed; |
| 1324 | } |
| 1325 | |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1326 | public void updateShowTouchesFromSettings() { |
| 1327 | int setting = getShowTouchesSetting(0); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1328 | nativeSetShowTouches(mPtr, setting != 0); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | private void registerShowTouchesSettingObserver() { |
| 1332 | mContext.getContentResolver().registerContentObserver( |
| 1333 | Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true, |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1334 | new ContentObserver(mHandler) { |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1335 | @Override |
| 1336 | public void onChange(boolean selfChange) { |
| 1337 | updateShowTouchesFromSettings(); |
| 1338 | } |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1339 | }, UserHandle.USER_ALL); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | private int getShowTouchesSetting(int defaultValue) { |
| 1343 | int result = defaultValue; |
| 1344 | try { |
Jeff Brown | d493596 | 2012-09-25 13:27:20 -0700 | [diff] [blame] | 1345 | result = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 1346 | Settings.System.SHOW_TOUCHES, UserHandle.USER_CURRENT); |
Jeff Brown | daf4a12 | 2011-08-26 17:14:14 -0700 | [diff] [blame] | 1347 | } catch (SettingNotFoundException snfe) { |
| 1348 | } |
| 1349 | return result; |
| 1350 | } |
| 1351 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1352 | // Binder call |
| 1353 | @Override |
| 1354 | public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) { |
| 1355 | if (repeat >= pattern.length) { |
| 1356 | throw new ArrayIndexOutOfBoundsException(); |
| 1357 | } |
| 1358 | |
| 1359 | VibratorToken v; |
| 1360 | synchronized (mVibratorLock) { |
| 1361 | v = mVibratorTokens.get(token); |
| 1362 | if (v == null) { |
| 1363 | v = new VibratorToken(deviceId, token, mNextVibratorTokenValue++); |
| 1364 | try { |
| 1365 | token.linkToDeath(v, 0); |
| 1366 | } catch (RemoteException ex) { |
| 1367 | // give up |
| 1368 | throw new RuntimeException(ex); |
| 1369 | } |
| 1370 | mVibratorTokens.put(token, v); |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | synchronized (v) { |
| 1375 | v.mVibrating = true; |
| 1376 | nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue); |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | // Binder call |
| 1381 | @Override |
| 1382 | public void cancelVibrate(int deviceId, IBinder token) { |
| 1383 | VibratorToken v; |
| 1384 | synchronized (mVibratorLock) { |
| 1385 | v = mVibratorTokens.get(token); |
| 1386 | if (v == null || v.mDeviceId != deviceId) { |
| 1387 | return; // nothing to cancel |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | cancelVibrateIfNeeded(v); |
| 1392 | } |
| 1393 | |
| 1394 | void onVibratorTokenDied(VibratorToken v) { |
| 1395 | synchronized (mVibratorLock) { |
| 1396 | mVibratorTokens.remove(v.mToken); |
| 1397 | } |
| 1398 | |
| 1399 | cancelVibrateIfNeeded(v); |
| 1400 | } |
| 1401 | |
| 1402 | private void cancelVibrateIfNeeded(VibratorToken v) { |
| 1403 | synchronized (v) { |
| 1404 | if (v.mVibrating) { |
| 1405 | nativeCancelVibrate(mPtr, v.mDeviceId, v.mTokenValue); |
| 1406 | v.mVibrating = false; |
| 1407 | } |
| 1408 | } |
| 1409 | } |
| 1410 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame^] | 1411 | // Binder call |
| 1412 | @Override |
| 1413 | public void setPointerIconShape(int iconId) { |
| 1414 | nativeSetPointerIconShape(mPtr, iconId); |
| 1415 | } |
| 1416 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1417 | @Override |
| 1418 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Brown | a3bc565 | 2012-04-17 11:42:25 -0700 | [diff] [blame] | 1419 | if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP) |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1420 | != PackageManager.PERMISSION_GRANTED) { |
| 1421 | pw.println("Permission Denial: can't dump InputManager from from pid=" |
| 1422 | + Binder.getCallingPid() |
| 1423 | + ", uid=" + Binder.getCallingUid()); |
| 1424 | return; |
| 1425 | } |
| 1426 | |
| 1427 | pw.println("INPUT MANAGER (dumpsys input)\n"); |
| 1428 | String dumpStr = nativeDump(mPtr); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1429 | if (dumpStr != null) { |
| 1430 | pw.println(dumpStr); |
| 1431 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1432 | } |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1433 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1434 | private boolean checkCallingPermission(String permission, String func) { |
| 1435 | // Quick check: if the calling permission is me, it's all okay. |
| 1436 | if (Binder.getCallingPid() == Process.myPid()) { |
| 1437 | return true; |
| 1438 | } |
| 1439 | |
| 1440 | if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) { |
| 1441 | return true; |
| 1442 | } |
| 1443 | String msg = "Permission Denial: " + func + " from pid=" |
| 1444 | + Binder.getCallingPid() |
| 1445 | + ", uid=" + Binder.getCallingUid() |
| 1446 | + " requires " + permission; |
| 1447 | Slog.w(TAG, msg); |
| 1448 | return false; |
| 1449 | } |
| 1450 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1451 | // Called by the heartbeat to ensure locks are not held indefinitely (for deadlock detection). |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1452 | @Override |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1453 | public void monitor() { |
| 1454 | synchronized (mInputFilterLock) { } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1455 | nativeMonitor(mPtr); |
Jeff Brown | 89ef072 | 2011-08-10 16:25:21 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1458 | // Native callback. |
| 1459 | private void notifyConfigurationChanged(long whenNanos) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1460 | mWindowManagerCallbacks.notifyConfigurationChanged(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | // Native callback. |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1464 | private void notifyInputDevicesChanged(InputDevice[] inputDevices) { |
| 1465 | synchronized (mInputDevicesLock) { |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1466 | if (!mInputDevicesChangedPending) { |
| 1467 | mInputDevicesChangedPending = true; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1468 | mHandler.obtainMessage(MSG_DELIVER_INPUT_DEVICES_CHANGED, |
| 1469 | mInputDevices).sendToTarget(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1470 | } |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1471 | |
| 1472 | mInputDevices = inputDevices; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | // Native callback. |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 1477 | private void notifySwitch(long whenNanos, int switchValues, int switchMask) { |
| 1478 | if (DEBUG) { |
| 1479 | Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues) |
| 1480 | + ", mask=" + Integer.toHexString(switchMask)); |
| 1481 | } |
| 1482 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1483 | if ((switchMask & SW_LID_BIT) != 0) { |
| 1484 | final boolean lidOpen = ((switchValues & SW_LID_BIT) == 0); |
Jeff Brown | bcc046a | 2012-09-27 20:46:43 -0700 | [diff] [blame] | 1485 | mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen); |
Jeff Brown | 5338428 | 2012-08-20 20:16:01 -0700 | [diff] [blame] | 1486 | } |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1487 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1488 | if ((switchMask & SW_CAMERA_LENS_COVER_BIT) != 0) { |
Michael Wright | 9e10d25 | 2014-09-13 19:41:20 -0700 | [diff] [blame] | 1489 | final boolean lensCovered = ((switchValues & SW_CAMERA_LENS_COVER_BIT) != 0); |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1490 | mWindowManagerCallbacks.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered); |
| 1491 | } |
| 1492 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1493 | if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) { |
| 1494 | mWiredAccessoryCallbacks.notifyWiredAccessoryChanged(whenNanos, switchValues, |
| 1495 | switchMask); |
| 1496 | } |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 1497 | |
| 1498 | if ((switchMask & SW_TABLET_MODE) != 0) { |
| 1499 | SomeArgs args = SomeArgs.obtain(); |
| 1500 | args.argi1 = (int) (whenNanos & 0xFFFFFFFF); |
| 1501 | args.argi2 = (int) (whenNanos >> 32); |
| 1502 | args.arg1 = Boolean.valueOf((switchValues & SW_TABLET_MODE_BIT) != 0); |
| 1503 | mHandler.obtainMessage(MSG_DELIVER_TABLET_MODE_CHANGED, |
| 1504 | args).sendToTarget(); |
| 1505 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | // Native callback. |
| 1509 | private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1510 | mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | // Native callback. |
| 1514 | private long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 1515 | InputWindowHandle inputWindowHandle, String reason) { |
| 1516 | return mWindowManagerCallbacks.notifyANR( |
| 1517 | inputApplicationHandle, inputWindowHandle, reason); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | // Native callback. |
| 1521 | final boolean filterInputEvent(InputEvent event, int policyFlags) { |
| 1522 | synchronized (mInputFilterLock) { |
| 1523 | if (mInputFilter != null) { |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1524 | try { |
| 1525 | mInputFilter.filterInputEvent(event, policyFlags); |
| 1526 | } catch (RemoteException e) { |
| 1527 | /* ignore */ |
| 1528 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | } |
| 1532 | event.recycle(); |
| 1533 | return true; |
| 1534 | } |
| 1535 | |
| 1536 | // Native callback. |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1537 | private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
| 1538 | return mWindowManagerCallbacks.interceptKeyBeforeQueueing(event, policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | // Native callback. |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 1542 | private int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 1543 | return mWindowManagerCallbacks.interceptMotionBeforeQueueingNonInteractive( |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 1544 | whenNanos, policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | // Native callback. |
| 1548 | private long interceptKeyBeforeDispatching(InputWindowHandle focus, |
| 1549 | KeyEvent event, int policyFlags) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1550 | return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | // Native callback. |
| 1554 | private KeyEvent dispatchUnhandledKey(InputWindowHandle focus, |
| 1555 | KeyEvent event, int policyFlags) { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1556 | return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | // Native callback. |
| 1560 | private boolean checkInjectEventsPermission(int injectorPid, int injectorUid) { |
| 1561 | return mContext.checkPermission(android.Manifest.permission.INJECT_EVENTS, |
| 1562 | injectorPid, injectorUid) == PackageManager.PERMISSION_GRANTED; |
| 1563 | } |
| 1564 | |
| 1565 | // Native callback. |
| 1566 | private int getVirtualKeyQuietTimeMillis() { |
| 1567 | return mContext.getResources().getInteger( |
| 1568 | com.android.internal.R.integer.config_virtualKeyQuietTimeMillis); |
| 1569 | } |
| 1570 | |
| 1571 | // Native callback. |
| 1572 | private String[] getExcludedDeviceNames() { |
| 1573 | ArrayList<String> names = new ArrayList<String>(); |
| 1574 | |
| 1575 | // Read partner-provided list of excluded input devices |
| 1576 | XmlPullParser parser = null; |
| 1577 | // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". |
| 1578 | File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH); |
| 1579 | FileReader confreader = null; |
| 1580 | try { |
| 1581 | confreader = new FileReader(confFile); |
| 1582 | parser = Xml.newPullParser(); |
| 1583 | parser.setInput(confreader); |
| 1584 | XmlUtils.beginDocument(parser, "devices"); |
| 1585 | |
| 1586 | while (true) { |
| 1587 | XmlUtils.nextElement(parser); |
| 1588 | if (!"device".equals(parser.getName())) { |
| 1589 | break; |
| 1590 | } |
| 1591 | String name = parser.getAttributeValue(null, "name"); |
| 1592 | if (name != null) { |
| 1593 | names.add(name); |
| 1594 | } |
| 1595 | } |
| 1596 | } catch (FileNotFoundException e) { |
| 1597 | // It's ok if the file does not exist. |
| 1598 | } catch (Exception e) { |
| 1599 | Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e); |
| 1600 | } finally { |
| 1601 | try { if (confreader != null) confreader.close(); } catch (IOException e) { } |
| 1602 | } |
| 1603 | |
| 1604 | return names.toArray(new String[names.size()]); |
| 1605 | } |
| 1606 | |
| 1607 | // Native callback. |
| 1608 | private int getKeyRepeatTimeout() { |
| 1609 | return ViewConfiguration.getKeyRepeatTimeout(); |
| 1610 | } |
| 1611 | |
| 1612 | // Native callback. |
| 1613 | private int getKeyRepeatDelay() { |
| 1614 | return ViewConfiguration.getKeyRepeatDelay(); |
| 1615 | } |
| 1616 | |
| 1617 | // Native callback. |
| 1618 | private int getHoverTapTimeout() { |
| 1619 | return ViewConfiguration.getHoverTapTimeout(); |
| 1620 | } |
| 1621 | |
| 1622 | // Native callback. |
| 1623 | private int getHoverTapSlop() { |
| 1624 | return ViewConfiguration.getHoverTapSlop(); |
| 1625 | } |
| 1626 | |
| 1627 | // Native callback. |
| 1628 | private int getDoubleTapTimeout() { |
| 1629 | return ViewConfiguration.getDoubleTapTimeout(); |
| 1630 | } |
| 1631 | |
| 1632 | // Native callback. |
| 1633 | private int getLongPressTimeout() { |
| 1634 | return ViewConfiguration.getLongPressTimeout(); |
| 1635 | } |
| 1636 | |
| 1637 | // Native callback. |
| 1638 | private int getPointerLayer() { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1639 | return mWindowManagerCallbacks.getPointerLayer(); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | // Native callback. |
| 1643 | private PointerIcon getPointerIcon() { |
| 1644 | return PointerIcon.getDefaultIcon(mContext); |
| 1645 | } |
| 1646 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1647 | // Native callback. |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1648 | private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1649 | if (!mSystemReady) { |
| 1650 | return null; |
| 1651 | } |
| 1652 | |
RoboErik | fb290df | 2013-12-16 11:27:55 -0800 | [diff] [blame] | 1653 | String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1654 | if (keyboardLayoutDescriptor == null) { |
| 1655 | return null; |
| 1656 | } |
| 1657 | |
| 1658 | final String[] result = new String[2]; |
| 1659 | visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() { |
| 1660 | @Override |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 1661 | public void visitKeyboardLayout(Resources resources, String descriptor, String label, |
| 1662 | String collection, int keyboardLayoutResId, int priority) { |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1663 | try { |
| 1664 | result[0] = descriptor; |
| 1665 | result[1] = Streams.readFully(new InputStreamReader( |
Jeff Brown | 2f09576 | 2012-05-10 21:29:33 -0700 | [diff] [blame] | 1666 | resources.openRawResource(keyboardLayoutResId))); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1667 | } catch (IOException ex) { |
| 1668 | } catch (NotFoundException ex) { |
| 1669 | } |
| 1670 | } |
| 1671 | }); |
| 1672 | if (result[0] == null) { |
| 1673 | Log.w(TAG, "Could not get keyboard layout with descriptor '" |
| 1674 | + keyboardLayoutDescriptor + "'."); |
| 1675 | return null; |
| 1676 | } |
| 1677 | return result; |
| 1678 | } |
| 1679 | |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1680 | // Native callback. |
| 1681 | private String getDeviceAlias(String uniqueId) { |
Matthew Xie | 9631314 | 2012-06-29 16:57:31 -0700 | [diff] [blame] | 1682 | if (BluetoothAdapter.checkBluetoothAddress(uniqueId)) { |
| 1683 | // TODO(BT) mBluetoothService.getRemoteAlias(uniqueId) |
| 1684 | return null; |
Jeff Brown | 5bbd4b4 | 2012-04-20 19:28:00 -0700 | [diff] [blame] | 1685 | } |
| 1686 | return null; |
| 1687 | } |
| 1688 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1689 | /** |
| 1690 | * Callback interface implemented by the Window Manager. |
| 1691 | */ |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1692 | public interface WindowManagerCallbacks { |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1693 | public void notifyConfigurationChanged(); |
| 1694 | |
| 1695 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen); |
| 1696 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 1697 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered); |
| 1698 | |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1699 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle); |
| 1700 | |
| 1701 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 1702 | InputWindowHandle inputWindowHandle, String reason); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1703 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1704 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1705 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 1706 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags); |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1707 | |
| 1708 | public long interceptKeyBeforeDispatching(InputWindowHandle focus, |
| 1709 | KeyEvent event, int policyFlags); |
| 1710 | |
| 1711 | public KeyEvent dispatchUnhandledKey(InputWindowHandle focus, |
| 1712 | KeyEvent event, int policyFlags); |
| 1713 | |
| 1714 | public int getPointerLayer(); |
| 1715 | } |
| 1716 | |
| 1717 | /** |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1718 | * Callback interface implemented by WiredAccessoryObserver. |
| 1719 | */ |
| 1720 | public interface WiredAccessoryCallbacks { |
| 1721 | public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask); |
Eric Laurent | 4a5eeb9 | 2014-05-06 10:49:04 -0700 | [diff] [blame] | 1722 | public void systemReady(); |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | /** |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1726 | * Private handler for the input manager. |
| 1727 | */ |
| 1728 | private final class InputManagerHandler extends Handler { |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 1729 | public InputManagerHandler(Looper looper) { |
| 1730 | super(looper, null, true /*async*/); |
Jeff Brown | a2910d0 | 2012-08-25 12:29:46 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1733 | @Override |
| 1734 | public void handleMessage(Message msg) { |
| 1735 | switch (msg.what) { |
| 1736 | case MSG_DELIVER_INPUT_DEVICES_CHANGED: |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 1737 | deliverInputDevicesChanged((InputDevice[])msg.obj); |
| 1738 | break; |
| 1739 | case MSG_SWITCH_KEYBOARD_LAYOUT: |
| 1740 | handleSwitchKeyboardLayout(msg.arg1, msg.arg2); |
| 1741 | break; |
| 1742 | case MSG_RELOAD_KEYBOARD_LAYOUTS: |
| 1743 | reloadKeyboardLayouts(); |
| 1744 | break; |
| 1745 | case MSG_UPDATE_KEYBOARD_LAYOUTS: |
| 1746 | updateKeyboardLayouts(); |
| 1747 | break; |
| 1748 | case MSG_RELOAD_DEVICE_ALIASES: |
| 1749 | reloadDeviceAliases(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1750 | break; |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 1751 | case MSG_DELIVER_TABLET_MODE_CHANGED: |
| 1752 | SomeArgs args = (SomeArgs) msg.obj; |
| 1753 | long whenNanos = (args.argi1 & 0xFFFFFFFFl) | ((long) args.argi2 << 32); |
| 1754 | boolean inTabletMode = (boolean) args.arg1; |
| 1755 | deliverTabletModeChanged(whenNanos, inTabletMode); |
| 1756 | break; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | /** |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 1762 | * Hosting interface for input filters to call back into the input manager. |
| 1763 | */ |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1764 | private final class InputFilterHost extends IInputFilterHost.Stub { |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1765 | private boolean mDisconnected; |
| 1766 | |
| 1767 | public void disconnectLocked() { |
| 1768 | mDisconnected = true; |
| 1769 | } |
| 1770 | |
Craig Mautner | 2f39e9f | 2012-09-21 11:39:54 -0700 | [diff] [blame] | 1771 | @Override |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1772 | public void sendInputEvent(InputEvent event, int policyFlags) { |
| 1773 | if (event == null) { |
| 1774 | throw new IllegalArgumentException("event must not be null"); |
| 1775 | } |
| 1776 | |
| 1777 | synchronized (mInputFilterLock) { |
| 1778 | if (!mDisconnected) { |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 1779 | nativeInjectInputEvent(mPtr, event, Display.DEFAULT_DISPLAY, 0, 0, |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 1780 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, 0, |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 1781 | policyFlags | WindowManagerPolicy.FLAG_FILTERED); |
| 1782 | } |
| 1783 | } |
| 1784 | } |
| 1785 | } |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 1786 | |
| 1787 | private static final class KeyboardLayoutDescriptor { |
| 1788 | public String packageName; |
| 1789 | public String receiverName; |
| 1790 | public String keyboardLayoutName; |
| 1791 | |
| 1792 | public static String format(String packageName, |
| 1793 | String receiverName, String keyboardName) { |
| 1794 | return packageName + "/" + receiverName + "/" + keyboardName; |
| 1795 | } |
| 1796 | |
| 1797 | public static KeyboardLayoutDescriptor parse(String descriptor) { |
| 1798 | int pos = descriptor.indexOf('/'); |
| 1799 | if (pos < 0 || pos + 1 == descriptor.length()) { |
| 1800 | return null; |
| 1801 | } |
| 1802 | int pos2 = descriptor.indexOf('/', pos + 1); |
| 1803 | if (pos2 < pos + 2 || pos2 + 1 == descriptor.length()) { |
| 1804 | return null; |
| 1805 | } |
| 1806 | |
| 1807 | KeyboardLayoutDescriptor result = new KeyboardLayoutDescriptor(); |
| 1808 | result.packageName = descriptor.substring(0, pos); |
| 1809 | result.receiverName = descriptor.substring(pos + 1, pos2); |
| 1810 | result.keyboardLayoutName = descriptor.substring(pos2 + 1); |
| 1811 | return result; |
| 1812 | } |
| 1813 | } |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1814 | |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1815 | private interface KeyboardLayoutVisitor { |
Michael Wright | 8ebac23 | 2014-09-18 18:29:49 -0700 | [diff] [blame] | 1816 | void visitKeyboardLayout(Resources resources, String descriptor, String label, |
| 1817 | String collection, int keyboardLayoutResId, int priority); |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 1820 | private final class InputDevicesChangedListenerRecord implements DeathRecipient { |
| 1821 | private final int mPid; |
| 1822 | private final IInputDevicesChangedListener mListener; |
| 1823 | |
| 1824 | public InputDevicesChangedListenerRecord(int pid, IInputDevicesChangedListener listener) { |
| 1825 | mPid = pid; |
| 1826 | mListener = listener; |
| 1827 | } |
| 1828 | |
| 1829 | @Override |
| 1830 | public void binderDied() { |
| 1831 | if (DEBUG) { |
| 1832 | Slog.d(TAG, "Input devices changed listener for pid " + mPid + " died."); |
| 1833 | } |
| 1834 | onInputDevicesChangedListenerDied(mPid); |
| 1835 | } |
| 1836 | |
| 1837 | public void notifyInputDevicesChanged(int[] info) { |
| 1838 | try { |
| 1839 | mListener.onInputDevicesChanged(info); |
| 1840 | } catch (RemoteException ex) { |
| 1841 | Slog.w(TAG, "Failed to notify process " |
| 1842 | + mPid + " that input devices changed, assuming it died.", ex); |
| 1843 | binderDied(); |
| 1844 | } |
| 1845 | } |
| 1846 | } |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1847 | |
Michael Wright | 39e5e94 | 2015-08-19 22:52:47 +0100 | [diff] [blame] | 1848 | private final class TabletModeChangedListenerRecord implements DeathRecipient { |
| 1849 | private final int mPid; |
| 1850 | private final ITabletModeChangedListener mListener; |
| 1851 | |
| 1852 | public TabletModeChangedListenerRecord(int pid, ITabletModeChangedListener listener) { |
| 1853 | mPid = pid; |
| 1854 | mListener = listener; |
| 1855 | } |
| 1856 | |
| 1857 | @Override |
| 1858 | public void binderDied() { |
| 1859 | if (DEBUG) { |
| 1860 | Slog.d(TAG, "Tablet mode changed listener for pid " + mPid + " died."); |
| 1861 | } |
| 1862 | onTabletModeChangedListenerDied(mPid); |
| 1863 | } |
| 1864 | |
| 1865 | public void notifyTabletModeChanged(long whenNanos, boolean inTabletMode) { |
| 1866 | try { |
| 1867 | mListener.onTabletModeChanged(whenNanos, inTabletMode); |
| 1868 | } catch (RemoteException ex) { |
| 1869 | Slog.w(TAG, "Failed to notify process " + mPid + |
| 1870 | " that tablet mode changed, assuming it died.", ex); |
| 1871 | binderDied(); |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 1876 | private final class VibratorToken implements DeathRecipient { |
| 1877 | public final int mDeviceId; |
| 1878 | public final IBinder mToken; |
| 1879 | public final int mTokenValue; |
| 1880 | |
| 1881 | public boolean mVibrating; |
| 1882 | |
| 1883 | public VibratorToken(int deviceId, IBinder token, int tokenValue) { |
| 1884 | mDeviceId = deviceId; |
| 1885 | mToken = token; |
| 1886 | mTokenValue = tokenValue; |
| 1887 | } |
| 1888 | |
| 1889 | @Override |
| 1890 | public void binderDied() { |
| 1891 | if (DEBUG) { |
| 1892 | Slog.d(TAG, "Vibrator token died."); |
| 1893 | } |
| 1894 | onVibratorTokenDied(this); |
| 1895 | } |
| 1896 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1897 | |
| 1898 | private final class LocalService extends InputManagerInternal { |
| 1899 | @Override |
| 1900 | public void setDisplayViewports( |
| 1901 | DisplayViewport defaultViewport, DisplayViewport externalTouchViewport) { |
| 1902 | setDisplayViewportsInternal(defaultViewport, externalTouchViewport); |
| 1903 | } |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 1904 | |
| 1905 | @Override |
| 1906 | public boolean injectInputEvent(InputEvent event, int displayId, int mode) { |
| 1907 | return injectInputEventInternal(event, displayId, mode); |
| 1908 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1909 | |
| 1910 | @Override |
| 1911 | public void setInteractive(boolean interactive) { |
| 1912 | nativeSetInteractive(mPtr, interactive); |
| 1913 | } |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 1914 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1915 | } |