blob: a8ff5002bc5845e78c28be4ef3a074c7f3321969 [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
Adrian Roosb125e0b2019-10-02 14:55:14 +020029import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import 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
Adrian Roose99bc052017-11-20 17:55:31 +010050import com.android.server.policy.WindowManagerPolicy;
Adrian Roosb125e0b2019-10-02 14:55:14 +020051import com.android.server.protolog.common.ProtoLog;
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;
chaviw86dc82e2019-04-01 16:53:30 -070066 private boolean mApplyImmediately;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067
Robert Carrb600bc22018-08-21 15:05:16 -070068 // Currently focused input window handle.
69 private InputWindowHandle mFocusedInputWindowHandle;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080070
Wale Ogunwale6213caa2016-12-02 16:47:15 +000071 private boolean mDisableWallpaperTouchEvents;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080072 private final Rect mTmpRect = new Rect();
Arthur Hung678024f2019-01-16 20:58:51 +080073 private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer;
Jeff Brown9302c872011-07-13 22:51:29 -070074
Vishnu Nair9e7dbc82018-12-20 08:45:28 -080075 private final int mDisplayId;
Jorim Jaggiae962e62018-12-27 17:23:48 +010076 private final DisplayContent mDisplayContent;
77 private boolean mDisplayRemoved;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078
Vishnu Nair9e7dbc82018-12-20 08:45:28 -080079 private final SurfaceControl.Transaction mInputTransaction;
Jorim Jaggiae962e62018-12-27 17:23:48 +010080 private final Handler mHandler;
Robert Carr679ccb02018-08-08 15:32:35 -070081
Winson41275482016-10-10 15:17:45 -070082 /**
83 * The set of input consumer added to the window manager by name, which consumes input events
84 * for the windows below it.
85 */
86 private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
87
88 private static final class EventReceiverInputConsumer extends InputConsumerImpl
89 implements WindowManagerPolicy.InputConsumer {
90 private InputMonitor mInputMonitor;
91 private final InputEventReceiver mInputEventReceiver;
92
93 EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
94 Looper looper, String name,
Winson Chung6463c362017-09-25 16:23:26 -070095 InputEventReceiver.Factory inputEventReceiverFactory,
Arthur Hung95b38a92018-07-20 18:56:12 +080096 int clientPid, UserHandle clientUser, int displayId) {
97 super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser,
98 displayId);
Winson41275482016-10-10 15:17:45 -070099 mInputMonitor = monitor;
100 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
101 mClientChannel, looper);
102 }
103
104 @Override
105 public void dismiss() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700106 synchronized (mService.mGlobalLock) {
Winson41275482016-10-10 15:17:45 -0700107 if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
108 mInputEventReceiver.dispose();
109 }
110 }
111 }
112 }
113
Riddle Hsu2ca561b2019-10-08 21:58:58 +0800114 private class UpdateInputWindows implements Runnable {
Jorim Jaggiae962e62018-12-27 17:23:48 +0100115 @Override
116 public void run() {
117 synchronized (mService.mGlobalLock) {
118 mUpdateInputWindowsPending = false;
119 mUpdateInputWindowsNeeded = false;
120
121 if (mDisplayRemoved) {
122 return;
123 }
124
125 // Populate the input window list with information about all of the windows that
126 // could potentially receive input.
127 // As an optimization, we could try to prune the list of windows but this turns
128 // out to be difficult because only the native code knows for sure which window
129 // currently has touch focus.
130
131 // If there's a drag in flight, provide a pseudo-window to catch drag input
132 final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100133 final boolean inPositioning =
134 mService.mTaskPositioningController.isPositioningLocked();
135 if (inPositioning) {
136 if (DEBUG_TASK_POSITIONING) {
137 Log.d(TAG_WM, "Inserting window handle for repositioning");
138 }
139 mService.mTaskPositioningController.showInputSurface(mInputTransaction,
140 mDisplayId);
141 } else {
142 mService.mTaskPositioningController.hideInputSurface(mInputTransaction,
143 mDisplayId);
144 }
145
146 // Add all windows on the default display.
147 mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);
148 }
149 }
Riddle Hsu2ca561b2019-10-08 21:58:58 +0800150 }
151
152 private final UpdateInputWindows mUpdateInputWindows = new UpdateInputWindows();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100153
Arthur Hung95b38a92018-07-20 18:56:12 +0800154 public InputMonitor(WindowManagerService service, int displayId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 mService = service;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100156 mDisplayContent = mService.mRoot.getDisplayContent(displayId);
Arthur Hung95b38a92018-07-20 18:56:12 +0800157 mDisplayId = displayId;
Vishnu Nair33197392019-08-30 10:29:37 -0700158 mInputTransaction = mService.mTransactionFactory.get();
Riddle Hsue459c632020-01-03 22:37:47 +0800159 mHandler = mService.mAnimationHandler;
Arthur Hung678024f2019-01-16 20:58:51 +0800160 mUpdateInputForAllWindowsConsumer = new UpdateInputForAllWindowsConsumer();
Jorim Jaggiae962e62018-12-27 17:23:48 +0100161 }
162
163 void onDisplayRemoved() {
164 mHandler.removeCallbacks(mUpdateInputWindows);
Riddle Hsu3f2de742019-02-25 15:21:38 +0800165 mService.mInputManager.onDisplayRemoved(mDisplayId);
Jorim Jaggiae962e62018-12-27 17:23:48 +0100166 mDisplayRemoved = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700168
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700169 private void addInputConsumer(String name, InputConsumerImpl consumer) {
Winson41275482016-10-10 15:17:45 -0700170 mInputConsumers.put(name, consumer);
Winson Chung6463c362017-09-25 16:23:26 -0700171 consumer.linkToDeathRecipient();
Winson41275482016-10-10 15:17:45 -0700172 updateInputWindowsLw(true /* force */);
173 }
174
175 boolean destroyInputConsumer(String name) {
176 if (disposeInputConsumer(mInputConsumers.remove(name))) {
177 updateInputWindowsLw(true /* force */);
178 return true;
179 }
180 return false;
181 }
182
183 private boolean disposeInputConsumer(InputConsumerImpl consumer) {
184 if (consumer != null) {
185 consumer.disposeChannelsLw();
Robert Carra80ad042018-08-14 12:54:20 -0700186 consumer.hide(mInputTransaction);
Winson41275482016-10-10 15:17:45 -0700187 return true;
188 }
189 return false;
190 }
191
Arthur Hung95b38a92018-07-20 18:56:12 +0800192 InputConsumerImpl getInputConsumer(String name) {
193 return mInputConsumers.get(name);
Winson41275482016-10-10 15:17:45 -0700194 }
195
196 void layoutInputConsumers(int dw, int dh) {
Jorim Jaggi4981f152019-03-26 18:58:45 +0100197 try {
198 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "layoutInputConsumer");
199 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
200 mInputConsumers.valueAt(i).layout(mInputTransaction, dw, dh);
201 }
202 } finally {
203 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Robert Carra80ad042018-08-14 12:54:20 -0700204 }
205 }
206
207 // The visibility of the input consumers is recomputed each time we
208 // update the input windows. We use a model where consumers begin invisible
209 // (set so by this function) and must meet some condition for visibility on each update.
210 void resetInputConsumers(SurfaceControl.Transaction t) {
211 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
212 mInputConsumers.valueAt(i).hide(t);
Winson41275482016-10-10 15:17:45 -0700213 }
214 }
215
216 WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
217 InputEventReceiver.Factory inputEventReceiverFactory) {
218 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800219 throw new IllegalStateException("Existing input consumer found with name: " + name
220 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700221 }
Winson41275482016-10-10 15:17:45 -0700222 final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
Winson Chung6463c362017-09-25 16:23:26 -0700223 this, looper, name, inputEventReceiverFactory, Process.myPid(),
Arthur Hung95b38a92018-07-20 18:56:12 +0800224 UserHandle.SYSTEM, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700225 addInputConsumer(name, consumer);
226 return consumer;
227 }
228
Winson Chung6463c362017-09-25 16:23:26 -0700229 void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid,
230 UserHandle clientUser) {
Winson41275482016-10-10 15:17:45 -0700231 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800232 throw new IllegalStateException("Existing input consumer found with name: " + name
233 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700234 }
235
Winson Chung6463c362017-09-25 16:23:26 -0700236 final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name,
Arthur Hung95b38a92018-07-20 18:56:12 +0800237 inputChannel, clientPid, clientUser, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700238 switch (name) {
239 case INPUT_CONSUMER_WALLPAPER:
240 consumer.mWindowHandle.hasWallpaper = true;
241 break;
242 case INPUT_CONSUMER_PIP:
243 // The touchable region of the Pip input window is cropped to the bounds of the
244 // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700245 consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL;
Winson41275482016-10-10 15:17:45 -0700246 break;
247 }
248 addInputConsumer(name, consumer);
249 }
250
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251
Robert Carrb600bc22018-08-21 15:05:16 -0700252 void populateInputWindowHandle(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800253 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800254 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700255 // Add a window to our list of input windows.
256 inputWindowHandle.name = child.toString();
Vishnu Nair93d68c22019-03-22 13:45:31 -0700257 flags = child.getSurfaceTouchableRegion(inputWindowHandle, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700258 inputWindowHandle.layoutParamsFlags = flags;
259 inputWindowHandle.layoutParamsType = type;
260 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
261 inputWindowHandle.visible = isVisible;
262 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
263 inputWindowHandle.hasFocus = hasFocus;
264 inputWindowHandle.hasWallpaper = hasWallpaper;
Garfield Tane8d84ab2019-10-11 09:49:40 -0700265 inputWindowHandle.paused = child.mActivityRecord != null ? child.mActivityRecord.paused : false;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700266 inputWindowHandle.ownerPid = child.mSession.mPid;
267 inputWindowHandle.ownerUid = child.mSession.mUid;
268 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
Arthur Hung95b38a92018-07-20 18:56:12 +0800269 inputWindowHandle.displayId = child.getDisplayId();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700270
chaviw492139a2018-07-16 16:07:35 -0700271 final Rect frame = child.getFrameLw();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700272 inputWindowHandle.frameLeft = frame.left;
273 inputWindowHandle.frameTop = frame.top;
274 inputWindowHandle.frameRight = frame.right;
275 inputWindowHandle.frameBottom = frame.bottom;
276
Robert Carrfcc08522018-11-14 14:02:52 -0800277 // Surface insets are hardcoded to be the same in all directions
278 // and we could probably deprecate the "left/right/top/bottom" concept.
279 // we avoid reintroducing this concept by just choosing one of them here.
280 inputWindowHandle.surfaceInset = child.getAttrs().surfaceInsets.left;
281
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700282 if (child.mGlobalScale != 1) {
283 // If we are scaling the window, input coordinates need
284 // to be inversely scaled to map from what is on screen
285 // to what is actually being touched in the UI.
286 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
287 } else {
288 inputWindowHandle.scaleFactor = 1;
289 }
290
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700291 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800292 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800293 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700294 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700295
Robert Carrb600bc22018-08-21 15:05:16 -0700296 if (hasFocus) {
297 mFocusedInputWindowHandle = inputWindowHandle;
Jeff Brown9302c872011-07-13 22:51:29 -0700298 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299 }
300
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000301 void setUpdateInputWindowsNeededLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 mUpdateInputWindowsNeeded = true;
303 }
304
305 /* Updates the cached window information provided to the input dispatcher. */
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000306 void updateInputWindowsLw(boolean force) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 if (!force && !mUpdateInputWindowsNeeded) {
308 return;
309 }
Jorim Jaggiae962e62018-12-27 17:23:48 +0100310 scheduleUpdateInputWindows();
311 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312
Jorim Jaggiae962e62018-12-27 17:23:48 +0100313 private void scheduleUpdateInputWindows() {
314 if (mDisplayRemoved) {
315 return;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 }
317
Jorim Jaggiae962e62018-12-27 17:23:48 +0100318 if (!mUpdateInputWindowsPending) {
319 mUpdateInputWindowsPending = true;
320 mHandler.post(mUpdateInputWindows);
Chong Zhang8e89b312015-09-09 15:09:30 -0700321 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000322 }
323
chaviw86dc82e2019-04-01 16:53:30 -0700324 void updateInputWindowsImmediately() {
wilsonshih6164e012019-05-06 09:31:02 +0800325 mHandler.removeCallbacks(mUpdateInputWindows);
326 mApplyImmediately = true;
327 mUpdateInputWindows.run();
328 mApplyImmediately = false;
chaviw86dc82e2019-04-01 16:53:30 -0700329 }
330
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 /* Called when the current input focus changes.
332 * Layer assignment is assumed to be complete by the time this is called.
333 */
334 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Adrian Roosb125e0b2019-10-02 14:55:14 +0200335 ProtoLog.d(WM_DEBUG_FOCUS_LIGHT, "Input focus has changed to %s", newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336
337 if (newWindow != mInputFocus) {
338 if (newWindow != null && newWindow.canReceiveKeys()) {
339 // Displaying a window implicitly causes dispatching to be unpaused.
340 // This is to protect against bugs if someone pauses dispatching but
341 // forgets to resume.
342 newWindow.mToken.paused = false;
343 }
344
345 mInputFocus = newWindow;
346 setUpdateInputWindowsNeededLw();
347
348 if (updateInputWindows) {
349 updateInputWindowsLw(false /*force*/);
350 }
351 }
352 }
Craig Mautner58458122013-09-14 14:59:50 -0700353
Garfield Tane8d84ab2019-10-11 09:49:40 -0700354 public void setFocusedAppLw(ActivityRecord newApp) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 // Focused app has changed.
356 if (newApp == null) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800357 mService.mInputManager.setFocusedApplication(mDisplayId, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700359 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
360 handle.name = newApp.toString();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800361 handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800363 mService.mInputManager.setFocusedApplication(mDisplayId, handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 }
365 }
Craig Mautner58458122013-09-14 14:59:50 -0700366
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 public void pauseDispatchingLw(WindowToken window) {
368 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700369 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800370 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700372
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373 window.paused = true;
374 updateInputWindowsLw(true /*force*/);
375 }
376 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700377
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 public void resumeDispatchingLw(WindowToken window) {
379 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700380 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800381 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 window.paused = false;
385 updateInputWindowsLw(true /*force*/);
386 }
387 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700388
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800389 void dump(PrintWriter pw, String prefix) {
Winson Chung853c99a2017-03-21 22:16:42 -0700390 final Set<String> inputConsumerKeys = mInputConsumers.keySet();
391 if (!inputConsumerKeys.isEmpty()) {
392 pw.println(prefix + "InputConsumers:");
393 for (String key : inputConsumerKeys) {
Winson Chung6463c362017-09-25 16:23:26 -0700394 mInputConsumers.get(key).dump(pw, key, prefix);
Winson Chung853c99a2017-03-21 22:16:42 -0700395 }
396 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800397 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800398
399 private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800400 InputConsumerImpl navInputConsumer;
401 InputConsumerImpl pipInputConsumer;
402 InputConsumerImpl wallpaperInputConsumer;
Winson Chunga89ffed2018-01-25 17:46:11 +0000403 InputConsumerImpl recentsAnimationInputConsumer;
Arthur Hung95b38a92018-07-20 18:56:12 +0800404
405 private boolean mAddInputConsumerHandle;
406 private boolean mAddPipInputConsumerHandle;
407 private boolean mAddWallpaperInputConsumerHandle;
408 private boolean mAddRecentsAnimationInputConsumerHandle;
409
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800410 boolean inDrag;
411 WallpaperController wallpaperController;
412
Arthur Hung678024f2019-01-16 20:58:51 +0800413 // An invalid window handle that tells SurfaceFlinger not update the input info.
Vishnu Nair18782162019-10-08 14:57:16 -0700414 final InputWindowHandle mInvalidInputWindow = new InputWindowHandle(null, mDisplayId);
Arthur Hung678024f2019-01-16 20:58:51 +0800415
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800416 private void updateInputWindows(boolean inDrag) {
Jorim Jaggi4981f152019-03-26 18:58:45 +0100417 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
Jorim Jaggi60640512018-06-29 01:14:31 +0200418
Arthur Hung95b38a92018-07-20 18:56:12 +0800419 navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION);
420 pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP);
421 wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER);
422 recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION);
423
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800424 mAddInputConsumerHandle = navInputConsumer != null;
425 mAddPipInputConsumerHandle = pipInputConsumer != null;
426 mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
Winson Chunga89ffed2018-01-25 17:46:11 +0000427 mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null;
Arthur Hung95b38a92018-07-20 18:56:12 +0800428
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800429 mTmpRect.setEmpty();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800430 mDisableWallpaperTouchEvents = false;
431 this.inDrag = inDrag;
Jorim Jaggiae962e62018-12-27 17:23:48 +0100432 wallpaperController = mDisplayContent.mWallpaperController;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800433
Robert Carra80ad042018-08-14 12:54:20 -0700434 resetInputConsumers(mInputTransaction);
435
Jorim Jaggiae962e62018-12-27 17:23:48 +0100436 mDisplayContent.forAllWindows(this,
Robert Carra80ad042018-08-14 12:54:20 -0700437 true /* traverseTopToBottom */);
438
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800439 if (mAddWallpaperInputConsumerHandle) {
Robert Carrb600bc22018-08-21 15:05:16 -0700440 wallpaperInputConsumer.show(mInputTransaction, 0);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800441 }
442
chaviw86dc82e2019-04-01 16:53:30 -0700443 if (mApplyImmediately) {
444 mInputTransaction.apply();
445 } else {
446 mDisplayContent.getPendingTransaction().merge(mInputTransaction);
447 mDisplayContent.scheduleAnimation();
448 }
Vladislav Kaznacheev2e96c632016-12-13 14:31:24 -0800449
Jorim Jaggi4981f152019-03-26 18:58:45 +0100450 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800451 }
452
453 @Override
454 public void accept(WindowState w) {
455 final InputChannel inputChannel = w.mInputChannel;
456 final InputWindowHandle inputWindowHandle = w.mInputWindowHandle;
457 if (inputChannel == null || inputWindowHandle == null || w.mRemoved
Robert Carrebdf8582018-09-04 14:50:15 -0700458 || w.cantReceiveTouchInput()) {
Arthur Hung678024f2019-01-16 20:58:51 +0800459 if (w.mWinAnimator.hasSurface()) {
460 mInputTransaction.setInputWindowInfo(
461 w.mWinAnimator.mSurfaceController.mSurfaceControl, mInvalidInputWindow);
462 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800463 // Skip this window because it cannot possibly receive input.
464 return;
465 }
466
Winson Chung61ecc1b2017-02-17 10:46:17 -0800467 final int flags = w.mAttrs.flags;
468 final int privateFlags = w.mAttrs.privateFlags;
469 final int type = w.mAttrs.type;
Arthur Hung39134b22018-08-14 11:58:28 +0800470 final boolean hasFocus = w.isFocused();
Winson Chung61ecc1b2017-02-17 10:46:17 -0800471 final boolean isVisible = w.isVisibleLw();
472
Winson Chunga89ffed2018-01-25 17:46:11 +0000473 if (mAddRecentsAnimationInputConsumerHandle) {
474 final RecentsAnimationController recentsAnimationController =
475 mService.getRecentsAnimationController();
476 if (recentsAnimationController != null
Garfield Tane8d84ab2019-10-11 09:49:40 -0700477 && recentsAnimationController.shouldApplyInputConsumer(w.mActivityRecord)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000478 if (recentsAnimationController.updateInputConsumerForApp(
Arthur Hung95b38a92018-07-20 18:56:12 +0800479 recentsAnimationInputConsumer.mWindowHandle, hasFocus)) {
Robert Carra80ad042018-08-14 12:54:20 -0700480 recentsAnimationInputConsumer.show(mInputTransaction, w);
Winson Chunga89ffed2018-01-25 17:46:11 +0000481 mAddRecentsAnimationInputConsumerHandle = false;
482 }
Winson Chunga89ffed2018-01-25 17:46:11 +0000483 }
484 }
485
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700486 if (w.inPinnedWindowingMode()) {
Robert Carra80ad042018-08-14 12:54:20 -0700487 if (mAddPipInputConsumerHandle) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800488 // Update the bounds of the Pip input consumer to match the window bounds.
Winson Chunga89ffed2018-01-25 17:46:11 +0000489 w.getBounds(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700490 pipInputConsumer.layout(mInputTransaction, mTmpRect);
Robert Carr47ea21d2018-11-28 13:42:45 -0800491
492 // The touchable region is relative to the surface top-left
493 mTmpRect.offsetTo(0, 0);
Winson Chunga89ffed2018-01-25 17:46:11 +0000494 pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
Robert Carra80ad042018-08-14 12:54:20 -0700495 pipInputConsumer.show(mInputTransaction, w);
Winson Chung61ecc1b2017-02-17 10:46:17 -0800496 mAddPipInputConsumerHandle = false;
497 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800498 }
499
chaviw7a67d072019-12-30 14:04:08 -0800500 if (mAddInputConsumerHandle) {
Robert Carra80ad042018-08-14 12:54:20 -0700501 navInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800502 mAddInputConsumerHandle = false;
503 }
504
505 if (mAddWallpaperInputConsumerHandle) {
506 if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) {
507 // Add the wallpaper input consumer above the first visible wallpaper.
Robert Carra80ad042018-08-14 12:54:20 -0700508 wallpaperInputConsumer.show(mInputTransaction, w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800509 mAddWallpaperInputConsumerHandle = false;
510 }
511 }
512
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800513 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
514 mDisableWallpaperTouchEvents = true;
515 }
516 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w)
517 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
518 && !mDisableWallpaperTouchEvents;
519
520 // If there's a drag in progress and 'child' is a potential drop target,
521 // make sure it's been told about the drag
522 if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) {
Daichi Hirono768012e2017-10-30 10:05:37 +0900523 mService.mDragDropController.sendDragStartedIfNeededLocked(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800524 }
525
Robert Carrb600bc22018-08-21 15:05:16 -0700526 populateInputWindowHandle(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800527 inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
Robert Carr679ccb02018-08-08 15:32:35 -0700528
Vishnu Nair539334a2019-09-20 10:46:21 -0700529 // register key interception info
530 mService.mKeyInterceptionInfoForToken.put(inputWindowHandle.token,
531 w.getKeyInterceptionInfo());
532
Robert Carr679ccb02018-08-08 15:32:35 -0700533 if (w.mWinAnimator.hasSurface()) {
534 mInputTransaction.setInputWindowInfo(
535 w.mWinAnimator.mSurfaceController.mSurfaceControl, inputWindowHandle);
536 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800537 }
538 }
Jeff Brownea426552011-07-18 16:53:48 -0700539}