blob: 56694519b7fc27fb29b8d216f9c05e3daf70f099 [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_FOCUS_LIGHT;
29import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
30import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
31import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -070032
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080033import android.graphics.Rect;
Jorim Jaggiae962e62018-12-27 17:23:48 +010034import android.os.Handler;
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
Jorim Jaggiae962e62018-12-27 17:23:48 +010049import com.android.server.AnimationThread;
Adrian Roose99bc052017-11-20 17:55:31 +010050import com.android.server.policy.WindowManagerPolicy;
Selim Cinekf83e8242015-05-19 18:08:14 -070051
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080052import java.io.PrintWriter;
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;
Jorim Jaggiae962e62018-12-27 17:23:48 +010064 private boolean mUpdateInputWindowsPending;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065
Robert Carrb600bc22018-08-21 15:05:16 -070066 // Currently focused input window handle.
67 private InputWindowHandle mFocusedInputWindowHandle;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080068
Wale Ogunwale6213caa2016-12-02 16:47:15 +000069 private boolean mDisableWallpaperTouchEvents;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080070 private final Rect mTmpRect = new Rect();
Arthur Hung678024f2019-01-16 20:58:51 +080071 private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer;
Jeff Brown9302c872011-07-13 22:51:29 -070072
Vishnu Nair9e7dbc82018-12-20 08:45:28 -080073 private final int mDisplayId;
Jorim Jaggiae962e62018-12-27 17:23:48 +010074 private final DisplayContent mDisplayContent;
75 private boolean mDisplayRemoved;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076
Vishnu Nair9e7dbc82018-12-20 08:45:28 -080077 private final SurfaceControl.Transaction mInputTransaction;
Jorim Jaggiae962e62018-12-27 17:23:48 +010078 private final Handler mHandler;
Robert Carr679ccb02018-08-08 15:32:35 -070079
Winson41275482016-10-10 15:17:45 -070080 /**
81 * The set of input consumer added to the window manager by name, which consumes input events
82 * for the windows below it.
83 */
84 private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
85
86 private static final class EventReceiverInputConsumer extends InputConsumerImpl
87 implements WindowManagerPolicy.InputConsumer {
88 private InputMonitor mInputMonitor;
89 private final InputEventReceiver mInputEventReceiver;
90
91 EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
92 Looper looper, String name,
Winson Chung6463c362017-09-25 16:23:26 -070093 InputEventReceiver.Factory inputEventReceiverFactory,
Arthur Hung95b38a92018-07-20 18:56:12 +080094 int clientPid, UserHandle clientUser, int displayId) {
95 super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser,
96 displayId);
Winson41275482016-10-10 15:17:45 -070097 mInputMonitor = monitor;
98 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
99 mClientChannel, looper);
100 }
101
102 @Override
103 public void dismiss() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700104 synchronized (mService.mGlobalLock) {
Winson41275482016-10-10 15:17:45 -0700105 if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
106 mInputEventReceiver.dispose();
107 }
108 }
109 }
110 }
111
Jorim Jaggiae962e62018-12-27 17:23:48 +0100112 private final Runnable mUpdateInputWindows = new Runnable() {
113 @Override
114 public void run() {
115 synchronized (mService.mGlobalLock) {
116 mUpdateInputWindowsPending = false;
117 mUpdateInputWindowsNeeded = false;
118
119 if (mDisplayRemoved) {
120 return;
121 }
122
123 // Populate the input window list with information about all of the windows that
124 // could potentially receive input.
125 // As an optimization, we could try to prune the list of windows but this turns
126 // out to be difficult because only the native code knows for sure which window
127 // currently has touch focus.
128
129 // If there's a drag in flight, provide a pseudo-window to catch drag input
130 final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100131 final boolean inPositioning =
132 mService.mTaskPositioningController.isPositioningLocked();
133 if (inPositioning) {
134 if (DEBUG_TASK_POSITIONING) {
135 Log.d(TAG_WM, "Inserting window handle for repositioning");
136 }
137 mService.mTaskPositioningController.showInputSurface(mInputTransaction,
138 mDisplayId);
139 } else {
140 mService.mTaskPositioningController.hideInputSurface(mInputTransaction,
141 mDisplayId);
142 }
143
144 // Add all windows on the default display.
145 mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);
146 }
147 }
148 };
149
Arthur Hung95b38a92018-07-20 18:56:12 +0800150 public InputMonitor(WindowManagerService service, int displayId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 mService = service;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100152 mDisplayContent = mService.mRoot.getDisplayContent(displayId);
Arthur Hung95b38a92018-07-20 18:56:12 +0800153 mDisplayId = displayId;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100154 mInputTransaction = mDisplayContent.getPendingTransaction();
155 mHandler = AnimationThread.getHandler();
Arthur Hung678024f2019-01-16 20:58:51 +0800156 mUpdateInputForAllWindowsConsumer = new UpdateInputForAllWindowsConsumer();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100157 }
158
159 void onDisplayRemoved() {
160 mHandler.removeCallbacks(mUpdateInputWindows);
Riddle Hsu3f2de742019-02-25 15:21:38 +0800161 mService.mInputManager.onDisplayRemoved(mDisplayId);
Jorim Jaggiae962e62018-12-27 17:23:48 +0100162 mDisplayRemoved = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700164
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700165 private void addInputConsumer(String name, InputConsumerImpl consumer) {
Winson41275482016-10-10 15:17:45 -0700166 mInputConsumers.put(name, consumer);
Winson Chung6463c362017-09-25 16:23:26 -0700167 consumer.linkToDeathRecipient();
Winson41275482016-10-10 15:17:45 -0700168 updateInputWindowsLw(true /* force */);
169 }
170
171 boolean destroyInputConsumer(String name) {
172 if (disposeInputConsumer(mInputConsumers.remove(name))) {
173 updateInputWindowsLw(true /* force */);
174 return true;
175 }
176 return false;
177 }
178
179 private boolean disposeInputConsumer(InputConsumerImpl consumer) {
180 if (consumer != null) {
181 consumer.disposeChannelsLw();
Robert Carra80ad042018-08-14 12:54:20 -0700182 consumer.hide(mInputTransaction);
Winson41275482016-10-10 15:17:45 -0700183 return true;
184 }
185 return false;
186 }
187
Arthur Hung95b38a92018-07-20 18:56:12 +0800188 InputConsumerImpl getInputConsumer(String name) {
189 return mInputConsumers.get(name);
Winson41275482016-10-10 15:17:45 -0700190 }
191
192 void layoutInputConsumers(int dw, int dh) {
193 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
Robert Carra80ad042018-08-14 12:54:20 -0700194 mInputConsumers.valueAt(i).layout(mInputTransaction, dw, dh);
195 }
196 }
197
198 // The visibility of the input consumers is recomputed each time we
199 // update the input windows. We use a model where consumers begin invisible
200 // (set so by this function) and must meet some condition for visibility on each update.
201 void resetInputConsumers(SurfaceControl.Transaction t) {
202 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
203 mInputConsumers.valueAt(i).hide(t);
Winson41275482016-10-10 15:17:45 -0700204 }
205 }
206
207 WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
208 InputEventReceiver.Factory inputEventReceiverFactory) {
209 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800210 throw new IllegalStateException("Existing input consumer found with name: " + name
211 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700212 }
Winson41275482016-10-10 15:17:45 -0700213 final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
Winson Chung6463c362017-09-25 16:23:26 -0700214 this, looper, name, inputEventReceiverFactory, Process.myPid(),
Arthur Hung95b38a92018-07-20 18:56:12 +0800215 UserHandle.SYSTEM, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700216 addInputConsumer(name, consumer);
217 return consumer;
218 }
219
Winson Chung6463c362017-09-25 16:23:26 -0700220 void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid,
221 UserHandle clientUser) {
Winson41275482016-10-10 15:17:45 -0700222 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800223 throw new IllegalStateException("Existing input consumer found with name: " + name
224 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700225 }
226
Winson Chung6463c362017-09-25 16:23:26 -0700227 final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name,
Arthur Hung95b38a92018-07-20 18:56:12 +0800228 inputChannel, clientPid, clientUser, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700229 switch (name) {
230 case INPUT_CONSUMER_WALLPAPER:
231 consumer.mWindowHandle.hasWallpaper = true;
232 break;
233 case INPUT_CONSUMER_PIP:
234 // The touchable region of the Pip input window is cropped to the bounds of the
235 // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700236 consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL;
Winson41275482016-10-10 15:17:45 -0700237 break;
238 }
239 addInputConsumer(name, consumer);
240 }
241
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242
Robert Carrb600bc22018-08-21 15:05:16 -0700243 void populateInputWindowHandle(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800244 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800245 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700246 // Add a window to our list of input windows.
247 inputWindowHandle.name = child.toString();
Riddle Hsuff03df52018-12-05 21:43:02 +0800248 flags = child.getSurfaceTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700249 inputWindowHandle.layoutParamsFlags = flags;
250 inputWindowHandle.layoutParamsType = type;
251 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
252 inputWindowHandle.visible = isVisible;
253 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
254 inputWindowHandle.hasFocus = hasFocus;
255 inputWindowHandle.hasWallpaper = hasWallpaper;
256 inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
257 inputWindowHandle.layer = child.mLayer;
258 inputWindowHandle.ownerPid = child.mSession.mPid;
259 inputWindowHandle.ownerUid = child.mSession.mUid;
260 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
Arthur Hung95b38a92018-07-20 18:56:12 +0800261 inputWindowHandle.displayId = child.getDisplayId();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700262
chaviw492139a2018-07-16 16:07:35 -0700263 final Rect frame = child.getFrameLw();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700264 inputWindowHandle.frameLeft = frame.left;
265 inputWindowHandle.frameTop = frame.top;
266 inputWindowHandle.frameRight = frame.right;
267 inputWindowHandle.frameBottom = frame.bottom;
268
Robert Carrfcc08522018-11-14 14:02:52 -0800269 // Surface insets are hardcoded to be the same in all directions
270 // and we could probably deprecate the "left/right/top/bottom" concept.
271 // we avoid reintroducing this concept by just choosing one of them here.
272 inputWindowHandle.surfaceInset = child.getAttrs().surfaceInsets.left;
273
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700274 if (child.mGlobalScale != 1) {
275 // If we are scaling the window, input coordinates need
276 // to be inversely scaled to map from what is on screen
277 // to what is actually being touched in the UI.
278 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
279 } else {
280 inputWindowHandle.scaleFactor = 1;
281 }
282
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700283 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800284 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800285 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700286 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700287
Robert Carrb600bc22018-08-21 15:05:16 -0700288 if (hasFocus) {
289 mFocusedInputWindowHandle = inputWindowHandle;
Jeff Brown9302c872011-07-13 22:51:29 -0700290 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 }
292
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000293 void setUpdateInputWindowsNeededLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 mUpdateInputWindowsNeeded = true;
295 }
296
297 /* Updates the cached window information provided to the input dispatcher. */
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000298 void updateInputWindowsLw(boolean force) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 if (!force && !mUpdateInputWindowsNeeded) {
300 return;
301 }
Jorim Jaggiae962e62018-12-27 17:23:48 +0100302 scheduleUpdateInputWindows();
303 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304
Jorim Jaggiae962e62018-12-27 17:23:48 +0100305 private void scheduleUpdateInputWindows() {
306 if (mDisplayRemoved) {
307 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308 }
309
Jorim Jaggiae962e62018-12-27 17:23:48 +0100310 if (!mUpdateInputWindowsPending) {
311 mUpdateInputWindowsPending = true;
312 mHandler.post(mUpdateInputWindows);
Chong Zhang8e89b312015-09-09 15:09:30 -0700313 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000314 }
315
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 /* Called when the current input focus changes.
317 * Layer assignment is assumed to be complete by the time this is called.
318 */
319 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700320 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800321 Slog.d(TAG_WM, "Input focus has changed to " + newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 }
323
324 if (newWindow != mInputFocus) {
325 if (newWindow != null && newWindow.canReceiveKeys()) {
326 // Displaying a window implicitly causes dispatching to be unpaused.
327 // This is to protect against bugs if someone pauses dispatching but
328 // forgets to resume.
329 newWindow.mToken.paused = false;
330 }
331
332 mInputFocus = newWindow;
333 setUpdateInputWindowsNeededLw();
334
335 if (updateInputWindows) {
336 updateInputWindowsLw(false /*force*/);
337 }
338 }
339 }
Craig Mautner58458122013-09-14 14:59:50 -0700340
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800341 public void setFocusedAppLw(AppWindowToken newApp) {
342 // Focused app has changed.
343 if (newApp == null) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800344 mService.mInputManager.setFocusedApplication(mDisplayId, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700346 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
347 handle.name = newApp.toString();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800348 handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800350 mService.mInputManager.setFocusedApplication(mDisplayId, handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 }
352 }
Craig Mautner58458122013-09-14 14:59:50 -0700353
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 public void pauseDispatchingLw(WindowToken window) {
355 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700356 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800357 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700359
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 window.paused = true;
361 updateInputWindowsLw(true /*force*/);
362 }
363 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700364
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 public void resumeDispatchingLw(WindowToken window) {
366 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700367 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800368 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700370
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 window.paused = false;
372 updateInputWindowsLw(true /*force*/);
373 }
374 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700375
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800376 void dump(PrintWriter pw, String prefix) {
Winson Chung853c99a2017-03-21 22:16:42 -0700377 final Set<String> inputConsumerKeys = mInputConsumers.keySet();
378 if (!inputConsumerKeys.isEmpty()) {
379 pw.println(prefix + "InputConsumers:");
380 for (String key : inputConsumerKeys) {
Winson Chung6463c362017-09-25 16:23:26 -0700381 mInputConsumers.get(key).dump(pw, key, prefix);
Winson Chung853c99a2017-03-21 22:16:42 -0700382 }
383 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800384 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800385
386 private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800387 InputConsumerImpl navInputConsumer;
388 InputConsumerImpl pipInputConsumer;
389 InputConsumerImpl wallpaperInputConsumer;
Winson Chunga89ffed2018-01-25 17:46:11 +0000390 InputConsumerImpl recentsAnimationInputConsumer;
Arthur Hung95b38a92018-07-20 18:56:12 +0800391
392 private boolean mAddInputConsumerHandle;
393 private boolean mAddPipInputConsumerHandle;
394 private boolean mAddWallpaperInputConsumerHandle;
395 private boolean mAddRecentsAnimationInputConsumerHandle;
396
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800397 boolean inDrag;
398 WallpaperController wallpaperController;
399
Arthur Hung678024f2019-01-16 20:58:51 +0800400 // An invalid window handle that tells SurfaceFlinger not update the input info.
401 final InputWindowHandle mInvalidInputWindow = new InputWindowHandle(null, null, mDisplayId);
402
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800403 private void updateInputWindows(boolean inDrag) {
Jorim Jaggi60640512018-06-29 01:14:31 +0200404 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
405
Arthur Hung95b38a92018-07-20 18:56:12 +0800406 navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION);
407 pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP);
408 wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER);
409 recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION);
410
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800411 mAddInputConsumerHandle = navInputConsumer != null;
412 mAddPipInputConsumerHandle = pipInputConsumer != null;
413 mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
Winson Chunga89ffed2018-01-25 17:46:11 +0000414 mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null;
Arthur Hung95b38a92018-07-20 18:56:12 +0800415
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800416 mTmpRect.setEmpty();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800417 mDisableWallpaperTouchEvents = false;
418 this.inDrag = inDrag;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100419 wallpaperController = mDisplayContent.mWallpaperController;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800420
Robert Carra80ad042018-08-14 12:54:20 -0700421 resetInputConsumers(mInputTransaction);
422
Jorim Jaggiae962e62018-12-27 17:23:48 +0100423 mDisplayContent.forAllWindows(this,
Robert Carra80ad042018-08-14 12:54:20 -0700424 true /* traverseTopToBottom */);
425
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800426 if (mAddWallpaperInputConsumerHandle) {
Robert Carrb600bc22018-08-21 15:05:16 -0700427 wallpaperInputConsumer.show(mInputTransaction, 0);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800428 }
429
Jorim Jaggiae962e62018-12-27 17:23:48 +0100430 mDisplayContent.scheduleAnimation();
Vladislav Kaznacheev2e96c632016-12-13 14:31:24 -0800431
Jorim Jaggi60640512018-06-29 01:14:31 +0200432 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800433 }
434
435 @Override
436 public void accept(WindowState w) {
437 final InputChannel inputChannel = w.mInputChannel;
438 final InputWindowHandle inputWindowHandle = w.mInputWindowHandle;
439 if (inputChannel == null || inputWindowHandle == null || w.mRemoved
Robert Carrebdf8582018-09-04 14:50:15 -0700440 || w.cantReceiveTouchInput()) {
Arthur Hung678024f2019-01-16 20:58:51 +0800441 if (w.mWinAnimator.hasSurface()) {
442 mInputTransaction.setInputWindowInfo(
443 w.mWinAnimator.mSurfaceController.mSurfaceControl, mInvalidInputWindow);
444 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800445 // Skip this window because it cannot possibly receive input.
446 return;
447 }
448
Winson Chung61ecc1b2017-02-17 10:46:17 -0800449 final int flags = w.mAttrs.flags;
450 final int privateFlags = w.mAttrs.privateFlags;
451 final int type = w.mAttrs.type;
Arthur Hung39134b22018-08-14 11:58:28 +0800452 final boolean hasFocus = w.isFocused();
Winson Chung61ecc1b2017-02-17 10:46:17 -0800453 final boolean isVisible = w.isVisibleLw();
454
Winson Chunga89ffed2018-01-25 17:46:11 +0000455 if (mAddRecentsAnimationInputConsumerHandle) {
456 final RecentsAnimationController recentsAnimationController =
457 mService.getRecentsAnimationController();
458 if (recentsAnimationController != null
Winson Chungdb111ee2018-10-03 14:25:34 -0700459 && recentsAnimationController.shouldApplyInputConsumer(w.mAppToken)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000460 if (recentsAnimationController.updateInputConsumerForApp(
Arthur Hung95b38a92018-07-20 18:56:12 +0800461 recentsAnimationInputConsumer.mWindowHandle, hasFocus)) {
Robert Carra80ad042018-08-14 12:54:20 -0700462 recentsAnimationInputConsumer.show(mInputTransaction, w);
Winson Chunga89ffed2018-01-25 17:46:11 +0000463 mAddRecentsAnimationInputConsumerHandle = false;
464 }
Winson Chunga89ffed2018-01-25 17:46:11 +0000465 }
466 }
467
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700468 if (w.inPinnedWindowingMode()) {
Robert Carra80ad042018-08-14 12:54:20 -0700469 if (mAddPipInputConsumerHandle) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800470 // Update the bounds of the Pip input consumer to match the window bounds.
Winson Chunga89ffed2018-01-25 17:46:11 +0000471 w.getBounds(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700472 pipInputConsumer.layout(mInputTransaction, mTmpRect);
Robert Carr47ea21d2018-11-28 13:42:45 -0800473
474 // The touchable region is relative to the surface top-left
475 mTmpRect.offsetTo(0, 0);
Winson Chunga89ffed2018-01-25 17:46:11 +0000476 pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700477 pipInputConsumer.show(mInputTransaction, w);
Winson Chung61ecc1b2017-02-17 10:46:17 -0800478 mAddPipInputConsumerHandle = false;
479 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800480 }
481
482 if (mAddInputConsumerHandle
483 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
Robert Carra80ad042018-08-14 12:54:20 -0700484 navInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800485 mAddInputConsumerHandle = false;
486 }
487
488 if (mAddWallpaperInputConsumerHandle) {
489 if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) {
490 // Add the wallpaper input consumer above the first visible wallpaper.
Robert Carra80ad042018-08-14 12:54:20 -0700491 wallpaperInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800492 mAddWallpaperInputConsumerHandle = false;
493 }
494 }
495
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800496 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
497 mDisableWallpaperTouchEvents = true;
498 }
499 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w)
500 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
501 && !mDisableWallpaperTouchEvents;
502
503 // If there's a drag in progress and 'child' is a potential drop target,
504 // make sure it's been told about the drag
505 if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) {
Daichi Hirono768012e2017-10-30 10:05:37 +0900506 mService.mDragDropController.sendDragStartedIfNeededLocked(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800507 }
508
Robert Carrb600bc22018-08-21 15:05:16 -0700509 populateInputWindowHandle(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800510 inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
Robert Carr679ccb02018-08-08 15:32:35 -0700511
512 if (w.mWinAnimator.hasSurface()) {
513 mInputTransaction.setInputWindowInfo(
514 w.mWinAnimator.mSurfaceController.mSurfaceControl, inputWindowHandle);
515 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800516 }
517 }
Jeff Brownea426552011-07-18 16:53:48 -0700518}