blob: 88b22cb5e01e5f2828600b9522b0aa089cd85ea0 [file] [log] [blame]
Dianne Hackbornf56e1022011-02-22 10:47:13 -08001/*
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 Hackborn6e1eb762011-02-17 16:07:28 -080015 */
Dianne Hackbornf56e1022011-02-22 10:47:13 -080016
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080017package com.android.server.wm;
18
Wale Ogunwale6213caa2016-12-02 16:47:15 +000019import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
Winson41275482016-10-10 15:17:45 -070020import static android.view.WindowManager.INPUT_CONSUMER_PIP;
Winson Chunga89ffed2018-01-25 17:46:11 +000021import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION;
Winson41275482016-10-10 15:17:45 -070022import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070023import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale6213caa2016-12-02 16:47:15 +000024import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
25import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
26import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Winson Chung6463c362017-09-25 16:23:26 -070027
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080028import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
29import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
31import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
32import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -070033
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080034import android.graphics.Rect;
Winson Chung6463c362017-09-25 16:23:26 -070035import android.os.IBinder;
Winson41275482016-10-10 15:17:45 -070036import android.os.Looper;
Winson Chung6463c362017-09-25 16:23:26 -070037import android.os.Process;
Jorim Jaggi60640512018-06-29 01:14:31 +020038import android.os.Trace;
Winson Chung6463c362017-09-25 16:23:26 -070039import android.os.UserHandle;
Winson41275482016-10-10 15:17:45 -070040import android.util.ArrayMap;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080041import android.util.Log;
42import android.util.Slog;
wilsonshihc32538e2018-11-07 17:27:34 +080043import android.view.InputApplicationHandle;
Jeff Browncc4f7db2011-08-30 20:34:48 -070044import android.view.InputChannel;
Winson41275482016-10-10 15:17:45 -070045import android.view.InputEventReceiver;
Robert Carr788f5742018-07-30 17:46:45 -070046import android.view.InputWindowHandle;
Robert Carr679ccb02018-08-08 15:32:35 -070047import android.view.SurfaceControl;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080048
Adrian Roose99bc052017-11-20 17:55:31 +010049import com.android.server.policy.WindowManagerPolicy;
Selim Cinekf83e8242015-05-19 18:08:14 -070050
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080051import java.io.PrintWriter;
Jeff Brown9302c872011-07-13 22:51:29 -070052import java.util.Arrays;
Winson Chung853c99a2017-03-21 22:16:42 -070053import java.util.Set;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080054import java.util.function.Consumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080055
Arthur Hung95b38a92018-07-20 18:56:12 +080056final class InputMonitor {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070058
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059 // Current window with input focus for keys and other non-touch events. May be null.
60 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070061
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062 // When true, need to call updateInputWindowsLw().
63 private boolean mUpdateInputWindowsNeeded = true;
64
Robert Carrb600bc22018-08-21 15:05:16 -070065 // Currently focused input window handle.
66 private InputWindowHandle mFocusedInputWindowHandle;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080067
Wale Ogunwale6213caa2016-12-02 16:47:15 +000068 private boolean mDisableWallpaperTouchEvents;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080069 private final Rect mTmpRect = new Rect();
70 private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer =
71 new UpdateInputForAllWindowsConsumer();
Jeff Brown9302c872011-07-13 22:51:29 -070072
Arthur Hung95b38a92018-07-20 18:56:12 +080073 private int mDisplayId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074
Robert Carr679ccb02018-08-08 15:32:35 -070075 SurfaceControl.Transaction mInputTransaction = new SurfaceControl.Transaction();
76
Winson41275482016-10-10 15:17:45 -070077 /**
78 * The set of input consumer added to the window manager by name, which consumes input events
79 * for the windows below it.
80 */
81 private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
82
83 private static final class EventReceiverInputConsumer extends InputConsumerImpl
84 implements WindowManagerPolicy.InputConsumer {
85 private InputMonitor mInputMonitor;
86 private final InputEventReceiver mInputEventReceiver;
87
88 EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
89 Looper looper, String name,
Winson Chung6463c362017-09-25 16:23:26 -070090 InputEventReceiver.Factory inputEventReceiverFactory,
Arthur Hung95b38a92018-07-20 18:56:12 +080091 int clientPid, UserHandle clientUser, int displayId) {
92 super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser,
93 displayId);
Winson41275482016-10-10 15:17:45 -070094 mInputMonitor = monitor;
95 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
96 mClientChannel, looper);
97 }
98
99 @Override
100 public void dismiss() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700101 synchronized (mService.mGlobalLock) {
Winson41275482016-10-10 15:17:45 -0700102 if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
103 mInputEventReceiver.dispose();
104 }
105 }
106 }
107 }
108
Arthur Hung95b38a92018-07-20 18:56:12 +0800109 public InputMonitor(WindowManagerService service, int displayId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110 mService = service;
Arthur Hung95b38a92018-07-20 18:56:12 +0800111 mDisplayId = displayId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800112 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700113
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700114 private void addInputConsumer(String name, InputConsumerImpl consumer) {
Winson41275482016-10-10 15:17:45 -0700115 mInputConsumers.put(name, consumer);
Winson Chung6463c362017-09-25 16:23:26 -0700116 consumer.linkToDeathRecipient();
Winson41275482016-10-10 15:17:45 -0700117 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 Carra80ad042018-08-14 12:54:20 -0700131 consumer.hide(mInputTransaction);
Winson41275482016-10-10 15:17:45 -0700132 return true;
133 }
134 return false;
135 }
136
Arthur Hung95b38a92018-07-20 18:56:12 +0800137 InputConsumerImpl getInputConsumer(String name) {
138 return mInputConsumers.get(name);
Winson41275482016-10-10 15:17:45 -0700139 }
140
141 void layoutInputConsumers(int dw, int dh) {
142 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
Robert Carra80ad042018-08-14 12:54:20 -0700143 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);
Winson41275482016-10-10 15:17:45 -0700153 }
154 }
155
156 WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
157 InputEventReceiver.Factory inputEventReceiverFactory) {
158 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800159 throw new IllegalStateException("Existing input consumer found with name: " + name
160 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700161 }
Winson41275482016-10-10 15:17:45 -0700162 final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
Winson Chung6463c362017-09-25 16:23:26 -0700163 this, looper, name, inputEventReceiverFactory, Process.myPid(),
Arthur Hung95b38a92018-07-20 18:56:12 +0800164 UserHandle.SYSTEM, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700165 addInputConsumer(name, consumer);
166 return consumer;
167 }
168
Winson Chung6463c362017-09-25 16:23:26 -0700169 void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid,
170 UserHandle clientUser) {
Winson41275482016-10-10 15:17:45 -0700171 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800172 throw new IllegalStateException("Existing input consumer found with name: " + name
173 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700174 }
175
Winson Chung6463c362017-09-25 16:23:26 -0700176 final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name,
Arthur Hung95b38a92018-07-20 18:56:12 +0800177 inputChannel, clientPid, clientUser, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700178 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 Ogunwalef7cab102016-10-25 15:25:14 -0700185 consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL;
Winson41275482016-10-10 15:17:45 -0700186 break;
187 }
188 addInputConsumer(name, consumer);
189 }
190
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191
Robert Carrb600bc22018-08-21 15:05:16 -0700192 void populateInputWindowHandle(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800193 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800194 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700195 // Add a window to our list of input windows.
196 inputWindowHandle.name = child.toString();
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800197 flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700198 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 Hung95b38a92018-07-20 18:56:12 +0800210 inputWindowHandle.displayId = child.getDisplayId();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700211
chaviw492139a2018-07-16 16:07:35 -0700212 final Rect frame = child.getFrameLw();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700213 inputWindowHandle.frameLeft = frame.left;
214 inputWindowHandle.frameTop = frame.top;
215 inputWindowHandle.frameRight = frame.right;
216 inputWindowHandle.frameBottom = frame.bottom;
217
Robert Carrfcc08522018-11-14 14:02:52 -0800218 // 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 Hackborna4b7f2f2012-05-21 11:28:41 -0700223 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 Gruszczynskif8a2a632015-10-28 11:18:02 -0700232 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800233 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800234 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700235 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700236
Robert Carrb600bc22018-08-21 15:05:16 -0700237 if (hasFocus) {
238 mFocusedInputWindowHandle = inputWindowHandle;
Jeff Brown9302c872011-07-13 22:51:29 -0700239 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 }
241
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000242 void setUpdateInputWindowsNeededLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 mUpdateInputWindowsNeeded = true;
244 }
245
246 /* Updates the cached window information provided to the input dispatcher. */
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000247 void updateInputWindowsLw(boolean force) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 if (!force && !mUpdateInputWindowsNeeded) {
249 return;
250 }
251 mUpdateInputWindowsNeeded = false;
252
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800253 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw");
Jeff Brown9302c872011-07-13 22:51:29 -0700254
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 // 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 Hackborn6e1eb762011-02-17 16:07:28 -0800260
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700261 // If there's a drag in flight, provide a pseudo-window to catch drag input
Daichi Hirono76a26aa2017-09-11 15:13:38 +0900262 final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 if (inDrag) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800264 if (DEBUG_DRAG) {
265 Log.d(TAG_WM, "Inserting drag window");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 }
Robert Carre92c80c2018-08-14 15:38:44 -0700267 mService.mDragDropController.showInputSurface(mInputTransaction, mDisplayId);
268 } else {
269 mService.mDragDropController.hideInputSurface(mInputTransaction, mDisplayId);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 }
271
Daichi Hirono34fb7312017-12-04 10:00:24 +0900272 final boolean inPositioning = mService.mTaskPositioningController.isPositioningLocked();
Chong Zhang8e89b312015-09-09 15:09:30 -0700273 if (inPositioning) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800274 if (DEBUG_TASK_POSITIONING) {
275 Log.d(TAG_WM, "Inserting window handle for repositioning");
Chong Zhang8e89b312015-09-09 15:09:30 -0700276 }
Robert Carre92c80c2018-08-14 15:38:44 -0700277 mService.mTaskPositioningController.showInputSurface(mInputTransaction, mDisplayId);
278 } else {
279 mService.mTaskPositioningController.hideInputSurface(mInputTransaction, mDisplayId);
Chong Zhang8e89b312015-09-09 15:09:30 -0700280 }
281
Jeff Brown83d616a2012-09-09 20:33:43 -0700282 // Add all windows on the default display.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800283 mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000284
285 if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
286 }
287
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 /* 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 Gruszczynskif8a2a632015-10-28 11:18:02 -0700292 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800293 Slog.d(TAG_WM, "Input focus has changed to " + newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 }
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 Mautner58458122013-09-14 14:59:50 -0700312
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 public void setFocusedAppLw(AppWindowToken newApp) {
314 // Focused app has changed.
315 if (newApp == null) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800316 mService.mInputManager.setFocusedApplication(mDisplayId, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800317 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700318 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
319 handle.name = newApp.toString();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800320 handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800322 mService.mInputManager.setFocusedApplication(mDisplayId, handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 }
324 }
Craig Mautner58458122013-09-14 14:59:50 -0700325
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326 public void pauseDispatchingLw(WindowToken window) {
327 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700328 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800329 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700331
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332 window.paused = true;
333 updateInputWindowsLw(true /*force*/);
334 }
335 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700336
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 public void resumeDispatchingLw(WindowToken window) {
338 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700339 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800340 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700342
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800343 window.paused = false;
344 updateInputWindowsLw(true /*force*/);
345 }
346 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700347
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800348 void dump(PrintWriter pw, String prefix) {
Winson Chung853c99a2017-03-21 22:16:42 -0700349 final Set<String> inputConsumerKeys = mInputConsumers.keySet();
350 if (!inputConsumerKeys.isEmpty()) {
351 pw.println(prefix + "InputConsumers:");
352 for (String key : inputConsumerKeys) {
Winson Chung6463c362017-09-25 16:23:26 -0700353 mInputConsumers.get(key).dump(pw, key, prefix);
Winson Chung853c99a2017-03-21 22:16:42 -0700354 }
355 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800356 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800357
358 private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800359 InputConsumerImpl navInputConsumer;
360 InputConsumerImpl pipInputConsumer;
361 InputConsumerImpl wallpaperInputConsumer;
Winson Chunga89ffed2018-01-25 17:46:11 +0000362 InputConsumerImpl recentsAnimationInputConsumer;
Arthur Hung95b38a92018-07-20 18:56:12 +0800363
364 private boolean mAddInputConsumerHandle;
365 private boolean mAddPipInputConsumerHandle;
366 private boolean mAddWallpaperInputConsumerHandle;
367 private boolean mAddRecentsAnimationInputConsumerHandle;
368
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800369 boolean inDrag;
370 WallpaperController wallpaperController;
371
372 private void updateInputWindows(boolean inDrag) {
Jorim Jaggi60640512018-06-29 01:14:31 +0200373 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
374
Arthur Hung95b38a92018-07-20 18:56:12 +0800375 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 Ogunwale1e129a42016-11-21 13:03:47 -0800380 mAddInputConsumerHandle = navInputConsumer != null;
381 mAddPipInputConsumerHandle = pipInputConsumer != null;
382 mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
Winson Chunga89ffed2018-01-25 17:46:11 +0000383 mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null;
Arthur Hung95b38a92018-07-20 18:56:12 +0800384
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800385 mTmpRect.setEmpty();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800386 mDisableWallpaperTouchEvents = false;
387 this.inDrag = inDrag;
wilsonshihc32538e2018-11-07 17:27:34 +0800388 final DisplayContent dc = mService.mRoot.getDisplayContent(mDisplayId);
389 wallpaperController = dc.mWallpaperController;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800390
Robert Carra80ad042018-08-14 12:54:20 -0700391 resetInputConsumers(mInputTransaction);
392
393 dc.forAllWindows(this,
394 true /* traverseTopToBottom */);
395
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800396 if (mAddWallpaperInputConsumerHandle) {
Robert Carrb600bc22018-08-21 15:05:16 -0700397 wallpaperInputConsumer.show(mInputTransaction, 0);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800398 }
399
Robert Carr679ccb02018-08-08 15:32:35 -0700400 mInputTransaction.apply();
Vladislav Kaznacheev2e96c632016-12-13 14:31:24 -0800401
Jorim Jaggi60640512018-06-29 01:14:31 +0200402 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800403 }
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 Carrebdf8582018-09-04 14:50:15 -0700410 || w.cantReceiveTouchInput()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800411 // Skip this window because it cannot possibly receive input.
412 return;
413 }
414
Winson Chung61ecc1b2017-02-17 10:46:17 -0800415 final int flags = w.mAttrs.flags;
416 final int privateFlags = w.mAttrs.privateFlags;
417 final int type = w.mAttrs.type;
Arthur Hung39134b22018-08-14 11:58:28 +0800418 final boolean hasFocus = w.isFocused();
Winson Chung61ecc1b2017-02-17 10:46:17 -0800419 final boolean isVisible = w.isVisibleLw();
420
Winson Chunga89ffed2018-01-25 17:46:11 +0000421 if (mAddRecentsAnimationInputConsumerHandle) {
422 final RecentsAnimationController recentsAnimationController =
423 mService.getRecentsAnimationController();
424 if (recentsAnimationController != null
Winson Chungdb111ee2018-10-03 14:25:34 -0700425 && recentsAnimationController.shouldApplyInputConsumer(w.mAppToken)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000426 if (recentsAnimationController.updateInputConsumerForApp(
Arthur Hung95b38a92018-07-20 18:56:12 +0800427 recentsAnimationInputConsumer.mWindowHandle, hasFocus)) {
Robert Carra80ad042018-08-14 12:54:20 -0700428 recentsAnimationInputConsumer.show(mInputTransaction, w);
Winson Chunga89ffed2018-01-25 17:46:11 +0000429 mAddRecentsAnimationInputConsumerHandle = false;
430 }
Winson Chunga89ffed2018-01-25 17:46:11 +0000431 }
432 }
433
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700434 if (w.inPinnedWindowingMode()) {
Robert Carra80ad042018-08-14 12:54:20 -0700435 if (mAddPipInputConsumerHandle) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800436 // Update the bounds of the Pip input consumer to match the window bounds.
Winson Chunga89ffed2018-01-25 17:46:11 +0000437 w.getBounds(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700438 pipInputConsumer.layout(mInputTransaction, mTmpRect);
Robert Carr47ea21d2018-11-28 13:42:45 -0800439
440 // The touchable region is relative to the surface top-left
441 mTmpRect.offsetTo(0, 0);
Winson Chunga89ffed2018-01-25 17:46:11 +0000442 pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700443 pipInputConsumer.show(mInputTransaction, w);
Winson Chung61ecc1b2017-02-17 10:46:17 -0800444 mAddPipInputConsumerHandle = false;
445 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800446 }
447
448 if (mAddInputConsumerHandle
449 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
Robert Carra80ad042018-08-14 12:54:20 -0700450 navInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800451 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 Carra80ad042018-08-14 12:54:20 -0700457 wallpaperInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800458 mAddWallpaperInputConsumerHandle = false;
459 }
460 }
461
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800462 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 Hirono768012e2017-10-30 10:05:37 +0900472 mService.mDragDropController.sendDragStartedIfNeededLocked(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800473 }
474
Robert Carrb600bc22018-08-21 15:05:16 -0700475 populateInputWindowHandle(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800476 inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
Robert Carr679ccb02018-08-08 15:32:35 -0700477
478 if (w.mWinAnimator.hasSurface()) {
479 mInputTransaction.setInputWindowInfo(
480 w.mWinAnimator.mSurfaceController.mSurfaceControl, inputWindowHandle);
481 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800482 }
483 }
Jeff Brownea426552011-07-18 16:53:48 -0700484}