Dianne Hackborn | f56e102 | 2011-02-22 10:47:13 -0800 | [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. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 15 | */ |
Dianne Hackborn | f56e102 | 2011-02-22 10:47:13 -0800 | [diff] [blame] | 16 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
| 18 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 19 | import static android.view.Display.DEFAULT_DISPLAY; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 20 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 21 | import static android.view.WindowManager.INPUT_CONSUMER_PIP; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 22 | import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 23 | import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER; |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS; |
| 26 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 29 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT; |
| 33 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
| 34 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 35 | |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 36 | import android.app.ActivityManager; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 37 | import android.graphics.Rect; |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 38 | import android.os.Debug; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 39 | import android.os.IBinder; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 40 | import android.os.Looper; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 41 | import android.os.Process; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 42 | import android.os.RemoteException; |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 43 | import android.os.Trace; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 44 | import android.os.UserHandle; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 45 | import android.util.ArrayMap; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 46 | import android.util.Log; |
| 47 | import android.util.Slog; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 48 | import android.view.InputChannel; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 49 | import android.view.InputEventReceiver; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 50 | import android.view.KeyEvent; |
| 51 | import android.view.WindowManager; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 52 | |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 53 | import com.android.server.input.InputApplicationHandle; |
| 54 | import com.android.server.input.InputManagerService; |
| 55 | import com.android.server.input.InputWindowHandle; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 56 | import com.android.server.policy.WindowManagerPolicy; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 57 | |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 58 | import java.io.PrintWriter; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 59 | import java.util.Arrays; |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 60 | import java.util.Set; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 61 | import java.util.function.Consumer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 62 | |
Jeff Brown | a9d131c | 2012-09-20 16:48:17 -0700 | [diff] [blame] | 63 | final class InputMonitor implements InputManagerService.WindowManagerCallbacks { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 64 | private final WindowManagerService mService; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 65 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 66 | // Current window with input focus for keys and other non-touch events. May be null. |
| 67 | private WindowState mInputFocus; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 68 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 69 | // When true, prevents input dispatch from proceeding until set to false again. |
| 70 | private boolean mInputDispatchFrozen; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 71 | |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 72 | // The reason the input is currently frozen or null if the input isn't frozen. |
| 73 | private String mInputFreezeReason = null; |
| 74 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 75 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
Jeff Brown | c042ee2 | 2012-05-08 13:03:42 -0700 | [diff] [blame] | 76 | // Initially false, so that input does not get dispatched until boot is finished at |
| 77 | // which point the ActivityManager will enable dispatching. |
| 78 | private boolean mInputDispatchEnabled; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 79 | |
| 80 | // When true, need to call updateInputWindowsLw(). |
| 81 | private boolean mUpdateInputWindowsNeeded = true; |
| 82 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 83 | // Array of window handles to provide to the input dispatcher. |
| 84 | private InputWindowHandle[] mInputWindowHandles; |
| 85 | private int mInputWindowHandleCount; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 86 | private InputWindowHandle mFocusedInputWindowHandle; |
| 87 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 88 | private boolean mAddInputConsumerHandle; |
| 89 | private boolean mAddPipInputConsumerHandle; |
| 90 | private boolean mAddWallpaperInputConsumerHandle; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 91 | private boolean mAddRecentsAnimationInputConsumerHandle; |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 92 | private boolean mDisableWallpaperTouchEvents; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 93 | private final Rect mTmpRect = new Rect(); |
| 94 | private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer = |
| 95 | new UpdateInputForAllWindowsConsumer(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 96 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 97 | // Set to true when the first input device configuration change notification |
| 98 | // is received to indicate that the input devices are ready. |
| 99 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 100 | private boolean mInputDevicesReady; |
| 101 | |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 102 | /** |
| 103 | * The set of input consumer added to the window manager by name, which consumes input events |
| 104 | * for the windows below it. |
| 105 | */ |
| 106 | private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap(); |
| 107 | |
| 108 | private static final class EventReceiverInputConsumer extends InputConsumerImpl |
| 109 | implements WindowManagerPolicy.InputConsumer { |
| 110 | private InputMonitor mInputMonitor; |
| 111 | private final InputEventReceiver mInputEventReceiver; |
| 112 | |
| 113 | EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor, |
| 114 | Looper looper, String name, |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 115 | InputEventReceiver.Factory inputEventReceiverFactory, |
| 116 | int clientPid, UserHandle clientUser) { |
| 117 | super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 118 | mInputMonitor = monitor; |
| 119 | mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver( |
| 120 | mClientChannel, looper); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void dismiss() { |
| 125 | synchronized (mService.mWindowMap) { |
| 126 | if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) { |
| 127 | mInputEventReceiver.dispose(); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 133 | public InputMonitor(WindowManagerService service) { |
| 134 | mService = service; |
| 135 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 136 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 137 | private void addInputConsumer(String name, InputConsumerImpl consumer) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 138 | mInputConsumers.put(name, consumer); |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 139 | consumer.linkToDeathRecipient(); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 140 | updateInputWindowsLw(true /* force */); |
| 141 | } |
| 142 | |
| 143 | boolean destroyInputConsumer(String name) { |
| 144 | if (disposeInputConsumer(mInputConsumers.remove(name))) { |
| 145 | updateInputWindowsLw(true /* force */); |
| 146 | return true; |
| 147 | } |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | private boolean disposeInputConsumer(InputConsumerImpl consumer) { |
| 152 | if (consumer != null) { |
| 153 | consumer.disposeChannelsLw(); |
| 154 | return true; |
| 155 | } |
| 156 | return false; |
| 157 | } |
| 158 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 159 | InputConsumerImpl getInputConsumer(String name, int displayId) { |
| 160 | // TODO(multi-display): Allow input consumers on non-default displays? |
| 161 | return (displayId == DEFAULT_DISPLAY) ? mInputConsumers.get(name) : null; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void layoutInputConsumers(int dw, int dh) { |
| 165 | for (int i = mInputConsumers.size() - 1; i >= 0; i--) { |
| 166 | mInputConsumers.valueAt(i).layout(dw, dh); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name, |
| 171 | InputEventReceiver.Factory inputEventReceiverFactory) { |
| 172 | if (mInputConsumers.containsKey(name)) { |
| 173 | throw new IllegalStateException("Existing input consumer found with name: " + name); |
| 174 | } |
| 175 | |
| 176 | final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService, |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 177 | this, looper, name, inputEventReceiverFactory, Process.myPid(), |
| 178 | UserHandle.SYSTEM); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 179 | addInputConsumer(name, consumer); |
| 180 | return consumer; |
| 181 | } |
| 182 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 183 | void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid, |
| 184 | UserHandle clientUser) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 185 | if (mInputConsumers.containsKey(name)) { |
| 186 | throw new IllegalStateException("Existing input consumer found with name: " + name); |
| 187 | } |
| 188 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 189 | final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name, |
| 190 | inputChannel, clientPid, clientUser); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 191 | switch (name) { |
| 192 | case INPUT_CONSUMER_WALLPAPER: |
| 193 | consumer.mWindowHandle.hasWallpaper = true; |
| 194 | break; |
| 195 | case INPUT_CONSUMER_PIP: |
| 196 | // The touchable region of the Pip input window is cropped to the bounds of the |
| 197 | // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 198 | consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 199 | break; |
| 200 | } |
| 201 | addInputConsumer(name, consumer); |
| 202 | } |
| 203 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 204 | /* Notifies the window manager about a broken input channel. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 205 | * |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 206 | * Called by the InputManager. |
| 207 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 208 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 209 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 210 | if (inputWindowHandle == null) { |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | synchronized (mService.mWindowMap) { |
| 215 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 216 | if (windowState != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 217 | Slog.i(TAG_WM, "WINDOW DIED " + windowState); |
Wale Ogunwale | 92fc372 | 2016-08-05 12:19:08 -0700 | [diff] [blame] | 218 | windowState.removeIfPossible(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 219 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 220 | } |
| 221 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 222 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | /* Notifies the window manager about an application that is not responding. |
| 224 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 225 | * |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 226 | * Called by the InputManager. |
| 227 | */ |
Craig Mautner | 4cd0c13f | 2013-04-16 15:55:52 -0700 | [diff] [blame] | 228 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 229 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 230 | InputWindowHandle inputWindowHandle, String reason) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 231 | AppWindowToken appWindowToken = null; |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 232 | WindowState windowState = null; |
| 233 | boolean aboveSystem = false; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 234 | synchronized (mService.mWindowMap) { |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 235 | if (inputWindowHandle != null) { |
| 236 | windowState = (WindowState) inputWindowHandle.windowState; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 237 | if (windowState != null) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 238 | appWindowToken = windowState.mAppToken; |
| 239 | } |
| 240 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 241 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 242 | appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 243 | } |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 244 | |
| 245 | if (windowState != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 246 | Slog.i(TAG_WM, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 247 | + "sending to " + windowState.mAttrs.getTitle() |
| 248 | + ". Reason: " + reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 249 | // Figure out whether this window is layered above system windows. |
| 250 | // We need to do this here to help the activity manager know how to |
| 251 | // layer its ANR dialog. |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 252 | int systemAlertLayer = mService.mPolicy.getWindowLayerFromTypeLw( |
| 253 | TYPE_APPLICATION_OVERLAY, windowState.mOwnerCanAddInternalSystemWindow); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 254 | aboveSystem = windowState.mBaseLayer > systemAlertLayer; |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 255 | } else if (appWindowToken != null) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 256 | Slog.i(TAG_WM, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 257 | + "sending to application " + appWindowToken.stringName |
| 258 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 259 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 260 | Slog.i(TAG_WM, "Input event dispatching timed out " |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 261 | + ". Reason: " + reason); |
Jeff Brown | ee17241 | 2012-06-18 12:58:03 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 264 | mService.saveANRStateLocked(appWindowToken, windowState, reason); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Wale Ogunwale | f128591 | 2017-06-09 15:20:29 -0700 | [diff] [blame] | 267 | // All the calls below need to happen without the WM lock held since they call into AM. |
| 268 | mService.mAmInternal.saveANRState(reason); |
| 269 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 270 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 271 | // Notify the activity manager about the timeout and let it decide whether |
| 272 | // to abort dispatching or keep waiting. |
| 273 | final AppWindowContainerController controller = appWindowToken.getController(); |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 274 | final boolean abort = controller != null |
Brian Carlstrom | 7b0f2e8 | 2017-03-31 00:24:18 -0700 | [diff] [blame] | 275 | && controller.keyDispatchingTimedOut(reason, |
| 276 | (windowState != null) ? windowState.mSession.mPid : -1); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 277 | if (!abort) { |
| 278 | // The activity manager declined to abort dispatching. |
| 279 | // Wait a bit longer and timeout again later. |
| 280 | return appWindowToken.mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 281 | } |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 282 | } else if (windowState != null) { |
| 283 | try { |
| 284 | // Notify the activity manager about the timeout and let it decide whether |
| 285 | // to abort dispatching or keep waiting. |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 286 | long timeout = ActivityManager.getService().inputDispatchingTimedOut( |
Jeff Brown | bd181bb | 2013-09-10 16:44:24 -0700 | [diff] [blame] | 287 | windowState.mSession.mPid, aboveSystem, reason); |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 288 | if (timeout >= 0) { |
| 289 | // The activity manager declined to abort dispatching. |
| 290 | // Wait a bit longer and timeout again later. |
baik.han | def340d | 2015-04-15 10:21:05 +0900 | [diff] [blame] | 291 | return timeout * 1000000L; // nanoseconds |
Dianne Hackborn | 5fe7e2a | 2012-10-04 11:58:16 -0700 | [diff] [blame] | 292 | } |
| 293 | } catch (RemoteException ex) { |
| 294 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 295 | } |
| 296 | return 0; // abort dispatching |
| 297 | } |
| 298 | |
Wale Ogunwale | 7402ddf | 2017-03-29 12:58:24 -0700 | [diff] [blame] | 299 | private void addInputWindowHandle(final InputWindowHandle windowHandle) { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 300 | if (mInputWindowHandles == null) { |
| 301 | mInputWindowHandles = new InputWindowHandle[16]; |
| 302 | } |
| 303 | if (mInputWindowHandleCount >= mInputWindowHandles.length) { |
| 304 | mInputWindowHandles = Arrays.copyOf(mInputWindowHandles, |
| 305 | mInputWindowHandleCount * 2); |
| 306 | } |
| 307 | mInputWindowHandles[mInputWindowHandleCount++] = windowHandle; |
| 308 | } |
| 309 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 310 | void addInputWindowHandle(final InputWindowHandle inputWindowHandle, |
Craig Mautner | c08eab8 | 2014-11-11 09:03:59 -0800 | [diff] [blame] | 311 | final WindowState child, int flags, final int type, final boolean isVisible, |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 312 | final boolean hasFocus, final boolean hasWallpaper) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 313 | // Add a window to our list of input windows. |
| 314 | inputWindowHandle.name = child.toString(); |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 315 | flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 316 | inputWindowHandle.layoutParamsFlags = flags; |
| 317 | inputWindowHandle.layoutParamsType = type; |
| 318 | inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 319 | inputWindowHandle.visible = isVisible; |
| 320 | inputWindowHandle.canReceiveKeys = child.canReceiveKeys(); |
| 321 | inputWindowHandle.hasFocus = hasFocus; |
| 322 | inputWindowHandle.hasWallpaper = hasWallpaper; |
| 323 | inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 324 | inputWindowHandle.layer = child.mLayer; |
| 325 | inputWindowHandle.ownerPid = child.mSession.mPid; |
| 326 | inputWindowHandle.ownerUid = child.mSession.mUid; |
| 327 | inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures; |
| 328 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 329 | final Rect frame = child.getFrameLw(); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 330 | inputWindowHandle.frameLeft = frame.left; |
| 331 | inputWindowHandle.frameTop = frame.top; |
| 332 | inputWindowHandle.frameRight = frame.right; |
| 333 | inputWindowHandle.frameBottom = frame.bottom; |
| 334 | |
| 335 | if (child.mGlobalScale != 1) { |
| 336 | // If we are scaling the window, input coordinates need |
| 337 | // to be inversely scaled to map from what is on screen |
| 338 | // to what is actually being touched in the UI. |
| 339 | inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale; |
| 340 | } else { |
| 341 | inputWindowHandle.scaleFactor = 1; |
| 342 | } |
| 343 | |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 344 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 345 | Slog.d(TAG_WM, "addInputWindowHandle: " |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 346 | + child + ", " + inputWindowHandle); |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 347 | } |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 348 | addInputWindowHandle(inputWindowHandle); |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 349 | if (hasFocus) { |
| 350 | mFocusedInputWindowHandle = inputWindowHandle; |
| 351 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 354 | private void clearInputWindowHandlesLw() { |
| 355 | while (mInputWindowHandleCount != 0) { |
| 356 | mInputWindowHandles[--mInputWindowHandleCount] = null; |
| 357 | } |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 358 | mFocusedInputWindowHandle = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 361 | void setUpdateInputWindowsNeededLw() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 362 | mUpdateInputWindowsNeeded = true; |
| 363 | } |
| 364 | |
| 365 | /* Updates the cached window information provided to the input dispatcher. */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 366 | void updateInputWindowsLw(boolean force) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 367 | if (!force && !mUpdateInputWindowsNeeded) { |
| 368 | return; |
| 369 | } |
| 370 | mUpdateInputWindowsNeeded = false; |
| 371 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 372 | if (false) Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw"); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 373 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 374 | // Populate the input window list with information about all of the windows that |
| 375 | // could potentially receive input. |
| 376 | // As an optimization, we could try to prune the list of windows but this turns |
| 377 | // out to be difficult because only the native code knows for sure which window |
| 378 | // currently has touch focus. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 379 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 380 | // If there's a drag in flight, provide a pseudo-window to catch drag input |
Daichi Hirono | 76a26aa | 2017-09-11 15:13:38 +0900 | [diff] [blame] | 381 | final boolean inDrag = mService.mDragDropController.dragDropActiveLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 382 | if (inDrag) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 383 | if (DEBUG_DRAG) { |
| 384 | Log.d(TAG_WM, "Inserting drag window"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 385 | } |
Daichi Hirono | 76a26aa | 2017-09-11 15:13:38 +0900 | [diff] [blame] | 386 | final InputWindowHandle dragWindowHandle = |
Daichi Hirono | 768012e | 2017-10-30 10:05:37 +0900 | [diff] [blame] | 387 | mService.mDragDropController.getInputWindowHandleLocked(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 388 | if (dragWindowHandle != null) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 389 | addInputWindowHandle(dragWindowHandle); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 390 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 391 | Slog.w(TAG_WM, "Drag is in progress but there is no " |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 392 | + "drag window handle."); |
| 393 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 396 | final boolean inPositioning = mService.mTaskPositioningController.isPositioningLocked(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 397 | if (inPositioning) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 398 | if (DEBUG_TASK_POSITIONING) { |
| 399 | Log.d(TAG_WM, "Inserting window handle for repositioning"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 400 | } |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 401 | final InputWindowHandle dragWindowHandle = |
| 402 | mService.mTaskPositioningController.getDragWindowHandleLocked(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 403 | if (dragWindowHandle != null) { |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 404 | addInputWindowHandle(dragWindowHandle); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 405 | } else { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 406 | Slog.e(TAG_WM, |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 407 | "Repositioning is in progress but there is no drag window handle."); |
| 408 | } |
| 409 | } |
| 410 | |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 411 | // Add all windows on the default display. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 412 | mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 413 | |
| 414 | if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw"); |
| 415 | } |
| 416 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 417 | /* Notifies that the input device configuration has changed. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 418 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 419 | public void notifyConfigurationChanged() { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 420 | // TODO(multi-display): Notify proper displays that are associated with this input device. |
| 421 | mService.sendNewConfiguration(DEFAULT_DISPLAY); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 422 | |
| 423 | synchronized (mInputDevicesReadyMonitor) { |
| 424 | if (!mInputDevicesReady) { |
| 425 | mInputDevicesReady = true; |
| 426 | mInputDevicesReadyMonitor.notifyAll(); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /* Waits until the built-in input devices have been configured. */ |
| 432 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 433 | synchronized (mInputDevicesReadyMonitor) { |
| 434 | if (!mInputDevicesReady) { |
| 435 | try { |
| 436 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 437 | } catch (InterruptedException ex) { |
| 438 | } |
| 439 | } |
| 440 | return mInputDevicesReady; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | /* Notifies that the lid switch changed state. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 445 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 446 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 447 | mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 448 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 449 | |
Michael Wright | 3818c92 | 2014-09-02 13:59:07 -0700 | [diff] [blame] | 450 | /* Notifies that the camera lens cover state has changed. */ |
| 451 | @Override |
| 452 | public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) { |
| 453 | mService.mPolicy.notifyCameraLensCoverSwitchChanged(whenNanos, lensCovered); |
| 454 | } |
| 455 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 456 | /* Provides an opportunity for the window manager policy to intercept early key |
| 457 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 458 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 459 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
| 460 | return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 461 | } |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 462 | |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 463 | /* Provides an opportunity for the window manager policy to intercept early motion event |
| 464 | * processing when the device is in a non-interactive state since these events are normally |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 465 | * dropped. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 466 | @Override |
Michael Wright | 70af00a | 2014-09-03 19:30:20 -0700 | [diff] [blame] | 467 | public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) { |
| 468 | return mService.mPolicy.interceptMotionBeforeQueueingNonInteractive( |
| 469 | whenNanos, policyFlags); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 472 | /* Provides an opportunity for the window manager policy to process a key before |
| 473 | * ordinary dispatch. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 474 | @Override |
Jeff Brown | 905805a | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 475 | public long interceptKeyBeforeDispatching( |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 476 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 477 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 478 | return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
| 479 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 480 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 481 | /* Provides an opportunity for the window manager policy to process a key that |
| 482 | * the application did not handle. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 483 | @Override |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 484 | public KeyEvent dispatchUnhandledKey( |
| 485 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| 486 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| 487 | return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
| 488 | } |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 489 | |
| 490 | /* Callback to get pointer layer. */ |
Jeff Brown | 0b31d81 | 2013-08-22 19:41:29 -0700 | [diff] [blame] | 491 | @Override |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 492 | public int getPointerLayer() { |
Wale Ogunwale | 5cd907d | 2017-01-26 14:14:08 -0800 | [diff] [blame] | 493 | return mService.mPolicy.getWindowLayerFromTypeLw(WindowManager.LayoutParams.TYPE_POINTER) |
Jeff Brown | 4532e61 | 2012-04-05 14:27:12 -0700 | [diff] [blame] | 494 | * WindowManagerService.TYPE_LAYER_MULTIPLIER |
| 495 | + WindowManagerService.TYPE_LAYER_OFFSET; |
| 496 | } |
| 497 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 498 | /* Called when the current input focus changes. |
| 499 | * Layer assignment is assumed to be complete by the time this is called. |
| 500 | */ |
| 501 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 502 | if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 503 | Slog.d(TAG_WM, "Input focus has changed to " + newWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | if (newWindow != mInputFocus) { |
| 507 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 508 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 509 | // This is to protect against bugs if someone pauses dispatching but |
| 510 | // forgets to resume. |
| 511 | newWindow.mToken.paused = false; |
| 512 | } |
| 513 | |
| 514 | mInputFocus = newWindow; |
| 515 | setUpdateInputWindowsNeededLw(); |
| 516 | |
| 517 | if (updateInputWindows) { |
| 518 | updateInputWindowsLw(false /*force*/); |
| 519 | } |
| 520 | } |
| 521 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 522 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 523 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 524 | // Focused app has changed. |
| 525 | if (newApp == null) { |
| 526 | mService.mInputManager.setFocusedApplication(null); |
| 527 | } else { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 528 | final InputApplicationHandle handle = newApp.mInputApplicationHandle; |
| 529 | handle.name = newApp.toString(); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 530 | handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 531 | |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 532 | mService.mInputManager.setFocusedApplication(handle); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 535 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 536 | public void pauseDispatchingLw(WindowToken window) { |
| 537 | if (! window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 538 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 539 | Slog.v(TAG_WM, "Pausing WindowToken " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 540 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 541 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 542 | window.paused = true; |
| 543 | updateInputWindowsLw(true /*force*/); |
| 544 | } |
| 545 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 546 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 547 | public void resumeDispatchingLw(WindowToken window) { |
| 548 | if (window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 549 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 550 | Slog.v(TAG_WM, "Resuming WindowToken " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 551 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 552 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 553 | window.paused = false; |
| 554 | updateInputWindowsLw(true /*force*/); |
| 555 | } |
| 556 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 557 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 558 | public void freezeInputDispatchingLw() { |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 559 | if (!mInputDispatchFrozen) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 560 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 561 | Slog.v(TAG_WM, "Freezing input dispatching"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 562 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 563 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 564 | mInputDispatchFrozen = true; |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 565 | |
| 566 | if (DEBUG_INPUT || true) { |
| 567 | mInputFreezeReason = Debug.getCallers(6); |
| 568 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 569 | updateInputDispatchModeLw(); |
| 570 | } |
| 571 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 572 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 573 | public void thawInputDispatchingLw() { |
| 574 | if (mInputDispatchFrozen) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 575 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 576 | Slog.v(TAG_WM, "Thawing input dispatching"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 577 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 578 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 579 | mInputDispatchFrozen = false; |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 580 | mInputFreezeReason = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 581 | updateInputDispatchModeLw(); |
| 582 | } |
| 583 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 584 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 585 | public void setEventDispatchingLw(boolean enabled) { |
| 586 | if (mInputDispatchEnabled != enabled) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 587 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 588 | Slog.v(TAG_WM, "Setting event dispatching to " + enabled); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 589 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 590 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 591 | mInputDispatchEnabled = enabled; |
| 592 | updateInputDispatchModeLw(); |
| 593 | } |
| 594 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 595 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 596 | private void updateInputDispatchModeLw() { |
| 597 | mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 598 | } |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 599 | |
| 600 | void dump(PrintWriter pw, String prefix) { |
| 601 | if (mInputFreezeReason != null) { |
| 602 | pw.println(prefix + "mInputFreezeReason=" + mInputFreezeReason); |
| 603 | } |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 604 | final Set<String> inputConsumerKeys = mInputConsumers.keySet(); |
| 605 | if (!inputConsumerKeys.isEmpty()) { |
| 606 | pw.println(prefix + "InputConsumers:"); |
| 607 | for (String key : inputConsumerKeys) { |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 608 | mInputConsumers.get(key).dump(pw, key, prefix); |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 611 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 612 | |
| 613 | private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> { |
| 614 | |
| 615 | InputConsumerImpl navInputConsumer; |
| 616 | InputConsumerImpl pipInputConsumer; |
| 617 | InputConsumerImpl wallpaperInputConsumer; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 618 | InputConsumerImpl recentsAnimationInputConsumer; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 619 | boolean inDrag; |
| 620 | WallpaperController wallpaperController; |
| 621 | |
| 622 | private void updateInputWindows(boolean inDrag) { |
| 623 | |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 624 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows"); |
| 625 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 626 | // TODO: multi-display |
| 627 | navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION, DEFAULT_DISPLAY); |
| 628 | pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP, DEFAULT_DISPLAY); |
| 629 | wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER, DEFAULT_DISPLAY); |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 630 | recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION, |
| 631 | DEFAULT_DISPLAY); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 632 | mAddInputConsumerHandle = navInputConsumer != null; |
| 633 | mAddPipInputConsumerHandle = pipInputConsumer != null; |
| 634 | mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 635 | mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 636 | mTmpRect.setEmpty(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 637 | mDisableWallpaperTouchEvents = false; |
| 638 | this.inDrag = inDrag; |
| 639 | wallpaperController = mService.mRoot.mWallpaperController; |
| 640 | |
| 641 | mService.mRoot.forAllWindows(this, true /* traverseTopToBottom */); |
| 642 | if (mAddWallpaperInputConsumerHandle) { |
| 643 | // No visible wallpaper found, add the wallpaper input consumer at the end. |
| 644 | addInputWindowHandle(wallpaperInputConsumer.mWindowHandle); |
| 645 | } |
| 646 | |
| 647 | // Send windows to native code. |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 648 | mService.mInputManager.setInputWindows(mInputWindowHandles, mFocusedInputWindowHandle); |
Vladislav Kaznacheev | 2e96c63 | 2016-12-13 14:31:24 -0800 | [diff] [blame] | 649 | |
| 650 | clearInputWindowHandlesLw(); |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 651 | |
| 652 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | @Override |
| 656 | public void accept(WindowState w) { |
| 657 | final InputChannel inputChannel = w.mInputChannel; |
| 658 | final InputWindowHandle inputWindowHandle = w.mInputWindowHandle; |
| 659 | if (inputChannel == null || inputWindowHandle == null || w.mRemoved |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 660 | || w.canReceiveTouchInput()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 661 | // Skip this window because it cannot possibly receive input. |
| 662 | return; |
| 663 | } |
| 664 | |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 665 | final int flags = w.mAttrs.flags; |
| 666 | final int privateFlags = w.mAttrs.privateFlags; |
| 667 | final int type = w.mAttrs.type; |
| 668 | final boolean hasFocus = w == mInputFocus; |
| 669 | final boolean isVisible = w.isVisibleLw(); |
| 670 | |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 671 | if (mAddRecentsAnimationInputConsumerHandle) { |
| 672 | final RecentsAnimationController recentsAnimationController = |
| 673 | mService.getRecentsAnimationController(); |
| 674 | if (recentsAnimationController != null |
| 675 | && recentsAnimationController.hasInputConsumerForApp(w.mAppToken)) { |
| 676 | if (recentsAnimationController.updateInputConsumerForApp( |
| 677 | recentsAnimationInputConsumer, hasFocus)) { |
| 678 | addInputWindowHandle(recentsAnimationInputConsumer.mWindowHandle); |
| 679 | mAddRecentsAnimationInputConsumerHandle = false; |
| 680 | } |
| 681 | // Skip adding the window below regardless of whether there is an input consumer |
| 682 | // to handle it |
| 683 | return; |
| 684 | } |
| 685 | } |
| 686 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 687 | if (w.inPinnedWindowingMode()) { |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 688 | if (mAddPipInputConsumerHandle |
| 689 | && (inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 690 | // Update the bounds of the Pip input consumer to match the window bounds. |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 691 | w.getBounds(mTmpRect); |
| 692 | pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect); |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 693 | addInputWindowHandle(pipInputConsumer.mWindowHandle); |
| 694 | mAddPipInputConsumerHandle = false; |
| 695 | } |
| 696 | // TODO: Fix w.canReceiveTouchInput() to handle this case |
| 697 | if (!hasFocus) { |
| 698 | // Skip this pinned stack window if it does not have focus |
| 699 | return; |
| 700 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | if (mAddInputConsumerHandle |
| 704 | && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) { |
| 705 | addInputWindowHandle(navInputConsumer.mWindowHandle); |
| 706 | mAddInputConsumerHandle = false; |
| 707 | } |
| 708 | |
| 709 | if (mAddWallpaperInputConsumerHandle) { |
| 710 | if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) { |
| 711 | // Add the wallpaper input consumer above the first visible wallpaper. |
| 712 | addInputWindowHandle(wallpaperInputConsumer.mWindowHandle); |
| 713 | mAddWallpaperInputConsumerHandle = false; |
| 714 | } |
| 715 | } |
| 716 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 717 | if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) { |
| 718 | mDisableWallpaperTouchEvents = true; |
| 719 | } |
| 720 | final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w) |
| 721 | && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0 |
| 722 | && !mDisableWallpaperTouchEvents; |
| 723 | |
| 724 | // If there's a drag in progress and 'child' is a potential drop target, |
| 725 | // make sure it's been told about the drag |
| 726 | if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) { |
Daichi Hirono | 768012e | 2017-10-30 10:05:37 +0900 | [diff] [blame] | 727 | mService.mDragDropController.sendDragStartedIfNeededLocked(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | addInputWindowHandle( |
| 731 | inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper); |
| 732 | } |
| 733 | } |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 734 | } |