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