blob: ba030340ef36a8e8a3a4c4a721e4bd80dd79c83e [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 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.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale65ebd952018-04-25 15:41:44 -070019import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale61911492017-10-11 08:50:50 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070021import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
24import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
27import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070028import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
29import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070030import static android.view.Display.DEFAULT_DISPLAY;
31import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070032import static android.view.Surface.ROTATION_0;
33import static android.view.Surface.ROTATION_180;
34import static android.view.Surface.ROTATION_270;
35import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070036import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070037import static android.view.WindowManager.DOCKED_BOTTOM;
38import static android.view.WindowManager.DOCKED_INVALID;
39import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080040import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
41import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070043import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070044import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070045import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
46import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070047import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070048import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070050import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080051import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070052import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070053import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070054import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
55import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070056import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070057import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
58import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070059import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070060import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080061import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
62
Adrian Roose99bc052017-11-20 17:55:31 +010063import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
64import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
66import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080067import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
lumark588a3e82018-07-20 18:53:54 +080068import static com.android.server.wm.DisplayContentProto.APP_TRANSITION;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080069import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
70import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
71import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
72import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
73import static com.android.server.wm.DisplayContentProto.DPI;
Tiger Huang1e5b10a2018-07-30 20:19:51 +080074import static com.android.server.wm.DisplayContentProto.FOCUSED_APP;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080075import static com.android.server.wm.DisplayContentProto.ID;
76import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
77import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
78import static com.android.server.wm.DisplayContentProto.ROTATION;
79import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
80import static com.android.server.wm.DisplayContentProto.STACKS;
Louis Chang7501e332018-08-20 13:08:39 +080081import static com.android.server.wm.DisplayContentProto.SURFACE_SIZE;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080082import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
lumark588a3e82018-07-20 18:53:54 +080084import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwale494009b82016-10-21 09:01:38 -070085import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
88import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080096import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070098import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070099import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700100import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800101import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700102import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800103import static com.android.server.wm.WindowManagerService.H.REPORT_FOCUS_CHANGE;
104import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700105import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
106import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700107import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700108import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700109import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
110import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800111import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
112import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
113import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700114import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700115import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700116import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700117import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700118import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700119import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700120import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700121import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700122import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700123
lumark588a3e82018-07-20 18:53:54 +0800124import android.animation.AnimationHandler;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700125import android.annotation.CallSuper;
Riddle Hsuf53da812018-08-15 22:00:27 +0800126import android.annotation.IntDef;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700127import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700128import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700129import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700130import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700131import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700132import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800133import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700134import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700135import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100136import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700137import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700138import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700139import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700140import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700141import android.os.RemoteException;
142import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100143import android.os.Trace;
Riddle Hsuf53da812018-08-15 22:00:27 +0800144import android.os.UserHandle;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800145import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700146import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700147import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700148import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700149import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100150import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700151import android.view.DisplayInfo;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800152import android.view.Gravity;
Arthur Hungbe5ce212018-09-13 18:41:56 +0800153import android.view.InputChannel;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700154import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700155import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700156import android.view.Surface;
157import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100158import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700159import android.view.SurfaceSession;
Arthur Hungbe5ce212018-09-13 18:41:56 +0800160import android.view.WindowManagerPolicyConstants.PointerEventListener;
lumark588a3e82018-07-20 18:53:54 +0800161import android.view.WindowManager;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700162
Bryce Lee48f4b572017-04-10 10:54:15 -0700163import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800164import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100165import com.android.server.policy.WindowManagerPolicy;
Issei Suzuki43190bd2018-08-20 17:28:41 +0200166import com.android.server.wm.utils.DisplayRotationUtil;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100167import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100168import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700169
170import java.io.PrintWriter;
Riddle Hsuf53da812018-08-15 22:00:27 +0800171import java.lang.annotation.Retention;
172import java.lang.annotation.RetentionPolicy;
Craig Mautner59c00972012-07-30 12:10:24 -0700173import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700174import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700175import java.util.HashMap;
176import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700177import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700178import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100179import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800180import java.util.function.Consumer;
181import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700182
Craig Mautner59c00972012-07-30 12:10:24 -0700183/**
184 * Utility class for keeping track of the WindowStates and other pertinent contents of a
185 * particular Display.
186 *
187 * IMPORTANT: No method from this class should ever be used without holding
188 * WindowManagerService.mWindowMap.
189 */
Riddle Hsuad256a12018-07-18 16:11:30 +0800190class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
191 implements WindowManagerPolicy.DisplayContentInfo {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700192 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700193
Riddle Hsuf53da812018-08-15 22:00:27 +0800194 /** The default scaling mode that scales content automatically. */
195 static final int FORCE_SCALING_MODE_AUTO = 0;
196 /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */
197 static final int FORCE_SCALING_MODE_DISABLED = 1;
198
199 @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = {
200 FORCE_SCALING_MODE_AUTO,
201 FORCE_SCALING_MODE_DISABLED
202 })
203 @Retention(RetentionPolicy.SOURCE)
204 @interface ForceScalingMode {}
205
Craig Mautner59c00972012-07-30 12:10:24 -0700206 /** Unique identifier of this stack. */
207 private final int mDisplayId;
208
Wale Ogunwale3a931692016-11-02 16:49:48 -0700209 /** The containers below are the only child containers the display can have. */
210 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100211 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700212 // Contains all non-app window containers that should be displayed above the app containers
213 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800214 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100215 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700216 // Contains all non-app window containers that should be displayed below the app containers
217 // (e.g. Wallpaper).
218 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100219 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700220 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
221 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
Robert Carr9034d962018-01-04 18:27:42 -0800222 // window containers together and move them in-sync if/when needed. We use a subclass of
223 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
224 private final NonMagnifiableWindowContainers mImeWindowsContainers =
225 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700226
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000227 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800228 private WindowState mTmpWindow2;
229 private WindowAnimator mTmpWindowAnimator;
230 private boolean mTmpRecoveringMemory;
231 private boolean mUpdateImeTarget;
232 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700233 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700234
lumark588a3e82018-07-20 18:53:54 +0800235 final AppTransition mAppTransition;
236 final AppTransitionController mAppTransitionController;
237 boolean mSkipAppTransitionAnimation = false;
238
239 final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>();
240 final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>();
241 final UnknownAppVisibilityController mUnknownAppVisibilityController;
242 BoundsAnimationController mBoundsAnimationController;
243
244 /**
245 * List of clients without a transtiton animation that we notify once we are done
246 * transitioning since they won't be notified through the app window animator.
247 */
248 final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>();
249
Wale Ogunwale02319a62016-09-26 15:21:22 -0700250 // Mapping from a token IBinder to a WindowToken object on this display.
251 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
252
Andrii Kuliancd097992017-03-23 18:31:59 -0700253 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700254 int mInitialDisplayWidth = 0;
255 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700256 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700257
Adrian Roos1cf585052018-01-03 18:43:27 +0100258 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100259 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100260 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100261
Andrii Kuliancd097992017-03-23 18:31:59 -0700262 /**
263 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
264 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
265 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
266 */
Craig Mautner59c00972012-07-30 12:10:24 -0700267 int mBaseDisplayWidth = 0;
268 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700269 /**
270 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
271 * but can be set from Settings or via shell command "adb shell wm density".
272 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
273 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700274 int mBaseDisplayDensity = 0;
Riddle Hsuf53da812018-08-15 22:00:27 +0800275
276 /**
277 * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling".
278 * @see WindowManagerService#setForcedDisplayScalingMode(int, int)
279 */
Jeff Brownd46747a2015-04-15 19:02:36 -0700280 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700281 private final DisplayInfo mDisplayInfo = new DisplayInfo();
282 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700283 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800284 private final DisplayPolicy mDisplayPolicy;
285 private DisplayRotation mDisplayRotation;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000286 DisplayFrames mDisplayFrames;
287
Andrii Kulian06d07d62017-03-14 11:11:47 -0700288 /**
289 * For default display it contains real metrics, empty for others.
290 * @see WindowManagerService#createWatermarkInTransaction()
291 */
292 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
293 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
294 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700295
Andrii Kulian06d07d62017-03-14 11:11:47 -0700296 /**
297 * Compat metrics computed based on {@link #mDisplayMetrics}.
298 * @see #updateDisplayAndOrientation(int)
299 */
300 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
301
302 /** The desired scaling factor for compatible apps. */
303 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700304
Andrii Kulian8ee72852017-03-10 10:36:45 -0800305 /**
306 * Current rotation of the display.
307 * Constants as per {@link android.view.Surface.Rotation}.
308 *
Robert Carrae606b42018-02-15 15:36:23 -0800309 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800310 */
311 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700312
Andrii Kulian8ee72852017-03-10 10:36:45 -0800313 /**
314 * Last applied orientation of the display.
315 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
316 *
317 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
318 */
319 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700320
Andrii Kulian8ee72852017-03-10 10:36:45 -0800321 /**
322 * Flag indicating that the application is receiving an orientation that has different metrics
323 * than it expected. E.g. Portrait instead of Landscape.
324 *
Robert Carrae606b42018-02-15 15:36:23 -0800325 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800326 */
327 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700328
Andrii Kulian8ee72852017-03-10 10:36:45 -0800329 /**
330 * Orientation forced by some window. If there is no visible window that specifies orientation
331 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
332 *
333 * @see NonAppWindowContainers#getOrientation()
334 */
335 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700336
Andrii Kulian8ee72852017-03-10 10:36:45 -0800337 /**
338 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
339 * occluded.
340 *
341 * @see NonAppWindowContainers#getOrientation()
342 */
343 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
344
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700345 /**
346 * Keep track of wallpaper visibility to notify changes.
347 */
348 private boolean mLastWallpaperVisible = false;
349
Andrii Kulian06d07d62017-03-14 11:11:47 -0700350 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700351
Craig Mautner39834192012-09-02 07:47:24 -0700352 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700353 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700354 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800355 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800356
Andrii Kulian839def92016-11-02 10:58:58 -0700357 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800358 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800359 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800360
Andrii Kulianf0379de2018-03-14 16:24:07 -0700361 /**
362 * Flag indicating whether WindowManager should override info for this display in
363 * DisplayManager.
364 */
365 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700366
Craig Mautnerdc548482014-02-05 13:35:24 -0800367 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700368 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800369
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700370 /** Detect user tapping outside of current focused task bounds .*/
371 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700372
Craig Mautner6601b7b2013-04-29 10:29:11 -0700373 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700374 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700375
Craig Mautner6601b7b2013-04-29 10:29:11 -0700376 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800377 private final Rect mTmpRect = new Rect();
378 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700379 private final RectF mTmpRectF = new RectF();
380 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800381 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700382
Issei Suzuki43190bd2018-08-20 17:28:41 +0200383
Bryce Leef3c6a472017-11-14 14:53:06 -0800384 /** Used for handing back size of display */
385 private final Rect mTmpBounds = new Rect();
386
Craig Mautner95da1082014-02-24 17:54:35 -0800387 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700388 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800389
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700390 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700391 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700392
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800393 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800394 /** A collection of windows that provide tap exclude regions inside of them. */
395 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800396
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000397 private boolean mHaveBootMsg = false;
398 private boolean mHaveApp = false;
399 private boolean mHaveWallpaper = false;
400 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700401
402 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
403
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700404 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
405 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000406 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
407 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700408
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700409 // True if this display is in the process of being removed. Used to determine if the removal of
410 // the display's direct children should be allowed.
411 private boolean mRemovingDisplay = false;
412
Bryce Leed1871262017-06-12 14:12:29 -0700413 // {@code false} if this display is in the processing of being created.
414 private boolean mDisplayReady = false;
415
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800416 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700417
Robert Carrb1579c82017-09-05 14:54:47 -0700418 private final SurfaceSession mSession = new SurfaceSession();
419
420 /**
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800421 * Window that is currently interacting with the user. This window is responsible for receiving
422 * key events and pointer events from the user.
423 */
424 WindowState mCurrentFocus = null;
425
426 /**
427 * The last focused window that we've notified the client that the focus is changed.
428 */
429 WindowState mLastFocus = null;
430
431 /**
432 * Windows that have lost input focus and are waiting for the new focus window to be displayed
433 * before they are told about this.
434 */
435 ArrayList<WindowState> mLosingFocus = new ArrayList<>();
436
437 /**
438 * The foreground app of this display. Windows below this app cannot be the focused window. If
439 * the user taps on the area outside of the task of the focused app, we will notify AM about the
440 * new task the user wants to interact with.
441 */
442 AppWindowToken mFocusedApp = null;
443
444 /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
445 final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>();
446
447 /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
448 final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>();
449
450 /**
Robert Carrb1579c82017-09-05 14:54:47 -0700451 * We organize all top-level Surfaces in to the following layers.
452 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800453 * and omitted from Screen-Magnification, for example the strict mode flash or
454 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700455 * {@link #mWindowingLayer} contains everything else.
456 */
457 private SurfaceControl mOverlayLayer;
458
459 /**
460 * See {@link #mOverlayLayer}
461 */
462 private SurfaceControl mWindowingLayer;
463
464 /**
465 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
466 * <p>
467 * For these surfaces currently we use a surface based on the larger of width or height so we
468 * don't have to resize when rotating the display.
469 */
470 private int mSurfaceSize;
471
Adrian Roos5251b1d2018-03-23 18:57:43 +0100472 /**
473 * Sequence number for the current layout pass.
474 */
475 int mLayoutSeq = 0;
476
Chavi Weingarten3a748552018-05-14 17:32:42 +0000477 /**
478 * Specifies the count to determine whether to defer updating the IME target until ready.
479 */
480 private int mDeferUpdateImeTargetCount;
481
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100482 /** Temporary float array to retrieve 3x3 matrix values. */
483 private final float[] mTmpFloats = new float[9];
484
Robert Carr24be9ab2018-04-30 17:54:53 -0700485 private MagnificationSpec mMagnificationSpec;
486
Arthur Hung95b38a92018-07-20 18:56:12 +0800487 private InputMonitor mInputMonitor;
488
Jorim Jaggif1292892018-09-10 11:58:13 +0200489 /** Caches the value whether told display manager that we have content. */
490 private boolean mLastHasContent;
491
Issei Suzuki43190bd2018-08-20 17:28:41 +0200492 private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil();
493
lumark90120a82018-08-15 00:33:03 +0800494 /**
495 * The input method window for this display.
496 */
497 WindowState mInputMethodWindow;
498
Arthur Hungbe5ce212018-09-13 18:41:56 +0800499 private final PointerEventDispatcher mPointerEventDispatcher;
500
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800501 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
502 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800503 final AppWindowToken atoken = w.mAppToken;
504 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200505 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800506 if (w.performShowLocked()) {
507 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
508 if (DEBUG_LAYOUT_REPEATS) {
509 mService.mWindowPlacerLocked.debugLayoutRepeats(
510 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
511 }
512 }
513 }
514 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800515 };
516
517 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
518 final WindowStateAnimator winAnimator = w.mWinAnimator;
519 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
520 return;
521 }
522
Jorim Jaggi8f520872018-08-14 17:00:20 +0200523 // If this window is animating, ensure the animation background is set.
524 final AnimationAdapter anim = w.mAppToken != null
525 ? w.mAppToken.getAnimation()
526 : w.getAnimation();
527 if (anim != null) {
528 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800529 if (color != 0) {
530 final TaskStack stack = w.getStack();
531 if (stack != null) {
532 stack.setAnimationBackground(winAnimator, color);
533 }
534 }
535 }
536 };
537
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800538 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
539 final int lostFocusUid = mTmpWindow.mOwnerUid;
540 final Handler handler = mService.mH;
541 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
542 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
543 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
544 w.mAttrs.hideTimeoutMilliseconds);
545 }
546 }
547 };
548
549 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800550 final AppWindowToken focusedApp = mFocusedApp;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800551 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
552 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
553
554 if (!w.canReceiveKeys()) {
555 return false;
556 }
557
558 final AppWindowToken wtoken = w.mAppToken;
559
560 // If this window's application has been removed, just skip it.
561 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
562 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
563 + (wtoken.removed ? "removed" : "sendingToBottom"));
564 return false;
565 }
566
567 if (focusedApp == null) {
568 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
569 + " using new focus @ " + w);
570 mTmpWindow = w;
571 return true;
572 }
573
574 if (!focusedApp.windowsAreFocusable()) {
575 // Current focused app windows aren't focusable...
576 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
577 + " focusable using new focus @ " + w);
578 mTmpWindow = w;
579 return true;
580 }
581
582 // Descend through all of the app tokens and find the first that either matches
583 // win.mAppToken (return win) or mFocusedApp (return null).
584 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
585 if (focusedApp.compareTo(wtoken) > 0) {
586 // App stack below focused app stack. No focus for you!!!
587 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
588 "findFocusedWindow: Reached focused app=" + focusedApp);
589 mTmpWindow = null;
590 return true;
591 }
592 }
593
594 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
595 mTmpWindow = w;
596 return true;
597 };
598
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800599 private final Consumer<WindowState> mPerformLayout = w -> {
600 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
601 // wasting time and funky changes while a window is animating away.
602 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
603 || w.isGoneForLayoutLw();
604
605 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
606 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
607 + " mLayoutAttached=" + w.mLayoutAttached
608 + " screen changed=" + w.isConfigChanged());
609 final AppWindowToken atoken = w.mAppToken;
610 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200611 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800612 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
613 + " parentHidden=" + w.isParentWindowHidden());
614 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200615 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800616 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
617 + " parentHidden=" + w.isParentWindowHidden());
618 }
619
620 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
621 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
622 // since that means "perform layout as normal, just don't display").
623 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
624 || ((w.isConfigChanged() || w.setReportResizeHints())
625 && !w.isGoneForLayoutLw() &&
626 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
627 (w.mHasSurface && w.mAppToken != null &&
628 w.mAppToken.layoutConfigChanges)))) {
629 if (!w.mLayoutAttached) {
630 if (mTmpInitial) {
631 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700632 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800633 }
634 if (w.mAttrs.type == TYPE_DREAM) {
635 // Don't layout windows behind a dream, so that if it does stuff like hide
636 // the status bar we won't get a bad transition when it goes away.
637 mTmpWindow = w;
638 }
639 w.mLayoutNeeded = false;
640 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200641 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000642 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100643 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800644
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200645 // If this is the first layout, we need to initialize the last inset values as
646 // otherwise we'd immediately cause an unnecessary resize.
647 if (firstLayout) {
648 w.updateLastInsetValues();
649 }
650
Adrian Roos23df3a32018-03-15 15:41:13 +0100651 if (w.mAppToken != null) {
652 w.mAppToken.layoutLetterbox(w);
653 }
654
chaviw492139a2018-07-16 16:07:35 -0700655 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700656 + " mContainingFrame=" + w.getContainingFrame()
657 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800658 }
659 }
660 };
661
662 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
663 if (w.mLayoutAttached) {
664 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
665 + " mViewVisibility=" + w.mViewVisibility
666 + " mRelayoutCalled=" + w.mRelayoutCalled);
667 // If this view is GONE, then skip it -- keep the current frame, and let the caller
668 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
669 // windows, since that means "perform layout as normal, just don't display").
670 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
671 return;
672 }
673 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
674 || w.mLayoutNeeded) {
675 if (mTmpInitial) {
676 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700677 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800678 }
679 w.mLayoutNeeded = false;
680 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000681 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100682 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700683 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700684 + " mContainingFrame=" + w.getContainingFrame()
685 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800686 }
687 } else if (w.mAttrs.type == TYPE_DREAM) {
688 // Don't layout windows behind a dream, so that if it does stuff like hide the
689 // status bar we won't get a bad transition when it goes away.
690 mTmpWindow = mTmpWindow2;
691 }
692 };
693
694 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
695 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
696 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
697 return w.canBeImeTarget();
698 };
699
700 private final Consumer<WindowState> mApplyPostLayoutPolicy =
701 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
702 mService.mInputMethodTarget);
703
704 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
705 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
706 final boolean obscuredChanged = w.mObscured !=
707 mTmpApplySurfaceChangesTransactionState.obscured;
708 final RootWindowContainer root = mService.mRoot;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800709
710 // Update effect.
711 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
712 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
713 final boolean isDisplayed = w.isDisplayedLw();
714
715 if (isDisplayed && w.isObscuringDisplay()) {
716 // This window completely covers everything behind it, so we want to leave all
717 // of them as undimmed (for performance reasons).
718 root.mObscuringWindow = w;
719 mTmpApplySurfaceChangesTransactionState.obscured = true;
720 }
721
722 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
723 root.handleNotObscuredLocked(w,
724 mTmpApplySurfaceChangesTransactionState.obscured,
725 mTmpApplySurfaceChangesTransactionState.syswin);
726
727 if (w.mHasSurface && isDisplayed) {
728 final int type = w.mAttrs.type;
729 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
730 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
731 mTmpApplySurfaceChangesTransactionState.syswin = true;
732 }
733 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
734 && w.mAttrs.preferredRefreshRate != 0) {
735 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
736 = w.mAttrs.preferredRefreshRate;
737 }
738 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
739 && w.mAttrs.preferredDisplayModeId != 0) {
740 mTmpApplySurfaceChangesTransactionState.preferredModeId
741 = w.mAttrs.preferredDisplayModeId;
742 }
743 }
744 }
745
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800746 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
747 && mWallpaperController.isWallpaperTarget(w)) {
748 // This is the wallpaper target and its obscured state changed... make sure the
749 // current wallpaper's visibility has been updated accordingly.
750 mWallpaperController.updateWallpaperVisibility();
751 }
752
chaviw161ea3e2018-01-31 12:01:12 -0800753 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800754
755 final WindowStateAnimator winAnimator = w.mWinAnimator;
756
757 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
chaviw1454b392018-08-06 09:54:04 -0700758 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800759
760 // Moved from updateWindowsAndWallpaperLocked().
761 if (w.mHasSurface) {
762 // Take care of the window being ready to display.
763 final boolean committed = winAnimator.commitFinishDrawingLocked();
764 if (isDefaultDisplay && committed) {
765 if (w.mAttrs.type == TYPE_DREAM) {
766 // HACK: When a dream is shown, it may at that point hide the lock screen.
767 // So we need to redo the layout to let the phone window manager make this
768 // happen.
769 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
770 if (DEBUG_LAYOUT_REPEATS) {
771 surfacePlacer.debugLayoutRepeats(
772 "dream and commitFinishDrawingLocked true",
773 pendingLayoutChanges);
774 }
775 }
776 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
777 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
778 "First draw done in potential wallpaper target " + w);
779 root.mWallpaperMayChange = true;
780 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
781 if (DEBUG_LAYOUT_REPEATS) {
782 surfacePlacer.debugLayoutRepeats(
783 "wallpaper and commitFinishDrawingLocked true",
784 pendingLayoutChanges);
785 }
786 }
787 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800788 }
789
790 final AppWindowToken atoken = w.mAppToken;
791 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100792 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800793 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
794 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
795 mTmpUpdateAllDrawn.add(atoken);
796 }
797 }
798
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800799 if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) {
800 mService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800801 }
802
803 w.updateResizingWindowIfNeeded();
804 };
805
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800806 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800807 * Create new {@link DisplayContent} instance, add itself to the root window container and
808 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700809 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800810 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700811 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
812 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700813 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700814 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800815 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100816 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800817 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800818 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
819 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
820 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
821 + " new=" + display);
822 }
823
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700824 mDisplay = display;
825 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700826 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700827 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700828 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700829 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100830 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
831 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700832 initializeDisplayBaseInfo();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800833 mDisplayPolicy = new DisplayPolicy(service);
834 mDisplayRotation = new DisplayRotation(service, this);
835 if (isDefaultDisplay) {
836 // The policy may be invoked right after here, so it requires the necessary default
837 // fields of this display content.
838 mService.mPolicy.setDefaultDisplay(this);
839 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800840 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700841 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700842
lumark588a3e82018-07-20 18:53:54 +0800843 mAppTransition = new AppTransition(service.mContext, service, this);
844 mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier);
845 mAppTransitionController = new AppTransitionController(service, this);
846 mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this);
847
848 AnimationHandler animationHandler = new AnimationHandler();
849 mBoundsAnimationController = new BoundsAnimationController(service.mContext,
850 mAppTransition, SurfaceAnimationThread.getHandler(), animationHandler);
851
Robert Carr74a66a22018-02-23 12:17:51 -0800852 // We use this as our arbitrary surface size for buffer-less parents
853 // that don't impose cropping on their children. It may need to be larger
854 // than the display size because fullscreen windows can be shifted offscreen
855 // due to surfaceInsets. 2 times the largest display dimension feels like an
856 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
857 // layers the ability to match their parent sizes and be able to skip
858 // such arbitrary size settings.
859 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700860
861 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
862 .setSize(mSurfaceSize, mSurfaceSize)
863 .setOpaque(true);
864 mWindowingLayer = b.setName("Display Root").build();
865 mOverlayLayer = b.setName("Display Overlays").build();
866
Robert Carrf59b8dd2017-10-02 18:58:36 -0700867 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700868 .setLayerStack(mWindowingLayer, mDisplayId)
869 .show(mWindowingLayer)
870 .setLayer(mOverlayLayer, 1)
871 .setLayerStack(mOverlayLayer, mDisplayId)
872 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700873 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700874
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700875 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700876 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700877 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700878 super.addChild(mAboveAppWindowsContainers, null);
879 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800880
881 // Add itself as a child to the root container.
882 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700883
884 // TODO(b/62541591): evaluate whether this is the best spot to declare the
885 // {@link DisplayContent} ready for use.
886 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800887
Riddle Hsuf53da812018-08-15 22:00:27 +0800888 mService.mAnimator.addDisplayLocked(mDisplayId);
Arthur Hung39134b22018-08-14 11:58:28 +0800889 mInputMonitor = new InputMonitor(service, mDisplayId);
Arthur Hungbe5ce212018-09-13 18:41:56 +0800890
891 if (mService.mInputManager != null) {
892 final InputChannel inputChannel = mService.mInputManager.monitorInput("Display "
893 + mDisplayId, mDisplayId);
894 mPointerEventDispatcher = inputChannel != null
895 ? new PointerEventDispatcher(inputChannel) : null;
896 } else {
897 mPointerEventDispatcher = null;
898 }
Bryce Leed1871262017-06-12 14:12:29 -0700899 }
900
901 boolean isReady() {
902 // The display is ready when the system and the individual display are both ready.
903 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700904 }
905
906 int getDisplayId() {
907 return mDisplayId;
908 }
909
Wale Ogunwale02319a62016-09-26 15:21:22 -0700910 WindowToken getWindowToken(IBinder binder) {
911 return mTokenMap.get(binder);
912 }
913
914 AppWindowToken getAppWindowToken(IBinder binder) {
915 final WindowToken token = getWindowToken(binder);
916 if (token == null) {
917 return null;
918 }
919 return token.asAppWindowToken();
920 }
921
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700922 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700923 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
924 if (dc != null) {
925 // We currently don't support adding a window token to the display if the display
926 // already has the binder mapped to another token. If there is a use case for supporting
927 // this moving forward we will either need to merge the WindowTokens some how or have
928 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700929 throw new IllegalArgumentException("Can't map token=" + token + " to display="
930 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700931 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700932 if (binder == null) {
933 throw new IllegalArgumentException("Can't map token=" + token + " to display="
934 + getName() + " binder is null");
935 }
936 if (token == null) {
937 throw new IllegalArgumentException("Can't map null token to display="
938 + getName() + " binder=" + binder);
939 }
940
Wale Ogunwale02319a62016-09-26 15:21:22 -0700941 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700942
943 if (token.asAppWindowToken() == null) {
944 // Add non-app token to container hierarchy on the display. App tokens are added through
945 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700946 switch (token.windowType) {
947 case TYPE_WALLPAPER:
948 mBelowAppWindowsContainers.addChild(token);
949 break;
950 case TYPE_INPUT_METHOD:
951 case TYPE_INPUT_METHOD_DIALOG:
952 mImeWindowsContainers.addChild(token);
953 break;
954 default:
955 mAboveAppWindowsContainers.addChild(token);
956 break;
957 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700958 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700959 }
960
961 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700962 final WindowToken token = mTokenMap.remove(binder);
963 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800964 token.setExiting();
965 }
966 return token;
967 }
968
969 /** Changes the display the input window token is housed on to this one. */
970 void reParentWindowToken(WindowToken token) {
971 final DisplayContent prevDc = token.getDisplayContent();
972 if (prevDc == this) {
973 return;
974 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800975 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
976 && token.asAppWindowToken() == null) {
977 // Removed the token from the map, but made sure it's not an app token before removing
978 // from parent.
979 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700980 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800981
982 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700983 }
984
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700985 void removeAppToken(IBinder binder) {
986 final WindowToken token = removeWindowToken(binder);
987 if (token == null) {
988 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
989 return;
990 }
991
992 final AppWindowToken appToken = token.asAppWindowToken();
993
994 if (appToken == null) {
995 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
996 return;
997 }
998
999 appToken.onRemovedFromDisplay();
1000 }
1001
Riddle Hsuad256a12018-07-18 16:11:30 +08001002 @Override
Riddle Hsu86cb7de2018-08-13 23:29:58 +08001003 DisplayWindowController getController() {
1004 return (DisplayWindowController) super.getController();
1005 }
1006
1007 @Override
Riddle Hsuad256a12018-07-18 16:11:30 +08001008 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -07001009 return mDisplay;
1010 }
1011
Craig Mautner59c00972012-07-30 12:10:24 -07001012 DisplayInfo getDisplayInfo() {
1013 return mDisplayInfo;
1014 }
1015
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001016 DisplayMetrics getDisplayMetrics() {
1017 return mDisplayMetrics;
1018 }
1019
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001020 DisplayPolicy getDisplayPolicy() {
1021 return mDisplayPolicy;
1022 }
1023
Riddle Hsuad256a12018-07-18 16:11:30 +08001024 @Override
1025 public DisplayRotation getDisplayRotation() {
1026 return mDisplayRotation;
1027 }
1028
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001029 @VisibleForTesting
1030 void setDisplayRotation(DisplayRotation displayRotation) {
1031 mDisplayRotation = displayRotation;
1032 }
1033
Andrii Kulian8ee72852017-03-10 10:36:45 -08001034 int getRotation() {
1035 return mRotation;
1036 }
1037
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001038 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -08001039 void setRotation(int newRotation) {
1040 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +08001041 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001042 }
1043
1044 int getLastOrientation() {
1045 return mLastOrientation;
1046 }
1047
1048 void setLastOrientation(int orientation) {
1049 mLastOrientation = orientation;
1050 }
1051
1052 boolean getAltOrientation() {
1053 return mAltOrientation;
1054 }
1055
1056 void setAltOrientation(boolean altOrientation) {
1057 mAltOrientation = altOrientation;
1058 }
1059
1060 int getLastWindowForcedOrientation() {
1061 return mLastWindowForcedOrientation;
1062 }
1063
Andrii Kulian06d07d62017-03-14 11:11:47 -07001064 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +08001065 * Temporarily pauses rotation changes until resumed.
1066 *
1067 * This can be used to prevent rotation changes from occurring while the user is
1068 * performing certain operations, such as drag and drop.
1069 *
1070 * This call nests and must be matched by an equal number of calls to
1071 * {@link #resumeRotationLocked}.
1072 */
1073 void pauseRotationLocked() {
1074 mDeferredRotationPauseCount++;
1075 }
1076
1077 /**
1078 * Resumes normal rotation changes after being paused.
1079 */
1080 void resumeRotationLocked() {
1081 if (mDeferredRotationPauseCount <= 0) {
1082 return;
1083 }
1084
1085 mDeferredRotationPauseCount--;
1086 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001087 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001088 }
1089 }
1090
1091 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001092 * If this is true we have updated our desired orientation, but not yet changed the real
1093 * orientation our applied our screen rotation animation. For example, because a previous
1094 * screen rotation was in progress.
1095 *
1096 * @return {@code true} if the there is an ongoing rotation change.
1097 */
1098 boolean rotationNeedsUpdate() {
1099 final int lastOrientation = getLastOrientation();
1100 final int oldRotation = getRotation();
1101 final boolean oldAltOrientation = getAltOrientation();
1102
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001103 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001104 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1105 lastOrientation, rotation);
1106 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1107 return false;
1108 }
1109 return true;
1110 }
1111
1112 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001113 * Update rotation of the display and send configuration if the rotation is changed.
1114 *
1115 * @return {@code true} if the rotation has been changed and the new config is sent.
1116 */
1117 boolean updateRotationAndSendNewConfigIfNeeded() {
1118 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1119 if (changed) {
1120 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
1121 }
1122 return changed;
1123 }
1124
1125 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001126 * Update rotation of the display.
1127 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001128 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1129 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001130 */
Robert Carrae606b42018-02-15 15:36:23 -08001131 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001132 return updateRotationUnchecked(false /* forceUpdate */);
1133 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001134
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001135 /**
1136 * Update rotation of the display with an option to force the update.
1137 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1138 * orientation because we're waiting for some rotation to finish or display
1139 * to unfreeze, which results in configuration of the previously visible
1140 * activity being applied to a newly visible one. Forcing the rotation
1141 * update allows to workaround this issue.
1142 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1143 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
1144 */
1145 boolean updateRotationUnchecked(boolean forceUpdate) {
1146 ScreenRotationAnimation screenRotationAnimation;
1147 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001148 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001149 // Rotation updates have been paused temporarily. Defer the update until
1150 // updates have been resumed.
1151 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1152 return false;
1153 }
1154
1155 screenRotationAnimation =
1156 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
1157 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1158 // Rotation updates cannot be performed while the previous rotation change
1159 // animation is still in progress. Skip this update. We will try updating
1160 // again after the animation is finished and the display is unfrozen.
1161 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1162 return false;
1163 }
1164 if (mService.mDisplayFrozen) {
1165 // Even if the screen rotation animation has finished (e.g. isAnimating
1166 // returns false), there is still some time where we haven't yet unfrozen
1167 // the display. We also need to abort rotation here.
1168 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1169 "Deferring rotation, still finishing previous rotation");
1170 return false;
1171 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001172 }
1173
1174 if (!mService.mDisplayEnabled) {
1175 // No point choosing a rotation if the display is not enabled.
1176 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1177 return false;
1178 }
1179
1180 final int oldRotation = mRotation;
1181 final int lastOrientation = mLastOrientation;
1182 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001183 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001184 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1185 + mDisplayId + " based on lastOrientation=" + lastOrientation
1186 + " and oldRotation=" + oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001187 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(mDisplayRotation,
1188 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001189
Robert Carr0e007272017-10-02 13:00:55 -07001190 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001191 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001192 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001193 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1194 // to complete (that is, waiting for windows to redraw). It's tempting to check
1195 // w.mSeamlessRotationCount but that could be incorrect in the case of
1196 // window-removal.
1197 return false;
1198 }
Robert Carr0e007272017-10-02 13:00:55 -07001199
1200 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001201 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001202 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001203 mayRotateSeamlessly = false;
1204 }
1205 for (int i = 0; i < mService.mSessions.size(); i++) {
1206 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1207 mayRotateSeamlessly = false;
1208 break;
1209 }
1210 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001211 }
Robert Carr0e007272017-10-02 13:00:55 -07001212 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001213
1214 // TODO: Implement forced rotation changes.
1215 // Set mAltOrientation to indicate that the application is receiving
1216 // an orientation that has different metrics than it expected.
1217 // eg. Portrait instead of Landscape.
1218
Riddle Hsuad256a12018-07-18 16:11:30 +08001219 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001220 lastOrientation, rotation);
1221
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001222 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1223 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001224 + ", got rotation " + rotation + " which has "
1225 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1226
1227 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1228 // No change.
1229 return false;
1230 }
1231
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001232 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1233 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001234 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1235 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1236
1237 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1238 mService.mWaitingForConfig = true;
1239 }
1240
Riddle Hsuad256a12018-07-18 16:11:30 +08001241 setRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001242 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001243
1244 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
Riddle Hsu654a6f92018-07-13 22:59:36 +08001245 mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1246 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001247
1248 setLayoutNeeded();
1249 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001250 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001251
1252 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001253 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001254 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1255 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1256 mDisplayId);
1257 } else {
1258 // The screen rotation animation uses a screenshot to freeze the screen
1259 // while windows resize underneath.
1260 // When we are rotating seamlessly, we allow the elements to transition
1261 // to their rotated state independently and without a freeze required.
1262 screenRotationAnimation = null;
1263
Robert Carrefc75702018-02-16 11:46:16 -08001264 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001265 }
1266
1267 // We need to update our screen size information to match the new rotation. If the rotation
1268 // has actually changed then this method will return true and, according to the comment at
1269 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1270 // By updating the Display info here it will be available to
1271 // #computeScreenConfiguration() later.
1272 updateDisplayAndOrientation(getConfiguration().uiMode);
1273
Robert Carrae606b42018-02-15 15:36:23 -08001274 // NOTE: We disable the rotation in the emulator because
1275 // it doesn't support hardware OpenGL emulation yet.
1276 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1277 && screenRotationAnimation.hasScreenshot()) {
1278 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1279 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1280 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1281 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001282 }
1283 }
1284
Vishnu Nair83537a72018-07-19 21:27:48 -07001285 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001286 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1287 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001288 }, true /* traverseTopToBottom */);
1289
Robert Carrae606b42018-02-15 15:36:23 -08001290 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1291 scheduleAnimation();
1292
Andrii Kulian06d07d62017-03-14 11:11:47 -07001293 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001294 if (w.mHasSurface && !rotateSeamlessly) {
1295 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001296 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001297 mService.mRoot.mOrientationChangeComplete = false;
1298 w.mLastFreezeDuration = 0;
1299 }
1300 w.mReportOrientationChanged = true;
1301 }, true /* traverseTopToBottom */);
1302
1303 if (rotateSeamlessly) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001304 mService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1305 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001306 }
1307
1308 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1309 final WindowManagerService.RotationWatcher rotationWatcher
1310 = mService.mRotationWatchers.get(i);
1311 if (rotationWatcher.mDisplayId == mDisplayId) {
1312 try {
1313 rotationWatcher.mWatcher.onRotationChanged(rotation);
1314 } catch (RemoteException e) {
1315 // Ignore
1316 }
1317 }
1318 }
1319
1320 // TODO (multi-display): Magnification is supported only for the default display.
1321 // Announce rotation only if we will not animate as we already have the
1322 // windows in final state. Otherwise, we make this call at the rotation end.
1323 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1324 && isDefaultDisplay) {
1325 mService.mAccessibilityController.onRotationChangedLocked(this);
1326 }
1327
1328 return true;
1329 }
1330
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001331 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001332 final int width = mBaseDisplayWidth;
1333 final int height = mBaseDisplayHeight;
1334 final int shortSize;
1335 final int longSize;
1336 if (width > height) {
1337 shortSize = height;
1338 longSize = width;
1339 } else {
1340 shortSize = width;
1341 longSize = height;
1342 }
1343
1344 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1345 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1346
1347 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1348 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001349
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001350 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1351 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Arthur Hungbe5ce212018-09-13 18:41:56 +08001352
1353 // Tap Listeners are supported for:
1354 // 1. All physical displays (multi-display).
1355 // 2. VirtualDisplays on VR, AA (and everything else).
1356 if (mPointerEventDispatcher != null && mTapDetector == null) {
1357 if (DEBUG_DISPLAY) {
1358 Slog.d(TAG,
1359 "Registering PointerEventListener for DisplayId: " + mDisplayId);
1360 }
1361 mTapDetector = new TaskTapPointerEventListener(mService, this);
1362 registerPointerEventListener(mTapDetector);
1363 registerPointerEventListener(mService.mMousePositionTracker);
1364 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001365 }
1366
Andrii Kulian06d07d62017-03-14 11:11:47 -07001367 /**
1368 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1369 * changed.
1370 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1371 */
1372 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1373 // Use the effective "visual" dimensions based on current rotation
1374 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1375 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1376 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1377 int dw = realdw;
1378 int dh = realdh;
1379
1380 if (mAltOrientation) {
1381 if (realdw > realdh) {
1382 // Turn landscape into portrait.
1383 int maxw = (int)(realdh/1.3f);
1384 if (maxw < realdw) {
1385 dw = maxw;
1386 }
1387 } else {
1388 // Turn portrait into landscape.
1389 int maxh = (int)(realdw/1.3f);
1390 if (maxh < realdh) {
1391 dh = maxh;
1392 }
1393 }
1394 }
1395
1396 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001397 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1398 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1399
Andrii Kulian06d07d62017-03-14 11:11:47 -07001400 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001401 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001402 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001403 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001404 mDisplayInfo.rotation = mRotation;
1405 mDisplayInfo.logicalWidth = dw;
1406 mDisplayInfo.logicalHeight = dh;
1407 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1408 mDisplayInfo.appWidth = appWidth;
1409 mDisplayInfo.appHeight = appHeight;
1410 if (isDefaultDisplay) {
1411 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1412 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1413 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001414 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001415 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1416 if (mDisplayScalingDisabled) {
1417 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1418 } else {
1419 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1420 }
1421
Andrii Kulianf0379de2018-03-14 16:24:07 -07001422 // We usually set the override info in DisplayManager so that we get consistent display
1423 // metrics values when displays are changing and don't send out new values until WM is aware
1424 // of them. However, we don't do this for displays that serve as containers for ActivityView
1425 // because we don't want letter-/pillar-boxing during resize.
1426 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1427 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001428 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001429 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001430
1431 mBaseDisplayRect.set(0, 0, dw, dh);
1432
1433 if (isDefaultDisplay) {
1434 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1435 mCompatDisplayMetrics);
1436 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001437
1438 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001439 return mDisplayInfo;
1440 }
1441
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001442 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001443 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1444 }
1445
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001446 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001447 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001448 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001449 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001450 }
Adrian Roos11c25582018-02-19 18:06:36 +01001451 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001452 return WmDisplayCutout.computeSafeInsets(
1453 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001454 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001455 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Issei Suzuki43190bd2018-08-20 17:28:41 +02001456 final Rect[] newBounds = mRotationUtil.getRotatedBounds(
1457 WmDisplayCutout.computeSafeInsets(
Jorim Jaggi60640512018-06-29 01:14:31 +02001458 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
Issei Suzuki43190bd2018-08-20 17:28:41 +02001459 .getDisplayCutout().getBoundingRectsAll(),
1460 rotation, mInitialDisplayWidth, mInitialDisplayHeight);
1461 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds),
Adrian Roos24264212018-02-19 16:26:15 +01001462 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1463 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001464 }
1465
Andrii Kulian06d07d62017-03-14 11:11:47 -07001466 /**
1467 * Compute display configuration based on display properties and policy settings.
1468 * Do not call if mDisplayReady == false.
1469 */
1470 void computeScreenConfiguration(Configuration config) {
1471 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1472
1473 final int dw = displayInfo.logicalWidth;
1474 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001475 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001476 config.windowConfiguration.setWindowingMode(getWindowingMode());
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001477
Adrian Roos11c25582018-02-19 18:06:36 +01001478 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001479 config.screenWidthDp =
1480 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001481 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001482 config.screenHeightDp =
1483 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001484 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001485
Adrian Roos11c25582018-02-19 18:06:36 +01001486 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1487 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001488 final int leftInset = mTmpRect.left;
1489 final int topInset = mTmpRect.top;
1490 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001491 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1492 leftInset + displayInfo.appWidth /* right */,
1493 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001494 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1495 || displayInfo.rotation == Surface.ROTATION_270);
1496
1497 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001498 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001499
1500 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1501 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1502 ? Configuration.SCREENLAYOUT_ROUND_YES
1503 : Configuration.SCREENLAYOUT_ROUND_NO);
1504
1505 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1506 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1507 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1508 dh, mDisplayId);
1509 config.densityDpi = displayInfo.logicalDensityDpi;
1510
1511 config.colorMode =
Chia-I Wuf739bad2018-05-09 12:36:57 -07001512 ((displayInfo.isHdr() && mService.hasHdrSupport())
Andrii Kulian06d07d62017-03-14 11:11:47 -07001513 ? Configuration.COLOR_MODE_HDR_YES
1514 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001515 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001516 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1517 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1518
1519 // Update the configuration based on available input devices, lid switch,
1520 // and platform configuration.
1521 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1522 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1523 config.navigation = Configuration.NAVIGATION_NONAV;
1524
1525 int keyboardPresence = 0;
1526 int navigationPresence = 0;
1527 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1528 final int len = devices != null ? devices.length : 0;
1529 for (int i = 0; i < len; i++) {
1530 InputDevice device = devices[i];
1531 if (!device.isVirtual()) {
1532 final int sources = device.getSources();
1533 final int presenceFlag = device.isExternal() ?
1534 WindowManagerPolicy.PRESENCE_EXTERNAL :
1535 WindowManagerPolicy.PRESENCE_INTERNAL;
1536
1537 // TODO(multi-display): Configure on per-display basis.
1538 if (mService.mIsTouchDevice) {
1539 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1540 InputDevice.SOURCE_TOUCHSCREEN) {
1541 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1542 }
1543 } else {
1544 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1545 }
1546
1547 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1548 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1549 navigationPresence |= presenceFlag;
1550 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1551 && config.navigation == Configuration.NAVIGATION_NONAV) {
1552 config.navigation = Configuration.NAVIGATION_DPAD;
1553 navigationPresence |= presenceFlag;
1554 }
1555
1556 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1557 config.keyboard = Configuration.KEYBOARD_QWERTY;
1558 keyboardPresence |= presenceFlag;
1559 }
1560 }
1561 }
1562
1563 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1564 config.navigation = Configuration.NAVIGATION_DPAD;
1565 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1566 }
1567
1568 // Determine whether a hard keyboard is available and enabled.
1569 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1570 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1571 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1572 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1573 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1574 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1575 }
1576
1577 // Let the policy update hidden states.
1578 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1579 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1580 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1581 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1582 }
1583
1584 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1585 int displayId) {
1586 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1587 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1588 final int unrotDw, unrotDh;
1589 if (rotated) {
1590 unrotDw = dh;
1591 unrotDh = dw;
1592 } else {
1593 unrotDw = dw;
1594 unrotDh = dh;
1595 }
1596 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1597 displayId);
1598 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1599 displayId);
1600 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1601 displayId);
1602 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1603 displayId);
1604 return sw;
1605 }
1606
1607 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1608 DisplayMetrics dm, int dw, int dh, int displayId) {
1609 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001610 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001611 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001612 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001613 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1614 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1615 if (curSize == 0 || size < curSize) {
1616 curSize = size;
1617 }
1618 return curSize;
1619 }
1620
1621 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1622 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1623
1624 // We need to determine the smallest width that will occur under normal
1625 // operation. To this, start with the base screen size and compute the
1626 // width under the different possible rotations. We need to un-rotate
1627 // the current screen dimensions before doing this.
1628 int unrotDw, unrotDh;
1629 if (rotated) {
1630 unrotDw = dh;
1631 unrotDh = dw;
1632 } else {
1633 unrotDw = dw;
1634 unrotDh = dh;
1635 }
1636 displayInfo.smallestNominalAppWidth = 1<<30;
1637 displayInfo.smallestNominalAppHeight = 1<<30;
1638 displayInfo.largestNominalAppWidth = 0;
1639 displayInfo.largestNominalAppHeight = 0;
1640 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1641 unrotDh);
1642 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1643 unrotDw);
1644 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1645 unrotDh);
1646 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1647 unrotDw);
1648 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1649 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1650 displayId);
1651 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1652 displayId);
1653 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1654 displayId);
1655 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1656 displayId);
1657 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1658 outConfig.screenLayout = sl;
1659 }
1660
1661 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1662 int uiMode, int displayId) {
1663 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001664 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1665 mDisplayInfo.displayCutout);
1666 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1667 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001668
1669 // Compute the screen layout size class for this rotation.
1670 int longSize = w;
1671 int shortSize = h;
1672 if (longSize < shortSize) {
1673 int tmp = longSize;
1674 longSize = shortSize;
1675 shortSize = tmp;
1676 }
1677 longSize = (int)(longSize/density);
1678 shortSize = (int)(shortSize/density);
1679 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1680 }
1681
1682 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1683 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001684 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1685 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001686 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001687 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001688 if (width < displayInfo.smallestNominalAppWidth) {
1689 displayInfo.smallestNominalAppWidth = width;
1690 }
1691 if (width > displayInfo.largestNominalAppWidth) {
1692 displayInfo.largestNominalAppWidth = width;
1693 }
1694 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001695 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001696 if (height < displayInfo.smallestNominalAppHeight) {
1697 displayInfo.smallestNominalAppHeight = height;
1698 }
1699 if (height > displayInfo.largestNominalAppHeight) {
1700 displayInfo.largestNominalAppHeight = height;
1701 }
1702 }
1703
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001704 /**
1705 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1706 * theme attribute) on devices that feature a physical options menu key attempt to position
1707 * their menu panel window along the edge of the screen nearest the physical menu key.
1708 * This lowers the travel distance between invoking the menu panel and selecting
1709 * a menu option.
1710 *
1711 * This method helps control where that menu is placed. Its current implementation makes
1712 * assumptions about the menu key and its relationship to the screen based on whether
1713 * the device's natural orientation is portrait (width < height) or landscape.
1714 *
1715 * The menu key is assumed to be located along the bottom edge of natural-portrait
1716 * devices and along the right edge of natural-landscape devices. If these assumptions
1717 * do not hold for the target device, this method should be changed to reflect that.
1718 *
1719 * @return A {@link Gravity} value for placing the options menu window.
1720 */
1721 int getPreferredOptionsPanelGravity() {
1722 final int rotation = getRotation();
1723 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1724 // On devices with a natural orientation of portrait.
1725 switch (rotation) {
1726 default:
1727 case Surface.ROTATION_0:
1728 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1729 case Surface.ROTATION_90:
1730 return Gravity.RIGHT | Gravity.BOTTOM;
1731 case Surface.ROTATION_180:
1732 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1733 case Surface.ROTATION_270:
1734 return Gravity.START | Gravity.BOTTOM;
1735 }
1736 }
1737
1738 // On devices with a natural orientation of landscape.
1739 switch (rotation) {
1740 default:
1741 case Surface.ROTATION_0:
1742 return Gravity.RIGHT | Gravity.BOTTOM;
1743 case Surface.ROTATION_90:
1744 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1745 case Surface.ROTATION_180:
1746 return Gravity.START | Gravity.BOTTOM;
1747 case Surface.ROTATION_270:
1748 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1749 }
1750 }
1751
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001752 DockedStackDividerController getDockedDividerController() {
1753 return mDividerControllerLocked;
1754 }
1755
Winson Chung655332c2016-10-31 13:14:28 -07001756 PinnedStackController getPinnedStackController() {
1757 return mPinnedStackControllerLocked;
1758 }
1759
Jeff Browna506a6e2013-06-04 00:02:38 -07001760 /**
1761 * Returns true if the specified UID has access to this display.
1762 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001763 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001764 return mDisplay.hasAccess(uid);
1765 }
1766
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001767 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001768 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001769 }
1770
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001771 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001772 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001773 }
1774
Wale Ogunwale61911492017-10-11 08:50:50 -07001775 /**
1776 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1777 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001778 TaskStack getSplitScreenPrimaryStack() {
1779 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001780 return (stack != null && stack.isVisible()) ? stack : null;
1781 }
1782
Robert Carr9785cf32018-04-25 15:06:07 -07001783 boolean hasSplitScreenPrimaryStack() {
1784 return getSplitScreenPrimaryStack() != null;
1785 }
1786
Wale Ogunwale61911492017-10-11 08:50:50 -07001787 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001788 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001789 * not visible.
1790 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001791 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1792 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001793 }
1794
1795 TaskStack getPinnedStack() {
1796 return mTaskStackContainers.getPinnedStack();
1797 }
1798
1799 private boolean hasPinnedStack() {
1800 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001801 }
1802
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001803 /**
1804 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1805 * Null is no compatible stack on the display.
1806 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001807 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001808 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1809 }
1810
1811 /**
1812 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1813 * activity type. Null is no compatible stack on the display.
1814 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001815 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001816 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001817 }
1818
Bryce Lee48f4b572017-04-10 10:54:15 -07001819 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001820 WindowList<TaskStack> getStacks() {
1821 return mTaskStackContainers.mChildren;
1822 }
1823
1824 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001825 TaskStack getTopStack() {
1826 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001827 }
1828
Winson Chunge2d72172018-01-25 17:46:20 +00001829 ArrayList<Task> getVisibleTasks() {
1830 return mTaskStackContainers.getVisibleTasks();
1831 }
1832
Wale Ogunwale61911492017-10-11 08:50:50 -07001833 void onStackWindowingModeChanged(TaskStack stack) {
1834 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001835 }
1836
Andrii Kulian441e4492016-09-29 15:25:00 -07001837 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001838 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001839 super.onConfigurationChanged(newParentConfig);
1840
Andrii Kulian3a507b52016-09-19 18:14:12 -07001841 // The display size information is heavily dependent on the resources in the current
1842 // configuration, so we need to reconfigure it every time the configuration changes.
Riddle Hsuf53da812018-08-15 22:00:27 +08001843 // See {@link #configureDisplayPolicy}...sigh...
Andrii Kulian3a507b52016-09-19 18:14:12 -07001844 mService.reconfigureDisplayLocked(this);
1845
Bryce Leef3c6a472017-11-14 14:53:06 -08001846 final DockedStackDividerController dividerController = getDockedDividerController();
1847
1848 if (dividerController != null) {
1849 getDockedDividerController().onConfigurationChanged();
1850 }
1851
1852 final PinnedStackController pinnedStackController = getPinnedStackController();
1853
1854 if (pinnedStackController != null) {
1855 getPinnedStackController().onConfigurationChanged();
1856 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001857 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001858
Andrii Kulian441e4492016-09-29 15:25:00 -07001859 /**
1860 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1861 * bounds were updated.
1862 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001863 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001864 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1865 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001866 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001867 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001868 }
1869 }
Winson Chung32c566f2017-04-11 18:31:21 -07001870
1871 // If there was no pinned stack, we still need to notify the controller of the display info
1872 // update as a result of the config change. We do this here to consolidate the flow between
1873 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001874 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001875 mPinnedStackControllerLocked.onDisplayInfoChanged();
1876 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001877 }
1878
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001879 @Override
1880 boolean fillsParent() {
1881 return true;
1882 }
1883
1884 @Override
1885 boolean isVisible() {
1886 return true;
1887 }
1888
1889 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001890 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001891 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001892 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001893 }
1894
Robert Carr9785cf32018-04-25 15:06:07 -07001895 /**
1896 * In split-screen mode we process the IME containers above the docked divider
1897 * rather than directly above their target.
1898 */
1899 private boolean skipTraverseChild(WindowContainer child) {
1900 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null
1901 && !hasSplitScreenPrimaryStack()) {
1902 return true;
1903 }
1904 return false;
1905 }
1906
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001907 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001908 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1909 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1910 // target, or here in order if there isn't an IME target.
1911 if (traverseTopToBottom) {
1912 for (int i = mChildren.size() - 1; i >= 0; --i) {
1913 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001914 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001915 continue;
1916 }
Robert Carr9785cf32018-04-25 15:06:07 -07001917
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001918 if (child.forAllWindows(callback, traverseTopToBottom)) {
1919 return true;
1920 }
1921 }
1922 } else {
1923 final int count = mChildren.size();
1924 for (int i = 0; i < count; i++) {
1925 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001926 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001927 continue;
1928 }
Robert Carr9785cf32018-04-25 15:06:07 -07001929
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001930 if (child.forAllWindows(callback, traverseTopToBottom)) {
1931 return true;
1932 }
1933 }
1934 }
1935 return false;
1936 }
1937
1938 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1939 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1940 }
1941
Wale Ogunwale399c8692017-05-08 14:22:42 -07001942 @Override
1943 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001944 final WindowManagerPolicy policy = mService.mPolicy;
1945
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001946 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001947 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001948 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1949 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001950 // If the display is frozen, some activities may be in the middle of restarting, and
1951 // thus have removed their old window. If the window has the flag to hide the lock
1952 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1953 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001954 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001955 } else if (policy.isKeyguardLocked()) {
1956 // Use the last orientation the while the display is frozen with the keyguard
1957 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1958 // window. We don't want to check the show when locked window directly though as
1959 // things aren't stable while the display is frozen, for example the window could be
1960 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001961 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1962 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001963 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001964 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001965 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001966 final int orientation = mAboveAppWindowsContainers.getOrientation();
1967 if (orientation != SCREEN_ORIENTATION_UNSET) {
1968 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001969 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001970 }
1971
Wale Ogunwale399c8692017-05-08 14:22:42 -07001972 // Top system windows are not requesting an orientation. Start searching from apps.
1973 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001974 }
1975
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001976 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001977 // Check if display metrics changed and update base values if needed.
1978 updateBaseDisplayMetricsIfNeeded();
1979
Craig Mautner722285e2012-09-07 13:55:58 -07001980 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001981 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001982
Wale Ogunwale61911492017-10-11 08:50:50 -07001983 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1984 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001985 }
Craig Mautner722285e2012-09-07 13:55:58 -07001986 }
1987
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001988 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001989 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1990 if (displayManagerInternal != null) {
1991 // Bootstrap the default logical display from the display manager.
1992 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1993 if (newDisplayInfo != null) {
1994 mDisplayInfo.copyFrom(newDisplayInfo);
1995 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001996 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001997
Andrii Kuliancd097992017-03-23 18:31:59 -07001998 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1999 mDisplayInfo.logicalDensityDpi);
2000 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
2001 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
2002 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002003 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002004 }
2005
Andrii Kuliancd097992017-03-23 18:31:59 -07002006 /**
2007 * If display metrics changed, overrides are not set and it's not just a rotation - update base
2008 * values.
2009 */
2010 private void updateBaseDisplayMetricsIfNeeded() {
2011 // Get real display metrics without overrides from WM.
2012 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
2013 final int orientation = mDisplayInfo.rotation;
2014 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2015 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
2016 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
2017 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002018 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002019
2020 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
2021 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01002022 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
2023 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07002024
2025 if (displayMetricsChanged) {
2026 // Check if display size or density is forced.
2027 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
2028 || mBaseDisplayHeight != mInitialDisplayHeight;
2029 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
2030
2031 // If there is an override set for base values - use it, otherwise use new values.
2032 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
2033 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
2034 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
2035
2036 // Real display metrics changed, so we should also update initial values.
2037 mInitialDisplayWidth = newWidth;
2038 mInitialDisplayHeight = newHeight;
2039 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01002040 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002041 mService.reconfigureDisplayLocked(this);
2042 }
2043 }
2044
Bryce Lee27cec322017-03-21 09:41:37 -07002045 /** Sets the maximum width the screen resolution can be */
2046 void setMaxUiWidth(int width) {
2047 if (DEBUG_DISPLAY) {
2048 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
2049 }
2050
2051 mMaxUiWidth = width;
2052
2053 // Update existing metrics.
2054 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
2055 }
2056
2057 /** Update base (override) display metrics. */
2058 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
2059 mBaseDisplayWidth = baseWidth;
2060 mBaseDisplayHeight = baseHeight;
2061 mBaseDisplayDensity = baseDensity;
2062
2063 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
2064 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
2065 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
2066 mBaseDisplayWidth = mMaxUiWidth;
2067
2068 if (DEBUG_DISPLAY) {
2069 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
2070 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
2071 + " on display:" + getDisplayId());
2072 }
2073 }
2074
2075 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08002076
2077 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07002078 }
2079
Riddle Hsuf53da812018-08-15 22:00:27 +08002080 /**
2081 * Forces this display to use the specified density.
2082 *
2083 * @param density The density in DPI to use. If the value equals to initial density, the setting
2084 * will be cleared.
2085 * @param userId The target user to apply. Only meaningful when this is default display. If the
2086 * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings
2087 * so only need to configure display.
2088 */
2089 void setForcedDensity(int density, int userId) {
2090 final boolean clear = density == mInitialDisplayDensity;
2091 final boolean updateCurrent = userId == UserHandle.USER_CURRENT;
2092 if (mService.mCurrentUserId == userId || updateCurrent) {
2093 mBaseDisplayDensity = density;
2094 mService.reconfigureDisplayLocked(this);
2095 }
2096 if (updateCurrent) {
2097 // We are applying existing settings so no need to save it again.
2098 return;
2099 }
2100
2101 if (density == mInitialDisplayDensity) {
2102 density = 0;
2103 }
2104 mService.mDisplaySettings.setForcedDensity(this, density, userId);
2105 }
2106
2107 /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */
2108 void setForcedScalingMode(@ForceScalingMode int mode) {
2109 if (mode != FORCE_SCALING_MODE_DISABLED) {
2110 mode = FORCE_SCALING_MODE_AUTO;
2111 }
2112
2113 mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO);
2114 Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto"));
2115 mService.reconfigureDisplayLocked(this);
2116
2117 mService.mDisplaySettings.setForcedScalingMode(this, mode);
2118 }
2119
2120 /** If the given width and height equal to initial size, the setting will be cleared. */
2121 void setForcedSize(int width, int height) {
2122 final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height;
2123 if (!clear) {
2124 // Set some sort of reasonable bounds on the size of the display that we will try
2125 // to emulate.
2126 final int minSize = 200;
2127 final int maxScale = 2;
2128 width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale);
2129 height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale);
2130 }
2131
2132 Slog.i(TAG_WM, "Using new display size: " + width + "x" + height);
2133 updateBaseDisplayMetrics(width, height, mBaseDisplayDensity);
2134 mService.reconfigureDisplayLocked(this);
2135
2136 if (clear) {
2137 width = height = 0;
2138 }
2139 mService.mDisplaySettings.setForcedSize(this, width, height);
2140 }
2141
Wale Ogunwaledb506192017-12-08 10:57:32 -08002142 void getStableRect(Rect out) {
2143 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08002144 }
2145
Wale Ogunwale61911492017-10-11 08:50:50 -07002146 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002147 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
2148 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07002149
Wale Ogunwale61911492017-10-11 08:50:50 -07002150 final TaskStack stack = new TaskStack(mService, stackId, controller);
2151 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08002152 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07002153 }
2154
Andrii Kulian51c1b672017-04-07 18:39:32 -07002155 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002156 final DisplayContent prevDc = stack.getDisplayContent();
2157 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002158 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2159 + " which is not currently attached to any display");
2160 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002161 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002162 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2163 + " to its current displayId=" + mDisplayId);
2164 }
2165
lumark588a3e82018-07-20 18:53:54 +08002166 // Clean up all pending transitions when stack reparent to another display.
2167 stack.forAllAppWindows(AppWindowToken::removeFromPendingTransition);
2168
Wale Ogunwale61911492017-10-11 08:50:50 -07002169 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002170 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002171 }
2172
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002173 @Override
2174 protected void addChild(DisplayChildWindowContainer child,
2175 Comparator<DisplayChildWindowContainer> comparator) {
2176 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2177 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002178
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002179 @Override
2180 protected void addChild(DisplayChildWindowContainer child, int index) {
2181 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2182 }
2183
2184 @Override
2185 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002186 // Only allow removal of direct children from this display if the display is in the process
2187 // of been removed.
2188 if (mRemovingDisplay) {
2189 super.removeChild(child);
2190 return;
2191 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002192 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002193 }
2194
Andrii Kuliand2765632016-12-12 22:26:34 -08002195 @Override
2196 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2197 // Children of the display are statically ordered, so the real intention here is to perform
2198 // the operation on the display and not the static direct children.
2199 getParent().positionChildAt(position, this, includingParents);
2200 }
2201
Riddle Hsu57831b52018-07-27 00:31:48 +08002202 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2203 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002204 layoutAndAssignWindowLayersIfNeeded();
2205 }
2206
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002207 /**
2208 * Used to obtain task ID when user taps on coordinate (x, y) in this display, and outside
2209 * current task in focus.
2210 *
2211 * This returns the task ID of the foremost task at (x, y) if the task is not home. Otherwise it
2212 * returns -1.
2213 *
2214 * @param x horizontal coordinate of the tap position
2215 * @param y vertical coordinate of the tap position
2216 * @return the task ID if a non-home task is found; -1 if not
2217 */
2218 int taskForTapOutside(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002219 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2220 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002221 if (stack.isActivityTypeHome() && !stack.inMultiWindowMode()) {
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002222 // We skip not only home stack, but also everything behind home because user can't
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002223 // see them when home stack is isn't in multi-window mode.
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002224 break;
2225 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002226 final int taskId = stack.taskIdFromPoint(x, y);
2227 if (taskId != -1) {
2228 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002229 }
2230 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002231 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002232 }
2233
Chong Zhang8e89b312015-09-09 15:09:30 -07002234 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002235 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002236 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002237 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002238 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002239 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002240 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002241 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2242 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002243 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002244 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002245 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002246
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002247 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2248 if (mTmpTaskForResizePointSearchResult.searchDone) {
2249 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002250 }
2251 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002252 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002253 }
2254
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002255 void updateTouchExcludeRegion() {
2256 final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null);
David Stevensee9e2772017-02-09 16:30:27 -08002257 if (focusedTask == null) {
2258 mTouchExcludeRegion.setEmpty();
2259 } else {
2260 mTouchExcludeRegion.set(mBaseDisplayRect);
2261 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2262 mTmpRect2.setEmpty();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002263 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0;
2264 --stackNdx) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002265 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002266 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2267 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002268 }
2269 // If we removed the focused task above, add it back and only leave its
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002270 // outside touch area in the exclusion. TapDetector is not interested in
David Stevensee9e2772017-02-09 16:30:27 -08002271 // any touch inside the focused task itself.
2272 if (!mTmpRect2.isEmpty()) {
2273 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2274 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002275 }
lumark90120a82018-08-15 00:33:03 +08002276 if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) {
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002277 // If the input method is visible and the user is typing, we don't want these touch
2278 // events to be intercepted and used to change focus. This would likely cause a
2279 // disappearance of the input method.
lumark90120a82018-08-15 00:33:03 +08002280 mInputMethodWindow.getTouchableRegion(mTmpRegion);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002281 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002282 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002283 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002284 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002285 win.getTouchableRegion(mTmpRegion);
2286 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2287 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002288 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2289 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2290 win.amendTapExcludeRegion(mTouchExcludeRegion);
2291 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002292 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002293 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002294 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002295 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002296 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2297 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002298 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002299 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002300 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002301 }
2302
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002303 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002304 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002305 super.switchUser();
2306 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002307 }
2308
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002309 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002310 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2311 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002312 }
2313 }
2314
Wale Ogunwale10124582016-09-15 20:25:50 -07002315 @Override
2316 void removeIfPossible() {
2317 if (isAnimating()) {
2318 mDeferredRemoval = true;
2319 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002320 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002321 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002322 }
2323
Wale Ogunwale10124582016-09-15 20:25:50 -07002324 @Override
2325 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002326 mRemovingDisplay = true;
2327 try {
lumark588a3e82018-07-20 18:53:54 +08002328 // Clear all transitions & screen frozen states when removing display.
2329 mOpeningApps.clear();
2330 mClosingApps.clear();
2331 mUnknownAppVisibilityController.clear();
2332 mAppTransition.removeAppTransitionTimeoutCallbacks();
2333 handleAnimatingStoppedAndTransition();
2334 mService.stopFreezingDisplayLocked();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002335 super.removeImmediately();
2336 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002337 if (mPointerEventDispatcher != null && mTapDetector != null) {
2338 unregisterPointerEventListener(mTapDetector);
2339 unregisterPointerEventListener(mService.mMousePositionTracker);
2340 mTapDetector = null;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002341 }
Jorim Jaggia3844032018-01-03 15:54:43 +01002342 mService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002343 mWindowingLayer.release();
2344 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002345 } finally {
2346 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002347 }
Bryce Leef19cbe22018-02-02 15:09:21 -08002348
Arthur Hung39134b22018-08-14 11:58:28 +08002349 mInputMonitor.onRemoved();
Riddle Hsuf53da812018-08-15 22:00:27 +08002350 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautner95da1082014-02-24 17:54:35 -08002351 }
2352
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002353 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002354 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002355 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002356 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2357
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002358 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002359 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002360 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002361 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002362 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002363 }
2364
Andrii Kulian0214ed92017-05-16 13:44:05 -07002365 /** @return 'true' if removal of this display content is deferred due to active animation. */
2366 boolean isRemovalDeferred() {
2367 return mDeferredRemoval;
2368 }
2369
Wale Ogunwale10124582016-09-15 20:25:50 -07002370 boolean animateForIme(float interpolatedValue, float animationTarget,
2371 float dividerAnimationTarget) {
2372 boolean updated = false;
2373
Wale Ogunwale61911492017-10-11 08:50:50 -07002374 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2375 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002376 if (stack == null || !stack.isAdjustedForIme()) {
2377 continue;
2378 }
2379
2380 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2381 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2382 updated = true;
2383 } else {
2384 mDividerControllerLocked.mLastAnimationProgress =
2385 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2386 mDividerControllerLocked.mLastDividerProgress =
2387 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2388 updated |= stack.updateAdjustForIme(
2389 mDividerControllerLocked.mLastAnimationProgress,
2390 mDividerControllerLocked.mLastDividerProgress,
2391 false /* force */);
2392 }
2393 if (interpolatedValue >= 1f) {
2394 stack.endImeAdjustAnimation();
2395 }
2396 }
2397
2398 return updated;
2399 }
2400
2401 boolean clearImeAdjustAnimation() {
2402 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002403 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2404 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002405 if (stack != null && stack.isAdjustedForIme()) {
2406 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2407 changed = true;
2408 }
2409 }
2410 return changed;
2411 }
2412
2413 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002414 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2415 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002416 if (stack.isVisible() && stack.isAdjustedForIme()) {
2417 stack.beginImeAdjustAnimation();
2418 }
2419 }
2420 }
2421
2422 void adjustForImeIfNeeded() {
lumark90120a82018-08-15 00:33:03 +08002423 final WindowState imeWin = mInputMethodWindow;
Wale Ogunwale10124582016-09-15 20:25:50 -07002424 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2425 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002426 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002427 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2428 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2429 imeTargetStack.getDockSide() : DOCKED_INVALID;
2430 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2431 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2432 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002433 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002434 final boolean imeHeightChanged = imeVisible &&
2435 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2436
2437 // The divider could be adjusted for IME position, or be thinner than usual,
2438 // or both. There are three possible cases:
2439 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2440 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2441 // - If IME is not visible, divider is not moved and is normal width.
2442
2443 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002444 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2445 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002446 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002447 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2448 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002449 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2450 } else {
2451 stack.resetAdjustedForIme(false);
2452 }
2453 }
2454 mDividerControllerLocked.setAdjustedForIme(
2455 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2456 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002457 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2458 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002459 stack.resetAdjustedForIme(!dockVisible);
2460 }
2461 mDividerControllerLocked.setAdjustedForIme(
2462 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2463 }
Winson Chung655332c2016-10-31 13:14:28 -07002464 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002465 }
2466
2467 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002468 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2469 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002470 stack.prepareFreezingTaskBounds();
2471 }
2472 }
2473
Wale Ogunwale94744212015-09-21 19:01:47 -07002474 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002475 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002476
2477 // Compute a transform matrix to undo the coordinate space transformation,
2478 // and present the window at the same physical position it previously occupied.
2479 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2480 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2481
2482 mTmpRectF.set(bounds);
2483 mTmpMatrix.mapRect(mTmpRectF);
2484 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002485 }
2486
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002487 static int deltaRotation(int oldRotation, int newRotation) {
2488 int delta = newRotation - oldRotation;
2489 if (delta < 0) delta += 4;
2490 return delta;
2491 }
2492
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002493 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002494 Matrix outMatrix) {
2495 // For rotations without Z-ordering we don't need the target rectangle's position.
2496 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2497 displayHeight, outMatrix);
2498 }
2499
2500 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2501 float displayWidth, float displayHeight, Matrix outMatrix) {
2502 switch (rotation) {
2503 case ROTATION_0:
2504 outMatrix.reset();
2505 break;
2506 case ROTATION_270:
2507 outMatrix.setRotate(270, 0, 0);
2508 outMatrix.postTranslate(0, displayHeight);
2509 outMatrix.postTranslate(rectTop, 0);
2510 break;
2511 case ROTATION_180:
2512 outMatrix.reset();
2513 break;
2514 case ROTATION_90:
2515 outMatrix.setRotate(90, 0, 0);
2516 outMatrix.postTranslate(displayWidth, 0);
2517 outMatrix.postTranslate(-rectTop, rectLeft);
2518 break;
2519 }
2520 }
2521
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002522 @CallSuper
2523 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002524 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002525 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002526 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002527 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002528 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2529 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002530 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002531 }
2532 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2533 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002534 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2535 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002536 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002537 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002538 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2539 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002540 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002541 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002542 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2543 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002544 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002545 }
2546 proto.write(DPI, mBaseDisplayDensity);
2547 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002548 proto.write(ROTATION, mRotation);
2549 final ScreenRotationAnimation screenRotationAnimation =
2550 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2551 if (screenRotationAnimation != null) {
2552 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2553 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002554 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
lumark588a3e82018-07-20 18:53:54 +08002555 mAppTransition.writeToProto(proto, APP_TRANSITION);
Louis Chang7501e332018-08-20 13:08:39 +08002556 proto.write(SURFACE_SIZE, mSurfaceSize);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002557 if (mFocusedApp != null) {
2558 mFocusedApp.writeNameToProto(proto, FOCUSED_APP);
2559 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002560 proto.end(token);
2561 }
2562
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002563 @Override
2564 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2565 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002566 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2567 final String subPrefix = " " + prefix;
2568 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2569 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2570 pw.print("dpi");
2571 if (mInitialDisplayWidth != mBaseDisplayWidth
2572 || mInitialDisplayHeight != mBaseDisplayHeight
2573 || mInitialDisplayDensity != mBaseDisplayDensity) {
2574 pw.print(" base=");
2575 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2576 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2577 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002578 if (mDisplayScalingDisabled) {
2579 pw.println(" noscale");
2580 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002581 pw.print(" cur=");
2582 pw.print(mDisplayInfo.logicalWidth);
2583 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2584 pw.print(" app=");
2585 pw.print(mDisplayInfo.appWidth);
2586 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2587 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2588 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2589 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2590 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002591 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002592 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002593 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002594
Craig Mautnerdc548482014-02-05 13:35:24 -08002595 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002596 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002597 pw.print(prefix);
2598 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002599
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002600 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
2601 if (mLastFocus != mCurrentFocus) {
2602 pw.print(" mLastFocus="); pw.println(mLastFocus);
2603 }
2604 if (mLosingFocus.size() > 0) {
2605 pw.println();
2606 pw.println(" Windows losing focus:");
2607 for (int i = mLosingFocus.size() - 1; i >= 0; i--) {
2608 final WindowState w = mLosingFocus.get(i);
2609 pw.print(" Losing #"); pw.print(i); pw.print(' ');
2610 pw.print(w);
2611 if (dumpAll) {
2612 pw.println(":");
2613 w.dump(pw, " ", true);
2614 } else {
2615 pw.println();
2616 }
2617 }
2618 }
2619 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
2620
Adrian Roos5251b1d2018-03-23 18:57:43 +01002621 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002622 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002623 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2624 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002625 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002626 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002627
Craig Mautnerdc548482014-02-05 13:35:24 -08002628 pw.println();
2629 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002630 pw.println();
2631 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002632 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002633 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002634 pw.print(" Exiting #"); pw.print(i);
2635 pw.print(' '); pw.print(token);
2636 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002637 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002638 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002639 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002640
Jorim Jaggi31f71702016-05-04 16:43:04 -07002641 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002642
2643 // Dump stack references
2644 final TaskStack homeStack = getHomeStack();
2645 if (homeStack != null) {
2646 pw.println(prefix + "homeStack=" + homeStack.getName());
2647 }
2648 final TaskStack pinnedStack = getPinnedStack();
2649 if (pinnedStack != null) {
2650 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2651 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002652 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002653 if (splitScreenPrimaryStack != null) {
2654 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2655 }
2656
2657 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002658 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002659 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002660 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002661
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002662 pw.println();
2663 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002664 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002665 mDisplayPolicy.dump(prefix, pw);
2666 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002667 mDisplayRotation.dump(prefix, pw);
2668 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002669 mInputMonitor.dump(pw, " ");
Craig Mautner59c00972012-07-30 12:10:24 -07002670 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002671
2672 @Override
2673 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002674 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002675 }
2676
2677 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002678 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002679 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002680
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002681 /** Returns true if the stack in the windowing mode is visible. */
2682 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002683 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002684 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002685 }
2686
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002687 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002688 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002689 final int x = (int) xf;
2690 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002691 final WindowState touchedWin = getWindow(w -> {
2692 final int flags = w.mAttrs.flags;
2693 if (!w.isVisibleLw()) {
2694 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002695 }
2696 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002697 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002698 }
2699
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002700 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002701 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002702 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002703 }
2704
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002705 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002706
2707 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002708 return mTmpRegion.contains(x, y) || touchFlags == 0;
2709 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002710
2711 return touchedWin;
2712 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002713
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002714 boolean canAddToastWindowForUid(int uid) {
2715 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002716 // Also if the app is focused adding more than one toast at
2717 // a time for better backwards compatibility.
2718 final WindowState focusedWindowForUid = getWindow(w ->
2719 w.mOwnerUid == uid && w.isFocused());
2720 if (focusedWindowForUid != null) {
2721 return true;
2722 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002723 final WindowState win = getWindow(w ->
2724 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2725 && !w.mWindowRemovalAllowed);
2726 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002727 }
2728
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002729 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002730 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2731 return;
2732 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002733
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002734 // Used to communicate the old focus to the callback method.
2735 mTmpWindow = oldFocus;
2736
2737 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002738 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002739
2740 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002741 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002742
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002743 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002744
2745 if (mTmpWindow == null) {
2746 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2747 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002748 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002749 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002750 }
2751
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002752
2753 /**
2754 * Update the focused window and make some adjustments if the focus has changed.
2755 *
2756 * @param mode Indicates the situation we are in. Possible modes are:
2757 * {@link WindowManagerService#UPDATE_FOCUS_NORMAL},
2758 * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES},
2759 * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES},
2760 * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS}
2761 * @param updateInputWindows Whether to sync the window information to the input module.
2762 * @return {@code true} if the focused window has changed.
2763 */
2764 boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, boolean focusFound) {
2765 final WindowState newFocus = findFocusedWindow();
2766 if (mCurrentFocus == newFocus) {
2767 return false;
2768 }
2769 mService.mH.obtainMessage(REPORT_FOCUS_CHANGE, this).sendToTarget();
2770 boolean imWindowChanged = false;
2771 // TODO (b/111080190): Multi-Session IME
2772 if (!focusFound) {
2773 final WindowState imWindow = mInputMethodWindow;
2774 if (imWindow != null) {
2775 final WindowState prevTarget = mService.mInputMethodTarget;
2776
2777 final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/);
2778 imWindowChanged = prevTarget != newTarget;
2779
2780 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
2781 && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2782 assignWindowLayers(false /* setLayoutNeeded */);
2783 }
2784 }
2785 }
2786
2787 if (imWindowChanged) {
2788 mService.mWindowsChanged = true;
2789 setLayoutNeeded();
2790 }
2791
2792 if (DEBUG_FOCUS_LIGHT || mService.localLOGV) Slog.v(TAG_WM, "Changing focus from "
2793 + mCurrentFocus + " to " + newFocus + " displayId=" + getDisplayId()
2794 + " Callers=" + Debug.getCallers(4));
2795 final WindowState oldFocus = mCurrentFocus;
2796 mCurrentFocus = newFocus;
2797 mLosingFocus.remove(newFocus);
2798
2799 if (newFocus != null) {
2800 mWinAddedSinceNullFocus.clear();
2801 mWinRemovedSinceNullFocus.clear();
2802
2803 if (newFocus.canReceiveKeys()) {
2804 // Displaying a window implicitly causes dispatching to be unpaused.
2805 // This is to protect against bugs if someone pauses dispatching but
2806 // forgets to resume.
2807 newFocus.mToken.paused = false;
2808 }
2809 }
2810
2811 // System UI is only shown on the default display.
2812 int focusChanged = isDefaultDisplay
2813 ? mService.mPolicy.focusChangedLw(oldFocus, newFocus) : 0;
2814
2815 if (imWindowChanged && oldFocus != mInputMethodWindow) {
2816 // Focus of the input method window changed. Perform layout if needed.
2817 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2818 performLayout(true /*initial*/, updateInputWindows);
2819 focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT;
2820 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2821 // Client will do the layout, but we need to assign layers
2822 // for handleNewWindowLocked() below.
2823 assignWindowLayers(false /* setLayoutNeeded */);
2824 }
2825 }
2826
2827 if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2828 // The change in focus caused us to need to do a layout. Okay.
2829 setLayoutNeeded();
2830 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2831 performLayout(true /*initial*/, updateInputWindows);
2832 } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) {
2833 mService.mRoot.performSurfacePlacement(false);
2834 }
2835 }
2836
2837 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
2838 // If we defer assigning layers, then the caller is responsible for doing this part.
2839 getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
2840 }
2841
2842 adjustForImeIfNeeded();
2843
2844 // We may need to schedule some toast windows to be removed. The toasts for an app that
2845 // does not have input focus are removed within a timeout to prevent apps to redress
2846 // other apps' UI.
2847 scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus);
2848
2849 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2850 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2851 }
2852 return true;
2853 }
2854
2855 /**
2856 * Set the new focused app to this display.
2857 *
2858 * @param newFocus the new focused AppWindowToken.
2859 * @return true if the focused app is changed.
2860 */
2861 boolean setFocusedApp(AppWindowToken newFocus) {
2862 if (newFocus != null) {
2863 final DisplayContent appDisplay = newFocus.getDisplayContent();
2864 if (appDisplay != this) {
2865 throw new IllegalStateException(newFocus + " is not on " + getName()
2866 + " but " + ((appDisplay != null) ? appDisplay.getName() : "none"));
2867 }
2868 }
2869 if (mFocusedApp == newFocus) {
2870 return false;
2871 }
2872 mFocusedApp = newFocus;
2873 getInputMonitor().setFocusedAppLw(newFocus);
2874 updateTouchExcludeRegion();
2875 return true;
2876 }
2877
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002878 /** Updates the layer assignment of windows on this display. */
2879 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002880 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002881 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002882 if (setLayoutNeeded) {
2883 setLayoutNeeded();
2884 }
Robert Carrb1579c82017-09-05 14:54:47 -07002885
Robert Carrf59b8dd2017-10-02 18:58:36 -07002886 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002887 // the application of this transaction until the animation pass triggers
2888 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2889 // the hiding and showing of surfaces.
2890 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002891 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002892 }
2893
Wale Ogunwale1666e312016-12-16 11:27:18 -08002894 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2895 // moving containers or resizing them. Need to investigate the best way to have it automatically
2896 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002897 void layoutAndAssignWindowLayersIfNeeded() {
2898 mService.mWindowsChanged = true;
2899 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002900
2901 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2902 false /*updateInputWindows*/)) {
2903 assignWindowLayers(false /* setLayoutNeeded */);
2904 }
2905
Arthur Hung95b38a92018-07-20 18:56:12 +08002906 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002907 mService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08002908 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002909 }
2910
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002911 /** Returns true if a leaked surface was destroyed */
2912 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002913 // Used to indicate that a surface was leaked.
2914 mTmpWindow = null;
2915 forAllWindows(w -> {
2916 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002917 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002918 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002919 }
2920 if (!mService.mSessions.contains(wsa.mSession)) {
2921 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002922 + w + " surface=" + wsa.mSurfaceController
2923 + " token=" + w.mToken
2924 + " pid=" + w.mSession.mPid
2925 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002926 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002927 mService.mForceRemoves.add(w);
2928 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002929 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002930 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002931 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002932 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002933 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002934 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002935 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002936 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002937 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002938
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002939 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002940 }
2941
2942 /**
lumark90120a82018-08-15 00:33:03 +08002943 * Set input method window for the display.
2944 * @param win Set when window added or Null when destroyed.
2945 */
2946 void setInputMethodWindowLocked(WindowState win) {
2947 mInputMethodWindow = win;
lumark70865a82018-09-17 16:56:26 +08002948 // Update display configuration for IME process.
2949 if (mInputMethodWindow != null) {
2950 final int imePid = mInputMethodWindow.mSession.mPid;
2951 mService.mAtmInternal.onImeWindowSetOnDisplay(imePid,
2952 mInputMethodWindow.getDisplayId());
2953 }
lumark90120a82018-08-15 00:33:03 +08002954 computeImeTarget(true /* updateImeTarget */);
2955 }
2956
2957 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002958 * Determine and return the window that should be the IME target.
2959 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2960 * @return The window that should be used as the IME target or null if there isn't any.
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002961 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002962 WindowState computeImeTarget(boolean updateImeTarget) {
lumark90120a82018-08-15 00:33:03 +08002963 if (mInputMethodWindow == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002964 // There isn't an IME so there shouldn't be a target...That was easy!
2965 if (updateImeTarget) {
2966 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2967 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002968 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002969 }
2970 return null;
2971 }
2972
Chavi Weingarten3a748552018-05-14 17:32:42 +00002973 final WindowState curTarget = mService.mInputMethodTarget;
2974 if (!canUpdateImeTarget()) {
2975 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
2976 return curTarget;
2977 }
2978
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002979 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2980 // same display. Or even when the current IME/target are not on the same screen as the next
2981 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002982 mUpdateImeTarget = updateImeTarget;
2983 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002984
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002985
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002986 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2987 // to be on top of it, but it is not -really- where input will go. So look down below
2988 // for a real window to target...
2989 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2990 final AppWindowToken token = target.mAppToken;
2991 if (token != null) {
2992 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2993 if (betterTarget != null) {
2994 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002995 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002996 }
2997 }
2998
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002999 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
3000 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003001
chaviw1c13ad32018-06-12 16:44:23 -07003002 // Now, a special case -- if the last target's window is in the process of exiting, but
3003 // not removed, and the new target is home, keep on the last target to avoid flicker.
3004 // Home is a special case since its above other stacks in the ordering list, but layed
3005 // out below the others.
3006 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
3007 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07003008 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00003009 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003010 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003011 }
3012
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003013 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
3014 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003015
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003016 if (target == null) {
3017 if (updateImeTarget) {
3018 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
3019 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
3020 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003021 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003022 }
3023
3024 return null;
3025 }
3026
3027 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003028 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
3029 if (token != null) {
3030
3031 // Now some fun for dealing with window animations that modify the Z order. We need
3032 // to look at all windows below the current target that are in this app, finding the
3033 // highest visible one in layering.
3034 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003035 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003036 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003037 }
3038
3039 if (highestTarget != null) {
lumark588a3e82018-07-20 18:53:54 +08003040 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, mAppTransition + " " + highestTarget
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003041 + " animating=" + highestTarget.isAnimating());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003042
lumark588a3e82018-07-20 18:53:54 +08003043 if (mAppTransition.isTransitionSet()) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003044 // If we are currently setting up for an animation, hold everything until we
3045 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003046 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003047 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003048 }
3049 }
3050 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003051
3052 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
3053 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003054 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003055 }
3056
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003057 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003058 }
3059
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003060 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003061 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003062 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003063 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003064 }
3065
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003066 mService.mInputMethodTarget = target;
3067 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003068 assignWindowLayers(false /* setLayoutNeeded */);
3069 }
3070
3071 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
3072 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3073 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
3074 }
3075
3076 // Used to indicate we have reached the first window in the range we are interested in.
3077 mTmpWindow = null;
3078
3079 // TODO: Figure-out a more efficient way to do this.
3080 final WindowState candidate = getWindow(w -> {
3081 if (w == top) {
3082 // Reached the first window in the range we are interested in.
3083 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003084 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003085 if (mTmpWindow == null) {
3086 return false;
3087 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003088
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003089 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3090 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003091 }
3092 // If we reached the bottom of the range of windows we are considering,
3093 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003094 if (w == bottom) {
3095 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003096 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003097 return false;
3098 });
3099
3100 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003101 }
3102
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003103 void setLayoutNeeded() {
3104 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
3105 mLayoutNeeded = true;
3106 }
3107
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003108 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003109 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
3110 mLayoutNeeded = false;
3111 }
3112
3113 boolean isLayoutNeeded() {
3114 return mLayoutNeeded;
3115 }
3116
Wale Ogunwale02319a62016-09-26 15:21:22 -07003117 void dumpTokens(PrintWriter pw, boolean dumpAll) {
3118 if (mTokenMap.isEmpty()) {
3119 return;
3120 }
3121 pw.println(" Display #" + mDisplayId);
3122 final Iterator<WindowToken> it = mTokenMap.values().iterator();
3123 while (it.hasNext()) {
3124 final WindowToken token = it.next();
3125 pw.print(" ");
3126 pw.print(token);
3127 if (dumpAll) {
3128 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003129 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07003130 } else {
3131 pw.println();
3132 }
3133 }
lumark588a3e82018-07-20 18:53:54 +08003134
3135 if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty()) {
3136 pw.println();
3137 if (mOpeningApps.size() > 0) {
3138 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
3139 }
3140 if (mClosingApps.size() > 0) {
3141 pw.print(" mClosingApps="); pw.println(mClosingApps);
3142 }
3143 }
3144
3145 mUnknownAppVisibilityController.dump(pw, " ");
Wale Ogunwale02319a62016-09-26 15:21:22 -07003146 }
3147
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003148 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003149 final int[] index = new int[1];
3150 forAllWindows(w -> {
3151 final WindowStateAnimator wAnim = w.mWinAnimator;
3152 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
3153 index[0] = index[0] + 1;
3154 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003155 }
3156
Jorim Jaggife762342016-10-13 14:33:27 +02003157 /**
3158 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
3159 */
3160 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
3161 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003162 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02003163 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
3164 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01003165 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02003166 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003167 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02003168 }
3169
Wale Ogunwale494009b82016-10-21 09:01:38 -07003170 boolean checkWaitingForWindows() {
3171
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003172 mHaveBootMsg = false;
3173 mHaveApp = false;
3174 mHaveWallpaper = false;
3175 mHaveKeyguard = true;
3176
3177 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003178 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
3179 return true;
3180 }
3181 if (w.isDrawnLw()) {
3182 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003183 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003184 } else if (w.mAttrs.type == TYPE_APPLICATION
3185 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003186 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003187 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003188 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003189 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003190 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003191 }
3192 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003193 return false;
3194 });
3195
3196 if (visibleWindow != null) {
3197 // We have a visible window.
3198 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003199 }
3200
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003201 // if the wallpaper service is disabled on the device, we're never going to have
3202 // wallpaper, don't bother waiting for it
3203 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
3204 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09003205 && mService.mContext.getResources().getBoolean(
3206 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003207 && !mService.mOnlyCore;
3208
Wale Ogunwale494009b82016-10-21 09:01:38 -07003209 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
3210 "******** booted=" + mService.mSystemBooted
3211 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003212 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
3213 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
3214 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003215
3216 // If we are turning on the screen to show the boot message, don't do it until the boot
3217 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003218 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003219 return true;
3220 }
3221
3222 // If we are turning on the screen after the boot is completed normally, don't do so until
3223 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003224 if (mService.mSystemBooted
3225 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003226 return true;
3227 }
3228
3229 return false;
3230 }
3231
Jorim Jaggi8f520872018-08-14 17:00:20 +02003232 void updateWindowsForAnimator() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003233 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003234 }
3235
Jorim Jaggi8f520872018-08-14 17:00:20 +02003236 /**
3237 * Updates the {@link TaskStack#setAnimationBackground} for all windows.
3238 */
3239 void updateBackgroundForAnimator() {
Jorim Jaggi7156b652016-10-25 08:31:58 -07003240 resetAnimationBackgroundAnimator();
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003241 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003242 }
3243
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003244 boolean isInputMethodClientFocus(int uid, int pid) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003245 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003246 if (imFocus == null) {
3247 return false;
3248 }
3249
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003250 if (DEBUG_INPUT_METHOD) {
3251 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003252 Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
3253 Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003254 }
3255
Wale Ogunwale494009b82016-10-21 09:01:38 -07003256 if (DEBUG_INPUT_METHOD) {
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003257 Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
3258 + "/" + imFocus.mSession.mPid);
3259 Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003260 }
3261
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003262 return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003263 }
3264
3265 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003266 final WindowState win = getWindow(
3267 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
3268 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003269 }
3270
3271 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003272 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003273 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003274 final int curValue = w.mSystemUiVisibility;
3275 final int diff = (curValue ^ visibility) & globalDiff;
3276 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003277 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003278 w.mSeq++;
3279 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003280 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003281 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
3282 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07003283 visibility, newValue, diff);
3284 }
3285 } catch (RemoteException e) {
3286 // so sorry
3287 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003288 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003289 }
3290
3291 void onWindowFreezeTimeout() {
3292 Slog.w(TAG_WM, "Window freeze timeout expired.");
3293 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003294
3295 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003296 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003297 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003298 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07003299 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003300 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3301 - mService.mDisplayFreezeTime);
3302 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003303 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003304 mService.mWindowPlacerLocked.performSurfacePlacement();
3305 }
3306
3307 void waitForAllWindowsDrawn() {
3308 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003309 forAllWindows(w -> {
3310 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3311 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3312 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003313 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07003314 w.resetLastContentInsets();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003315 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003316 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003317 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003318 }
3319
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003320 // TODO: Super crazy long method that should be broken down...
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003321 void applySurfaceChangesTransaction(boolean recoveringMemory) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003322
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003323 final int dw = mDisplayInfo.logicalWidth;
3324 final int dh = mDisplayInfo.logicalHeight;
3325 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
3326
3327 mTmpUpdateAllDrawn.clear();
3328
3329 int repeats = 0;
3330 do {
3331 repeats++;
3332 if (repeats > 6) {
3333 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3334 clearLayoutNeeded();
3335 break;
3336 }
3337
3338 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3339 pendingLayoutChanges);
3340
Andrii Kulian839def92016-11-02 10:58:58 -07003341 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
3342 // the wallpaper window jumping across displays.
3343 // Remove check for default display when there will be support for multiple wallpaper
3344 // targets (on different displays).
3345 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003346 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003347 }
3348
Riddle Hsu654a6f92018-07-13 22:59:36 +08003349 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003350 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08003351 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003352 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07003353 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003354 }
3355 }
3356
3357 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3358 setLayoutNeeded();
3359 }
3360
3361 // FIRST LOOP: Perform a layout, if needed.
3362 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3363 performLayout(repeats == 1, false /* updateInputWindows */);
3364 } else {
3365 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3366 }
3367
3368 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3369 pendingLayoutChanges = 0;
3370
3371 if (isDefaultDisplay) {
3372 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003373 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003374 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
3375 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3376 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
3377 }
3378 } while (pendingLayoutChanges != 0);
3379
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003380 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003381
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003382 mTmpRecoveringMemory = recoveringMemory;
3383 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003384 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003385
Jorim Jaggif1292892018-09-10 11:58:13 +02003386 mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003387 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggif1292892018-09-10 11:58:13 +02003388 mLastHasContent,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003389 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3390 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003391 true /* inTraversal, must call performTraversalInTrans... below */);
3392
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003393 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3394 if (wallpaperVisible != mLastWallpaperVisible) {
3395 mLastWallpaperVisible = wallpaperVisible;
3396 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
3397 }
3398
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003399 while (!mTmpUpdateAllDrawn.isEmpty()) {
3400 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3401 // See if any windows have been drawn, so they (and others associated with them)
3402 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003403 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003404 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003405 }
3406
Bryce Leef3c6a472017-11-14 14:53:06 -08003407 private void updateBounds() {
3408 calculateBounds(mTmpBounds);
3409 setBounds(mTmpBounds);
3410 }
3411
3412 // Determines the current display bounds based on the current state
3413 private void calculateBounds(Rect out) {
3414 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
3415 final int orientation = mDisplayInfo.rotation;
3416 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
3417 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3418 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
3419 int width = mDisplayInfo.logicalWidth;
3420 int left = (physWidth - width) / 2;
3421 int height = mDisplayInfo.logicalHeight;
3422 int top = (physHeight - height) / 2;
3423 out.set(left, top, left + width, top + height);
3424 }
3425
3426 @Override
3427 public void getBounds(Rect out) {
3428 calculateBounds(out);
3429 }
3430
3431 private void getBounds(Rect out, int orientation) {
3432 getBounds(out);
3433
3434 // Rotate the Rect if needed.
3435 final int currentRotation = mDisplayInfo.rotation;
3436 final int rotationDelta = deltaRotation(currentRotation, orientation);
3437 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3438 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3439 mTmpRectF.set(out);
3440 mTmpMatrix.mapRect(mTmpRectF);
3441 mTmpRectF.round(out);
3442 }
3443 }
3444
Louis Chang7501e332018-08-20 13:08:39 +08003445 int getSurfaceSize() {
3446 return mSurfaceSize;
3447 }
3448
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003449 void performLayout(boolean initial, boolean updateInputWindows) {
3450 if (!isLayoutNeeded()) {
3451 return;
3452 }
3453 clearLayoutNeeded();
3454
3455 final int dw = mDisplayInfo.logicalWidth;
3456 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003457 if (DEBUG_LAYOUT) {
3458 Slog.v(TAG, "-------------------------------------");
3459 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3460 }
3461
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003462 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3463 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003464 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3465 // display info above...
3466 mDisplayFrames.mRotation = mRotation;
3467 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003468 if (isDefaultDisplay) {
3469 // Not needed on non-default displays.
3470 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
3471 mService.mScreenRect.set(0, 0, dw, dh);
3472 }
3473
Adrian Roos5251b1d2018-03-23 18:57:43 +01003474 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003475 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003476 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003477
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003478 // Used to indicate that we have processed the dream window and all additional windows are
3479 // behind it.
3480 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003481 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003482
3483 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003484 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003485
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003486 // Used to indicate that we have processed the dream window and all additional attached
3487 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003488 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003489 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003490
3491 // Now perform layout of attached windows, which usually depend on the position of the
3492 // window they are attached to. XXX does not deal with windows that are attached to windows
3493 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003494 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003495
3496 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003497 mInputMonitor.layoutInputConsumers(dw, dh);
3498 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003499 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003500 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003501 }
3502
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003503 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
3504 }
3505
3506 /**
3507 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3508 * In portrait mode, it grabs the full screenshot.
3509 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003510 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003511 */
chaviw0315a1a2018-03-05 15:28:35 -08003512 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
3513 if (!mService.mPolicy.isScreenOn()) {
3514 if (DEBUG_SCREENSHOT) {
3515 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003516 }
chaviw0315a1a2018-03-05 15:28:35 -08003517 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003518 }
chaviwfbe47df2017-11-10 16:14:49 -08003519
chaviw0315a1a2018-03-05 15:28:35 -08003520 int dw = mDisplayInfo.logicalWidth;
3521 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003522
chaviw0315a1a2018-03-05 15:28:35 -08003523 if (dw <= 0 || dh <= 0) {
3524 return null;
3525 }
chaviwfbe47df2017-11-10 16:14:49 -08003526
chaviw0315a1a2018-03-05 15:28:35 -08003527 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003528
chaviw0315a1a2018-03-05 15:28:35 -08003529 // The screenshot API does not apply the current screen rotation.
3530 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003531
chaviw0315a1a2018-03-05 15:28:35 -08003532 if (rot == ROTATION_90 || rot == ROTATION_270) {
3533 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3534 }
chaviwfbe47df2017-11-10 16:14:49 -08003535
chaviw0315a1a2018-03-05 15:28:35 -08003536 // SurfaceFlinger is not aware of orientation, so convert our logical
3537 // crop to SurfaceFlinger's portrait orientation.
3538 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3539
3540 final ScreenRotationAnimation screenRotationAnimation =
3541 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3542 final boolean inRotation = screenRotationAnimation != null &&
3543 screenRotationAnimation.isAnimating();
3544 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3545
3546 // TODO(b/68392460): We should screenshot Task controls directly
3547 // but it's difficult at the moment as the Task doesn't have the
3548 // correct size set.
chaviw08520a02018-09-10 16:44:56 -07003549 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot);
chaviw0315a1a2018-03-05 15:28:35 -08003550 if (bitmap == null) {
3551 Slog.w(TAG_WM, "Failed to take screenshot");
3552 return null;
3553 }
3554
3555 // Create a copy of the screenshot that is immutable and backed in ashmem.
3556 // This greatly reduces the overhead of passing the bitmap between processes.
3557 final Bitmap ret = bitmap.createAshmemBitmap(config);
3558 bitmap.recycle();
3559 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003560 }
3561
3562 // TODO: Can this use createRotationMatrix()?
3563 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3564 if (rot == Surface.ROTATION_90) {
3565 final int tmp = crop.top;
3566 crop.top = dw - crop.right;
3567 crop.right = crop.bottom;
3568 crop.bottom = dw - crop.left;
3569 crop.left = tmp;
3570 } else if (rot == Surface.ROTATION_180) {
3571 int tmp = crop.top;
3572 crop.top = dh - crop.bottom;
3573 crop.bottom = dh - tmp;
3574 tmp = crop.right;
3575 crop.right = dw - crop.left;
3576 crop.left = dw - tmp;
3577 } else if (rot == Surface.ROTATION_270) {
3578 final int tmp = crop.top;
3579 crop.top = crop.left;
3580 crop.left = dh - crop.bottom;
3581 crop.bottom = crop.right;
3582 crop.right = dh - tmp;
3583 }
3584 }
3585
3586 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003587 // Used to indicate the layout is needed.
3588 mTmpWindow = null;
3589
3590 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003591 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003592 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003593 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003594 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003595 w.setDisplayLayoutNeeded();
3596 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003597 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003598
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003599 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003600 mService.mWindowPlacerLocked.performSurfacePlacement();
3601 }
3602 }
3603
Wale Ogunwale1666e312016-12-16 11:27:18 -08003604 void setExitingTokensHasVisible(boolean hasVisible) {
3605 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3606 mExitingTokens.get(i).hasVisible = hasVisible;
3607 }
3608
3609 // Initialize state of exiting applications.
3610 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3611 }
3612
3613 void removeExistingTokensIfPossible() {
3614 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3615 final WindowToken token = mExitingTokens.get(i);
3616 if (!token.hasVisible) {
3617 mExitingTokens.remove(i);
3618 }
3619 }
3620
3621 // Time to remove any exiting applications?
3622 mTaskStackContainers.removeExistingAppTokensIfPossible();
3623 }
3624
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003625 @Override
3626 void onDescendantOverrideConfigurationChanged() {
3627 setLayoutNeeded();
3628 mService.requestTraversal();
3629 }
3630
David Stevens9440dc82017-03-16 19:00:20 -07003631 boolean okToDisplay() {
3632 if (mDisplayId == DEFAULT_DISPLAY) {
3633 return !mService.mDisplayFrozen
3634 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3635 }
3636 return mDisplayInfo.state == Display.STATE_ON;
3637 }
3638
3639 boolean okToAnimate() {
3640 return okToDisplay() &&
3641 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3642 }
3643
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003644 static final class TaskForResizePointSearchResult {
3645 boolean searchDone;
3646 Task taskForResize;
3647
3648 void reset() {
3649 searchDone = false;
3650 taskForResize = null;
3651 }
3652 }
Robert Carr3b716242016-08-16 16:02:21 -07003653
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003654 private static final class ApplySurfaceChangesTransactionState {
3655 boolean displayHasContent;
3656 boolean obscured;
3657 boolean syswin;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003658 float preferredRefreshRate;
3659 int preferredModeId;
3660
3661 void reset() {
3662 displayHasContent = false;
3663 obscured = false;
3664 syswin = false;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003665 preferredRefreshRate = 0;
3666 preferredModeId = 0;
3667 }
3668 }
3669
3670 private static final class ScreenshotApplicationState {
3671 WindowState appWin;
3672 int maxLayer;
3673 int minLayer;
3674 boolean screenshotReady;
3675
3676 void reset(boolean screenshotReady) {
3677 appWin = null;
3678 maxLayer = 0;
3679 minLayer = 0;
3680 this.screenshotReady = screenshotReady;
3681 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3682 }
3683 }
3684
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003685 /**
3686 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3687 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3688 * homogeneous children type which is currently required by sub-classes of
3689 * {@link WindowContainer} class.
3690 */
3691 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3692
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003693 DisplayChildWindowContainer(WindowManagerService service) {
3694 super(service);
3695 }
3696
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003697 @Override
3698 boolean fillsParent() {
3699 return true;
3700 }
3701
3702 @Override
3703 boolean isVisible() {
3704 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003705 }
3706 }
3707
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003708 /**
3709 * Window container class that contains all containers on this display relating to Apps.
3710 * I.e Activities.
3711 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003712 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003713 /**
3714 * A control placed at the appropriate level for transitions to occur.
3715 */
chaviw23ee71c2017-12-18 11:29:41 -08003716 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003717 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003718 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003719
Robert Carrf7a7ca82017-12-06 13:17:07 -08003720 /**
3721 * Given that the split-screen divider does not have an AppWindowToken, it
3722 * will have to live inside of a "NonAppWindowContainer", in particular
3723 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3724 * it will need to be interleaved with some of our children, appearing on top of
3725 * both docked stacks but underneath any assistant stacks.
3726 *
3727 * To solve this problem we have this anchor control, which will always exist so
3728 * we can always assign it the correct value in our {@link #assignChildLayers}.
3729 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3730 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3731 * events between the two containers.
3732 */
3733 SurfaceControl mSplitScreenDividerAnchor = null;
3734
Wale Ogunwale61911492017-10-11 08:50:50 -07003735 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3736 // through the list to find them.
3737 private TaskStack mHomeStack = null;
3738 private TaskStack mPinnedStack = null;
3739 private TaskStack mSplitScreenPrimaryStack = null;
3740
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003741 TaskStackContainers(WindowManagerService service) {
3742 super(service);
3743 }
3744
Wale Ogunwale61911492017-10-11 08:50:50 -07003745 /**
3746 * Returns the topmost stack on the display that is compatible with the input windowing mode
3747 * and activity type. Null is no compatible stack on the display.
3748 */
3749 TaskStack getStack(int windowingMode, int activityType) {
3750 if (activityType == ACTIVITY_TYPE_HOME) {
3751 return mHomeStack;
3752 }
3753 if (windowingMode == WINDOWING_MODE_PINNED) {
3754 return mPinnedStack;
3755 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3756 return mSplitScreenPrimaryStack;
3757 }
3758 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3759 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003760 if (activityType == ACTIVITY_TYPE_UNDEFINED
3761 && windowingMode == stack.getWindowingMode()) {
3762 // Passing in undefined type means we want to match the topmost stack with the
3763 // windowing mode.
3764 return stack;
3765 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003766 if (stack.isCompatible(windowingMode, activityType)) {
3767 return stack;
3768 }
3769 }
3770 return null;
3771 }
3772
3773 @VisibleForTesting
3774 TaskStack getTopStack() {
3775 return mTaskStackContainers.getChildCount() > 0
3776 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3777 }
3778
3779 TaskStack getHomeStack() {
3780 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3781 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3782 }
3783 return mHomeStack;
3784 }
3785
3786 TaskStack getPinnedStack() {
3787 return mPinnedStack;
3788 }
3789
Matthew Ng64e77cf2017-10-31 14:01:31 -07003790 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003791 return mSplitScreenPrimaryStack;
3792 }
3793
Winson Chunge2d72172018-01-25 17:46:20 +00003794 ArrayList<Task> getVisibleTasks() {
3795 final ArrayList<Task> visibleTasks = new ArrayList<>();
3796 forAllTasks(task -> {
3797 if (task.isVisible()) {
3798 visibleTasks.add(task);
3799 }
3800 });
3801 return visibleTasks;
3802 }
3803
Andrii Kulian839def92016-11-02 10:58:58 -07003804 /**
3805 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003806 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003807 */
3808 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003809 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003810 addChild(stack, onTop);
3811 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003812 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003813
Wale Ogunwale61911492017-10-11 08:50:50 -07003814 void onStackWindowingModeChanged(TaskStack stack) {
3815 removeStackReferenceIfNeeded(stack);
3816 addStackReferenceIfNeeded(stack);
3817 if (stack == mPinnedStack && getTopStack() != stack) {
3818 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3819 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3820 }
3821 }
3822
3823 private void addStackReferenceIfNeeded(TaskStack stack) {
3824 if (stack.isActivityTypeHome()) {
3825 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003826 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003827 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003828
Wale Ogunwale61911492017-10-11 08:50:50 -07003829 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003830 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003831 }
3832 final int windowingMode = stack.getWindowingMode();
3833 if (windowingMode == WINDOWING_MODE_PINNED) {
3834 if (mPinnedStack != null) {
3835 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3836 + mPinnedStack + " already exist on display=" + this
3837 + " stack=" + stack);
3838 }
3839 mPinnedStack = stack;
3840 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3841 if (mSplitScreenPrimaryStack != null) {
3842 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3843 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3844 + " already exist on display=" + this + " stack=" + stack);
3845 }
3846 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003847 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003848 }
3849 }
3850
3851 private void removeStackReferenceIfNeeded(TaskStack stack) {
3852 if (stack == mHomeStack) {
3853 mHomeStack = null;
3854 } else if (stack == mPinnedStack) {
3855 mPinnedStack = null;
3856 } else if (stack == mSplitScreenPrimaryStack) {
3857 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003858 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3859 mService.setDockedStackCreateStateLocked(
3860 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3861 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003862 }
Andrii Kulian839def92016-11-02 10:58:58 -07003863 }
3864
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003865 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003866 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3867 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003868 addChild(stack, addIndex);
3869 setLayoutNeeded();
3870 }
3871
Wale Ogunwale61911492017-10-11 08:50:50 -07003872 @Override
3873 protected void removeChild(TaskStack stack) {
3874 super.removeChild(stack);
3875 removeStackReferenceIfNeeded(stack);
3876 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003877
3878 @Override
3879 boolean isOnTop() {
3880 // Considered always on top
3881 return true;
3882 }
3883
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003884 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003885 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003886 if (child.getWindowConfiguration().isAlwaysOnTop()
3887 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003888 // This stack is always-on-top, override the default behavior.
3889 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3890
3891 // Moving to its current position, as we must call super but we don't want to
3892 // perform any meaningful action.
3893 final int currentPosition = mChildren.indexOf(child);
3894 super.positionChildAt(currentPosition, child, false /* includingParents */);
3895 return;
3896 }
3897
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003898 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3899 super.positionChildAt(targetPosition, child, includingParents);
3900
Riddle Hsu2f6e1742018-08-23 22:44:36 +08003901 if (includingParents) {
3902 // We still want to move the display of this stack container to top because even the
3903 // target position is adjusted to non-top, the intention of the condition is to have
3904 // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front
3905 // in a non-top display which is using picture-in-picture mode).
3906 final int topChildPosition = getChildCount() - 1;
3907 if (targetPosition < topChildPosition && position >= topChildPosition) {
3908 getParent().positionChildAt(POSITION_TOP, this /* child */,
3909 true /* includingParents */);
3910 }
3911 }
3912
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003913 setLayoutNeeded();
3914 }
3915
3916 /**
3917 * When stack is added or repositioned, find a proper position for it.
3918 * This will make sure that pinned stack always stays on top.
3919 * @param requestedPosition Position requested by caller.
3920 * @param stack Stack to be added or positioned.
3921 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3922 * @return The proper position for the stack.
3923 */
3924 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003925 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09003926 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09003927 }
3928
Kazuki Takisef85197b2018-06-18 18:18:36 +09003929 final int topChildPosition = mChildren.size() - 1;
3930 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
3931 for (int i = topChildPosition; i >= 0; --i) {
3932 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
3933 belowAlwaysOnTopPosition = i;
3934 break;
3935 }
3936 }
3937
3938 // The max possible position we can insert the stack at.
3939 int maxPosition = POSITION_TOP;
3940 // The min possible position we can insert the stack at.
3941 int minPosition = POSITION_BOTTOM;
3942
3943 if (stack.isAlwaysOnTop()) {
3944 if (hasPinnedStack()) {
3945 // Always-on-top stacks go below the pinned stack.
3946 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
3947 }
3948 // Always-on-top stacks need to be above all other stacks.
3949 minPosition = belowAlwaysOnTopPosition !=
3950 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
3951 } else {
3952 // Other stacks need to be below the always-on-top stacks.
3953 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08003954 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09003955 }
3956
3957 int targetPosition = requestedPosition;
3958 targetPosition = Math.min(targetPosition, maxPosition);
3959 targetPosition = Math.max(targetPosition, minPosition);
3960
3961 int prevPosition = getStacks().indexOf(stack);
3962 // The positions we calculated above (maxPosition, minPosition) do not take into
3963 // consideration the following edge cases.
3964 // 1) We need to adjust the position depending on the value "adding".
3965 // 2) When we are moving a stack to another position, we also need to adjust the
3966 // position depending on whether the stack is moving to a higher or lower position.
3967 if ((targetPosition != requestedPosition) &&
3968 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003969 targetPosition++;
3970 }
3971
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003972 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003973 }
3974
3975 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003976 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3977 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003978 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003979 if (super.forAllWindows(callback, traverseTopToBottom)) {
3980 return true;
3981 }
3982 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3983 return true;
3984 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003985 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003986 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3987 return true;
3988 }
3989 if (super.forAllWindows(callback, traverseTopToBottom)) {
3990 return true;
3991 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003992 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003993 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003994 }
3995
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003996 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003997 boolean traverseTopToBottom) {
3998 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3999 // app tokens.
4000 // TODO: Investigate if we need to continue to do this or if we can just process them
4001 // in-order.
4002 if (traverseTopToBottom) {
4003 for (int i = mChildren.size() - 1; i >= 0; --i) {
4004 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4005 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004006 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4007 traverseTopToBottom)) {
4008 return true;
4009 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004010 }
4011 }
4012 } else {
4013 final int count = mChildren.size();
4014 for (int i = 0; i < count; ++i) {
4015 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4016 final int appTokensCount = appTokens.size();
4017 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004018 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4019 traverseTopToBottom)) {
4020 return true;
4021 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004022 }
4023 }
4024 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004025 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004026 }
4027
Wale Ogunwale1666e312016-12-16 11:27:18 -08004028 void setExitingTokensHasVisible(boolean hasVisible) {
4029 for (int i = mChildren.size() - 1; i >= 0; --i) {
4030 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4031 for (int j = appTokens.size() - 1; j >= 0; --j) {
4032 appTokens.get(j).hasVisible = hasVisible;
4033 }
4034 }
4035 }
4036
4037 void removeExistingAppTokensIfPossible() {
4038 for (int i = mChildren.size() - 1; i >= 0; --i) {
4039 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4040 for (int j = appTokens.size() - 1; j >= 0; --j) {
4041 final AppWindowToken token = appTokens.get(j);
lumark588a3e82018-07-20 18:53:54 +08004042 if (!token.hasVisible && !mClosingApps.contains(token)
Wale Ogunwale1666e312016-12-16 11:27:18 -08004043 && (!token.mIsExiting || token.isEmpty())) {
4044 // Make sure there is no animation running on this token, so any windows
4045 // associated with it will be removed as soon as their animations are
4046 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02004047 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08004048 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4049 "performLayout: App token exiting now removed" + token);
4050 token.removeIfPossible();
4051 }
4052 }
4053 }
4054 }
4055
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004056 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004057 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004058 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
4059 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004060 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07004061 // docked or freeform stack is visible...except for the home stack if the docked
4062 // stack is minimized and it actually set something and the bounds is different from
4063 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004064 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004065 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004066 && !(mDividerControllerLocked.isHomeStackResizable()
4067 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004068 final int orientation = mHomeStack.getOrientation();
4069 if (orientation != SCREEN_ORIENTATION_UNSET) {
4070 return orientation;
4071 }
4072 }
4073 return SCREEN_ORIENTATION_UNSPECIFIED;
4074 }
4075
4076 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07004077 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
4078 PackageManager.FEATURE_AUTOMOTIVE);
4079 if (isCar) {
4080 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
4081 // allow anything but the default orientation.
4082 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004083 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
4084 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07004085 return SCREEN_ORIENTATION_UNSPECIFIED;
4086 }
4087
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004088 if (orientation != SCREEN_ORIENTATION_UNSET
4089 && orientation != SCREEN_ORIENTATION_BEHIND) {
4090 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004091 "App is requesting an orientation, return " + orientation
4092 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004093 return orientation;
4094 }
4095
4096 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004097 "No app is requesting an orientation, return " + mLastOrientation
4098 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004099 // The next app has not been requested to be visible, so we keep the current orientation
4100 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08004101 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004102 }
Robert Carrb1579c82017-09-05 14:54:47 -07004103
4104 @Override
4105 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004106 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004107
Robert Carr2f8aa392018-01-31 14:46:51 -08004108 for (int i = 0; i < mChildren.size(); i++) {
4109 final TaskStack s = mChildren.get(i);
4110 s.assignChildLayers(t);
4111 }
4112 }
4113
4114 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02004115
Robert Carrf7a7ca82017-12-06 13:17:07 -08004116 final int HOME_STACK_STATE = 0;
4117 final int NORMAL_STACK_STATE = 1;
4118 final int ALWAYS_ON_TOP_STATE = 2;
4119
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004120 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004121 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02004122 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02004123 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004124
Robert Carrf7a7ca82017-12-06 13:17:07 -08004125 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
4126 for (int i = 0; i < mChildren.size(); i++) {
4127 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08004128 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
4129 continue;
4130 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
4131 || s.isAlwaysOnTop())) {
4132 continue;
4133 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
4134 continue;
4135 }
4136 s.assignLayer(t, layer++);
4137 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
4138 t.setLayer(mSplitScreenDividerAnchor, layer++);
4139 }
Winson Chungd41f71d2018-03-16 15:26:07 -07004140 if ((s.isTaskAnimating() || s.isAppAnimating())
4141 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004142 // Ensure the animation layer ends up above the
4143 // highest animating stack and no higher.
4144 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004145 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004146 if (state != ALWAYS_ON_TOP_STATE) {
4147 layerForBoostedAnimationLayer = layer++;
4148 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08004149 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004150 if (state == HOME_STACK_STATE) {
4151 layerForHomeAnimationLayer = layer++;
4152 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004153 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004154 if (mAppAnimationLayer != null) {
4155 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004156 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004157 if (mBoostedAppAnimationLayer != null) {
4158 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
4159 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004160 if (mHomeAppAnimationLayer != null) {
4161 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
4162 }
Robert Carrb1579c82017-09-05 14:54:47 -07004163 }
4164
4165 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02004166 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
4167 switch (animationLayer) {
4168 case ANIMATION_LAYER_BOOSTED:
4169 return mBoostedAppAnimationLayer;
4170 case ANIMATION_LAYER_HOME:
4171 return mHomeAppAnimationLayer;
4172 case ANIMATION_LAYER_STANDARD:
4173 default:
4174 return mAppAnimationLayer;
4175 }
chaviw23ee71c2017-12-18 11:29:41 -08004176 }
4177
Robert Carrf7a7ca82017-12-06 13:17:07 -08004178 SurfaceControl getSplitScreenDividerAnchor() {
4179 return mSplitScreenDividerAnchor;
4180 }
4181
chaviw23ee71c2017-12-18 11:29:41 -08004182 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004183 void onParentSet() {
4184 super.onParentSet();
4185 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08004186 mAppAnimationLayer = makeChildSurface(null)
4187 .setName("animationLayer")
4188 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02004189 mBoostedAppAnimationLayer = makeChildSurface(null)
4190 .setName("boostedAnimationLayer")
4191 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02004192 mHomeAppAnimationLayer = makeChildSurface(null)
4193 .setName("homeAnimationLayer")
4194 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08004195 mSplitScreenDividerAnchor = makeChildSurface(null)
4196 .setName("splitScreenDividerAnchor")
4197 .build();
4198 getPendingTransaction()
4199 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02004200 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02004201 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08004202 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08004203 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07004204 } else {
chaviw23ee71c2017-12-18 11:29:41 -08004205 mAppAnimationLayer.destroy();
4206 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02004207 mBoostedAppAnimationLayer.destroy();
4208 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02004209 mHomeAppAnimationLayer.destroy();
4210 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004211 mSplitScreenDividerAnchor.destroy();
4212 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07004213 }
4214 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004215 }
4216
Robert Carree4d4b92017-11-22 12:21:46 -08004217 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004218 AboveAppWindowContainers(String name, WindowManagerService service) {
4219 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08004220 }
4221
Robert Carrb9506032018-02-13 13:54:00 -08004222 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07004223 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
4224 final SurfaceControl.Builder builder = super.makeChildSurface(child);
4225 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
4226 // To draw above the ColorFade layer during the screen off transition, the
4227 // rounded corner overlays need to be at the root of the surface hierarchy.
4228 // TODO: move the ColorLayer into the display overlay layer such that this is not
4229 // necessary anymore.
4230 builder.setParent(null);
4231 }
4232 return builder;
4233 }
4234
4235 @Override
Robert Carrb9506032018-02-13 13:54:00 -08004236 void assignChildLayers(SurfaceControl.Transaction t) {
4237 assignChildLayers(t, null /* imeContainer */);
4238 }
4239
Robert Carree4d4b92017-11-22 12:21:46 -08004240 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
4241 boolean needAssignIme = imeContainer != null
4242 && imeContainer.getSurfaceControl() != null;
4243 for (int j = 0; j < mChildren.size(); ++j) {
4244 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004245
4246 // See {@link mSplitScreenDividerAnchor}
4247 if (wt.windowType == TYPE_DOCK_DIVIDER) {
4248 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
4249 continue;
4250 }
Vishnu Nair83537a72018-07-19 21:27:48 -07004251 if (wt.mRoundedCornerOverlay) {
4252 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
4253 continue;
4254 }
Robert Carree4d4b92017-11-22 12:21:46 -08004255 wt.assignLayer(t, j);
4256 wt.assignChildLayers(t);
4257
4258 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
4259 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08004260
4261 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
4262 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004263 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08004264 needAssignIme = false;
4265 }
4266 }
4267 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004268 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08004269 }
4270 }
4271 }
4272
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004273 /**
4274 * Window container class that contains all containers on this display that are not related to
4275 * Apps. E.g. status bar.
4276 */
Robert Carree4d4b92017-11-22 12:21:46 -08004277 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07004278 /**
4279 * Compares two child window tokens returns -1 if the first is lesser than the second in
4280 * terms of z-order and 1 otherwise.
4281 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004282 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07004283 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004284 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
4285 token1.mOwnerCanManageAppTokens)
4286 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
4287 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004288
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004289 private final Predicate<WindowState> mGetOrientingWindow = w -> {
4290 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
4291 return false;
4292 }
4293 final int req = w.mAttrs.screenOrientation;
4294 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
4295 || req == SCREEN_ORIENTATION_UNSET) {
4296 return false;
4297 }
4298 return true;
4299 };
4300
Wale Ogunwale3a931692016-11-02 16:49:48 -07004301 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08004302 private final Dimmer mDimmer = new Dimmer(this);
4303 private final Rect mTmpDimBoundsRect = new Rect();
4304
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004305 NonAppWindowContainers(String name, WindowManagerService service) {
4306 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07004307 mName = name;
4308 }
4309
4310 void addChild(WindowToken token) {
4311 addChild(token, mWindowComparator);
4312 }
4313
4314 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004315 int getOrientation() {
4316 final WindowManagerPolicy policy = mService.mPolicy;
4317 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004318 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004319
4320 if (win != null) {
4321 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004322 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004323 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004324 if (mService.mKeyguardGoingAway) {
4325 // Keyguard can't affect the orientation if it is going away...
4326 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4327 return SCREEN_ORIENTATION_UNSET;
4328 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004329 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004330 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4331 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004332 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004333 }
4334
Andrii Kulian8ee72852017-03-10 10:36:45 -08004335 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004336
Jorim Jaggi1c530592018-04-06 15:11:47 +02004337 // Only allow force setting the orientation when all unknown visibilities have been
4338 // resolved, as otherwise we just may be starting another occluding activity.
4339 final boolean isUnoccluding =
lumark588a3e82018-07-20 18:53:54 +08004340 mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4341 && mUnknownAppVisibilityController.allResolved();
Jorim Jaggi1c530592018-04-06 15:11:47 +02004342 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004343 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004344 }
4345
4346 return SCREEN_ORIENTATION_UNSET;
4347 }
4348
4349 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004350 String getName() {
4351 return mName;
4352 }
chaviwf29223e2018-01-31 13:23:51 -08004353
4354 @Override
4355 Dimmer getDimmer() {
4356 return mDimmer;
4357 }
4358
4359 @Override
4360 void prepareSurfaces() {
4361 mDimmer.resetDimStates();
4362 super.prepareSurfaces();
4363 getBounds(mTmpDimBoundsRect);
4364
4365 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4366 scheduleAnimation();
4367 }
4368 }
Robert Carr3b716242016-08-16 16:02:21 -07004369 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004370
Robert Carr9034d962018-01-04 18:27:42 -08004371 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4372 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4373 super(name, service);
4374 }
4375
4376 @Override
4377 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4378 }
4379 };
4380
Robert Carrb1579c82017-09-05 14:54:47 -07004381 SurfaceControl.Builder makeSurface(SurfaceSession s) {
4382 return mService.makeSurfaceBuilder(s)
4383 .setParent(mWindowingLayer);
4384 }
4385
4386 @Override
4387 SurfaceSession getSession() {
4388 return mSession;
4389 }
4390
4391 @Override
4392 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004393 SurfaceSession s = child != null ? child.getSession() : getSession();
4394 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07004395 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004396
4397 if (child == null) {
4398 return b;
4399 }
4400
Robert Carree4d4b92017-11-22 12:21:46 -08004401 return b.setName(child.getName())
4402 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004403 }
4404
4405 /**
4406 * The makeSurface variants are for use by the window-container
4407 * hierarchy. makeOverlay here is a function for various non windowing
4408 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4409 * and other potpourii.
4410 */
4411 SurfaceControl.Builder makeOverlay() {
4412 return mService.makeSurfaceBuilder(mSession)
4413 .setParent(mOverlayLayer);
4414 }
4415
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004416 /**
4417 * Reparents the given surface to mOverlayLayer.
4418 */
4419 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4420 transaction.reparent(surface, mOverlayLayer.getHandle());
4421 }
4422
Robert Carrb1579c82017-09-05 14:54:47 -07004423 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004424 if (spec.scale != 1.0) {
4425 mMagnificationSpec = spec;
4426 } else {
4427 mMagnificationSpec = null;
4428 }
4429
Robert Carrf59b8dd2017-10-02 18:58:36 -07004430 applyMagnificationSpec(getPendingTransaction(), spec);
4431 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004432 }
4433
Robert Carr24be9ab2018-04-30 17:54:53 -07004434 void reapplyMagnificationSpec() {
4435 if (mMagnificationSpec != null) {
4436 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4437 }
4438 }
4439
Robert Carrb1579c82017-09-05 14:54:47 -07004440 @Override
4441 void onParentSet() {
4442 // Since we are the top of the SurfaceControl hierarchy here
4443 // we create the root surfaces explicitly rather than chaining
4444 // up as the default implementation in onParentSet does. So we
4445 // explicitly do NOT call super here.
4446 }
4447
4448 @Override
4449 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004450
4451 // These are layers as children of "mWindowingLayer"
4452 mBelowAppWindowsContainers.assignLayer(t, 0);
4453 mTaskStackContainers.assignLayer(t, 1);
4454 mAboveAppWindowsContainers.assignLayer(t, 2);
4455
4456 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004457 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004458
Robert Carree4d4b92017-11-22 12:21:46 -08004459 // In the case where we have an IME target that is not in split-screen
4460 // mode IME assignment is easy. We just need the IME to go directly above
4461 // the target. This way children of the target will naturally go above the IME
4462 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004463 //
Robert Carree4d4b92017-11-22 12:21:46 -08004464 // In the case of split-screen windowing mode, we need to elevate the IME above the
4465 // docked divider while keeping the app itself below the docked divider, so instead
4466 // we use relative layering of the IME targets child windows, and place the
4467 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004468 //
Robert Carr234b6332018-03-20 13:38:16 -07004469 // In the case the IME target is animating, the animation Z order may be different
4470 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4471 // IME target. In this case we just layer the IME over all transitions by placing it in the
4472 // above applications layer.
4473 //
Robert Carree4d4b92017-11-22 12:21:46 -08004474 // In the case where we have no IME target we assign it where it's base layer would
4475 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004476 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4477 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004478 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004479 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004480 // TODO: We need to use an extra level on the app surface to ensure
4481 // this is always above SurfaceView but always below attached window.
4482 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004483 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004484 }
4485
4486 // Above we have assigned layers to our children, now we ask them to assign
4487 // layers to their children.
4488 mBelowAppWindowsContainers.assignChildLayers(t);
4489 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004490 mAboveAppWindowsContainers.assignChildLayers(t,
4491 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004492 mImeWindowsContainers.assignChildLayers(t);
4493 }
4494
4495 /**
4496 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4497 * that the IME target is one of the docked applications. We'd like the docked divider to be
4498 * above both of the applications, and we'd like the IME to be above the docked divider.
4499 * However we need child windows of the applications to be above the IME (Text drag handles).
4500 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4501 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
4502 * with {@link #WindowState#assignLayer}
4503 */
4504 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004505 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004506 }
4507
4508 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004509 void prepareSurfaces() {
4510 final ScreenRotationAnimation screenRotationAnimation =
4511 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
4512 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4513 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4514 mPendingTransaction.setMatrix(mWindowingLayer,
4515 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4516 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4517 mPendingTransaction.setPosition(mWindowingLayer,
4518 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4519 mPendingTransaction.setAlpha(mWindowingLayer,
4520 screenRotationAnimation.getEnterTransformation().getAlpha());
4521 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004522
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004523 super.prepareSurfaces();
4524 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004525
Jorim Jaggibe418292018-03-26 16:14:12 +02004526 void assignStackOrdering() {
4527 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004528 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004529
4530 /**
4531 * Increment the deferral count to determine whether to update the IME target.
4532 */
4533 void deferUpdateImeTarget() {
4534 mDeferUpdateImeTargetCount++;
4535 }
4536
4537 /**
4538 * Decrement the deferral count to determine whether to update the IME target. If the count
4539 * reaches 0, a new ime target will get computed.
4540 */
4541 void continueUpdateImeTarget() {
4542 if (mDeferUpdateImeTargetCount == 0) {
4543 return;
4544 }
4545
4546 mDeferUpdateImeTargetCount--;
4547 if (mDeferUpdateImeTargetCount == 0) {
4548 computeImeTarget(true /* updateImeTarget */);
4549 }
4550 }
4551
4552 /**
4553 * @return Whether a new IME target should be computed.
4554 */
4555 private boolean canUpdateImeTarget() {
4556 return mDeferUpdateImeTargetCount == 0;
4557 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004558
4559 InputMonitor getInputMonitor() {
4560 return mInputMonitor;
4561 }
Jorim Jaggif1292892018-09-10 11:58:13 +02004562
4563 /**
4564 * @return Cached value whether we told display manager that we have content.
4565 */
4566 boolean getLastHasContent() {
4567 return mLastHasContent;
4568 }
Arthur Hungbe5ce212018-09-13 18:41:56 +08004569
4570 void registerPointerEventListener(@NonNull PointerEventListener listener) {
4571 if (mPointerEventDispatcher != null) {
4572 mPointerEventDispatcher.registerInputEventListener(listener);
4573 }
4574 }
4575
4576 void unregisterPointerEventListener(@NonNull PointerEventListener listener) {
4577 if (mPointerEventDispatcher != null) {
4578 mPointerEventDispatcher.unregisterInputEventListener(listener);
4579 }
4580 }
lumark588a3e82018-07-20 18:53:54 +08004581
4582 void prepareAppTransition(@WindowManager.TransitionType int transit,
4583 boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags,
4584 boolean forceOverride) {
4585 final boolean prepared = mAppTransition.prepareAppTransitionLocked(
4586 transit, alwaysKeepCurrent, flags, forceOverride);
4587 if (prepared && okToAnimate()) {
4588 mSkipAppTransitionAnimation = false;
4589 }
4590 }
4591
4592 void executeAppTransition() {
4593 if (mAppTransition.isTransitionSet()) {
4594 if (DEBUG_APP_TRANSITIONS) {
4595 Slog.w(TAG_WM, "Execute app transition: " + mAppTransition + ", displayId: "
4596 + mDisplayId + " Callers=" + Debug.getCallers(5));
4597 }
4598 mAppTransition.setReady();
4599 mService.mWindowPlacerLocked.requestTraversal();
4600 }
4601 }
4602
4603 /**
4604 * Update pendingLayoutChanges after app transition has finished.
4605 */
4606 void handleAnimatingStoppedAndTransition() {
4607 int changes = 0;
4608
4609 mAppTransition.setIdle();
4610
4611 for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) {
4612 final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i);
4613 mAppTransition.notifyAppTransitionFinishedLocked(token);
4614 }
4615 mNoAnimationNotifyOnTransitionFinished.clear();
4616
4617 mWallpaperController.hideDeferredWallpapersIfNeeded();
4618
4619 onAppTransitionDone();
4620
4621 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4622 if (DEBUG_WALLPAPER_LIGHT) {
4623 Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout");
4624 }
4625 computeImeTarget(true /* updateImeTarget */);
4626 mService.mRoot.mWallpaperMayChange = true;
4627 // Since the window list has been rebuilt, focus might have to be recomputed since the
4628 // actual order of windows might have changed again.
4629 mService.mFocusMayChange = true;
4630
4631 pendingLayoutChanges |= changes;
4632 }
Craig Mautner59c00972012-07-30 12:10:24 -07004633}