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