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 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 19 | import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 20 | import static android.view.WindowManager.INPUT_CONSUMER_PIP; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 21 | import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 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; |
| 26 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 27 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 28 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG; |
| 29 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT; |
| 30 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT; |
| 31 | import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING; |
| 32 | import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; |
Filip Gruszczynski | 9cac3b4 | 2015-10-30 14:20:37 -0700 | [diff] [blame] | 33 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 34 | import android.graphics.Rect; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 35 | import android.os.IBinder; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 36 | import android.os.Looper; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 37 | import android.os.Process; |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 38 | import android.os.Trace; |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 39 | import android.os.UserHandle; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 40 | import android.util.ArrayMap; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 41 | import android.util.Log; |
| 42 | import android.util.Slog; |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 43 | import android.view.InputApplicationHandle; |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 44 | import android.view.InputChannel; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 45 | import android.view.InputEventReceiver; |
Robert Carr | 788f574 | 2018-07-30 17:46:45 -0700 | [diff] [blame] | 46 | import android.view.InputWindowHandle; |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 47 | import android.view.SurfaceControl; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 48 | |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 49 | import com.android.server.policy.WindowManagerPolicy; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 50 | |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 51 | import java.io.PrintWriter; |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 52 | import java.util.Set; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 53 | import java.util.function.Consumer; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 54 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 55 | final class InputMonitor { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 56 | private final WindowManagerService mService; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 57 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 58 | // Current window with input focus for keys and other non-touch events. May be null. |
| 59 | private WindowState mInputFocus; |
Selim Cinek | f83e824 | 2015-05-19 18:08:14 -0700 | [diff] [blame] | 60 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 61 | // When true, need to call updateInputWindowsLw(). |
| 62 | private boolean mUpdateInputWindowsNeeded = true; |
| 63 | |
Robert Carr | b600bc2 | 2018-08-21 15:05:16 -0700 | [diff] [blame] | 64 | // Currently focused input window handle. |
| 65 | private InputWindowHandle mFocusedInputWindowHandle; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 66 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 67 | private boolean mDisableWallpaperTouchEvents; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 68 | private final Rect mTmpRect = new Rect(); |
| 69 | private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer = |
| 70 | new UpdateInputForAllWindowsConsumer(); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 71 | |
Vishnu Nair | 9e7dbc8 | 2018-12-20 08:45:28 -0800 | [diff] [blame] | 72 | private final int mDisplayId; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 73 | |
Vishnu Nair | 9e7dbc8 | 2018-12-20 08:45:28 -0800 | [diff] [blame] | 74 | private final SurfaceControl.Transaction mInputTransaction; |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 75 | |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 76 | /** |
| 77 | * The set of input consumer added to the window manager by name, which consumes input events |
| 78 | * for the windows below it. |
| 79 | */ |
| 80 | private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap(); |
| 81 | |
| 82 | private static final class EventReceiverInputConsumer extends InputConsumerImpl |
| 83 | implements WindowManagerPolicy.InputConsumer { |
| 84 | private InputMonitor mInputMonitor; |
| 85 | private final InputEventReceiver mInputEventReceiver; |
| 86 | |
| 87 | EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor, |
| 88 | Looper looper, String name, |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 89 | InputEventReceiver.Factory inputEventReceiverFactory, |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 90 | int clientPid, UserHandle clientUser, int displayId) { |
| 91 | super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser, |
| 92 | displayId); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 93 | mInputMonitor = monitor; |
| 94 | mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver( |
| 95 | mClientChannel, looper); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void dismiss() { |
Wale Ogunwale | db485de | 2018-10-29 09:47:07 -0700 | [diff] [blame] | 100 | synchronized (mService.mGlobalLock) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 101 | if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) { |
| 102 | mInputEventReceiver.dispose(); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 108 | public InputMonitor(WindowManagerService service, int displayId) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 109 | mService = service; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 110 | mDisplayId = displayId; |
Vishnu Nair | 9e7dbc8 | 2018-12-20 08:45:28 -0800 | [diff] [blame] | 111 | mInputTransaction = mService.mRoot.getDisplayContent(mDisplayId).getPendingTransaction(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 112 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 113 | |
Wale Ogunwale | f7cab10 | 2016-10-25 15:25:14 -0700 | [diff] [blame] | 114 | private void addInputConsumer(String name, InputConsumerImpl consumer) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 115 | mInputConsumers.put(name, consumer); |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 116 | consumer.linkToDeathRecipient(); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 117 | updateInputWindowsLw(true /* force */); |
| 118 | } |
| 119 | |
| 120 | boolean destroyInputConsumer(String name) { |
| 121 | if (disposeInputConsumer(mInputConsumers.remove(name))) { |
| 122 | updateInputWindowsLw(true /* force */); |
| 123 | return true; |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | private boolean disposeInputConsumer(InputConsumerImpl consumer) { |
| 129 | if (consumer != null) { |
| 130 | consumer.disposeChannelsLw(); |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 131 | consumer.hide(mInputTransaction); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 132 | return true; |
| 133 | } |
| 134 | return false; |
| 135 | } |
| 136 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 137 | InputConsumerImpl getInputConsumer(String name) { |
| 138 | return mInputConsumers.get(name); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void layoutInputConsumers(int dw, int dh) { |
| 142 | for (int i = mInputConsumers.size() - 1; i >= 0; i--) { |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 143 | mInputConsumers.valueAt(i).layout(mInputTransaction, dw, dh); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // The visibility of the input consumers is recomputed each time we |
| 148 | // update the input windows. We use a model where consumers begin invisible |
| 149 | // (set so by this function) and must meet some condition for visibility on each update. |
| 150 | void resetInputConsumers(SurfaceControl.Transaction t) { |
| 151 | for (int i = mInputConsumers.size() - 1; i >= 0; i--) { |
| 152 | mInputConsumers.valueAt(i).hide(t); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| 156 | WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name, |
| 157 | InputEventReceiver.Factory inputEventReceiverFactory) { |
| 158 | if (mInputConsumers.containsKey(name)) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 159 | throw new IllegalStateException("Existing input consumer found with name: " + name |
| 160 | + ", display: " + mDisplayId); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 161 | } |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 162 | final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService, |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 163 | this, looper, name, inputEventReceiverFactory, Process.myPid(), |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 164 | UserHandle.SYSTEM, mDisplayId); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 165 | addInputConsumer(name, consumer); |
| 166 | return consumer; |
| 167 | } |
| 168 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 169 | void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid, |
| 170 | UserHandle clientUser) { |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 171 | if (mInputConsumers.containsKey(name)) { |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 172 | throw new IllegalStateException("Existing input consumer found with name: " + name |
| 173 | + ", display: " + mDisplayId); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 176 | final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name, |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 177 | inputChannel, clientPid, clientUser, mDisplayId); |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 178 | switch (name) { |
| 179 | case INPUT_CONSUMER_WALLPAPER: |
| 180 | consumer.mWindowHandle.hasWallpaper = true; |
| 181 | break; |
| 182 | case INPUT_CONSUMER_PIP: |
| 183 | // The touchable region of the Pip input window is cropped to the bounds of the |
| 184 | // 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] | 185 | consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL; |
Winson | 4127548 | 2016-10-10 15:17:45 -0700 | [diff] [blame] | 186 | break; |
| 187 | } |
| 188 | addInputConsumer(name, consumer); |
| 189 | } |
| 190 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 191 | |
Robert Carr | b600bc2 | 2018-08-21 15:05:16 -0700 | [diff] [blame] | 192 | void populateInputWindowHandle(final InputWindowHandle inputWindowHandle, |
Craig Mautner | c08eab8 | 2014-11-11 09:03:59 -0800 | [diff] [blame] | 193 | final WindowState child, int flags, final int type, final boolean isVisible, |
Wale Ogunwale | 053c8e4 | 2015-11-16 14:27:21 -0800 | [diff] [blame] | 194 | final boolean hasFocus, final boolean hasWallpaper) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 195 | // Add a window to our list of input windows. |
| 196 | inputWindowHandle.name = child.toString(); |
Riddle Hsu | ff03df5 | 2018-12-05 21:43:02 +0800 | [diff] [blame] | 197 | flags = child.getSurfaceTouchableRegion(inputWindowHandle.touchableRegion, flags); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 198 | inputWindowHandle.layoutParamsFlags = flags; |
| 199 | inputWindowHandle.layoutParamsType = type; |
| 200 | inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 201 | inputWindowHandle.visible = isVisible; |
| 202 | inputWindowHandle.canReceiveKeys = child.canReceiveKeys(); |
| 203 | inputWindowHandle.hasFocus = hasFocus; |
| 204 | inputWindowHandle.hasWallpaper = hasWallpaper; |
| 205 | inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 206 | inputWindowHandle.layer = child.mLayer; |
| 207 | inputWindowHandle.ownerPid = child.mSession.mPid; |
| 208 | inputWindowHandle.ownerUid = child.mSession.mUid; |
| 209 | inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 210 | inputWindowHandle.displayId = child.getDisplayId(); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 211 | |
chaviw | 492139a | 2018-07-16 16:07:35 -0700 | [diff] [blame] | 212 | final Rect frame = child.getFrameLw(); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 213 | inputWindowHandle.frameLeft = frame.left; |
| 214 | inputWindowHandle.frameTop = frame.top; |
| 215 | inputWindowHandle.frameRight = frame.right; |
| 216 | inputWindowHandle.frameBottom = frame.bottom; |
| 217 | |
Robert Carr | fcc0852 | 2018-11-14 14:02:52 -0800 | [diff] [blame] | 218 | // Surface insets are hardcoded to be the same in all directions |
| 219 | // and we could probably deprecate the "left/right/top/bottom" concept. |
| 220 | // we avoid reintroducing this concept by just choosing one of them here. |
| 221 | inputWindowHandle.surfaceInset = child.getAttrs().surfaceInsets.left; |
| 222 | |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 223 | if (child.mGlobalScale != 1) { |
| 224 | // If we are scaling the window, input coordinates need |
| 225 | // to be inversely scaled to map from what is on screen |
| 226 | // to what is actually being touched in the UI. |
| 227 | inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale; |
| 228 | } else { |
| 229 | inputWindowHandle.scaleFactor = 1; |
| 230 | } |
| 231 | |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 232 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 233 | Slog.d(TAG_WM, "addInputWindowHandle: " |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 234 | + child + ", " + inputWindowHandle); |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 235 | } |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 236 | |
Robert Carr | b600bc2 | 2018-08-21 15:05:16 -0700 | [diff] [blame] | 237 | if (hasFocus) { |
| 238 | mFocusedInputWindowHandle = inputWindowHandle; |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 239 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 242 | void setUpdateInputWindowsNeededLw() { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 243 | mUpdateInputWindowsNeeded = true; |
| 244 | } |
| 245 | |
| 246 | /* Updates the cached window information provided to the input dispatcher. */ |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 247 | void updateInputWindowsLw(boolean force) { |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 248 | if (!force && !mUpdateInputWindowsNeeded) { |
| 249 | return; |
| 250 | } |
| 251 | mUpdateInputWindowsNeeded = false; |
| 252 | |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 253 | if (false) Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw"); |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 254 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 255 | // Populate the input window list with information about all of the windows that |
| 256 | // could potentially receive input. |
| 257 | // As an optimization, we could try to prune the list of windows but this turns |
| 258 | // out to be difficult because only the native code knows for sure which window |
| 259 | // currently has touch focus. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 260 | |
Wale Ogunwale | e05f501 | 2016-09-16 16:27:29 -0700 | [diff] [blame] | 261 | // 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] | 262 | final boolean inDrag = mService.mDragDropController.dragDropActiveLocked(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 263 | if (inDrag) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 264 | if (DEBUG_DRAG) { |
| 265 | Log.d(TAG_WM, "Inserting drag window"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 266 | } |
Robert Carr | e92c80c | 2018-08-14 15:38:44 -0700 | [diff] [blame] | 267 | mService.mDragDropController.showInputSurface(mInputTransaction, mDisplayId); |
| 268 | } else { |
| 269 | mService.mDragDropController.hideInputSurface(mInputTransaction, mDisplayId); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Daichi Hirono | 34fb731 | 2017-12-04 10:00:24 +0900 | [diff] [blame] | 272 | final boolean inPositioning = mService.mTaskPositioningController.isPositioningLocked(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 273 | if (inPositioning) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 274 | if (DEBUG_TASK_POSITIONING) { |
| 275 | Log.d(TAG_WM, "Inserting window handle for repositioning"); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 276 | } |
Robert Carr | e92c80c | 2018-08-14 15:38:44 -0700 | [diff] [blame] | 277 | mService.mTaskPositioningController.showInputSurface(mInputTransaction, mDisplayId); |
| 278 | } else { |
| 279 | mService.mTaskPositioningController.hideInputSurface(mInputTransaction, mDisplayId); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 282 | // Add all windows on the default display. |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 283 | mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag); |
Wale Ogunwale | 6213caa | 2016-12-02 16:47:15 +0000 | [diff] [blame] | 284 | |
| 285 | if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw"); |
| 286 | } |
| 287 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 288 | /* Called when the current input focus changes. |
| 289 | * Layer assignment is assumed to be complete by the time this is called. |
| 290 | */ |
| 291 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 292 | if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 293 | Slog.d(TAG_WM, "Input focus has changed to " + newWindow); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | if (newWindow != mInputFocus) { |
| 297 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 298 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 299 | // This is to protect against bugs if someone pauses dispatching but |
| 300 | // forgets to resume. |
| 301 | newWindow.mToken.paused = false; |
| 302 | } |
| 303 | |
| 304 | mInputFocus = newWindow; |
| 305 | setUpdateInputWindowsNeededLw(); |
| 306 | |
| 307 | if (updateInputWindows) { |
| 308 | updateInputWindowsLw(false /*force*/); |
| 309 | } |
| 310 | } |
| 311 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 312 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 313 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 314 | // Focused app has changed. |
| 315 | if (newApp == null) { |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 316 | mService.mInputManager.setFocusedApplication(mDisplayId, null); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 317 | } else { |
Jeff Brown | 9302c87 | 2011-07-13 22:51:29 -0700 | [diff] [blame] | 318 | final InputApplicationHandle handle = newApp.mInputApplicationHandle; |
| 319 | handle.name = newApp.toString(); |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 320 | handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 321 | |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 322 | mService.mInputManager.setFocusedApplication(mDisplayId, handle); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 323 | } |
| 324 | } |
Craig Mautner | 5845812 | 2013-09-14 14:59:50 -0700 | [diff] [blame] | 325 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 326 | public void pauseDispatchingLw(WindowToken window) { |
| 327 | if (! window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 328 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 329 | Slog.v(TAG_WM, "Pausing WindowToken " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 330 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 331 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 332 | window.paused = true; |
| 333 | updateInputWindowsLw(true /*force*/); |
| 334 | } |
| 335 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 336 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 337 | public void resumeDispatchingLw(WindowToken window) { |
| 338 | if (window.paused) { |
Filip Gruszczynski | f8a2a63 | 2015-10-28 11:18:02 -0700 | [diff] [blame] | 339 | if (DEBUG_INPUT) { |
Filip Gruszczynski | 0bd180d | 2015-12-07 15:43:52 -0800 | [diff] [blame] | 340 | Slog.v(TAG_WM, "Resuming WindowToken " + window); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 341 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 342 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 343 | window.paused = false; |
| 344 | updateInputWindowsLw(true /*force*/); |
| 345 | } |
| 346 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 347 | |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 348 | void dump(PrintWriter pw, String prefix) { |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 349 | final Set<String> inputConsumerKeys = mInputConsumers.keySet(); |
| 350 | if (!inputConsumerKeys.isEmpty()) { |
| 351 | pw.println(prefix + "InputConsumers:"); |
| 352 | for (String key : inputConsumerKeys) { |
Winson Chung | 6463c36 | 2017-09-25 16:23:26 -0700 | [diff] [blame] | 353 | mInputConsumers.get(key).dump(pw, key, prefix); |
Winson Chung | 853c99a | 2017-03-21 22:16:42 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
Wale Ogunwale | e89eeac | 2016-03-12 11:07:58 -0800 | [diff] [blame] | 356 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 357 | |
| 358 | private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 359 | InputConsumerImpl navInputConsumer; |
| 360 | InputConsumerImpl pipInputConsumer; |
| 361 | InputConsumerImpl wallpaperInputConsumer; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 362 | InputConsumerImpl recentsAnimationInputConsumer; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 363 | |
| 364 | private boolean mAddInputConsumerHandle; |
| 365 | private boolean mAddPipInputConsumerHandle; |
| 366 | private boolean mAddWallpaperInputConsumerHandle; |
| 367 | private boolean mAddRecentsAnimationInputConsumerHandle; |
| 368 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 369 | boolean inDrag; |
| 370 | WallpaperController wallpaperController; |
| 371 | |
| 372 | private void updateInputWindows(boolean inDrag) { |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 373 | Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows"); |
| 374 | |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 375 | navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION); |
| 376 | pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP); |
| 377 | wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER); |
| 378 | recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION); |
| 379 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 380 | mAddInputConsumerHandle = navInputConsumer != null; |
| 381 | mAddPipInputConsumerHandle = pipInputConsumer != null; |
| 382 | mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null; |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 383 | mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null; |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 384 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 385 | mTmpRect.setEmpty(); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 386 | mDisableWallpaperTouchEvents = false; |
| 387 | this.inDrag = inDrag; |
wilsonshih | c32538e | 2018-11-07 17:27:34 +0800 | [diff] [blame] | 388 | final DisplayContent dc = mService.mRoot.getDisplayContent(mDisplayId); |
| 389 | wallpaperController = dc.mWallpaperController; |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 390 | |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 391 | resetInputConsumers(mInputTransaction); |
| 392 | |
| 393 | dc.forAllWindows(this, |
| 394 | true /* traverseTopToBottom */); |
| 395 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 396 | if (mAddWallpaperInputConsumerHandle) { |
Robert Carr | b600bc2 | 2018-08-21 15:05:16 -0700 | [diff] [blame] | 397 | wallpaperInputConsumer.show(mInputTransaction, 0); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Vishnu Nair | 9e7dbc8 | 2018-12-20 08:45:28 -0800 | [diff] [blame] | 400 | dc.scheduleAnimation(); |
Vladislav Kaznacheev | 2e96c63 | 2016-12-13 14:31:24 -0800 | [diff] [blame] | 401 | |
Jorim Jaggi | 6064051 | 2018-06-29 01:14:31 +0200 | [diff] [blame] | 402 | Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | @Override |
| 406 | public void accept(WindowState w) { |
| 407 | final InputChannel inputChannel = w.mInputChannel; |
| 408 | final InputWindowHandle inputWindowHandle = w.mInputWindowHandle; |
| 409 | if (inputChannel == null || inputWindowHandle == null || w.mRemoved |
Robert Carr | ebdf858 | 2018-09-04 14:50:15 -0700 | [diff] [blame] | 410 | || w.cantReceiveTouchInput()) { |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 411 | // Skip this window because it cannot possibly receive input. |
| 412 | return; |
| 413 | } |
| 414 | |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 415 | final int flags = w.mAttrs.flags; |
| 416 | final int privateFlags = w.mAttrs.privateFlags; |
| 417 | final int type = w.mAttrs.type; |
Arthur Hung | 39134b2 | 2018-08-14 11:58:28 +0800 | [diff] [blame] | 418 | final boolean hasFocus = w.isFocused(); |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 419 | final boolean isVisible = w.isVisibleLw(); |
| 420 | |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 421 | if (mAddRecentsAnimationInputConsumerHandle) { |
| 422 | final RecentsAnimationController recentsAnimationController = |
| 423 | mService.getRecentsAnimationController(); |
| 424 | if (recentsAnimationController != null |
Winson Chung | db111ee | 2018-10-03 14:25:34 -0700 | [diff] [blame] | 425 | && recentsAnimationController.shouldApplyInputConsumer(w.mAppToken)) { |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 426 | if (recentsAnimationController.updateInputConsumerForApp( |
Arthur Hung | 95b38a9 | 2018-07-20 18:56:12 +0800 | [diff] [blame] | 427 | recentsAnimationInputConsumer.mWindowHandle, hasFocus)) { |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 428 | recentsAnimationInputConsumer.show(mInputTransaction, w); |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 429 | mAddRecentsAnimationInputConsumerHandle = false; |
| 430 | } |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 434 | if (w.inPinnedWindowingMode()) { |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 435 | if (mAddPipInputConsumerHandle) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 436 | // 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] | 437 | w.getBounds(mTmpRect); |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 438 | pipInputConsumer.layout(mInputTransaction, mTmpRect); |
Robert Carr | 47ea21d | 2018-11-28 13:42:45 -0800 | [diff] [blame] | 439 | |
| 440 | // The touchable region is relative to the surface top-left |
| 441 | mTmpRect.offsetTo(0, 0); |
Winson Chung | a89ffed | 2018-01-25 17:46:11 +0000 | [diff] [blame] | 442 | pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect); |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 443 | pipInputConsumer.show(mInputTransaction, w); |
Winson Chung | 61ecc1b | 2017-02-17 10:46:17 -0800 | [diff] [blame] | 444 | mAddPipInputConsumerHandle = false; |
| 445 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | if (mAddInputConsumerHandle |
| 449 | && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) { |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 450 | navInputConsumer.show(mInputTransaction, w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 451 | mAddInputConsumerHandle = false; |
| 452 | } |
| 453 | |
| 454 | if (mAddWallpaperInputConsumerHandle) { |
| 455 | if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) { |
| 456 | // Add the wallpaper input consumer above the first visible wallpaper. |
Robert Carr | a80ad04 | 2018-08-14 12:54:20 -0700 | [diff] [blame] | 457 | wallpaperInputConsumer.show(mInputTransaction, w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 458 | mAddWallpaperInputConsumerHandle = false; |
| 459 | } |
| 460 | } |
| 461 | |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 462 | if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) { |
| 463 | mDisableWallpaperTouchEvents = true; |
| 464 | } |
| 465 | final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w) |
| 466 | && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0 |
| 467 | && !mDisableWallpaperTouchEvents; |
| 468 | |
| 469 | // If there's a drag in progress and 'child' is a potential drop target, |
| 470 | // make sure it's been told about the drag |
| 471 | if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) { |
Daichi Hirono | 768012e | 2017-10-30 10:05:37 +0900 | [diff] [blame] | 472 | mService.mDragDropController.sendDragStartedIfNeededLocked(w); |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Robert Carr | b600bc2 | 2018-08-21 15:05:16 -0700 | [diff] [blame] | 475 | populateInputWindowHandle( |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 476 | inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper); |
Robert Carr | 679ccb0 | 2018-08-08 15:32:35 -0700 | [diff] [blame] | 477 | |
| 478 | if (w.mWinAnimator.hasSurface()) { |
| 479 | mInputTransaction.setInputWindowInfo( |
| 480 | w.mWinAnimator.mSurfaceController.mSurfaceControl, inputWindowHandle); |
| 481 | } |
Wale Ogunwale | 1e129a4 | 2016-11-21 13:03:47 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
Jeff Brown | ea42655 | 2011-07-18 16:53:48 -0700 | [diff] [blame] | 484 | } |