blob: ef3a770390efdbee9148136c5e0883c2038b29ab [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;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080045
Selim Cinekf83e8242015-05-19 18:08:14 -070046import com.android.server.input.InputApplicationHandle;
Selim Cinekf83e8242015-05-19 18:08:14 -070047import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +010048import com.android.server.policy.WindowManagerPolicy;
Selim Cinekf83e8242015-05-19 18:08:14 -070049
Wale Ogunwalee89eeac2016-03-12 11:07:58 -080050import java.io.PrintWriter;
Jeff Brown9302c872011-07-13 22:51:29 -070051import java.util.Arrays;
Winson Chung853c99a2017-03-21 22:16:42 -070052import java.util.Set;
Wale Ogunwale1e129a42016-11-21 13:03:47 -080053import java.util.function.Consumer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054
Arthur Hung95b38a92018-07-20 18:56:12 +080055final class InputMonitor {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080056 private final WindowManagerService mService;
Selim Cinekf83e8242015-05-19 18:08:14 -070057
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080058 // Current window with input focus for keys and other non-touch events. May be null.
59 private WindowState mInputFocus;
Selim Cinekf83e8242015-05-19 18:08:14 -070060
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080061 // When true, need to call updateInputWindowsLw().
62 private boolean mUpdateInputWindowsNeeded = true;
63
Jeff Brown9302c872011-07-13 22:51:29 -070064 // Array of window handles to provide to the input dispatcher.
65 private InputWindowHandle[] mInputWindowHandles;
66 private int mInputWindowHandleCount;
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -080067 private InputWindowHandle mFocusedInputWindowHandle;
68
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();
71 private final UpdateInputForAllWindowsConsumer mUpdateInputForAllWindowsConsumer =
72 new UpdateInputForAllWindowsConsumer();
Jeff Brown9302c872011-07-13 22:51:29 -070073
Arthur Hung95b38a92018-07-20 18:56:12 +080074 private int mDisplayId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080075
Winson41275482016-10-10 15:17:45 -070076 /**
77 * The set of input consumer added to the window manager by name, which consumes input events
78 * for the windows below it.
79 */
80 private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
81
82 private static final class EventReceiverInputConsumer extends InputConsumerImpl
83 implements WindowManagerPolicy.InputConsumer {
84 private InputMonitor mInputMonitor;
85 private final InputEventReceiver mInputEventReceiver;
86
87 EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
88 Looper looper, String name,
Winson Chung6463c362017-09-25 16:23:26 -070089 InputEventReceiver.Factory inputEventReceiverFactory,
Arthur Hung95b38a92018-07-20 18:56:12 +080090 int clientPid, UserHandle clientUser, int displayId) {
91 super(service, null /* token */, name, null /* inputChannel */, clientPid, clientUser,
92 displayId);
Winson41275482016-10-10 15:17:45 -070093 mInputMonitor = monitor;
94 mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
95 mClientChannel, looper);
96 }
97
98 @Override
99 public void dismiss() {
100 synchronized (mService.mWindowMap) {
101 if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
102 mInputEventReceiver.dispose();
103 }
104 }
105 }
106 }
107
Arthur Hung95b38a92018-07-20 18:56:12 +0800108 public InputMonitor(WindowManagerService service, int displayId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 mService = service;
Arthur Hung95b38a92018-07-20 18:56:12 +0800110 mDisplayId = displayId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700112
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700113 private void addInputConsumer(String name, InputConsumerImpl consumer) {
Winson41275482016-10-10 15:17:45 -0700114 mInputConsumers.put(name, consumer);
Winson Chung6463c362017-09-25 16:23:26 -0700115 consumer.linkToDeathRecipient();
Winson41275482016-10-10 15:17:45 -0700116 updateInputWindowsLw(true /* force */);
117 }
118
119 boolean destroyInputConsumer(String name) {
120 if (disposeInputConsumer(mInputConsumers.remove(name))) {
121 updateInputWindowsLw(true /* force */);
122 return true;
123 }
124 return false;
125 }
126
127 private boolean disposeInputConsumer(InputConsumerImpl consumer) {
128 if (consumer != null) {
129 consumer.disposeChannelsLw();
130 return true;
131 }
132 return false;
133 }
134
Arthur Hung95b38a92018-07-20 18:56:12 +0800135 InputConsumerImpl getInputConsumer(String name) {
136 return mInputConsumers.get(name);
Winson41275482016-10-10 15:17:45 -0700137 }
138
139 void layoutInputConsumers(int dw, int dh) {
140 for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
141 mInputConsumers.valueAt(i).layout(dw, dh);
142 }
143 }
144
145 WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
146 InputEventReceiver.Factory inputEventReceiverFactory) {
147 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800148 throw new IllegalStateException("Existing input consumer found with name: " + name
149 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700150 }
Winson41275482016-10-10 15:17:45 -0700151 final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
Winson Chung6463c362017-09-25 16:23:26 -0700152 this, looper, name, inputEventReceiverFactory, Process.myPid(),
Arthur Hung95b38a92018-07-20 18:56:12 +0800153 UserHandle.SYSTEM, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700154 addInputConsumer(name, consumer);
155 return consumer;
156 }
157
Winson Chung6463c362017-09-25 16:23:26 -0700158 void createInputConsumer(IBinder token, String name, InputChannel inputChannel, int clientPid,
159 UserHandle clientUser) {
Winson41275482016-10-10 15:17:45 -0700160 if (mInputConsumers.containsKey(name)) {
Arthur Hung95b38a92018-07-20 18:56:12 +0800161 throw new IllegalStateException("Existing input consumer found with name: " + name
162 + ", display: " + mDisplayId);
Winson41275482016-10-10 15:17:45 -0700163 }
164
Winson Chung6463c362017-09-25 16:23:26 -0700165 final InputConsumerImpl consumer = new InputConsumerImpl(mService, token, name,
Arthur Hung95b38a92018-07-20 18:56:12 +0800166 inputChannel, clientPid, clientUser, mDisplayId);
Winson41275482016-10-10 15:17:45 -0700167 switch (name) {
168 case INPUT_CONSUMER_WALLPAPER:
169 consumer.mWindowHandle.hasWallpaper = true;
170 break;
171 case INPUT_CONSUMER_PIP:
172 // The touchable region of the Pip input window is cropped to the bounds of the
173 // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700174 consumer.mWindowHandle.layoutParamsFlags |= FLAG_NOT_TOUCH_MODAL;
Winson41275482016-10-10 15:17:45 -0700175 break;
176 }
177 addInputConsumer(name, consumer);
178 }
179
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180
Wale Ogunwale7402ddf2017-03-29 12:58:24 -0700181 private void addInputWindowHandle(final InputWindowHandle windowHandle) {
Jeff Brown9302c872011-07-13 22:51:29 -0700182 if (mInputWindowHandles == null) {
183 mInputWindowHandles = new InputWindowHandle[16];
184 }
185 if (mInputWindowHandleCount >= mInputWindowHandles.length) {
186 mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
187 mInputWindowHandleCount * 2);
188 }
189 mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
190 }
191
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700192 void addInputWindowHandle(final InputWindowHandle inputWindowHandle,
Craig Mautnerc08eab82014-11-11 09:03:59 -0800193 final WindowState child, int flags, final int type, final boolean isVisible,
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800194 final boolean hasFocus, final boolean hasWallpaper) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700195 // Add a window to our list of input windows.
196 inputWindowHandle.name = child.toString();
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800197 flags = child.getTouchableRegion(inputWindowHandle.touchableRegion, flags);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700198 inputWindowHandle.layoutParamsFlags = flags;
199 inputWindowHandle.layoutParamsType = type;
200 inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
201 inputWindowHandle.visible = isVisible;
202 inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
203 inputWindowHandle.hasFocus = hasFocus;
204 inputWindowHandle.hasWallpaper = hasWallpaper;
205 inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
206 inputWindowHandle.layer = child.mLayer;
207 inputWindowHandle.ownerPid = child.mSession.mPid;
208 inputWindowHandle.ownerUid = child.mSession.mUid;
209 inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
Arthur Hung95b38a92018-07-20 18:56:12 +0800210 inputWindowHandle.displayId = child.getDisplayId();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700211
chaviw492139a2018-07-16 16:07:35 -0700212 final Rect frame = child.getFrameLw();
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700213 inputWindowHandle.frameLeft = frame.left;
214 inputWindowHandle.frameTop = frame.top;
215 inputWindowHandle.frameRight = frame.right;
216 inputWindowHandle.frameBottom = frame.bottom;
217
218 if (child.mGlobalScale != 1) {
219 // If we are scaling the window, input coordinates need
220 // to be inversely scaled to map from what is on screen
221 // to what is actually being touched in the UI.
222 inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
223 } else {
224 inputWindowHandle.scaleFactor = 1;
225 }
226
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700227 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800228 Slog.d(TAG_WM, "addInputWindowHandle: "
Chong Zhangb15758a2015-11-17 12:12:03 -0800229 + child + ", " + inputWindowHandle);
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700230 }
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700231 addInputWindowHandle(inputWindowHandle);
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800232 if (hasFocus) {
233 mFocusedInputWindowHandle = inputWindowHandle;
234 }
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700235 }
236
Jeff Brown9302c872011-07-13 22:51:29 -0700237 private void clearInputWindowHandlesLw() {
238 while (mInputWindowHandleCount != 0) {
239 mInputWindowHandles[--mInputWindowHandleCount] = null;
240 }
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800241 mFocusedInputWindowHandle = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 }
243
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000244 void setUpdateInputWindowsNeededLw() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 mUpdateInputWindowsNeeded = true;
246 }
247
248 /* Updates the cached window information provided to the input dispatcher. */
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000249 void updateInputWindowsLw(boolean force) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 if (!force && !mUpdateInputWindowsNeeded) {
251 return;
252 }
253 mUpdateInputWindowsNeeded = false;
254
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800255 if (false) Slog.d(TAG_WM, ">>>>>> ENTERED updateInputWindowsLw");
Jeff Brown9302c872011-07-13 22:51:29 -0700256
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 // Populate the input window list with information about all of the windows that
258 // could potentially receive input.
259 // As an optimization, we could try to prune the list of windows but this turns
260 // out to be difficult because only the native code knows for sure which window
261 // currently has touch focus.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262
Wale Ogunwalee05f5012016-09-16 16:27:29 -0700263 // If there's a drag in flight, provide a pseudo-window to catch drag input
Daichi Hirono76a26aa2017-09-11 15:13:38 +0900264 final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 if (inDrag) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800266 if (DEBUG_DRAG) {
267 Log.d(TAG_WM, "Inserting drag window");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 }
Daichi Hirono76a26aa2017-09-11 15:13:38 +0900269 final InputWindowHandle dragWindowHandle =
Daichi Hirono768012e2017-10-30 10:05:37 +0900270 mService.mDragDropController.getInputWindowHandleLocked();
Garfield Tan07544cd2018-09-12 16:16:54 -0700271 if (dragWindowHandle == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800272 Slog.w(TAG_WM, "Drag is in progress but there is no "
Jeff Browncc4f7db2011-08-30 20:34:48 -0700273 + "drag window handle.");
Garfield Tan07544cd2018-09-12 16:16:54 -0700274 } else if (dragWindowHandle.displayId == mDisplayId) {
275 addInputWindowHandle(dragWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -0700276 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 }
278
Daichi Hirono34fb7312017-12-04 10:00:24 +0900279 final boolean inPositioning = mService.mTaskPositioningController.isPositioningLocked();
Chong Zhang8e89b312015-09-09 15:09:30 -0700280 if (inPositioning) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800281 if (DEBUG_TASK_POSITIONING) {
282 Log.d(TAG_WM, "Inserting window handle for repositioning");
Chong Zhang8e89b312015-09-09 15:09:30 -0700283 }
Daichi Hirono34fb7312017-12-04 10:00:24 +0900284 final InputWindowHandle dragWindowHandle =
285 mService.mTaskPositioningController.getDragWindowHandleLocked();
Garfield Tan07544cd2018-09-12 16:16:54 -0700286 if (dragWindowHandle == null) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800287 Slog.e(TAG_WM,
Chong Zhang8e89b312015-09-09 15:09:30 -0700288 "Repositioning is in progress but there is no drag window handle.");
Garfield Tan07544cd2018-09-12 16:16:54 -0700289 } else if (dragWindowHandle.displayId == mDisplayId) {
290 addInputWindowHandle(dragWindowHandle);
Chong Zhang8e89b312015-09-09 15:09:30 -0700291 }
292 }
293
Jeff Brown83d616a2012-09-09 20:33:43 -0700294 // Add all windows on the default display.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800295 mUpdateInputForAllWindowsConsumer.updateInputWindows(inDrag);
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000296
297 if (false) Slog.d(TAG_WM, "<<<<<<< EXITED updateInputWindowsLw");
298 }
299
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 /* Called when the current input focus changes.
301 * Layer assignment is assumed to be complete by the time this is called.
302 */
303 public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700304 if (DEBUG_FOCUS_LIGHT || DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800305 Slog.d(TAG_WM, "Input focus has changed to " + newWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 }
307
308 if (newWindow != mInputFocus) {
309 if (newWindow != null && newWindow.canReceiveKeys()) {
310 // Displaying a window implicitly causes dispatching to be unpaused.
311 // This is to protect against bugs if someone pauses dispatching but
312 // forgets to resume.
313 newWindow.mToken.paused = false;
314 }
315
316 mInputFocus = newWindow;
317 setUpdateInputWindowsNeededLw();
318
319 if (updateInputWindows) {
320 updateInputWindowsLw(false /*force*/);
321 }
322 }
323 }
Craig Mautner58458122013-09-14 14:59:50 -0700324
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325 public void setFocusedAppLw(AppWindowToken newApp) {
326 // Focused app has changed.
327 if (newApp == null) {
328 mService.mInputManager.setFocusedApplication(null);
329 } else {
Jeff Brown9302c872011-07-13 22:51:29 -0700330 final InputApplicationHandle handle = newApp.mInputApplicationHandle;
331 handle.name = newApp.toString();
Wale Ogunwale72919d22016-12-08 18:58:50 -0800332 handle.dispatchingTimeoutNanos = newApp.mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333
Jeff Brown9302c872011-07-13 22:51:29 -0700334 mService.mInputManager.setFocusedApplication(handle);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 }
336 }
Craig Mautner58458122013-09-14 14:59:50 -0700337
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 public void pauseDispatchingLw(WindowToken window) {
339 if (! window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700340 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800341 Slog.v(TAG_WM, "Pausing WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800342 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700343
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 window.paused = true;
345 updateInputWindowsLw(true /*force*/);
346 }
347 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700348
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 public void resumeDispatchingLw(WindowToken window) {
350 if (window.paused) {
Filip Gruszczynskif8a2a632015-10-28 11:18:02 -0700351 if (DEBUG_INPUT) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800352 Slog.v(TAG_WM, "Resuming WindowToken " + window);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700354
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 window.paused = false;
356 updateInputWindowsLw(true /*force*/);
357 }
358 }
Chong Zhang8e89b312015-09-09 15:09:30 -0700359
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800360 void dump(PrintWriter pw, String prefix) {
Winson Chung853c99a2017-03-21 22:16:42 -0700361 final Set<String> inputConsumerKeys = mInputConsumers.keySet();
362 if (!inputConsumerKeys.isEmpty()) {
363 pw.println(prefix + "InputConsumers:");
364 for (String key : inputConsumerKeys) {
Winson Chung6463c362017-09-25 16:23:26 -0700365 mInputConsumers.get(key).dump(pw, key, prefix);
Winson Chung853c99a2017-03-21 22:16:42 -0700366 }
367 }
Wale Ogunwalee89eeac2016-03-12 11:07:58 -0800368 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800369
Arthur Hung39134b22018-08-14 11:58:28 +0800370 void onRemoved() {
371 // If DisplayContent removed, we need find a way to remove window handles of this display
372 // from InputDispatcher, so pass an empty InputWindowHandles to remove them.
373 mService.mInputManager.setInputWindows(mInputWindowHandles, mFocusedInputWindowHandle,
374 mDisplayId);
375 }
376
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800377 private final class UpdateInputForAllWindowsConsumer implements Consumer<WindowState> {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800378 InputConsumerImpl navInputConsumer;
379 InputConsumerImpl pipInputConsumer;
380 InputConsumerImpl wallpaperInputConsumer;
Winson Chunga89ffed2018-01-25 17:46:11 +0000381 InputConsumerImpl recentsAnimationInputConsumer;
Arthur Hung95b38a92018-07-20 18:56:12 +0800382
383 private boolean mAddInputConsumerHandle;
384 private boolean mAddPipInputConsumerHandle;
385 private boolean mAddWallpaperInputConsumerHandle;
386 private boolean mAddRecentsAnimationInputConsumerHandle;
387
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800388 boolean inDrag;
389 WallpaperController wallpaperController;
390
391 private void updateInputWindows(boolean inDrag) {
Jorim Jaggi60640512018-06-29 01:14:31 +0200392 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "updateInputWindows");
393
Arthur Hung95b38a92018-07-20 18:56:12 +0800394 navInputConsumer = getInputConsumer(INPUT_CONSUMER_NAVIGATION);
395 pipInputConsumer = getInputConsumer(INPUT_CONSUMER_PIP);
396 wallpaperInputConsumer = getInputConsumer(INPUT_CONSUMER_WALLPAPER);
397 recentsAnimationInputConsumer = getInputConsumer(INPUT_CONSUMER_RECENTS_ANIMATION);
398
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800399 mAddInputConsumerHandle = navInputConsumer != null;
400 mAddPipInputConsumerHandle = pipInputConsumer != null;
401 mAddWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
Winson Chunga89ffed2018-01-25 17:46:11 +0000402 mAddRecentsAnimationInputConsumerHandle = recentsAnimationInputConsumer != null;
Arthur Hung95b38a92018-07-20 18:56:12 +0800403
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800404 mTmpRect.setEmpty();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800405 mDisableWallpaperTouchEvents = false;
406 this.inDrag = inDrag;
407 wallpaperController = mService.mRoot.mWallpaperController;
408
Arthur Hung39134b22018-08-14 11:58:28 +0800409 mService.mRoot.getDisplayContent(mDisplayId).forAllWindows(this,
Arthur Hung95b38a92018-07-20 18:56:12 +0800410 true /* traverseTopToBottom */);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800411 if (mAddWallpaperInputConsumerHandle) {
412 // No visible wallpaper found, add the wallpaper input consumer at the end.
413 addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
414 }
415
416 // Send windows to native code.
Arthur Hung39134b22018-08-14 11:58:28 +0800417 mService.mInputManager.setInputWindows(mInputWindowHandles, mFocusedInputWindowHandle,
418 mDisplayId);
Vladislav Kaznacheev2e96c632016-12-13 14:31:24 -0800419
420 clearInputWindowHandlesLw();
Jorim Jaggi60640512018-06-29 01:14:31 +0200421
422 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800423 }
424
425 @Override
426 public void accept(WindowState w) {
427 final InputChannel inputChannel = w.mInputChannel;
428 final InputWindowHandle inputWindowHandle = w.mInputWindowHandle;
429 if (inputChannel == null || inputWindowHandle == null || w.mRemoved
Matthew Nge15352e2016-12-20 15:36:29 -0800430 || w.canReceiveTouchInput()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800431 // Skip this window because it cannot possibly receive input.
432 return;
433 }
434
Winson Chung61ecc1b2017-02-17 10:46:17 -0800435 final int flags = w.mAttrs.flags;
436 final int privateFlags = w.mAttrs.privateFlags;
437 final int type = w.mAttrs.type;
Arthur Hung39134b22018-08-14 11:58:28 +0800438 // TODO(b/111361570): multi-display focus, one focus window per display.
439 final boolean hasFocus = w.isFocused();
Winson Chung61ecc1b2017-02-17 10:46:17 -0800440 final boolean isVisible = w.isVisibleLw();
441
Winson Chunga89ffed2018-01-25 17:46:11 +0000442 if (mAddRecentsAnimationInputConsumerHandle) {
443 final RecentsAnimationController recentsAnimationController =
444 mService.getRecentsAnimationController();
445 if (recentsAnimationController != null
446 && recentsAnimationController.hasInputConsumerForApp(w.mAppToken)) {
447 if (recentsAnimationController.updateInputConsumerForApp(
Arthur Hung95b38a92018-07-20 18:56:12 +0800448 recentsAnimationInputConsumer.mWindowHandle, hasFocus)) {
Winson Chunga89ffed2018-01-25 17:46:11 +0000449 addInputWindowHandle(recentsAnimationInputConsumer.mWindowHandle);
450 mAddRecentsAnimationInputConsumerHandle = false;
451 }
452 // Skip adding the window below regardless of whether there is an input consumer
453 // to handle it
454 return;
455 }
456 }
457
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700458 if (w.inPinnedWindowingMode()) {
Winson Chung61ecc1b2017-02-17 10:46:17 -0800459 if (mAddPipInputConsumerHandle
460 && (inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer)) {
Bryce Leef3c6a472017-11-14 14:53:06 -0800461 // Update the bounds of the Pip input consumer to match the window bounds.
Winson Chunga89ffed2018-01-25 17:46:11 +0000462 w.getBounds(mTmpRect);
463 pipInputConsumer.mWindowHandle.touchableRegion.set(mTmpRect);
Winson Chung61ecc1b2017-02-17 10:46:17 -0800464 addInputWindowHandle(pipInputConsumer.mWindowHandle);
465 mAddPipInputConsumerHandle = false;
466 }
467 // TODO: Fix w.canReceiveTouchInput() to handle this case
468 if (!hasFocus) {
469 // Skip this pinned stack window if it does not have focus
470 return;
471 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800472 }
473
474 if (mAddInputConsumerHandle
475 && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
476 addInputWindowHandle(navInputConsumer.mWindowHandle);
477 mAddInputConsumerHandle = false;
478 }
479
480 if (mAddWallpaperInputConsumerHandle) {
481 if (w.mAttrs.type == TYPE_WALLPAPER && w.isVisibleLw()) {
482 // Add the wallpaper input consumer above the first visible wallpaper.
483 addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
484 mAddWallpaperInputConsumerHandle = false;
485 }
486 }
487
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800488 if ((privateFlags & PRIVATE_FLAG_DISABLE_WALLPAPER_TOUCH_EVENTS) != 0) {
489 mDisableWallpaperTouchEvents = true;
490 }
491 final boolean hasWallpaper = wallpaperController.isWallpaperTarget(w)
492 && (privateFlags & PRIVATE_FLAG_KEYGUARD) == 0
493 && !mDisableWallpaperTouchEvents;
494
495 // If there's a drag in progress and 'child' is a potential drop target,
496 // make sure it's been told about the drag
497 if (inDrag && isVisible && w.getDisplayContent().isDefaultDisplay) {
Daichi Hirono768012e2017-10-30 10:05:37 +0900498 mService.mDragDropController.sendDragStartedIfNeededLocked(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800499 }
500
501 addInputWindowHandle(
502 inputWindowHandle, w, flags, type, isVisible, hasFocus, hasWallpaper);
503 }
504 }
Jeff Brownea426552011-07-18 16:53:48 -0700505}