blob: 61bc4e405385e6ab10923eb4b09f87e5f3698321 [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;
Jeff Browncc4f7db2011-08-30 20:34:48 -070043import android.view.InputChannel;
Winson41275482016-10-10 15:17:45 -070044import android.view.InputEventReceiver;
Robert Carr788f5742018-07-30 17:46:45 -070045import android.view.KeyEvent;
46import android.view.WindowManager;
47import android.view.InputApplicationHandle;
48import android.view.InputWindowHandle;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080049
Robert Carr788f5742018-07-30 17:46:45 -070050import com.android.server.input.InputManagerService;
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;
Jeff Brown9302c872011-07-13 22:51:29 -070054import java.util.Arrays;
Winson Chung853c99a2017-03-21 22:16:42 -070055import java.util.Set;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080056import java.util.function.Consumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080057
Arthur Hung95b38a92018-07-20 18:56:12 +080058final class InputMonitor {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080059 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070060
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061 // Current window with input focus for keys and other non-touch events. May be null.
62 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070063
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080064 // When true, need to call updateInputWindowsLw().
65 private boolean mUpdateInputWindowsNeeded = true;
66
Jeff Brown9302c872011-07-13 22:51:29 -070067 // Array of window handles to provide to the input dispatcher.
68 private InputWindowHandle[] mInputWindowHandles;
69 private int mInputWindowHandleCount;
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();
73 private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer =
74 new UpdateInputForAllWindowsConsumer();
Jeff Brown9302c872011-07-13 22:51:29 -070075
Arthur Hung95b38a92018-07-20 18:56:12 +080076 private int mDisplayId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080077
Winson41275482016-10-10 15:17:45 -070078 /**
79 * The set of input consumer added to the window manager by name, which consumes input events
80 * for the windows below it.
81 */
82 private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
83
84 private static final class EventReceiverInputConsumer extends InputConsumerImpl
85 implements WindowManagerPolicy.InputConsumer {
86 private InputMonitor mInputMonitor;
87 private final InputEventReceiver mInputEventReceiver;
88
89 EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
90 Looper looper, String name,
Winson Chung6463c362017-09-25 16:23:26 -070091 InputEventReceiver.Factory inputEventReceiverFactory,
Arthur Hung95b38a92018-07-20 18:56:12 +080092 int clientPid, UserHandle clientUser, int displayId) {
93 super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser,
94 displayId);
Winson41275482016-10-10 15:17:45 -070095 mInputMonitor = monitor;
96 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
97 mClientChannel, looper);
98 }
99
100 @Override
101 public void dismiss() {
Wale Ogunwaledb485de2018-10-29 09:47:07 -0700102 synchronized (mService.mGlobalLock) {
Winson41275482016-10-10 15:17:45 -0700103 if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
104 mInputEventReceiver.dispose();
105 }
106 }
107 }
108 }
109
Arthur Hung95b38a92018-07-20 18:56:12 +0800110 public InputMonitor(WindowManagerService service, int displayId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 mService = service;
Arthur Hung95b38a92018-07-20 18:56:12 +0800112 mDisplayId = displayId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700114
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700115 private void addInputConsumer(String name, InputConsumerImpl consumer) {
Winson41275482016-10-10 15:17:45 -0700116 mInputConsumers.put(name, consumer);
Winson Chung6463c362017-09-25 16:23:26 -0700117 consumer.linkToDeathRecipient();
Winson41275482016-10-10 15:17:45 -0700118 updateInputWindowsLw(true /* force */);
119 }
120
121 boolean destroyInputConsumer(String name) {
122 if (disposeInputConsumer(mInputConsumers.remove(name))) {
123 updateInputWindowsLw(true /* force */);
124 return true;
125 }
126 return false;
127 }
128
129 private boolean disposeInputConsumer(InputConsumerImpl consumer) {
130 if (consumer != null) {
131 consumer.disposeChannelsLw();
132 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--) {
143 mInputConsumers.valueAt(i).layout(dw, dh);
144 }
145 }
146
147 WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
148 InputEventReceiver.Factory inputEventReceiverFactory) {
149 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800150 throw new IllegalStateException("Existing input consumer found with name: " + name
151 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700152 }
Winson41275482016-10-10 15:17:45 -0700153 final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
Winson Chung6463c362017-09-25 16:23:26 -0700154 this, looper, name, inputEventReceiverFactory, Process.myPid(),
Arthur Hung95b38a92018-07-20 18:56:12 +0800155 UserHandle.SYSTEM, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700156 addInputConsumer(name, consumer);
157 return consumer;
158 }
159
Winson Chung6463c362017-09-25 16:23:26 -0700160 void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid,
161 UserHandle clientUser) {
Winson41275482016-10-10 15:17:45 -0700162 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800163 throw new IllegalStateException("Existing input consumer found with name: " + name
164 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700165 }
166
Winson Chung6463c362017-09-25 16:23:26 -0700167 final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name,
Arthur Hung95b38a92018-07-20 18:56:12 +0800168 inputChannel, clientPid, clientUser, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700169 switch (name) {
170 case INPUT_CONSUMER_WALLPAPER:
171 consumer.mWindowHandle.hasWallpaper = true;
172 break;
173 case INPUT_CONSUMER_PIP:
174 // The touchable region of the Pip input window is cropped to the bounds of the
175 // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700176 consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL;
Winson41275482016-10-10 15:17:45 -0700177 break;
178 }
179 addInputConsumer(name, consumer);
180 }
181
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800182
Wale Ogunwale7402ddf2017-03-29 12:58:24 -0700183 private void addInputWindowHandle(final InputWindowHandle windowHandle) {
Jeff Brown9302c872011-07-13 22:51:29 -0700184 if (mInputWindowHandles == null) {
185 mInputWindowHandles = new InputWindowHandle[16];
186 }
187 if (mInputWindowHandleCount >= mInputWindowHandles.length) {
188 mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
189 mInputWindowHandleCount * 2);
190 }
191 mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
192 }
193
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700194 void addInputWindowHandle(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800195 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800196 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700197 // Add a window to our list of input windows.
198 inputWindowHandle.name = child.toString();
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800199 flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700200 inputWindowHandle.layoutParamsFlags = flags;
201 inputWindowHandle.layoutParamsType = type;
202 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
203 inputWindowHandle.visible = isVisible;
204 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
205 inputWindowHandle.hasFocus = hasFocus;
206 inputWindowHandle.hasWallpaper = hasWallpaper;
207 inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
208 inputWindowHandle.layer = child.mLayer;
209 inputWindowHandle.ownerPid = child.mSession.mPid;
210 inputWindowHandle.ownerUid = child.mSession.mUid;
211 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
Arthur Hung95b38a92018-07-20 18:56:12 +0800212 inputWindowHandle.displayId = child.getDisplayId();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700213
chaviw492139a2018-07-16 16:07:35 -0700214 final Rect frame = child.getFrameLw();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700215 inputWindowHandle.frameLeft = frame.left;
216 inputWindowHandle.frameTop = frame.top;
217 inputWindowHandle.frameRight = frame.right;
218 inputWindowHandle.frameBottom = frame.bottom;
219
220 if (child.mGlobalScale != 1) {
221 // If we are scaling the window, input coordinates need
222 // to be inversely scaled to map from what is on screen
223 // to what is actually being touched in the UI.
224 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
225 } else {
226 inputWindowHandle.scaleFactor = 1;
227 }
228
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700229 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800230 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800231 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700232 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700233 addInputWindowHandle(inputWindowHandle);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700234 }
235
Jeff Brown9302c872011-07-13 22:51:29 -0700236 private void clearInputWindowHandlesLw() {
237 while (mInputWindowHandleCount != 0) {
238 mInputWindowHandles[--mInputWindowHandleCount] = null;
239 }
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 }
Daichi Hirono76a26aa2017-09-11 15:13:38 +0900267 final InputWindowHandle dragWindowHandle =
Daichi Hirono768012e2017-10-30 10:05:37 +0900268 mService.mDragDropController.getInputWindowHandleLocked();
Garfield Tan07544cd2018-09-12 16:16:54 -0700269 if (dragWindowHandle == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800270 Slog.w(TAG_WM, "Drag is in progress but there is no "
Jeff Browncc4f7db2011-08-30 20:34:48 -0700271 + "drag window handle.");
Garfield Tan07544cd2018-09-12 16:16:54 -0700272 } else if (dragWindowHandle.displayId == mDisplayId) {
273 addInputWindowHandle(dragWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700274 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 }
276
Daichi Hirono34fb7312017-12-04 10:00:24 +0900277 final boolean inPositioning = mService.mTaskPositioningController.isPositioningLocked();
Chong Zhang8e89b312015-09-09 15:09:30 -0700278 if (inPositioning) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800279 if (DEBUG_TASK_POSITIONING) {
280 Log.d(TAG_WM, "Inserting window handle for repositioning");
Chong Zhang8e89b312015-09-09 15:09:30 -0700281 }
Daichi Hirono34fb7312017-12-04 10:00:24 +0900282 final InputWindowHandle dragWindowHandle =
283 mService.mTaskPositioningController.getDragWindowHandleLocked();
Garfield Tan07544cd2018-09-12 16:16:54 -0700284 if (dragWindowHandle == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800285 Slog.e(TAG_WM,
Chong Zhang8e89b312015-09-09 15:09:30 -0700286 "Repositioning is in progress but there is no drag window handle.");
Garfield Tan07544cd2018-09-12 16:16:54 -0700287 } else if (dragWindowHandle.displayId == mDisplayId) {
288 addInputWindowHandle(dragWindowHandle);
Chong Zhang8e89b312015-09-09 15:09:30 -0700289 }
290 }
291
Jeff Brown83d616a2012-09-09 20:33:43 -0700292 // Add all windows on the default display.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800293 mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000294
295 if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
296 }
297
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 /* Called when the current input focus changes.
299 * Layer assignment is assumed to be complete by the time this is called.
300 */
301 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700302 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800303 Slog.d(TAG_WM, "Input focus has changed to " + newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 }
305
306 if (newWindow != mInputFocus) {
307 if (newWindow != null && newWindow.canReceiveKeys()) {
308 // Displaying a window implicitly causes dispatching to be unpaused.
309 // This is to protect against bugs if someone pauses dispatching but
310 // forgets to resume.
311 newWindow.mToken.paused = false;
312 }
313
314 mInputFocus = newWindow;
315 setUpdateInputWindowsNeededLw();
316
317 if (updateInputWindows) {
318 updateInputWindowsLw(false /*force*/);
319 }
320 }
321 }
Craig Mautner58458122013-09-14 14:59:50 -0700322
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 public void setFocusedAppLw(AppWindowToken newApp) {
324 // Focused app has changed.
325 if (newApp == null) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800326 mService.mInputManager.setFocusedApplication(mDisplayId, null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700328 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
329 handle.name = newApp.toString();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800330 handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800332 mService.mInputManager.setFocusedApplication(mDisplayId, handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 }
334 }
Craig Mautner58458122013-09-14 14:59:50 -0700335
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 public void pauseDispatchingLw(WindowToken window) {
337 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700338 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800339 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700341
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 window.paused = true;
343 updateInputWindowsLw(true /*force*/);
344 }
345 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700346
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 public void resumeDispatchingLw(WindowToken window) {
348 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700349 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800350 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700352
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 window.paused = false;
354 updateInputWindowsLw(true /*force*/);
355 }
356 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700357
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800358 void dump(PrintWriter pw, String prefix) {
Winson Chung853c99a2017-03-21 22:16:42 -0700359 final Set<String> inputConsumerKeys = mInputConsumers.keySet();
360 if (!inputConsumerKeys.isEmpty()) {
361 pw.println(prefix + "InputConsumers:");
362 for (String key : inputConsumerKeys) {
Winson Chung6463c362017-09-25 16:23:26 -0700363 mInputConsumers.get(key).dump(pw, key, prefix);
Winson Chung853c99a2017-03-21 22:16:42 -0700364 }
365 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800366 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800367
Arthur Hung39134b22018-08-14 11:58:28 +0800368 void onRemoved() {
369 // If DisplayContent removed, we need find a way to remove window handles of this display
370 // from InputDispatcher, so pass an empty InputWindowHandles to remove them.
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800371 mService.mInputManager.setInputWindows(mInputWindowHandles, mDisplayId);
Arthur Hung39134b22018-08-14 11:58:28 +0800372 }
373
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800374 private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800375 InputConsumerImpl navInputConsumer;
376 InputConsumerImpl pipInputConsumer;
377 InputConsumerImpl wallpaperInputConsumer;
Winson Chunga89ffed2018-01-25 17:46:11 +0000378 InputConsumerImpl recentsAnimationInputConsumer;
Arthur Hung95b38a92018-07-20 18:56:12 +0800379
380 private boolean mAddInputConsumerHandle;
381 private boolean mAddPipInputConsumerHandle;
382 private boolean mAddWallpaperInputConsumerHandle;
383 private boolean mAddRecentsAnimationInputConsumerHandle;
384
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800385 boolean inDrag;
386 WallpaperController wallpaperController;
387
388 private void updateInputWindows(boolean inDrag) {
Jorim Jaggi60640512018-06-29 01:14:31 +0200389 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
390
Arthur Hung95b38a92018-07-20 18:56:12 +0800391 navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION);
392 pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP);
393 wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER);
394 recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION);
395
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800396 mAddInputConsumerHandle = navInputConsumer != null;
397 mAddPipInputConsumerHandle = pipInputConsumer != null;
398 mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
Winson Chunga89ffed2018-01-25 17:46:11 +0000399 mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null;
Arthur Hung95b38a92018-07-20 18:56:12 +0800400
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800401 mTmpRect.setEmpty();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800402 mDisableWallpaperTouchEvents = false;
403 this.inDrag = inDrag;
404 wallpaperController = mService.mRoot.mWallpaperController;
405
Arthur Hung39134b22018-08-14 11:58:28 +0800406 mService.mRoot.getDisplayContent(mDisplayId).forAllWindows(this,
Arthur Hung95b38a92018-07-20 18:56:12 +0800407 true /* traverseTopToBottom */);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800408 if (mAddWallpaperInputConsumerHandle) {
409 // No visible wallpaper found, add the wallpaper input consumer at the end.
410 addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
411 }
412
413 // Send windows to native code.
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800414 mService.mInputManager.setInputWindows(mInputWindowHandles, mDisplayId);
Vladislav Kaznacheev2e96c632016-12-13 14:31:24 -0800415
416 clearInputWindowHandlesLw();
Jorim Jaggi60640512018-06-29 01:14:31 +0200417
418 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800419 }
420
421 @Override
422 public void accept(WindowState w) {
423 final InputChannel inputChannel = w.mInputChannel;
424 final InputWindowHandle inputWindowHandle = w.mInputWindowHandle;
425 if (inputChannel == null || inputWindowHandle == null || w.mRemoved
Matthew Nge15352e2016-12-20 15:36:29 -0800426 || w.canReceiveTouchInput()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800427 // Skip this window because it cannot possibly receive input.
428 return;
429 }
430
Winson Chung61ecc1b2017-02-17 10:46:17 -0800431 final int flags = w.mAttrs.flags;
432 final int privateFlags = w.mAttrs.privateFlags;
433 final int type = w.mAttrs.type;
Arthur Hung39134b22018-08-14 11:58:28 +0800434 final boolean hasFocus = w.isFocused();
Winson Chung61ecc1b2017-02-17 10:46:17 -0800435 final boolean isVisible = w.isVisibleLw();
436
Winson Chunga89ffed2018-01-25 17:46:11 +0000437 if (mAddRecentsAnimationInputConsumerHandle) {
438 final RecentsAnimationController recentsAnimationController =
439 mService.getRecentsAnimationController();
440 if (recentsAnimationController != null
Winson Chungdb111ee2018-10-03 14:25:34 -0700441 && recentsAnimationController.shouldApplyInputConsumer(w.mAppToken)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000442 if (recentsAnimationController.updateInputConsumerForApp(
Arthur Hung95b38a92018-07-20 18:56:12 +0800443 recentsAnimationInputConsumer.mWindowHandle, hasFocus)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000444 addInputWindowHandle(recentsAnimationInputConsumer.mWindowHandle);
445 mAddRecentsAnimationInputConsumerHandle = false;
446 }
Winson Chungdb111ee2018-10-03 14:25:34 -0700447 // If the target app window does not yet exist, then we don't add the input
448 // consumer window, but also don't add the app window below.
Winson Chunga89ffed2018-01-25 17:46:11 +0000449 return;
450 }
451 }
452
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700453 if (w.inPinnedWindowingMode()) {
Winson Chung61ecc1b2017-02-17 10:46:17 -0800454 if (mAddPipInputConsumerHandle
455 && (inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer)) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800456 // Update the bounds of the Pip input consumer to match the window bounds.
Winson Chunga89ffed2018-01-25 17:46:11 +0000457 w.getBounds(mTmpRect);
458 pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
Winson Chung61ecc1b2017-02-17 10:46:17 -0800459 addInputWindowHandle(pipInputConsumer.mWindowHandle);
460 mAddPipInputConsumerHandle = false;
461 }
462 // TODO: Fix w.canReceiveTouchInput() to handle this case
463 if (!hasFocus) {
464 // Skip this pinned stack window if it does not have focus
465 return;
466 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800467 }
468
469 if (mAddInputConsumerHandle
470 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
471 addInputWindowHandle(navInputConsumer.mWindowHandle);
472 mAddInputConsumerHandle = false;
473 }
474
475 if (mAddWallpaperInputConsumerHandle) {
476 if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) {
477 // Add the wallpaper input consumer above the first visible wallpaper.
478 addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
479 mAddWallpaperInputConsumerHandle = false;
480 }
481 }
482
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800483 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
484 mDisableWallpaperTouchEvents = true;
485 }
486 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w)
487 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
488 && !mDisableWallpaperTouchEvents;
489
490 // If there's a drag in progress and 'child' is a potential drop target,
491 // make sure it's been told about the drag
492 if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) {
Daichi Hirono768012e2017-10-30 10:05:37 +0900493 mService.mDragDropController.sendDragStartedIfNeededLocked(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800494 }
495
496 addInputWindowHandle(
497 inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
498 }
499 }
Jeff Brownea426552011-07-18 16:53:48 -0700500}