blob: 835b9b1885a3b5ec802c46ff11c5a69e771e04fa [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
Jorim Jaggi4981f152019-03-26 18:58:45 +010019import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale6213caa2016-12-02 16:47:15 +000020import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
Winson41275482016-10-10 15:17:45 -070021import static android.view.WindowManager.INPUT_CONSUMER_PIP;
Winson Chunga89ffed2018-01-25 17:46:11 +000022import static android.view.WindowManager.INPUT_CONSUMER_RECENTS_ANIMATION;
Winson41275482016-10-10 15:17:45 -070023import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070024import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale6213caa2016-12-02 16:47:15 +000025import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS;
26import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
27import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Winson Chung6463c362017-09-25 16:23:26 -070028
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080029import 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;
Jorim Jaggiae962e62018-12-27 17:23:48 +010035import android.os.Handler;
Winson Chung6463c362017-09-25 16:23:26 -070036import android.os.IBinder;
Winson41275482016-10-10 15:17:45 -070037import android.os.Looper;
Winson Chung6463c362017-09-25 16:23:26 -070038import android.os.Process;
Jorim Jaggi60640512018-06-29 01:14:31 +020039import android.os.Trace;
Winson Chung6463c362017-09-25 16:23:26 -070040import android.os.UserHandle;
Winson41275482016-10-10 15:17:45 -070041import android.util.ArrayMap;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080042import android.util.Log;
43import android.util.Slog;
wilsonshihc32538e2018-11-07 17:27:34 +080044import android.view.InputApplicationHandle;
Jeff Browncc4f7db2011-08-30 20:34:48 -070045import android.view.InputChannel;
Winson41275482016-10-10 15:17:45 -070046import android.view.InputEventReceiver;
Robert Carr788f5742018-07-30 17:46:45 -070047import android.view.InputWindowHandle;
Robert Carr679ccb02018-08-08 15:32:35 -070048import android.view.SurfaceControl;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080049
Jorim Jaggiae962e62018-12-27 17:23:48 +010050import com.android.server.AnimationThread;
Adrian Roose99bc052017-11-20 17:55:31 +010051import com.android.server.policy.WindowManagerPolicy;
Selim Cinekf83e8242015-05-19 18:08:14 -070052
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080053import java.io.PrintWriter;
Winson Chung853c99a2017-03-21 22:16:42 -070054import java.util.Set;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080055import java.util.function.Consumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056
Arthur Hung95b38a92018-07-20 18:56:12 +080057final class InputMonitor {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070059
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060 // Current window with input focus for keys and other non-touch events. May be null.
61 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070062
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063 // When true, need to call updateInputWindowsLw().
64 private boolean mUpdateInputWindowsNeeded = true;
Jorim Jaggiae962e62018-12-27 17:23:48 +010065 private boolean mUpdateInputWindowsPending;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066
Robert Carrb600bc22018-08-21 15:05:16 -070067 // Currently focused input window handle.
68 private InputWindowHandle mFocusedInputWindowHandle;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080069
Wale Ogunwale6213caa2016-12-02 16:47:15 +000070 private boolean mDisableWallpaperTouchEvents;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080071 private final Rect mTmpRect = new Rect();
Arthur Hung678024f2019-01-16 20:58:51 +080072 private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer;
Jeff Brown9302c872011-07-13 22:51:29 -070073
Vishnu Nair9e7dbc82018-12-20 08:45:28 -080074 private final int mDisplayId;
Jorim Jaggiae962e62018-12-27 17:23:48 +010075 private final DisplayContent mDisplayContent;
76 private boolean mDisplayRemoved;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077
Vishnu Nair9e7dbc82018-12-20 08:45:28 -080078 private final SurfaceControl.Transaction mInputTransaction;
Jorim Jaggiae962e62018-12-27 17:23:48 +010079 private final Handler mHandler;
Robert Carr679ccb02018-08-08 15:32:35 -070080
Winson41275482016-10-10 15:17:45 -070081 /**
82 * The set of input consumer added to the window manager by name, which consumes input events
83 * for the windows below it.
84 */
85 private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
86
87 private static final class EventReceiverInputConsumer extends InputConsumerImpl
88 implements WindowManagerPolicy.InputConsumer {
89 private InputMonitor mInputMonitor;
90 private final InputEventReceiver mInputEventReceiver;
91
92 EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
93 Looper looper, String name,
Winson Chung6463c362017-09-25 16:23:26 -070094 InputEventReceiver.Factory inputEventReceiverFactory,
Arthur Hung95b38a92018-07-20 18:56:12 +080095 int clientPid, UserHandle clientUser, int displayId) {
96 super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser,
97 displayId);
Winson41275482016-10-10 15:17:45 -070098 mInputMonitor = monitor;
99 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
100 mClientChannel, looper);
101 }
102
103 @Override
104 public void dismiss() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700105 synchronized (mService.mGlobalLock) {
Winson41275482016-10-10 15:17:45 -0700106 if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
107 mInputEventReceiver.dispose();
108 }
109 }
110 }
111 }
112
Jorim Jaggiae962e62018-12-27 17:23:48 +0100113 private final Runnable mUpdateInputWindows = new Runnable() {
114 @Override
115 public void run() {
116 synchronized (mService.mGlobalLock) {
117 mUpdateInputWindowsPending = false;
118 mUpdateInputWindowsNeeded = false;
119
120 if (mDisplayRemoved) {
121 return;
122 }
123
124 // Populate the input window list with information about all of the windows that
125 // could potentially receive input.
126 // As an optimization, we could try to prune the list of windows but this turns
127 // out to be difficult because only the native code knows for sure which window
128 // currently has touch focus.
129
130 // If there's a drag in flight, provide a pseudo-window to catch drag input
131 final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100132 final boolean inPositioning =
133 mService.mTaskPositioningController.isPositioningLocked();
134 if (inPositioning) {
135 if (DEBUG_TASK_POSITIONING) {
136 Log.d(TAG_WM, "Inserting window handle for repositioning");
137 }
138 mService.mTaskPositioningController.showInputSurface(mInputTransaction,
139 mDisplayId);
140 } else {
141 mService.mTaskPositioningController.hideInputSurface(mInputTransaction,
142 mDisplayId);
143 }
144
145 // Add all windows on the default display.
146 mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);
147 }
148 }
149 };
150
Arthur Hung95b38a92018-07-20 18:56:12 +0800151 public InputMonitor(WindowManagerService service, int displayId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 mService = service;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100153 mDisplayContent = mService.mRoot.getDisplayContent(displayId);
Arthur Hung95b38a92018-07-20 18:56:12 +0800154 mDisplayId = displayId;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100155 mInputTransaction = mDisplayContent.getPendingTransaction();
156 mHandler = AnimationThread.getHandler();
Arthur Hung678024f2019-01-16 20:58:51 +0800157 mUpdateInputForAllWindowsConsumer = new UpdateInputForAllWindowsConsumer();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100158 }
159
160 void onDisplayRemoved() {
161 mHandler.removeCallbacks(mUpdateInputWindows);
Riddle Hsu3f2de742019-02-25 15:21:38 +0800162 mService.mInputManager.onDisplayRemoved(mDisplayId);
Jorim Jaggiae962e62018-12-27 17:23:48 +0100163 mDisplayRemoved = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700165
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700166 private void addInputConsumer(String name, InputConsumerImpl consumer) {
Winson41275482016-10-10 15:17:45 -0700167 mInputConsumers.put(name, consumer);
Winson Chung6463c362017-09-25 16:23:26 -0700168 consumer.linkToDeathRecipient();
Winson41275482016-10-10 15:17:45 -0700169 updateInputWindowsLw(true /* force */);
170 }
171
172 boolean destroyInputConsumer(String name) {
173 if (disposeInputConsumer(mInputConsumers.remove(name))) {
174 updateInputWindowsLw(true /* force */);
175 return true;
176 }
177 return false;
178 }
179
180 private boolean disposeInputConsumer(InputConsumerImpl consumer) {
181 if (consumer != null) {
182 consumer.disposeChannelsLw();
Robert Carra80ad042018-08-14 12:54:20 -0700183 consumer.hide(mInputTransaction);
Winson41275482016-10-10 15:17:45 -0700184 return true;
185 }
186 return false;
187 }
188
Arthur Hung95b38a92018-07-20 18:56:12 +0800189 InputConsumerImpl getInputConsumer(String name) {
190 return mInputConsumers.get(name);
Winson41275482016-10-10 15:17:45 -0700191 }
192
193 void layoutInputConsumers(int dw, int dh) {
Jorim Jaggi4981f152019-03-26 18:58:45 +0100194 try {
195 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "layoutInputConsumer");
196 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
197 mInputConsumers.valueAt(i).layout(mInputTransaction, dw, dh);
198 }
199 } finally {
200 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Robert Carra80ad042018-08-14 12:54:20 -0700201 }
202 }
203
204 // The visibility of the input consumers is recomputed each time we
205 // update the input windows. We use a model where consumers begin invisible
206 // (set so by this function) and must meet some condition for visibility on each update.
207 void resetInputConsumers(SurfaceControl.Transaction t) {
208 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
209 mInputConsumers.valueAt(i).hide(t);
Winson41275482016-10-10 15:17:45 -0700210 }
211 }
212
213 WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
214 InputEventReceiver.Factory inputEventReceiverFactory) {
215 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800216 throw new IllegalStateException("Existing input consumer found with name: " + name
217 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700218 }
Winson41275482016-10-10 15:17:45 -0700219 final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
Winson Chung6463c362017-09-25 16:23:26 -0700220 this, looper, name, inputEventReceiverFactory, Process.myPid(),
Arthur Hung95b38a92018-07-20 18:56:12 +0800221 UserHandle.SYSTEM, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700222 addInputConsumer(name, consumer);
223 return consumer;
224 }
225
Winson Chung6463c362017-09-25 16:23:26 -0700226 void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid,
227 UserHandle clientUser) {
Winson41275482016-10-10 15:17:45 -0700228 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800229 throw new IllegalStateException("Existing input consumer found with name: " + name
230 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700231 }
232
Winson Chung6463c362017-09-25 16:23:26 -0700233 final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name,
Arthur Hung95b38a92018-07-20 18:56:12 +0800234 inputChannel, clientPid, clientUser, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700235 switch (name) {
236 case INPUT_CONSUMER_WALLPAPER:
237 consumer.mWindowHandle.hasWallpaper = true;
238 break;
239 case INPUT_CONSUMER_PIP:
240 // The touchable region of the Pip input window is cropped to the bounds of the
241 // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700242 consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL;
Winson41275482016-10-10 15:17:45 -0700243 break;
244 }
245 addInputConsumer(name, consumer);
246 }
247
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248
Robert Carrb600bc22018-08-21 15:05:16 -0700249 void populateInputWindowHandle(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800250 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800251 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700252 // Add a window to our list of input windows.
253 inputWindowHandle.name = child.toString();
Riddle Hsuff03df52018-12-05 21:43:02 +0800254 flags = child.getSurfaceTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700255 inputWindowHandle.layoutParamsFlags = flags;
256 inputWindowHandle.layoutParamsType = type;
257 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
258 inputWindowHandle.visible = isVisible;
259 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
260 inputWindowHandle.hasFocus = hasFocus;
261 inputWindowHandle.hasWallpaper = hasWallpaper;
262 inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
263 inputWindowHandle.layer = child.mLayer;
264 inputWindowHandle.ownerPid = child.mSession.mPid;
265 inputWindowHandle.ownerUid = child.mSession.mUid;
266 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
Arthur Hung95b38a92018-07-20 18:56:12 +0800267 inputWindowHandle.displayId = child.getDisplayId();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700268
chaviw492139a2018-07-16 16:07:35 -0700269 final Rect frame = child.getFrameLw();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700270 inputWindowHandle.frameLeft = frame.left;
271 inputWindowHandle.frameTop = frame.top;
272 inputWindowHandle.frameRight = frame.right;
273 inputWindowHandle.frameBottom = frame.bottom;
274
Robert Carrfcc08522018-11-14 14:02:52 -0800275 // Surface insets are hardcoded to be the same in all directions
276 // and we could probably deprecate the "left/right/top/bottom" concept.
277 // we avoid reintroducing this concept by just choosing one of them here.
278 inputWindowHandle.surfaceInset = child.getAttrs().surfaceInsets.left;
279
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700280 if (child.mGlobalScale != 1) {
281 // If we are scaling the window, input coordinates need
282 // to be inversely scaled to map from what is on screen
283 // to what is actually being touched in the UI.
284 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
285 } else {
286 inputWindowHandle.scaleFactor = 1;
287 }
288
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700289 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800290 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800291 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700292 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700293
Robert Carrb600bc22018-08-21 15:05:16 -0700294 if (hasFocus) {
295 mFocusedInputWindowHandle = inputWindowHandle;
Jeff Brown9302c872011-07-13 22:51:29 -0700296 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 }
298
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000299 void setUpdateInputWindowsNeededLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 mUpdateInputWindowsNeeded = true;
301 }
302
303 /* Updates the cached window information provided to the input dispatcher. */
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000304 void updateInputWindowsLw(boolean force) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 if (!force && !mUpdateInputWindowsNeeded) {
306 return;
307 }
Jorim Jaggiae962e62018-12-27 17:23:48 +0100308 scheduleUpdateInputWindows();
309 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310
Jorim Jaggiae962e62018-12-27 17:23:48 +0100311 private void scheduleUpdateInputWindows() {
312 if (mDisplayRemoved) {
313 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 }
315
Jorim Jaggiae962e62018-12-27 17:23:48 +0100316 if (!mUpdateInputWindowsPending) {
317 mUpdateInputWindowsPending = true;
318 mHandler.post(mUpdateInputWindows);
Chong Zhang8e89b312015-09-09 15:09:30 -0700319 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000320 }
321
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 /* Called when the current input focus changes.
323 * Layer assignment is assumed to be complete by the time this is called.
324 */
325 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700326 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800327 Slog.d(TAG_WM, "Input focus has changed to " + newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 }
329
330 if (newWindow != mInputFocus) {
331 if (newWindow != null && newWindow.canReceiveKeys()) {
332 // Displaying a window implicitly causes dispatching to be unpaused.
333 // This is to protect against bugs if someone pauses dispatching but
334 // forgets to resume.
335 newWindow.mToken.paused = false;
336 }
337
338 mInputFocus = newWindow;
339 setUpdateInputWindowsNeededLw();
340
341 if (updateInputWindows) {
342 updateInputWindowsLw(false /*force*/);
343 }
344 }
345 }
Craig Mautner58458122013-09-14 14:59:50 -0700346
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 public void setFocusedAppLw(AppWindowToken newApp) {
348 // Focused app has changed.
349 if (newApp == null) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800350 mService.mInputManager.setFocusedApplication(mDisplayId, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700352 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
353 handle.name = newApp.toString();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800354 handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800356 mService.mInputManager.setFocusedApplication(mDisplayId, handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 }
358 }
Craig Mautner58458122013-09-14 14:59:50 -0700359
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800360 public void pauseDispatchingLw(WindowToken window) {
361 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700362 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800363 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700365
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 window.paused = true;
367 updateInputWindowsLw(true /*force*/);
368 }
369 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700370
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 public void resumeDispatchingLw(WindowToken window) {
372 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700373 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800374 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700376
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 window.paused = false;
378 updateInputWindowsLw(true /*force*/);
379 }
380 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700381
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800382 void dump(PrintWriter pw, String prefix) {
Winson Chung853c99a2017-03-21 22:16:42 -0700383 final Set<String> inputConsumerKeys = mInputConsumers.keySet();
384 if (!inputConsumerKeys.isEmpty()) {
385 pw.println(prefix + "InputConsumers:");
386 for (String key : inputConsumerKeys) {
Winson Chung6463c362017-09-25 16:23:26 -0700387 mInputConsumers.get(key).dump(pw, key, prefix);
Winson Chung853c99a2017-03-21 22:16:42 -0700388 }
389 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800390 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800391
392 private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800393 InputConsumerImpl navInputConsumer;
394 InputConsumerImpl pipInputConsumer;
395 InputConsumerImpl wallpaperInputConsumer;
Winson Chunga89ffed2018-01-25 17:46:11 +0000396 InputConsumerImpl recentsAnimationInputConsumer;
Arthur Hung95b38a92018-07-20 18:56:12 +0800397
398 private boolean mAddInputConsumerHandle;
399 private boolean mAddPipInputConsumerHandle;
400 private boolean mAddWallpaperInputConsumerHandle;
401 private boolean mAddRecentsAnimationInputConsumerHandle;
402
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800403 boolean inDrag;
404 WallpaperController wallpaperController;
405
Arthur Hung678024f2019-01-16 20:58:51 +0800406 // An invalid window handle that tells SurfaceFlinger not update the input info.
407 final InputWindowHandle mInvalidInputWindow = new InputWindowHandle(null, null, mDisplayId);
408
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800409 private void updateInputWindows(boolean inDrag) {
Jorim Jaggi4981f152019-03-26 18:58:45 +0100410 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
Jorim Jaggi60640512018-06-29 01:14:31 +0200411
Arthur Hung95b38a92018-07-20 18:56:12 +0800412 navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION);
413 pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP);
414 wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER);
415 recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION);
416
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800417 mAddInputConsumerHandle = navInputConsumer != null;
418 mAddPipInputConsumerHandle = pipInputConsumer != null;
419 mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
Winson Chunga89ffed2018-01-25 17:46:11 +0000420 mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null;
Arthur Hung95b38a92018-07-20 18:56:12 +0800421
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800422 mTmpRect.setEmpty();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800423 mDisableWallpaperTouchEvents = false;
424 this.inDrag = inDrag;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100425 wallpaperController = mDisplayContent.mWallpaperController;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800426
Robert Carra80ad042018-08-14 12:54:20 -0700427 resetInputConsumers(mInputTransaction);
428
Jorim Jaggiae962e62018-12-27 17:23:48 +0100429 mDisplayContent.forAllWindows(this,
Robert Carra80ad042018-08-14 12:54:20 -0700430 true /* traverseTopToBottom */);
431
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800432 if (mAddWallpaperInputConsumerHandle) {
Robert Carrb600bc22018-08-21 15:05:16 -0700433 wallpaperInputConsumer.show(mInputTransaction, 0);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800434 }
435
Jorim Jaggiae962e62018-12-27 17:23:48 +0100436 mDisplayContent.scheduleAnimation();
Vladislav Kaznacheev2e96c632016-12-13 14:31:24 -0800437
Jorim Jaggi4981f152019-03-26 18:58:45 +0100438 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800439 }
440
441 @Override
442 public void accept(WindowState w) {
443 final InputChannel inputChannel = w.mInputChannel;
444 final InputWindowHandle inputWindowHandle = w.mInputWindowHandle;
445 if (inputChannel == null || inputWindowHandle == null || w.mRemoved
Robert Carrebdf8582018-09-04 14:50:15 -0700446 || w.cantReceiveTouchInput()) {
Arthur Hung678024f2019-01-16 20:58:51 +0800447 if (w.mWinAnimator.hasSurface()) {
448 mInputTransaction.setInputWindowInfo(
449 w.mWinAnimator.mSurfaceController.mSurfaceControl, mInvalidInputWindow);
450 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800451 // Skip this window because it cannot possibly receive input.
452 return;
453 }
454
Winson Chung61ecc1b2017-02-17 10:46:17 -0800455 final int flags = w.mAttrs.flags;
456 final int privateFlags = w.mAttrs.privateFlags;
457 final int type = w.mAttrs.type;
Arthur Hung39134b22018-08-14 11:58:28 +0800458 final boolean hasFocus = w.isFocused();
Winson Chung61ecc1b2017-02-17 10:46:17 -0800459 final boolean isVisible = w.isVisibleLw();
460
Winson Chunga89ffed2018-01-25 17:46:11 +0000461 if (mAddRecentsAnimationInputConsumerHandle) {
462 final RecentsAnimationController recentsAnimationController =
463 mService.getRecentsAnimationController();
464 if (recentsAnimationController != null
Winson Chungdb111ee2018-10-03 14:25:34 -0700465 && recentsAnimationController.shouldApplyInputConsumer(w.mAppToken)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000466 if (recentsAnimationController.updateInputConsumerForApp(
Arthur Hung95b38a92018-07-20 18:56:12 +0800467 recentsAnimationInputConsumer.mWindowHandle, hasFocus)) {
Robert Carra80ad042018-08-14 12:54:20 -0700468 recentsAnimationInputConsumer.show(mInputTransaction, w);
Winson Chunga89ffed2018-01-25 17:46:11 +0000469 mAddRecentsAnimationInputConsumerHandle = false;
470 }
Winson Chunga89ffed2018-01-25 17:46:11 +0000471 }
472 }
473
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700474 if (w.inPinnedWindowingMode()) {
Robert Carra80ad042018-08-14 12:54:20 -0700475 if (mAddPipInputConsumerHandle) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800476 // Update the bounds of the Pip input consumer to match the window bounds.
Winson Chunga89ffed2018-01-25 17:46:11 +0000477 w.getBounds(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700478 pipInputConsumer.layout(mInputTransaction, mTmpRect);
Robert Carr47ea21d2018-11-28 13:42:45 -0800479
480 // The touchable region is relative to the surface top-left
481 mTmpRect.offsetTo(0, 0);
Winson Chunga89ffed2018-01-25 17:46:11 +0000482 pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700483 pipInputConsumer.show(mInputTransaction, w);
Winson Chung61ecc1b2017-02-17 10:46:17 -0800484 mAddPipInputConsumerHandle = false;
485 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800486 }
487
488 if (mAddInputConsumerHandle
489 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
Robert Carra80ad042018-08-14 12:54:20 -0700490 navInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800491 mAddInputConsumerHandle = false;
492 }
493
494 if (mAddWallpaperInputConsumerHandle) {
495 if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) {
496 // Add the wallpaper input consumer above the first visible wallpaper.
Robert Carra80ad042018-08-14 12:54:20 -0700497 wallpaperInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800498 mAddWallpaperInputConsumerHandle = false;
499 }
500 }
501
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800502 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
503 mDisableWallpaperTouchEvents = true;
504 }
505 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w)
506 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
507 && !mDisableWallpaperTouchEvents;
508
509 // If there's a drag in progress and 'child' is a potential drop target,
510 // make sure it's been told about the drag
511 if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) {
Daichi Hirono768012e2017-10-30 10:05:37 +0900512 mService.mDragDropController.sendDragStartedIfNeededLocked(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800513 }
514
Robert Carrb600bc22018-08-21 15:05:16 -0700515 populateInputWindowHandle(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800516 inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
Robert Carr679ccb02018-08-08 15:32:35 -0700517
518 if (w.mWinAnimator.hasSurface()) {
519 mInputTransaction.setInputWindowInfo(
520 w.mWinAnimator.mSurfaceController.mSurfaceControl, inputWindowHandle);
521 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800522 }
523 }
Jeff Brownea426552011-07-18 16:53:48 -0700524}