blob: da8fbb9ccceac236a17aaebaac6aa208a30755fd [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;
chaviwff2e7d82018-11-02 11:11:27 -070032import static android.view.InsetsState.TYPE_IME;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070033import static android.view.Surface.ROTATION_0;
34import static android.view.Surface.ROTATION_180;
35import static android.view.Surface.ROTATION_270;
36import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070037import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070038import static android.view.WindowManager.DOCKED_BOTTOM;
39import static android.view.WindowManager.DOCKED_INVALID;
40import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080041import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
43import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070044import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070045import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070046import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
47import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070051import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080052import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070053import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070054import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070055import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070057import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070058import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
59import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070060import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070061import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080062import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
63
Adrian Roose99bc052017-11-20 17:55:31 +010064import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
66import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
67import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080068import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
lumark588a3e82018-07-20 18:53:54 +080069import static com.android.server.wm.DisplayContentProto.APP_TRANSITION;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080070import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
71import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
72import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
73import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
74import static com.android.server.wm.DisplayContentProto.DPI;
Tiger Huang1e5b10a2018-07-30 20:19:51 +080075import static com.android.server.wm.DisplayContentProto.FOCUSED_APP;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080076import static com.android.server.wm.DisplayContentProto.ID;
77import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
78import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
79import static com.android.server.wm.DisplayContentProto.ROTATION;
80import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
81import static com.android.server.wm.DisplayContentProto.STACKS;
82import 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_LOSING_FOCUS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700104import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
105import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700106import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700107import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700108import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
109import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800110import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
111import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
112import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700113import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700114import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700115import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700116import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700117import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700118import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700119import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700120import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700121import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700122
lumark588a3e82018-07-20 18:53:54 +0800123import android.animation.AnimationHandler;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700124import android.annotation.CallSuper;
Riddle Hsuf53da812018-08-15 22:00:27 +0800125import android.annotation.IntDef;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700126import android.annotation.NonNull;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200127import android.annotation.Nullable;
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;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200155import android.view.InsetsState.InternalInsetType;
Robert Carrb1579c82017-09-05 14:54:47 -0700156import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700157import android.view.Surface;
158import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100159import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700160import android.view.SurfaceSession;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800161import android.view.View;
lumark588a3e82018-07-20 18:53:54 +0800162import android.view.WindowManager;
Evan Rosky39b6f232018-10-30 18:35:41 -0700163import android.view.WindowManagerPolicyConstants.PointerEventListener;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700164
Bryce Lee48f4b572017-04-10 10:54:15 -0700165import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800166import com.android.internal.util.ToBooleanFunction;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200167import com.android.internal.util.function.TriConsumer;
Adrian Roose99bc052017-11-20 17:55:31 +0100168import com.android.server.policy.WindowManagerPolicy;
Issei Suzuki43190bd2018-08-20 17:28:41 +0200169import com.android.server.wm.utils.DisplayRotationUtil;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100170import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100171import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700172
173import java.io.PrintWriter;
Riddle Hsuf53da812018-08-15 22:00:27 +0800174import java.lang.annotation.Retention;
175import java.lang.annotation.RetentionPolicy;
Craig Mautner59c00972012-07-30 12:10:24 -0700176import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700177import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700178import java.util.HashMap;
179import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700180import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700181import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100182import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800183import java.util.function.Consumer;
184import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700185
Craig Mautner59c00972012-07-30 12:10:24 -0700186/**
187 * Utility class for keeping track of the WindowStates and other pertinent contents of a
188 * particular Display.
Craig Mautner59c00972012-07-30 12:10:24 -0700189 */
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();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800293
294 /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */
Andrii Kulian06d07d62017-03-14 11:11:47 -0700295 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700296
Andrii Kulian06d07d62017-03-14 11:11:47 -0700297 /**
298 * Compat metrics computed based on {@link #mDisplayMetrics}.
299 * @see #updateDisplayAndOrientation(int)
300 */
301 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
302
303 /** The desired scaling factor for compatible apps. */
304 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700305
Andrii Kulian8ee72852017-03-10 10:36:45 -0800306 /**
307 * Current rotation of the display.
308 * Constants as per {@link android.view.Surface.Rotation}.
309 *
Robert Carrae606b42018-02-15 15:36:23 -0800310 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800311 */
312 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700313
Andrii Kulian8ee72852017-03-10 10:36:45 -0800314 /**
315 * Last applied orientation of the display.
316 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
317 *
Riddle Hsu4e611772018-10-31 18:58:28 +0800318 * @see #updateOrientationFromAppTokens()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800319 */
320 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700321
Andrii Kulian8ee72852017-03-10 10:36:45 -0800322 /**
323 * Flag indicating that the application is receiving an orientation that has different metrics
324 * than it expected. E.g. Portrait instead of Landscape.
325 *
Robert Carrae606b42018-02-15 15:36:23 -0800326 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800327 */
328 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700329
Andrii Kulian8ee72852017-03-10 10:36:45 -0800330 /**
331 * Orientation forced by some window. If there is no visible window that specifies orientation
332 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
333 *
334 * @see NonAppWindowContainers#getOrientation()
335 */
336 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700337
Andrii Kulian8ee72852017-03-10 10:36:45 -0800338 /**
339 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
340 * occluded.
341 *
342 * @see NonAppWindowContainers#getOrientation()
343 */
344 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
345
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700346 /**
347 * Keep track of wallpaper visibility to notify changes.
348 */
349 private boolean mLastWallpaperVisible = false;
350
Andrii Kulian06d07d62017-03-14 11:11:47 -0700351 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700352
Craig Mautner39834192012-09-02 07:47:24 -0700353 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700354 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700355 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800356 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800357
Vishnu Nairba183352018-11-21 11:16:49 -0800358 /**
359 * Used to gate application window layout until we have sent the complete configuration.
360 * TODO: There are still scenarios where we may be out of sync with the client. Ideally
361 * we want to replace this flag with a mechanism that will confirm the configuration
362 * applied by the client is the one expected by the system server.
363 */
364 boolean mWaitingForConfig;
365
Andrii Kulian839def92016-11-02 10:58:58 -0700366 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800367 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800368 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800369
Andrii Kulianf0379de2018-03-14 16:24:07 -0700370 /**
371 * Flag indicating whether WindowManager should override info for this display in
372 * DisplayManager.
373 */
374 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700375
Craig Mautnerdc548482014-02-05 13:35:24 -0800376 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700377 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800378
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700379 /** Detect user tapping outside of current focused task bounds .*/
380 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700381
Craig Mautner6601b7b2013-04-29 10:29:11 -0700382 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700383 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700384
Craig Mautner6601b7b2013-04-29 10:29:11 -0700385 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800386 private final Rect mTmpRect = new Rect();
387 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700388 private final RectF mTmpRectF = new RectF();
389 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800390 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700391
Issei Suzuki43190bd2018-08-20 17:28:41 +0200392
Bryce Leef3c6a472017-11-14 14:53:06 -0800393 /** Used for handing back size of display */
394 private final Rect mTmpBounds = new Rect();
395
Craig Mautner95da1082014-02-24 17:54:35 -0800396 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700397 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800398
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700399 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700400 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700401
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800402 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800403 /** A collection of windows that provide tap exclude regions inside of them. */
404 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800405
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000406 private boolean mHaveBootMsg = false;
407 private boolean mHaveApp = false;
408 private boolean mHaveWallpaper = false;
409 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700410
411 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
412
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700413 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
414 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000415 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
416 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700417
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700418 // True if this display is in the process of being removed. Used to determine if the removal of
419 // the display's direct children should be allowed.
420 private boolean mRemovingDisplay = false;
421
Bryce Leed1871262017-06-12 14:12:29 -0700422 // {@code false} if this display is in the processing of being created.
423 private boolean mDisplayReady = false;
424
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800425 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700426
wilsonshihc32538e2018-11-07 17:27:34 +0800427 boolean mWallpaperMayChange = false;
428
Robert Carrb1579c82017-09-05 14:54:47 -0700429 private final SurfaceSession mSession = new SurfaceSession();
430
431 /**
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800432 * Window that is currently interacting with the user. This window is responsible for receiving
433 * key events and pointer events from the user.
434 */
435 WindowState mCurrentFocus = null;
436
437 /**
438 * The last focused window that we've notified the client that the focus is changed.
439 */
440 WindowState mLastFocus = null;
441
442 /**
443 * Windows that have lost input focus and are waiting for the new focus window to be displayed
444 * before they are told about this.
445 */
446 ArrayList<WindowState> mLosingFocus = new ArrayList<>();
447
448 /**
449 * The foreground app of this display. Windows below this app cannot be the focused window. If
450 * the user taps on the area outside of the task of the focused app, we will notify AM about the
451 * new task the user wants to interact with.
452 */
453 AppWindowToken mFocusedApp = null;
454
455 /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
456 final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>();
457
458 /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
459 final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>();
460
461 /**
Robert Carrb1579c82017-09-05 14:54:47 -0700462 * We organize all top-level Surfaces in to the following layers.
463 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800464 * and omitted from Screen-Magnification, for example the strict mode flash or
465 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700466 * {@link #mWindowingLayer} contains everything else.
467 */
468 private SurfaceControl mOverlayLayer;
469
470 /**
471 * See {@link #mOverlayLayer}
472 */
473 private SurfaceControl mWindowingLayer;
474
475 /**
Adrian Roos5251b1d2018-03-23 18:57:43 +0100476 * Sequence number for the current layout pass.
477 */
478 int mLayoutSeq = 0;
479
Chavi Weingarten3a748552018-05-14 17:32:42 +0000480 /**
481 * Specifies the count to determine whether to defer updating the IME target until ready.
482 */
483 private int mDeferUpdateImeTargetCount;
484
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100485 /** Temporary float array to retrieve 3x3 matrix values. */
486 private final float[] mTmpFloats = new float[9];
487
Robert Carr24be9ab2018-04-30 17:54:53 -0700488 private MagnificationSpec mMagnificationSpec;
489
Arthur Hung95b38a92018-07-20 18:56:12 +0800490 private InputMonitor mInputMonitor;
491
Jorim Jaggif1292892018-09-10 11:58:13 +0200492 /** Caches the value whether told display manager that we have content. */
493 private boolean mLastHasContent;
494
Issei Suzuki43190bd2018-08-20 17:28:41 +0200495 private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil();
496
lumark90120a82018-08-15 00:33:03 +0800497 /**
498 * The input method window for this display.
499 */
500 WindowState mInputMethodWindow;
501
lumarkff0ab692018-11-05 20:32:30 +0800502 /**
503 * This just indicates the window the input method is on top of, not
504 * necessarily the window its input is going to.
505 */
506 WindowState mInputMethodTarget;
507
508 /** If true hold off on modifying the animation layer of mInputMethodTarget */
509 boolean mInputMethodTargetWaitingAnim;
510
Arthur Hungbe5ce212018-09-13 18:41:56 +0800511 private final PointerEventDispatcher mPointerEventDispatcher;
512
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200513 private final InsetsStateController mInsetsStateController;
514
Tiger Huang7c610aa2018-10-27 00:01:01 +0800515 // Last systemUiVisibility we received from status bar.
516 private int mLastStatusBarVisibility = 0;
517 // Last systemUiVisibility we dispatched to windows.
518 private int mLastDispatchedSystemUiVisibility = 0;
519
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800520 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
521 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800522 final AppWindowToken atoken = w.mAppToken;
523 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200524 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800525 if (w.performShowLocked()) {
526 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
527 if (DEBUG_LAYOUT_REPEATS) {
528 mService.mWindowPlacerLocked.debugLayoutRepeats(
529 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
530 }
531 }
532 }
533 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800534 };
535
536 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
537 final WindowStateAnimator winAnimator = w.mWinAnimator;
538 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
539 return;
540 }
541
Jorim Jaggi8f520872018-08-14 17:00:20 +0200542 // If this window is animating, ensure the animation background is set.
543 final AnimationAdapter anim = w.mAppToken != null
544 ? w.mAppToken.getAnimation()
545 : w.getAnimation();
546 if (anim != null) {
547 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800548 if (color != 0) {
549 final TaskStack stack = w.getStack();
550 if (stack != null) {
551 stack.setAnimationBackground(winAnimator, color);
552 }
553 }
554 }
555 };
556
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800557 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
558 final int lostFocusUid = mTmpWindow.mOwnerUid;
559 final Handler handler = mService.mH;
560 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
561 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
562 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
563 w.mAttrs.hideTimeoutMilliseconds);
564 }
565 }
566 };
567
568 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800569 final AppWindowToken focusedApp = mFocusedApp;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800570 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
571 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
572
573 if (!w.canReceiveKeys()) {
574 return false;
575 }
576
577 final AppWindowToken wtoken = w.mAppToken;
578
579 // If this window's application has been removed, just skip it.
580 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
581 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
582 + (wtoken.removed ? "removed" : "sendingToBottom"));
583 return false;
584 }
585
586 if (focusedApp == null) {
587 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
588 + " using new focus @ " + w);
589 mTmpWindow = w;
590 return true;
591 }
592
593 if (!focusedApp.windowsAreFocusable()) {
594 // Current focused app windows aren't focusable...
595 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
596 + " focusable using new focus @ " + w);
597 mTmpWindow = w;
598 return true;
599 }
600
601 // Descend through all of the app tokens and find the first that either matches
602 // win.mAppToken (return win) or mFocusedApp (return null).
603 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
604 if (focusedApp.compareTo(wtoken) > 0) {
605 // App stack below focused app stack. No focus for you!!!
606 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
607 "findFocusedWindow: Reached focused app=" + focusedApp);
608 mTmpWindow = null;
609 return true;
610 }
611 }
612
613 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
614 mTmpWindow = w;
615 return true;
616 };
617
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800618 private final Consumer<WindowState> mPerformLayout = w -> {
619 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
620 // wasting time and funky changes while a window is animating away.
621 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
622 || w.isGoneForLayoutLw();
623
624 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
625 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
626 + " mLayoutAttached=" + w.mLayoutAttached
627 + " screen changed=" + w.isConfigChanged());
628 final AppWindowToken atoken = w.mAppToken;
629 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200630 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800631 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
632 + " parentHidden=" + w.isParentWindowHidden());
633 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200634 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800635 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
636 + " parentHidden=" + w.isParentWindowHidden());
637 }
638
639 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
640 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
641 // since that means "perform layout as normal, just don't display").
642 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
643 || ((w.isConfigChanged() || w.setReportResizeHints())
644 && !w.isGoneForLayoutLw() &&
645 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
646 (w.mHasSurface && w.mAppToken != null &&
647 w.mAppToken.layoutConfigChanges)))) {
648 if (!w.mLayoutAttached) {
649 if (mTmpInitial) {
650 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700651 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800652 }
653 if (w.mAttrs.type == TYPE_DREAM) {
654 // Don't layout windows behind a dream, so that if it does stuff like hide
655 // the status bar we won't get a bad transition when it goes away.
656 mTmpWindow = w;
657 }
658 w.mLayoutNeeded = false;
659 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200660 final boolean firstLayout = !w.isLaidOut();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800661 getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100662 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800663
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200664 // If this is the first layout, we need to initialize the last inset values as
665 // otherwise we'd immediately cause an unnecessary resize.
666 if (firstLayout) {
667 w.updateLastInsetValues();
668 }
669
Adrian Roos23df3a32018-03-15 15:41:13 +0100670 if (w.mAppToken != null) {
671 w.mAppToken.layoutLetterbox(w);
672 }
673
chaviw492139a2018-07-16 16:07:35 -0700674 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700675 + " mContainingFrame=" + w.getContainingFrame()
676 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800677 }
678 }
679 };
680
681 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
682 if (w.mLayoutAttached) {
683 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
684 + " mViewVisibility=" + w.mViewVisibility
685 + " mRelayoutCalled=" + w.mRelayoutCalled);
686 // If this view is GONE, then skip it -- keep the current frame, and let the caller
687 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
688 // windows, since that means "perform layout as normal, just don't display").
689 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
690 return;
691 }
692 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
693 || w.mLayoutNeeded) {
694 if (mTmpInitial) {
695 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700696 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800697 }
698 w.mLayoutNeeded = false;
699 w.prelayout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800700 getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100701 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700702 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700703 + " mContainingFrame=" + w.getContainingFrame()
704 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800705 }
706 } else if (w.mAttrs.type == TYPE_DREAM) {
707 // Don't layout windows behind a dream, so that if it does stuff like hide the
708 // status bar we won't get a bad transition when it goes away.
709 mTmpWindow = mTmpWindow2;
710 }
711 };
712
713 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
714 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
715 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
716 return w.canBeImeTarget();
717 };
718
719 private final Consumer<WindowState> mApplyPostLayoutPolicy =
Tiger Huang7c610aa2018-10-27 00:01:01 +0800720 w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
lumarkff0ab692018-11-05 20:32:30 +0800721 mInputMethodTarget);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800722
723 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
724 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
725 final boolean obscuredChanged = w.mObscured !=
726 mTmpApplySurfaceChangesTransactionState.obscured;
727 final RootWindowContainer root = mService.mRoot;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800728
729 // Update effect.
730 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
731 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
732 final boolean isDisplayed = w.isDisplayedLw();
733
734 if (isDisplayed && w.isObscuringDisplay()) {
735 // This window completely covers everything behind it, so we want to leave all
736 // of them as undimmed (for performance reasons).
737 root.mObscuringWindow = w;
738 mTmpApplySurfaceChangesTransactionState.obscured = true;
739 }
740
741 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
742 root.handleNotObscuredLocked(w,
743 mTmpApplySurfaceChangesTransactionState.obscured,
744 mTmpApplySurfaceChangesTransactionState.syswin);
745
746 if (w.mHasSurface && isDisplayed) {
747 final int type = w.mAttrs.type;
748 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
749 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
750 mTmpApplySurfaceChangesTransactionState.syswin = true;
751 }
752 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
753 && w.mAttrs.preferredRefreshRate != 0) {
754 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
755 = w.mAttrs.preferredRefreshRate;
756 }
757 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
758 && w.mAttrs.preferredDisplayModeId != 0) {
759 mTmpApplySurfaceChangesTransactionState.preferredModeId
760 = w.mAttrs.preferredDisplayModeId;
761 }
762 }
763 }
764
wilsonshihc32538e2018-11-07 17:27:34 +0800765 if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800766 // This is the wallpaper target and its obscured state changed... make sure the
767 // current wallpaper's visibility has been updated accordingly.
768 mWallpaperController.updateWallpaperVisibility();
769 }
770
chaviw161ea3e2018-01-31 12:01:12 -0800771 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800772
773 final WindowStateAnimator winAnimator = w.mWinAnimator;
774
775 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
chaviw1454b392018-08-06 09:54:04 -0700776 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800777
778 // Moved from updateWindowsAndWallpaperLocked().
779 if (w.mHasSurface) {
780 // Take care of the window being ready to display.
781 final boolean committed = winAnimator.commitFinishDrawingLocked();
782 if (isDefaultDisplay && committed) {
783 if (w.mAttrs.type == TYPE_DREAM) {
784 // HACK: When a dream is shown, it may at that point hide the lock screen.
785 // So we need to redo the layout to let the phone window manager make this
786 // happen.
787 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
788 if (DEBUG_LAYOUT_REPEATS) {
789 surfacePlacer.debugLayoutRepeats(
790 "dream and commitFinishDrawingLocked true",
791 pendingLayoutChanges);
792 }
793 }
794 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
795 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
796 "First draw done in potential wallpaper target " + w);
wilsonshihc32538e2018-11-07 17:27:34 +0800797 mWallpaperMayChange = true;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800798 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
799 if (DEBUG_LAYOUT_REPEATS) {
800 surfacePlacer.debugLayoutRepeats(
801 "wallpaper and commitFinishDrawingLocked true",
802 pendingLayoutChanges);
803 }
804 }
805 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800806 }
807
808 final AppWindowToken atoken = w.mAppToken;
809 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100810 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800811 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
812 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
813 mTmpUpdateAllDrawn.add(atoken);
814 }
815 }
816
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800817 if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) {
818 mService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800819 }
820
821 w.updateResizingWindowIfNeeded();
822 };
823
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800824 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800825 * Create new {@link DisplayContent} instance, add itself to the root window container and
826 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700827 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800828 * @param service You know.
wilsonshihc32538e2018-11-07 17:27:34 +0800829 * @param controller The controller for the display container.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700830 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700831 DisplayContent(Display display, WindowManagerService service,
wilsonshihc32538e2018-11-07 17:27:34 +0800832 DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100833 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800834 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800835 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
836 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
837 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
838 + " new=" + display);
839 }
840
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700841 mDisplay = display;
842 mDisplayId = display.getDisplayId();
wilsonshihc32538e2018-11-07 17:27:34 +0800843 mWallpaperController = new WallpaperController(mService, this);
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700844 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700845 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700846 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100847 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
848 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700849 initializeDisplayBaseInfo();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700850
lumark588a3e82018-07-20 18:53:54 +0800851 mAppTransition = new AppTransition(service.mContext, service, this);
852 mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier);
853 mAppTransitionController = new AppTransitionController(service, this);
854 mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this);
855
856 AnimationHandler animationHandler = new AnimationHandler();
857 mBoundsAnimationController = new BoundsAnimationController(service.mContext,
858 mAppTransition, SurfaceAnimationThread.getHandler(), animationHandler);
859
Tiger Huang7c610aa2018-10-27 00:01:01 +0800860 if (mService.mInputManager != null) {
861 final InputChannel inputChannel = mService.mInputManager.monitorInput("Display "
862 + mDisplayId, mDisplayId);
863 mPointerEventDispatcher = inputChannel != null
864 ? new PointerEventDispatcher(inputChannel) : null;
865 } else {
866 mPointerEventDispatcher = null;
867 }
868 mDisplayPolicy = new DisplayPolicy(service, this);
869 mDisplayRotation = new DisplayRotation(service, this);
870 if (isDefaultDisplay) {
871 // The policy may be invoked right after here, so it requires the necessary default
872 // fields of this display content.
873 mService.mPolicy.setDefaultDisplay(this);
874 }
875 if (mService.mDisplayReady) {
876 mDisplayPolicy.onConfigurationChanged();
877 }
878 if (mService.mSystemReady) {
879 mDisplayPolicy.systemReady();
880 }
881 mDividerControllerLocked = new DockedStackDividerController(service, this);
882 mPinnedStackControllerLocked = new PinnedStackController(service, this);
883
Vishnu Naire86bd982018-11-28 13:23:17 -0800884 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession).setOpaque(true);
Robert Carrb1579c82017-09-05 14:54:47 -0700885 mWindowingLayer = b.setName("Display Root").build();
886 mOverlayLayer = b.setName("Display Overlays").build();
887
Robert Carrf59b8dd2017-10-02 18:58:36 -0700888 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700889 .setLayerStack(mWindowingLayer, mDisplayId)
890 .show(mWindowingLayer)
891 .setLayer(mOverlayLayer, 1)
892 .setLayerStack(mOverlayLayer, mDisplayId)
893 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700894 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700895
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700896 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700897 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700898 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700899 super.addChild(mAboveAppWindowsContainers, null);
900 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800901
902 // Add itself as a child to the root container.
903 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700904
905 // TODO(b/62541591): evaluate whether this is the best spot to declare the
906 // {@link DisplayContent} ready for use.
907 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800908
Riddle Hsuf53da812018-08-15 22:00:27 +0800909 mService.mAnimator.addDisplayLocked(mDisplayId);
Arthur Hung39134b22018-08-14 11:58:28 +0800910 mInputMonitor = new InputMonitor(service, mDisplayId);
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200911 mInsetsStateController = new InsetsStateController(this);
Bryce Leed1871262017-06-12 14:12:29 -0700912 }
913
914 boolean isReady() {
915 // The display is ready when the system and the individual display are both ready.
916 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700917 }
918
919 int getDisplayId() {
920 return mDisplayId;
921 }
922
Wale Ogunwale02319a62016-09-26 15:21:22 -0700923 WindowToken getWindowToken(IBinder binder) {
924 return mTokenMap.get(binder);
925 }
926
927 AppWindowToken getAppWindowToken(IBinder binder) {
928 final WindowToken token = getWindowToken(binder);
929 if (token == null) {
930 return null;
931 }
932 return token.asAppWindowToken();
933 }
934
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700935 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700936 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
937 if (dc != null) {
938 // We currently don't support adding a window token to the display if the display
939 // already has the binder mapped to another token. If there is a use case for supporting
940 // this moving forward we will either need to merge the WindowTokens some how or have
941 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700942 throw new IllegalArgumentException("Can't map token=" + token + " to display="
943 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700944 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700945 if (binder == null) {
946 throw new IllegalArgumentException("Can't map token=" + token + " to display="
947 + getName() + " binder is null");
948 }
949 if (token == null) {
950 throw new IllegalArgumentException("Can't map null token to display="
951 + getName() + " binder=" + binder);
952 }
953
Wale Ogunwale02319a62016-09-26 15:21:22 -0700954 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700955
956 if (token.asAppWindowToken() == null) {
957 // Add non-app token to container hierarchy on the display. App tokens are added through
958 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700959 switch (token.windowType) {
960 case TYPE_WALLPAPER:
961 mBelowAppWindowsContainers.addChild(token);
962 break;
963 case TYPE_INPUT_METHOD:
964 case TYPE_INPUT_METHOD_DIALOG:
965 mImeWindowsContainers.addChild(token);
966 break;
967 default:
968 mAboveAppWindowsContainers.addChild(token);
969 break;
970 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700971 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700972 }
973
974 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700975 final WindowToken token = mTokenMap.remove(binder);
976 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800977 token.setExiting();
978 }
979 return token;
980 }
981
982 /** Changes the display the input window token is housed on to this one. */
983 void reParentWindowToken(WindowToken token) {
984 final DisplayContent prevDc = token.getDisplayContent();
985 if (prevDc == this) {
986 return;
987 }
Riddle Hsu85bd04b2018-11-17 00:34:36 +0800988 if (prevDc != null) {
989 if (prevDc.mTokenMap.remove(token.token) != null && token.asAppWindowToken() == null) {
990 // Removed the token from the map, but made sure it's not an app token before
991 // removing from parent.
992 token.getParent().removeChild(token);
993 }
994 if (prevDc.mLastFocus == mCurrentFocus) {
995 // The window has become the focus of this display, so it should not be notified
996 // that it lost focus from the previous display.
997 prevDc.mLastFocus = null;
998 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700999 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -08001000
1001 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -07001002 }
1003
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001004 void removeAppToken(IBinder binder) {
1005 final WindowToken token = removeWindowToken(binder);
1006 if (token == null) {
1007 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
1008 return;
1009 }
1010
1011 final AppWindowToken appToken = token.asAppWindowToken();
1012
1013 if (appToken == null) {
1014 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
1015 return;
1016 }
1017
1018 appToken.onRemovedFromDisplay();
1019 }
1020
Riddle Hsuad256a12018-07-18 16:11:30 +08001021 @Override
Riddle Hsu86cb7de2018-08-13 23:29:58 +08001022 DisplayWindowController getController() {
1023 return (DisplayWindowController) super.getController();
1024 }
1025
1026 @Override
Riddle Hsuad256a12018-07-18 16:11:30 +08001027 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -07001028 return mDisplay;
1029 }
1030
Craig Mautner59c00972012-07-30 12:10:24 -07001031 DisplayInfo getDisplayInfo() {
1032 return mDisplayInfo;
1033 }
1034
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001035 DisplayMetrics getDisplayMetrics() {
1036 return mDisplayMetrics;
1037 }
1038
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001039 DisplayPolicy getDisplayPolicy() {
1040 return mDisplayPolicy;
1041 }
1042
Riddle Hsuad256a12018-07-18 16:11:30 +08001043 @Override
1044 public DisplayRotation getDisplayRotation() {
1045 return mDisplayRotation;
1046 }
1047
Jorim Jaggif96c90a2018-09-26 16:55:15 +02001048 /**
1049 * Marks a window as providing insets for the rest of the windows in the system.
1050 *
1051 * @param type The type of inset this window provides.
1052 * @param win The window.
1053 * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of
1054 * the window should be taken.
1055 */
1056 void setInsetProvider(@InternalInsetType int type, WindowState win,
1057 @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider) {
1058 mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider);
1059 }
1060
1061 InsetsStateController getInsetsStateController() {
1062 return mInsetsStateController;
1063 }
1064
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001065 @VisibleForTesting
1066 void setDisplayRotation(DisplayRotation displayRotation) {
1067 mDisplayRotation = displayRotation;
1068 }
1069
Andrii Kulian8ee72852017-03-10 10:36:45 -08001070 int getRotation() {
1071 return mRotation;
1072 }
1073
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001074 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -08001075 void setRotation(int newRotation) {
1076 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +08001077 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001078 }
1079
1080 int getLastOrientation() {
1081 return mLastOrientation;
1082 }
1083
Andrii Kulian8ee72852017-03-10 10:36:45 -08001084 boolean getAltOrientation() {
1085 return mAltOrientation;
1086 }
1087
Andrii Kulian8ee72852017-03-10 10:36:45 -08001088 int getLastWindowForcedOrientation() {
1089 return mLastWindowForcedOrientation;
1090 }
1091
Andrii Kulian06d07d62017-03-14 11:11:47 -07001092 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +08001093 * Temporarily pauses rotation changes until resumed.
1094 *
1095 * This can be used to prevent rotation changes from occurring while the user is
1096 * performing certain operations, such as drag and drop.
1097 *
1098 * This call nests and must be matched by an equal number of calls to
1099 * {@link #resumeRotationLocked}.
1100 */
1101 void pauseRotationLocked() {
1102 mDeferredRotationPauseCount++;
1103 }
1104
1105 /**
1106 * Resumes normal rotation changes after being paused.
1107 */
1108 void resumeRotationLocked() {
1109 if (mDeferredRotationPauseCount <= 0) {
1110 return;
1111 }
1112
1113 mDeferredRotationPauseCount--;
1114 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001115 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001116 }
1117 }
1118
1119 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001120 * If this is true we have updated our desired orientation, but not yet changed the real
1121 * orientation our applied our screen rotation animation. For example, because a previous
1122 * screen rotation was in progress.
1123 *
1124 * @return {@code true} if the there is an ongoing rotation change.
1125 */
1126 boolean rotationNeedsUpdate() {
1127 final int lastOrientation = getLastOrientation();
1128 final int oldRotation = getRotation();
1129 final boolean oldAltOrientation = getAltOrientation();
1130
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001131 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001132 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1133 lastOrientation, rotation);
1134 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1135 return false;
1136 }
1137 return true;
1138 }
1139
Riddle Hsu4e611772018-10-31 18:58:28 +08001140 /** Notify the configuration change of this display. */
1141 void sendNewConfiguration() {
1142 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget();
1143 }
1144
1145 /**
1146 * Determine the new desired orientation of this display.
1147 *
1148 * The orientation is computed from non-application windows first. If none of the
1149 * non-application windows specify orientation, the orientation is computed from application
1150 * tokens.
1151 *
1152 * @return {@code true} if the orientation is changed.
1153 */
1154 boolean updateOrientationFromAppTokens() {
1155 return updateOrientationFromAppTokens(false /* forceUpdate */);
1156 }
1157
1158 boolean updateOrientationFromAppTokens(boolean forceUpdate) {
1159 final int req = getOrientation();
1160 if (req != mLastOrientation || forceUpdate) {
1161 mLastOrientation = req;
1162 mDisplayRotation.setCurrentOrientation(req);
1163 return updateRotationUnchecked(forceUpdate);
1164 }
1165 return false;
1166 }
1167
Riddle Hsuad256a12018-07-18 16:11:30 +08001168 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001169 * Update rotation of the display and send configuration if the rotation is changed.
1170 *
1171 * @return {@code true} if the rotation has been changed and the new config is sent.
1172 */
1173 boolean updateRotationAndSendNewConfigIfNeeded() {
1174 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1175 if (changed) {
Riddle Hsu4e611772018-10-31 18:58:28 +08001176 sendNewConfiguration();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001177 }
1178 return changed;
1179 }
1180
1181 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001182 * Update rotation of the display.
1183 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001184 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1185 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001186 */
Robert Carrae606b42018-02-15 15:36:23 -08001187 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001188 return updateRotationUnchecked(false /* forceUpdate */);
1189 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001190
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001191 /**
Evan Roskye747c3e2018-10-30 20:06:41 -07001192 * Update rotation of the DisplayContent with an option to force the update. This updates
1193 * the container's perception of rotation and, depending on the top activities, will freeze
1194 * the screen or start seamless rotation. The display itself gets rotated in
1195 * {@link #applyRotationLocked} during {@link WindowManagerService#sendNewConfiguration}.
1196 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001197 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1198 * orientation because we're waiting for some rotation to finish or display
1199 * to unfreeze, which results in configuration of the previously visible
1200 * activity being applied to a newly visible one. Forcing the rotation
1201 * update allows to workaround this issue.
1202 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
Evan Roskye747c3e2018-10-30 20:06:41 -07001203 * {@link WindowManagerService#sendNewConfiguration(int)} TO COMPLETE THE ROTATION AND
1204 * UNFREEZE THE SCREEN.
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001205 */
1206 boolean updateRotationUnchecked(boolean forceUpdate) {
1207 ScreenRotationAnimation screenRotationAnimation;
1208 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001209 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001210 // Rotation updates have been paused temporarily. Defer the update until
1211 // updates have been resumed.
1212 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1213 return false;
1214 }
1215
1216 screenRotationAnimation =
1217 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
1218 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1219 // Rotation updates cannot be performed while the previous rotation change
1220 // animation is still in progress. Skip this update. We will try updating
1221 // again after the animation is finished and the display is unfrozen.
1222 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1223 return false;
1224 }
1225 if (mService.mDisplayFrozen) {
1226 // Even if the screen rotation animation has finished (e.g. isAnimating
1227 // returns false), there is still some time where we haven't yet unfrozen
1228 // the display. We also need to abort rotation here.
1229 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1230 "Deferring rotation, still finishing previous rotation");
1231 return false;
1232 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001233 }
1234
1235 if (!mService.mDisplayEnabled) {
1236 // No point choosing a rotation if the display is not enabled.
1237 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1238 return false;
1239 }
1240
1241 final int oldRotation = mRotation;
1242 final int lastOrientation = mLastOrientation;
1243 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001244 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001245 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1246 + mDisplayId + " based on lastOrientation=" + lastOrientation
1247 + " and oldRotation=" + oldRotation);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001248 boolean mayRotateSeamlessly = mDisplayPolicy.shouldRotateSeamlessly(mDisplayRotation,
Riddle Hsuad256a12018-07-18 16:11:30 +08001249 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001250
Robert Carr0e007272017-10-02 13:00:55 -07001251 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001252 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001253 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001254 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1255 // to complete (that is, waiting for windows to redraw). It's tempting to check
1256 // w.mSeamlessRotationCount but that could be incorrect in the case of
1257 // window-removal.
1258 return false;
1259 }
Robert Carr0e007272017-10-02 13:00:55 -07001260
1261 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001262 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001263 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001264 mayRotateSeamlessly = false;
1265 }
1266 for (int i = 0; i < mService.mSessions.size(); i++) {
1267 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1268 mayRotateSeamlessly = false;
1269 break;
1270 }
1271 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001272 }
Robert Carr0e007272017-10-02 13:00:55 -07001273 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001274
1275 // TODO: Implement forced rotation changes.
1276 // Set mAltOrientation to indicate that the application is receiving
1277 // an orientation that has different metrics than it expected.
1278 // eg. Portrait instead of Landscape.
1279
Riddle Hsuad256a12018-07-18 16:11:30 +08001280 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001281 lastOrientation, rotation);
1282
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001283 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1284 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001285 + ", got rotation " + rotation + " which has "
1286 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1287
1288 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1289 // No change.
1290 return false;
1291 }
1292
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001293 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1294 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001295 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1296 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1297
1298 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
Vishnu Nairba183352018-11-21 11:16:49 -08001299 mWaitingForConfig = true;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001300 }
1301
Evan Roskye747c3e2018-10-30 20:06:41 -07001302 mRotation = rotation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001303 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001304
1305 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
Riddle Hsu654a6f92018-07-13 22:59:36 +08001306 mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1307 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001308
1309 setLayoutNeeded();
1310 final int[] anim = new int[2];
Tiger Huang7c610aa2018-10-27 00:01:01 +08001311 mDisplayPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001312
1313 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001314 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001315 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001316 } else {
1317 // The screen rotation animation uses a screenshot to freeze the screen
1318 // while windows resize underneath.
1319 // When we are rotating seamlessly, we allow the elements to transition
1320 // to their rotated state independently and without a freeze required.
Robert Carrefc75702018-02-16 11:46:16 -08001321 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001322 }
1323
Evan Roskye747c3e2018-10-30 20:06:41 -07001324 return true;
1325 }
1326
1327 /**
1328 * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked}
1329 * (if it returned {@code true}) to actually finish the rotation.
1330 *
1331 * @param oldRotation the rotation we are coming from.
1332 * @param rotation the rotation to apply.
1333 */
1334 void applyRotationLocked(final int oldRotation, final int rotation) {
1335 mDisplayRotation.setRotation(rotation);
1336 final boolean rotateSeamlessly = mService.isRotatingSeamlessly();
1337 ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly
1338 ? null : mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001339 // We need to update our screen size information to match the new rotation. If the rotation
1340 // has actually changed then this method will return true and, according to the comment at
1341 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1342 // By updating the Display info here it will be available to
1343 // #computeScreenConfiguration() later.
1344 updateDisplayAndOrientation(getConfiguration().uiMode);
1345
Robert Carrae606b42018-02-15 15:36:23 -08001346 // NOTE: We disable the rotation in the emulator because
1347 // it doesn't support hardware OpenGL emulation yet.
1348 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1349 && screenRotationAnimation.hasScreenshot()) {
1350 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1351 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1352 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1353 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001354 }
1355 }
1356
Vishnu Nair83537a72018-07-19 21:27:48 -07001357 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001358 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1359 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001360 }, true /* traverseTopToBottom */);
1361
Robert Carrae606b42018-02-15 15:36:23 -08001362 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1363 scheduleAnimation();
1364
Andrii Kulian06d07d62017-03-14 11:11:47 -07001365 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001366 if (w.mHasSurface && !rotateSeamlessly) {
1367 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001368 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001369 mService.mRoot.mOrientationChangeComplete = false;
1370 w.mLastFreezeDuration = 0;
1371 }
1372 w.mReportOrientationChanged = true;
1373 }, true /* traverseTopToBottom */);
1374
1375 if (rotateSeamlessly) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001376 mService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1377 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001378 }
1379
1380 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1381 final WindowManagerService.RotationWatcher rotationWatcher
1382 = mService.mRotationWatchers.get(i);
1383 if (rotationWatcher.mDisplayId == mDisplayId) {
1384 try {
1385 rotationWatcher.mWatcher.onRotationChanged(rotation);
1386 } catch (RemoteException e) {
1387 // Ignore
1388 }
1389 }
1390 }
1391
1392 // TODO (multi-display): Magnification is supported only for the default display.
1393 // Announce rotation only if we will not animate as we already have the
1394 // windows in final state. Otherwise, we make this call at the rotation end.
1395 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1396 && isDefaultDisplay) {
1397 mService.mAccessibilityController.onRotationChangedLocked(this);
1398 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001399 }
1400
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001401 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001402 final int width = mBaseDisplayWidth;
1403 final int height = mBaseDisplayHeight;
1404 final int shortSize;
1405 final int longSize;
1406 if (width > height) {
1407 shortSize = height;
1408 longSize = width;
1409 } else {
1410 shortSize = width;
1411 longSize = height;
1412 }
1413
1414 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1415 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1416
1417 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1418 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001419
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001420 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1421 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Arthur Hungbe5ce212018-09-13 18:41:56 +08001422
1423 // Tap Listeners are supported for:
1424 // 1. All physical displays (multi-display).
1425 // 2. VirtualDisplays on VR, AA (and everything else).
1426 if (mPointerEventDispatcher != null && mTapDetector == null) {
1427 if (DEBUG_DISPLAY) {
1428 Slog.d(TAG,
1429 "Registering PointerEventListener for DisplayId: " + mDisplayId);
1430 }
1431 mTapDetector = new TaskTapPointerEventListener(mService, this);
1432 registerPointerEventListener(mTapDetector);
1433 registerPointerEventListener(mService.mMousePositionTracker);
1434 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001435 }
1436
Andrii Kulian06d07d62017-03-14 11:11:47 -07001437 /**
1438 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1439 * changed.
1440 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1441 */
1442 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1443 // Use the effective "visual" dimensions based on current rotation
1444 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1445 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1446 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1447 int dw = realdw;
1448 int dh = realdh;
1449
1450 if (mAltOrientation) {
1451 if (realdw > realdh) {
1452 // Turn landscape into portrait.
1453 int maxw = (int)(realdh/1.3f);
1454 if (maxw < realdw) {
1455 dw = maxw;
1456 }
1457 } else {
1458 // Turn portrait into landscape.
1459 int maxh = (int)(realdw/1.3f);
1460 if (maxh < realdh) {
1461 dh = maxh;
1462 }
1463 }
1464 }
1465
1466 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001467 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1468 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1469
Tiger Huang7c610aa2018-10-27 00:01:01 +08001470 final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1471 displayCutout);
1472 final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1473 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001474 mDisplayInfo.rotation = mRotation;
1475 mDisplayInfo.logicalWidth = dw;
1476 mDisplayInfo.logicalHeight = dh;
1477 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1478 mDisplayInfo.appWidth = appWidth;
1479 mDisplayInfo.appHeight = appHeight;
1480 if (isDefaultDisplay) {
1481 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1482 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1483 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001484 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001485 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1486 if (mDisplayScalingDisabled) {
1487 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1488 } else {
1489 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1490 }
1491
Andrii Kulianf0379de2018-03-14 16:24:07 -07001492 // We usually set the override info in DisplayManager so that we get consistent display
1493 // metrics values when displays are changing and don't send out new values until WM is aware
1494 // of them. However, we don't do this for displays that serve as containers for ActivityView
1495 // because we don't want letter-/pillar-boxing during resize.
1496 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1497 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001498 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001499 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001500
1501 mBaseDisplayRect.set(0, 0, dw, dh);
1502
1503 if (isDefaultDisplay) {
1504 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1505 mCompatDisplayMetrics);
1506 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001507
Andrii Kulian06d07d62017-03-14 11:11:47 -07001508 return mDisplayInfo;
1509 }
1510
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001511 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001512 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1513 }
1514
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001515 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001516 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001517 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001518 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001519 }
Adrian Roos11c25582018-02-19 18:06:36 +01001520 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001521 return WmDisplayCutout.computeSafeInsets(
1522 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001523 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001524 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Issei Suzuki43190bd2018-08-20 17:28:41 +02001525 final Rect[] newBounds = mRotationUtil.getRotatedBounds(
1526 WmDisplayCutout.computeSafeInsets(
Jorim Jaggi60640512018-06-29 01:14:31 +02001527 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
Issei Suzuki43190bd2018-08-20 17:28:41 +02001528 .getDisplayCutout().getBoundingRectsAll(),
1529 rotation, mInitialDisplayWidth, mInitialDisplayHeight);
1530 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds),
Adrian Roos24264212018-02-19 16:26:15 +01001531 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1532 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001533 }
1534
Andrii Kulian06d07d62017-03-14 11:11:47 -07001535 /**
1536 * Compute display configuration based on display properties and policy settings.
1537 * Do not call if mDisplayReady == false.
1538 */
1539 void computeScreenConfiguration(Configuration config) {
1540 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
Evan Roskye747c3e2018-10-30 20:06:41 -07001541 calculateBounds(displayInfo, mTmpBounds);
1542 config.windowConfiguration.setBounds(mTmpBounds);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001543
1544 final int dw = displayInfo.logicalWidth;
1545 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001546 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001547 config.windowConfiguration.setWindowingMode(getWindowingMode());
Evan Roskye747c3e2018-10-30 20:06:41 -07001548 config.windowConfiguration.setRotation(displayInfo.rotation);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001549
Adrian Roos11c25582018-02-19 18:06:36 +01001550 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001551 config.screenWidthDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001552 (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1553 config.uiMode, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001554 config.screenHeightDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001555 (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1556 config.uiMode, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001557
Tiger Huang7c610aa2018-10-27 00:01:01 +08001558 mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001559 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001560 final int leftInset = mTmpRect.left;
1561 final int topInset = mTmpRect.top;
1562 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001563 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1564 leftInset + displayInfo.appWidth /* right */,
1565 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001566 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1567 || displayInfo.rotation == Surface.ROTATION_270);
1568
Tiger Huang7c610aa2018-10-27 00:01:01 +08001569 computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh, density,
1570 config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001571
1572 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1573 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1574 ? Configuration.SCREENLAYOUT_ROUND_YES
1575 : Configuration.SCREENLAYOUT_ROUND_NO);
1576
1577 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1578 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1579 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001580 dh, displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001581 config.densityDpi = displayInfo.logicalDensityDpi;
1582
1583 config.colorMode =
Chia-I Wuf739bad2018-05-09 12:36:57 -07001584 ((displayInfo.isHdr() && mService.hasHdrSupport())
Andrii Kulian06d07d62017-03-14 11:11:47 -07001585 ? Configuration.COLOR_MODE_HDR_YES
1586 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001587 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001588 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1589 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1590
1591 // Update the configuration based on available input devices, lid switch,
1592 // and platform configuration.
1593 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1594 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1595 config.navigation = Configuration.NAVIGATION_NONAV;
1596
1597 int keyboardPresence = 0;
1598 int navigationPresence = 0;
1599 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1600 final int len = devices != null ? devices.length : 0;
1601 for (int i = 0; i < len; i++) {
1602 InputDevice device = devices[i];
1603 if (!device.isVirtual()) {
1604 final int sources = device.getSources();
1605 final int presenceFlag = device.isExternal() ?
1606 WindowManagerPolicy.PRESENCE_EXTERNAL :
1607 WindowManagerPolicy.PRESENCE_INTERNAL;
1608
1609 // TODO(multi-display): Configure on per-display basis.
1610 if (mService.mIsTouchDevice) {
1611 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1612 InputDevice.SOURCE_TOUCHSCREEN) {
1613 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1614 }
1615 } else {
1616 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1617 }
1618
1619 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1620 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1621 navigationPresence |= presenceFlag;
1622 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1623 && config.navigation == Configuration.NAVIGATION_NONAV) {
1624 config.navigation = Configuration.NAVIGATION_DPAD;
1625 navigationPresence |= presenceFlag;
1626 }
1627
1628 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1629 config.keyboard = Configuration.KEYBOARD_QWERTY;
1630 keyboardPresence |= presenceFlag;
1631 }
1632 }
1633 }
1634
1635 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1636 config.navigation = Configuration.NAVIGATION_DPAD;
1637 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1638 }
1639
1640 // Determine whether a hard keyboard is available and enabled.
1641 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1642 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1643 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1644 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1645 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1646 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1647 }
1648
Tiger Huang7c610aa2018-10-27 00:01:01 +08001649 mDisplayPolicy.updateConfigurationDependentBehaviors();
1650
Andrii Kulian06d07d62017-03-14 11:11:47 -07001651 // Let the policy update hidden states.
1652 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1653 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1654 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1655 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1656 }
1657
1658 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001659 DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001660 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1661 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1662 final int unrotDw, unrotDh;
1663 if (rotated) {
1664 unrotDw = dh;
1665 unrotDh = dw;
1666 } else {
1667 unrotDw = dw;
1668 unrotDh = dh;
1669 }
1670 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001671 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001672 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001673 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001674 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001675 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001676 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001677 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001678 return sw;
1679 }
1680
1681 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001682 DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) {
1683 dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1684 displayCutout);
1685 dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode,
1686 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001687 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1688 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1689 if (curSize == 0 || size < curSize) {
1690 curSize = size;
1691 }
1692 return curSize;
1693 }
1694
Tiger Huang7c610aa2018-10-27 00:01:01 +08001695 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
1696 int uiMode, int dw, int dh, float density, Configuration outConfig) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001697
1698 // We need to determine the smallest width that will occur under normal
1699 // operation. To this, start with the base screen size and compute the
1700 // width under the different possible rotations. We need to un-rotate
1701 // the current screen dimensions before doing this.
1702 int unrotDw, unrotDh;
1703 if (rotated) {
1704 unrotDw = dh;
1705 unrotDh = dw;
1706 } else {
1707 unrotDw = dw;
1708 unrotDh = dh;
1709 }
1710 displayInfo.smallestNominalAppWidth = 1<<30;
1711 displayInfo.smallestNominalAppHeight = 1<<30;
1712 displayInfo.largestNominalAppWidth = 0;
1713 displayInfo.largestNominalAppHeight = 0;
Tiger Huang7c610aa2018-10-27 00:01:01 +08001714 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh);
1715 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw);
1716 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh);
1717 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001718 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1719 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001720 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001721 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001722 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001723 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001724 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001725 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001726 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001727 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1728 outConfig.screenLayout = sl;
1729 }
1730
1731 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001732 int uiMode, DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001733 // Get the app screen size at this rotation.
Tiger Huang7c610aa2018-10-27 00:01:01 +08001734 int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout);
1735 int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001736
1737 // Compute the screen layout size class for this rotation.
1738 int longSize = w;
1739 int shortSize = h;
1740 if (longSize < shortSize) {
1741 int tmp = longSize;
1742 longSize = shortSize;
1743 shortSize = tmp;
1744 }
1745 longSize = (int)(longSize/density);
1746 shortSize = (int)(shortSize/density);
1747 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1748 }
1749
Tiger Huang7c610aa2018-10-27 00:01:01 +08001750 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001751 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001752 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1753 rotation).getDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +08001754 final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1755 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001756 if (width < displayInfo.smallestNominalAppWidth) {
1757 displayInfo.smallestNominalAppWidth = width;
1758 }
1759 if (width > displayInfo.largestNominalAppWidth) {
1760 displayInfo.largestNominalAppWidth = width;
1761 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001762 final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1763 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001764 if (height < displayInfo.smallestNominalAppHeight) {
1765 displayInfo.smallestNominalAppHeight = height;
1766 }
1767 if (height > displayInfo.largestNominalAppHeight) {
1768 displayInfo.largestNominalAppHeight = height;
1769 }
1770 }
1771
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001772 /**
1773 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1774 * theme attribute) on devices that feature a physical options menu key attempt to position
1775 * their menu panel window along the edge of the screen nearest the physical menu key.
1776 * This lowers the travel distance between invoking the menu panel and selecting
1777 * a menu option.
1778 *
1779 * This method helps control where that menu is placed. Its current implementation makes
1780 * assumptions about the menu key and its relationship to the screen based on whether
1781 * the device's natural orientation is portrait (width < height) or landscape.
1782 *
1783 * The menu key is assumed to be located along the bottom edge of natural-portrait
1784 * devices and along the right edge of natural-landscape devices. If these assumptions
1785 * do not hold for the target device, this method should be changed to reflect that.
1786 *
1787 * @return A {@link Gravity} value for placing the options menu window.
1788 */
1789 int getPreferredOptionsPanelGravity() {
1790 final int rotation = getRotation();
1791 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1792 // On devices with a natural orientation of portrait.
1793 switch (rotation) {
1794 default:
1795 case Surface.ROTATION_0:
1796 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1797 case Surface.ROTATION_90:
1798 return Gravity.RIGHT | Gravity.BOTTOM;
1799 case Surface.ROTATION_180:
1800 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1801 case Surface.ROTATION_270:
1802 return Gravity.START | Gravity.BOTTOM;
1803 }
1804 }
1805
1806 // On devices with a natural orientation of landscape.
1807 switch (rotation) {
1808 default:
1809 case Surface.ROTATION_0:
1810 return Gravity.RIGHT | Gravity.BOTTOM;
1811 case Surface.ROTATION_90:
1812 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1813 case Surface.ROTATION_180:
1814 return Gravity.START | Gravity.BOTTOM;
1815 case Surface.ROTATION_270:
1816 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1817 }
1818 }
1819
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001820 DockedStackDividerController getDockedDividerController() {
1821 return mDividerControllerLocked;
1822 }
1823
Winson Chung655332c2016-10-31 13:14:28 -07001824 PinnedStackController getPinnedStackController() {
1825 return mPinnedStackControllerLocked;
1826 }
1827
Jeff Browna506a6e2013-06-04 00:02:38 -07001828 /**
1829 * Returns true if the specified UID has access to this display.
1830 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001831 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001832 return mDisplay.hasAccess(uid);
1833 }
1834
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001835 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001836 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001837 }
1838
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001839 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001840 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001841 }
1842
Wale Ogunwale61911492017-10-11 08:50:50 -07001843 /**
1844 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1845 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001846 TaskStack getSplitScreenPrimaryStack() {
1847 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001848 return (stack != null && stack.isVisible()) ? stack : null;
1849 }
1850
Robert Carr9785cf32018-04-25 15:06:07 -07001851 boolean hasSplitScreenPrimaryStack() {
1852 return getSplitScreenPrimaryStack() != null;
1853 }
1854
Wale Ogunwale61911492017-10-11 08:50:50 -07001855 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001856 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001857 * not visible.
1858 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001859 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1860 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001861 }
1862
1863 TaskStack getPinnedStack() {
1864 return mTaskStackContainers.getPinnedStack();
1865 }
1866
1867 private boolean hasPinnedStack() {
1868 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001869 }
1870
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001871 /**
1872 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1873 * Null is no compatible stack on the display.
1874 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001875 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001876 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1877 }
1878
1879 /**
1880 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1881 * activity type. Null is no compatible stack on the display.
1882 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001883 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001884 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001885 }
1886
Bryce Lee48f4b572017-04-10 10:54:15 -07001887 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001888 WindowList<TaskStack> getStacks() {
1889 return mTaskStackContainers.mChildren;
1890 }
1891
1892 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001893 TaskStack getTopStack() {
1894 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001895 }
1896
Winson Chunge2d72172018-01-25 17:46:20 +00001897 ArrayList<Task> getVisibleTasks() {
1898 return mTaskStackContainers.getVisibleTasks();
1899 }
1900
Wale Ogunwale61911492017-10-11 08:50:50 -07001901 void onStackWindowingModeChanged(TaskStack stack) {
1902 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001903 }
1904
Andrii Kulian441e4492016-09-29 15:25:00 -07001905 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001906 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001907 super.onConfigurationChanged(newParentConfig);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001908 if (mDisplayPolicy != null) {
1909 mDisplayPolicy.onConfigurationChanged();
1910 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001911
Evan Roskye747c3e2018-10-30 20:06:41 -07001912 // If there was no pinned stack, we still need to notify the controller of the display info
1913 // update as a result of the config change.
1914 if (mPinnedStackControllerLocked != null && !hasPinnedStack()) {
1915 mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo());
1916 }
Evan Roskye747c3e2018-10-30 20:06:41 -07001917 }
1918
1919 /**
1920 * Updates the resources used by docked/pinned controllers. This needs to be called at the
1921 * beginning of a configuration update cascade since the metrics from these resources are used
1922 * for bounds calculations. Since ActivityDisplay initiates the configuration update, this
1923 * should be called from there instead of DisplayContent's onConfigurationChanged.
1924 */
1925 void preOnConfigurationChanged() {
Bryce Leef3c6a472017-11-14 14:53:06 -08001926 final DockedStackDividerController dividerController = getDockedDividerController();
1927
1928 if (dividerController != null) {
1929 getDockedDividerController().onConfigurationChanged();
1930 }
1931
1932 final PinnedStackController pinnedStackController = getPinnedStackController();
1933
1934 if (pinnedStackController != null) {
1935 getPinnedStackController().onConfigurationChanged();
1936 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001937 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001938
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001939 @Override
1940 boolean fillsParent() {
1941 return true;
1942 }
1943
1944 @Override
1945 boolean isVisible() {
1946 return true;
1947 }
1948
1949 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001950 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001951 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001952 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001953 }
1954
Robert Carr9785cf32018-04-25 15:06:07 -07001955 /**
1956 * In split-screen mode we process the IME containers above the docked divider
1957 * rather than directly above their target.
1958 */
1959 private boolean skipTraverseChild(WindowContainer child) {
lumarkff0ab692018-11-05 20:32:30 +08001960 if (child == mImeWindowsContainers && mInputMethodTarget != null
Robert Carr9785cf32018-04-25 15:06:07 -07001961 && !hasSplitScreenPrimaryStack()) {
1962 return true;
1963 }
1964 return false;
1965 }
1966
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001967 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001968 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1969 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1970 // target, or here in order if there isn't an IME target.
1971 if (traverseTopToBottom) {
1972 for (int i = mChildren.size() - 1; i >= 0; --i) {
1973 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001974 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001975 continue;
1976 }
Robert Carr9785cf32018-04-25 15:06:07 -07001977
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001978 if (child.forAllWindows(callback, traverseTopToBottom)) {
1979 return true;
1980 }
1981 }
1982 } else {
1983 final int count = mChildren.size();
1984 for (int i = 0; i < count; i++) {
1985 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001986 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001987 continue;
1988 }
Robert Carr9785cf32018-04-25 15:06:07 -07001989
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001990 if (child.forAllWindows(callback, traverseTopToBottom)) {
1991 return true;
1992 }
1993 }
1994 }
1995 return false;
1996 }
1997
1998 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1999 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
2000 }
2001
Wale Ogunwale399c8692017-05-08 14:22:42 -07002002 @Override
2003 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002004 final WindowManagerPolicy policy = mService.mPolicy;
2005
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002006 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08002007 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002008 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2009 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002010 // If the display is frozen, some activities may be in the middle of restarting, and
2011 // thus have removed their old window. If the window has the flag to hide the lock
2012 // screen, then the lock screen can re-appear and inflict its own orientation on us.
2013 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002014 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002015 } else if (policy.isKeyguardLocked()) {
2016 // Use the last orientation the while the display is frozen with the keyguard
2017 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
2018 // window. We don't want to check the show when locked window directly though as
2019 // things aren't stable while the display is frozen, for example the window could be
2020 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002021 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2022 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08002023 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07002024 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002025 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002026 final int orientation = mAboveAppWindowsContainers.getOrientation();
2027 if (orientation != SCREEN_ORIENTATION_UNSET) {
2028 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002029 }
Wale Ogunwale51362492016-09-08 17:49:17 -07002030 }
2031
Wale Ogunwale399c8692017-05-08 14:22:42 -07002032 // Top system windows are not requesting an orientation. Start searching from apps.
2033 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07002034 }
2035
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002036 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07002037 // Check if display metrics changed and update base values if needed.
2038 updateBaseDisplayMetricsIfNeeded();
2039
Craig Mautner722285e2012-09-07 13:55:58 -07002040 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07002041 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07002042
Garfield Tan2f145f22018-11-01 15:27:03 -07002043 onDisplayChanged(this);
Craig Mautner722285e2012-09-07 13:55:58 -07002044 }
2045
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002046 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002047 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
2048 if (displayManagerInternal != null) {
2049 // Bootstrap the default logical display from the display manager.
2050 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
2051 if (newDisplayInfo != null) {
2052 mDisplayInfo.copyFrom(newDisplayInfo);
2053 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002054 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002055
Andrii Kuliancd097992017-03-23 18:31:59 -07002056 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
2057 mDisplayInfo.logicalDensityDpi);
2058 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
2059 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
2060 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002061 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002062 }
2063
Andrii Kuliancd097992017-03-23 18:31:59 -07002064 /**
2065 * If display metrics changed, overrides are not set and it's not just a rotation - update base
2066 * values.
2067 */
2068 private void updateBaseDisplayMetricsIfNeeded() {
2069 // Get real display metrics without overrides from WM.
2070 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
2071 final int orientation = mDisplayInfo.rotation;
2072 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2073 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
2074 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
2075 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002076 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002077
2078 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
2079 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01002080 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
2081 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07002082
2083 if (displayMetricsChanged) {
2084 // Check if display size or density is forced.
2085 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
2086 || mBaseDisplayHeight != mInitialDisplayHeight;
2087 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
2088
2089 // If there is an override set for base values - use it, otherwise use new values.
2090 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
2091 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
2092 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
2093
2094 // Real display metrics changed, so we should also update initial values.
2095 mInitialDisplayWidth = newWidth;
2096 mInitialDisplayHeight = newHeight;
2097 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01002098 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002099 mService.reconfigureDisplayLocked(this);
2100 }
2101 }
2102
Bryce Lee27cec322017-03-21 09:41:37 -07002103 /** Sets the maximum width the screen resolution can be */
2104 void setMaxUiWidth(int width) {
2105 if (DEBUG_DISPLAY) {
2106 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
2107 }
2108
2109 mMaxUiWidth = width;
2110
2111 // Update existing metrics.
2112 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
2113 }
2114
2115 /** Update base (override) display metrics. */
2116 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
2117 mBaseDisplayWidth = baseWidth;
2118 mBaseDisplayHeight = baseHeight;
2119 mBaseDisplayDensity = baseDensity;
2120
2121 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
2122 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
2123 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
2124 mBaseDisplayWidth = mMaxUiWidth;
2125
2126 if (DEBUG_DISPLAY) {
2127 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
2128 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
2129 + " on display:" + getDisplayId());
2130 }
2131 }
2132
2133 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08002134
2135 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07002136 }
2137
Riddle Hsuf53da812018-08-15 22:00:27 +08002138 /**
2139 * Forces this display to use the specified density.
2140 *
2141 * @param density The density in DPI to use. If the value equals to initial density, the setting
2142 * will be cleared.
2143 * @param userId The target user to apply. Only meaningful when this is default display. If the
2144 * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings
2145 * so only need to configure display.
2146 */
2147 void setForcedDensity(int density, int userId) {
2148 final boolean clear = density == mInitialDisplayDensity;
2149 final boolean updateCurrent = userId == UserHandle.USER_CURRENT;
2150 if (mService.mCurrentUserId == userId || updateCurrent) {
2151 mBaseDisplayDensity = density;
2152 mService.reconfigureDisplayLocked(this);
2153 }
2154 if (updateCurrent) {
2155 // We are applying existing settings so no need to save it again.
2156 return;
2157 }
2158
2159 if (density == mInitialDisplayDensity) {
2160 density = 0;
2161 }
Chilun8753ad32018-10-09 15:56:45 +08002162 mService.mDisplayWindowSettings.setForcedDensity(this, density, userId);
Riddle Hsuf53da812018-08-15 22:00:27 +08002163 }
2164
2165 /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */
2166 void setForcedScalingMode(@ForceScalingMode int mode) {
2167 if (mode != FORCE_SCALING_MODE_DISABLED) {
2168 mode = FORCE_SCALING_MODE_AUTO;
2169 }
2170
2171 mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO);
2172 Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto"));
2173 mService.reconfigureDisplayLocked(this);
2174
Chilun8753ad32018-10-09 15:56:45 +08002175 mService.mDisplayWindowSettings.setForcedScalingMode(this, mode);
Riddle Hsuf53da812018-08-15 22:00:27 +08002176 }
2177
2178 /** If the given width and height equal to initial size, the setting will be cleared. */
2179 void setForcedSize(int width, int height) {
2180 final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height;
2181 if (!clear) {
2182 // Set some sort of reasonable bounds on the size of the display that we will try
2183 // to emulate.
2184 final int minSize = 200;
2185 final int maxScale = 2;
2186 width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale);
2187 height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale);
2188 }
2189
2190 Slog.i(TAG_WM, "Using new display size: " + width + "x" + height);
2191 updateBaseDisplayMetrics(width, height, mBaseDisplayDensity);
2192 mService.reconfigureDisplayLocked(this);
2193
2194 if (clear) {
2195 width = height = 0;
2196 }
Chilun8753ad32018-10-09 15:56:45 +08002197 mService.mDisplayWindowSettings.setForcedSize(this, width, height);
Riddle Hsuf53da812018-08-15 22:00:27 +08002198 }
2199
Wale Ogunwaledb506192017-12-08 10:57:32 -08002200 void getStableRect(Rect out) {
2201 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08002202 }
2203
Wale Ogunwale61911492017-10-11 08:50:50 -07002204 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002205 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
2206 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07002207
Wale Ogunwale61911492017-10-11 08:50:50 -07002208 final TaskStack stack = new TaskStack(mService, stackId, controller);
2209 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08002210 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07002211 }
2212
Andrii Kulian51c1b672017-04-07 18:39:32 -07002213 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002214 final DisplayContent prevDc = stack.getDisplayContent();
2215 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002216 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2217 + " which is not currently attached to any display");
2218 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002219 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002220 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2221 + " to its current displayId=" + mDisplayId);
2222 }
2223
lumark588a3e82018-07-20 18:53:54 +08002224 // Clean up all pending transitions when stack reparent to another display.
2225 stack.forAllAppWindows(AppWindowToken::removeFromPendingTransition);
2226
Wale Ogunwale61911492017-10-11 08:50:50 -07002227 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002228 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002229 }
2230
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002231 @Override
2232 protected void addChild(DisplayChildWindowContainer child,
2233 Comparator<DisplayChildWindowContainer> comparator) {
2234 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2235 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002236
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002237 @Override
2238 protected void addChild(DisplayChildWindowContainer child, int index) {
2239 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2240 }
2241
2242 @Override
2243 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002244 // Only allow removal of direct children from this display if the display is in the process
2245 // of been removed.
2246 if (mRemovingDisplay) {
2247 super.removeChild(child);
2248 return;
2249 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002250 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002251 }
2252
Andrii Kuliand2765632016-12-12 22:26:34 -08002253 @Override
2254 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2255 // Children of the display are statically ordered, so the real intention here is to perform
2256 // the operation on the display and not the static direct children.
2257 getParent().positionChildAt(position, this, includingParents);
2258 }
2259
Riddle Hsu57831b52018-07-27 00:31:48 +08002260 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2261 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002262 layoutAndAssignWindowLayersIfNeeded();
2263 }
2264
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002265 /**
2266 * Used to obtain task ID when user taps on coordinate (x, y) in this display, and outside
2267 * current task in focus.
2268 *
2269 * This returns the task ID of the foremost task at (x, y) if the task is not home. Otherwise it
2270 * returns -1.
2271 *
2272 * @param x horizontal coordinate of the tap position
2273 * @param y vertical coordinate of the tap position
2274 * @return the task ID if a non-home task is found; -1 if not
2275 */
2276 int taskForTapOutside(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002277 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2278 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002279 if (stack.isActivityTypeHome() && !stack.inMultiWindowMode()) {
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002280 // We skip not only home stack, but also everything behind home because user can't
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002281 // see them when home stack is isn't in multi-window mode.
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002282 break;
2283 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002284 final int taskId = stack.taskIdFromPoint(x, y);
2285 if (taskId != -1) {
2286 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002287 }
2288 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002289 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002290 }
2291
Chong Zhang8e89b312015-09-09 15:09:30 -07002292 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002293 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002294 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002295 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002296 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002297 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002298 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002299 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2300 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002301 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002302 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002303 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002304
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002305 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2306 if (mTmpTaskForResizePointSearchResult.searchDone) {
2307 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002308 }
2309 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002310 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002311 }
2312
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002313 void updateTouchExcludeRegion() {
2314 final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null);
David Stevensee9e2772017-02-09 16:30:27 -08002315 if (focusedTask == null) {
2316 mTouchExcludeRegion.setEmpty();
2317 } else {
2318 mTouchExcludeRegion.set(mBaseDisplayRect);
2319 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2320 mTmpRect2.setEmpty();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002321 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0;
2322 --stackNdx) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002323 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002324 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2325 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002326 }
2327 // If we removed the focused task above, add it back and only leave its
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002328 // outside touch area in the exclusion. TapDetector is not interested in
David Stevensee9e2772017-02-09 16:30:27 -08002329 // any touch inside the focused task itself.
2330 if (!mTmpRect2.isEmpty()) {
2331 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2332 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002333 }
lumark90120a82018-08-15 00:33:03 +08002334 if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) {
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002335 // If the input method is visible and the user is typing, we don't want these touch
2336 // events to be intercepted and used to change focus. This would likely cause a
2337 // disappearance of the input method.
lumark90120a82018-08-15 00:33:03 +08002338 mInputMethodWindow.getTouchableRegion(mTmpRegion);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002339 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002340 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002341 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002342 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002343 win.getTouchableRegion(mTmpRegion);
2344 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2345 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002346 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2347 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2348 win.amendTapExcludeRegion(mTouchExcludeRegion);
2349 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002350 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002351 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002352 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002353 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002354 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2355 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002356 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002357 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002358 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002359 }
2360
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002361 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002362 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002363 super.switchUser();
2364 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002365 }
2366
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002367 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002368 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2369 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002370 }
2371 }
2372
Wale Ogunwale10124582016-09-15 20:25:50 -07002373 @Override
2374 void removeIfPossible() {
2375 if (isAnimating()) {
2376 mDeferredRemoval = true;
2377 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002378 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002379 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002380 }
2381
Wale Ogunwale10124582016-09-15 20:25:50 -07002382 @Override
2383 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002384 mRemovingDisplay = true;
2385 try {
lumark588a3e82018-07-20 18:53:54 +08002386 // Clear all transitions & screen frozen states when removing display.
2387 mOpeningApps.clear();
2388 mClosingApps.clear();
2389 mUnknownAppVisibilityController.clear();
2390 mAppTransition.removeAppTransitionTimeoutCallbacks();
2391 handleAnimatingStoppedAndTransition();
2392 mService.stopFreezingDisplayLocked();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002393 super.removeImmediately();
2394 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002395 if (mPointerEventDispatcher != null && mTapDetector != null) {
2396 unregisterPointerEventListener(mTapDetector);
2397 unregisterPointerEventListener(mService.mMousePositionTracker);
2398 mTapDetector = null;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002399 }
Jorim Jaggia3844032018-01-03 15:54:43 +01002400 mService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002401 mWindowingLayer.release();
2402 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002403 } finally {
Riddle Hsu4e611772018-10-31 18:58:28 +08002404 mDisplayReady = false;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002405 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002406 }
Robert Carr679ccb02018-08-08 15:32:35 -07002407
Tiger Huang7c610aa2018-10-27 00:01:01 +08002408 mDisplayPolicy.onDisplayRemoved();
Riddle Hsuf53da812018-08-15 22:00:27 +08002409 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautner95da1082014-02-24 17:54:35 -08002410 }
2411
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002412 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002413 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002414 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002415 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2416
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002417 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002418 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002419 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002420 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002421 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002422 }
2423
Andrii Kulian0214ed92017-05-16 13:44:05 -07002424 /** @return 'true' if removal of this display content is deferred due to active animation. */
2425 boolean isRemovalDeferred() {
2426 return mDeferredRemoval;
2427 }
2428
Wale Ogunwale10124582016-09-15 20:25:50 -07002429 boolean animateForIme(float interpolatedValue, float animationTarget,
2430 float dividerAnimationTarget) {
2431 boolean updated = false;
2432
Wale Ogunwale61911492017-10-11 08:50:50 -07002433 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2434 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002435 if (stack == null || !stack.isAdjustedForIme()) {
2436 continue;
2437 }
2438
2439 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2440 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2441 updated = true;
2442 } else {
2443 mDividerControllerLocked.mLastAnimationProgress =
2444 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2445 mDividerControllerLocked.mLastDividerProgress =
2446 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2447 updated |= stack.updateAdjustForIme(
2448 mDividerControllerLocked.mLastAnimationProgress,
2449 mDividerControllerLocked.mLastDividerProgress,
2450 false /* force */);
2451 }
2452 if (interpolatedValue >= 1f) {
2453 stack.endImeAdjustAnimation();
2454 }
2455 }
2456
2457 return updated;
2458 }
2459
2460 boolean clearImeAdjustAnimation() {
2461 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002462 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2463 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002464 if (stack != null && stack.isAdjustedForIme()) {
2465 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2466 changed = true;
2467 }
2468 }
2469 return changed;
2470 }
2471
2472 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002473 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2474 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002475 if (stack.isVisible() && stack.isAdjustedForIme()) {
2476 stack.beginImeAdjustAnimation();
2477 }
2478 }
2479 }
2480
2481 void adjustForImeIfNeeded() {
lumark90120a82018-08-15 00:33:03 +08002482 final WindowState imeWin = mInputMethodWindow;
Wale Ogunwale10124582016-09-15 20:25:50 -07002483 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2484 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002485 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002486 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2487 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2488 imeTargetStack.getDockSide() : DOCKED_INVALID;
2489 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2490 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2491 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002492 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002493 final boolean imeHeightChanged = imeVisible &&
2494 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2495
2496 // The divider could be adjusted for IME position, or be thinner than usual,
2497 // or both. There are three possible cases:
2498 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2499 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2500 // - If IME is not visible, divider is not moved and is normal width.
2501
2502 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002503 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2504 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002505 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002506 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2507 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002508 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2509 } else {
2510 stack.resetAdjustedForIme(false);
2511 }
2512 }
2513 mDividerControllerLocked.setAdjustedForIme(
2514 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2515 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002516 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2517 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002518 stack.resetAdjustedForIme(!dockVisible);
2519 }
2520 mDividerControllerLocked.setAdjustedForIme(
2521 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2522 }
Winson Chung655332c2016-10-31 13:14:28 -07002523 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002524 }
2525
2526 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002527 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2528 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002529 stack.prepareFreezingTaskBounds();
2530 }
2531 }
2532
Wale Ogunwale94744212015-09-21 19:01:47 -07002533 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002534 getBounds(mTmpRect, newRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002535 rotateBounds(mTmpRect, oldRotation, newRotation, bounds);
2536 }
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002537
Evan Rosky39b6f232018-10-30 18:35:41 -07002538 void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002539 // Compute a transform matrix to undo the coordinate space transformation,
2540 // and present the window at the same physical position it previously occupied.
2541 final int deltaRotation = deltaRotation(newRotation, oldRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002542 createRotationMatrix(
2543 deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002544
2545 mTmpRectF.set(bounds);
2546 mTmpMatrix.mapRect(mTmpRectF);
2547 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002548 }
2549
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002550 static int deltaRotation(int oldRotation, int newRotation) {
2551 int delta = newRotation - oldRotation;
2552 if (delta < 0) delta += 4;
2553 return delta;
2554 }
2555
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002556 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002557 Matrix outMatrix) {
2558 // For rotations without Z-ordering we don't need the target rectangle's position.
2559 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2560 displayHeight, outMatrix);
2561 }
2562
2563 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2564 float displayWidth, float displayHeight, Matrix outMatrix) {
2565 switch (rotation) {
2566 case ROTATION_0:
2567 outMatrix.reset();
2568 break;
2569 case ROTATION_270:
2570 outMatrix.setRotate(270, 0, 0);
2571 outMatrix.postTranslate(0, displayHeight);
2572 outMatrix.postTranslate(rectTop, 0);
2573 break;
2574 case ROTATION_180:
2575 outMatrix.reset();
2576 break;
2577 case ROTATION_90:
2578 outMatrix.setRotate(90, 0, 0);
2579 outMatrix.postTranslate(displayWidth, 0);
2580 outMatrix.postTranslate(-rectTop, rectLeft);
2581 break;
2582 }
2583 }
2584
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002585 @CallSuper
2586 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002587 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002588 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002589 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002590 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002591 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2592 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002593 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002594 }
2595 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2596 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002597 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2598 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002599 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002600 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002601 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2602 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002603 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002604 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002605 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2606 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002607 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002608 }
2609 proto.write(DPI, mBaseDisplayDensity);
2610 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002611 proto.write(ROTATION, mRotation);
2612 final ScreenRotationAnimation screenRotationAnimation =
2613 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2614 if (screenRotationAnimation != null) {
2615 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2616 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002617 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
lumark588a3e82018-07-20 18:53:54 +08002618 mAppTransition.writeToProto(proto, APP_TRANSITION);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002619 if (mFocusedApp != null) {
2620 mFocusedApp.writeNameToProto(proto, FOCUSED_APP);
2621 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002622 proto.end(token);
2623 }
2624
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002625 @Override
2626 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2627 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002628 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2629 final String subPrefix = " " + prefix;
2630 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2631 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2632 pw.print("dpi");
2633 if (mInitialDisplayWidth != mBaseDisplayWidth
2634 || mInitialDisplayHeight != mBaseDisplayHeight
2635 || mInitialDisplayDensity != mBaseDisplayDensity) {
2636 pw.print(" base=");
2637 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2638 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2639 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002640 if (mDisplayScalingDisabled) {
2641 pw.println(" noscale");
2642 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002643 pw.print(" cur=");
2644 pw.print(mDisplayInfo.logicalWidth);
2645 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2646 pw.print(" app=");
2647 pw.print(mDisplayInfo.appWidth);
2648 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2649 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2650 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2651 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2652 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002653 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002654 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002655 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002656
Craig Mautnerdc548482014-02-05 13:35:24 -08002657 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002658 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002659 pw.print(prefix);
2660 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002661
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002662 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
2663 if (mLastFocus != mCurrentFocus) {
2664 pw.print(" mLastFocus="); pw.println(mLastFocus);
2665 }
2666 if (mLosingFocus.size() > 0) {
2667 pw.println();
2668 pw.println(" Windows losing focus:");
2669 for (int i = mLosingFocus.size() - 1; i >= 0; i--) {
2670 final WindowState w = mLosingFocus.get(i);
2671 pw.print(" Losing #"); pw.print(i); pw.print(' ');
2672 pw.print(w);
2673 if (dumpAll) {
2674 pw.println(":");
2675 w.dump(pw, " ", true);
2676 } else {
2677 pw.println();
2678 }
2679 }
2680 }
2681 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
Tiger Huang7c610aa2018-10-27 00:01:01 +08002682 if (mLastStatusBarVisibility != 0) {
2683 pw.print(" mLastStatusBarVisibility=0x");
2684 pw.println(Integer.toHexString(mLastStatusBarVisibility));
2685 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002686
Adrian Roos5251b1d2018-03-23 18:57:43 +01002687 pw.println();
wilsonshihc32538e2018-11-07 17:27:34 +08002688 mWallpaperController.dump(pw, " ");
2689
2690 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002691 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002692 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2693 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002694 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002695 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002696
Craig Mautnerdc548482014-02-05 13:35:24 -08002697 pw.println();
2698 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002699 pw.println();
2700 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002701 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002702 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002703 pw.print(" Exiting #"); pw.print(i);
2704 pw.print(' '); pw.print(token);
2705 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002706 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002707 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002708 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002709
Jorim Jaggi31f71702016-05-04 16:43:04 -07002710 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002711
2712 // Dump stack references
2713 final TaskStack homeStack = getHomeStack();
2714 if (homeStack != null) {
2715 pw.println(prefix + "homeStack=" + homeStack.getName());
2716 }
2717 final TaskStack pinnedStack = getPinnedStack();
2718 if (pinnedStack != null) {
2719 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2720 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002721 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002722 if (splitScreenPrimaryStack != null) {
2723 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2724 }
2725
2726 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002727 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002728 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002729 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002730
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002731 pw.println();
2732 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002733 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002734 mDisplayPolicy.dump(prefix, pw);
2735 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002736 mDisplayRotation.dump(prefix, pw);
2737 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002738 mInputMonitor.dump(pw, " ");
Jorim Jaggif96c90a2018-09-26 16:55:15 +02002739 pw.println();
2740 mInsetsStateController.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002741 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002742
2743 @Override
2744 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002745 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002746 }
2747
2748 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002749 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002750 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002751
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002752 /** Returns true if the stack in the windowing mode is visible. */
2753 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002754 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002755 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002756 }
2757
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002758 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002759 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002760 final int x = (int) xf;
2761 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002762 final WindowState touchedWin = getWindow(w -> {
2763 final int flags = w.mAttrs.flags;
2764 if (!w.isVisibleLw()) {
2765 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002766 }
2767 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002768 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002769 }
2770
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002771 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002772 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002773 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002774 }
2775
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002776 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002777
2778 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002779 return mTmpRegion.contains(x, y) || touchFlags == 0;
2780 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002781
2782 return touchedWin;
2783 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002784
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002785 boolean canAddToastWindowForUid(int uid) {
2786 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002787 // Also if the app is focused adding more than one toast at
2788 // a time for better backwards compatibility.
2789 final WindowState focusedWindowForUid = getWindow(w ->
2790 w.mOwnerUid == uid && w.isFocused());
2791 if (focusedWindowForUid != null) {
2792 return true;
2793 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002794 final WindowState win = getWindow(w ->
2795 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2796 && !w.mWindowRemovalAllowed);
2797 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002798 }
2799
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002800 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002801 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2802 return;
2803 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002804
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002805 // Used to communicate the old focus to the callback method.
2806 mTmpWindow = oldFocus;
2807
2808 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002809 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002810
2811 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002812 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002813
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002814 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002815
2816 if (mTmpWindow == null) {
2817 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2818 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002819 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002820 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002821 }
2822
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002823
2824 /**
2825 * Update the focused window and make some adjustments if the focus has changed.
2826 *
2827 * @param mode Indicates the situation we are in. Possible modes are:
2828 * {@link WindowManagerService#UPDATE_FOCUS_NORMAL},
2829 * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES},
2830 * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES},
2831 * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS}
2832 * @param updateInputWindows Whether to sync the window information to the input module.
2833 * @return {@code true} if the focused window has changed.
2834 */
2835 boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, boolean focusFound) {
2836 final WindowState newFocus = findFocusedWindow();
2837 if (mCurrentFocus == newFocus) {
2838 return false;
2839 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002840 boolean imWindowChanged = false;
2841 // TODO (b/111080190): Multi-Session IME
2842 if (!focusFound) {
2843 final WindowState imWindow = mInputMethodWindow;
2844 if (imWindow != null) {
lumarkff0ab692018-11-05 20:32:30 +08002845 final WindowState prevTarget = mInputMethodTarget;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002846
2847 final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/);
2848 imWindowChanged = prevTarget != newTarget;
2849
2850 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
2851 && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2852 assignWindowLayers(false /* setLayoutNeeded */);
2853 }
2854 }
2855 }
2856
2857 if (imWindowChanged) {
2858 mService.mWindowsChanged = true;
2859 setLayoutNeeded();
2860 }
2861
2862 if (DEBUG_FOCUS_LIGHT || mService.localLOGV) Slog.v(TAG_WM, "Changing focus from "
2863 + mCurrentFocus + " to " + newFocus + " displayId=" + getDisplayId()
2864 + " Callers=" + Debug.getCallers(4));
2865 final WindowState oldFocus = mCurrentFocus;
2866 mCurrentFocus = newFocus;
2867 mLosingFocus.remove(newFocus);
2868
2869 if (newFocus != null) {
2870 mWinAddedSinceNullFocus.clear();
2871 mWinRemovedSinceNullFocus.clear();
2872
2873 if (newFocus.canReceiveKeys()) {
2874 // Displaying a window implicitly causes dispatching to be unpaused.
2875 // This is to protect against bugs if someone pauses dispatching but
2876 // forgets to resume.
2877 newFocus.mToken.paused = false;
2878 }
2879 }
2880
Tiger Huang7c610aa2018-10-27 00:01:01 +08002881 int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002882
2883 if (imWindowChanged && oldFocus != mInputMethodWindow) {
2884 // Focus of the input method window changed. Perform layout if needed.
2885 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2886 performLayout(true /*initial*/, updateInputWindows);
2887 focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT;
2888 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2889 // Client will do the layout, but we need to assign layers
2890 // for handleNewWindowLocked() below.
2891 assignWindowLayers(false /* setLayoutNeeded */);
2892 }
2893 }
2894
2895 if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2896 // The change in focus caused us to need to do a layout. Okay.
2897 setLayoutNeeded();
2898 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2899 performLayout(true /*initial*/, updateInputWindows);
2900 } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) {
2901 mService.mRoot.performSurfacePlacement(false);
2902 }
2903 }
2904
2905 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
2906 // If we defer assigning layers, then the caller is responsible for doing this part.
2907 getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
2908 }
2909
2910 adjustForImeIfNeeded();
2911
2912 // We may need to schedule some toast windows to be removed. The toasts for an app that
2913 // does not have input focus are removed within a timeout to prevent apps to redress
2914 // other apps' UI.
2915 scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus);
2916
2917 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2918 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2919 }
2920 return true;
2921 }
2922
2923 /**
2924 * Set the new focused app to this display.
2925 *
2926 * @param newFocus the new focused AppWindowToken.
2927 * @return true if the focused app is changed.
2928 */
2929 boolean setFocusedApp(AppWindowToken newFocus) {
2930 if (newFocus != null) {
2931 final DisplayContent appDisplay = newFocus.getDisplayContent();
2932 if (appDisplay != this) {
2933 throw new IllegalStateException(newFocus + " is not on " + getName()
2934 + " but " + ((appDisplay != null) ? appDisplay.getName() : "none"));
2935 }
2936 }
2937 if (mFocusedApp == newFocus) {
2938 return false;
2939 }
2940 mFocusedApp = newFocus;
2941 getInputMonitor().setFocusedAppLw(newFocus);
2942 updateTouchExcludeRegion();
2943 return true;
2944 }
2945
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002946 /** Updates the layer assignment of windows on this display. */
2947 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002948 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002949 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002950 if (setLayoutNeeded) {
2951 setLayoutNeeded();
2952 }
Robert Carrb1579c82017-09-05 14:54:47 -07002953
Robert Carrf59b8dd2017-10-02 18:58:36 -07002954 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002955 // the application of this transaction until the animation pass triggers
2956 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2957 // the hiding and showing of surfaces.
2958 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002959 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002960 }
2961
Wale Ogunwale1666e312016-12-16 11:27:18 -08002962 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2963 // moving containers or resizing them. Need to investigate the best way to have it automatically
2964 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002965 void layoutAndAssignWindowLayersIfNeeded() {
2966 mService.mWindowsChanged = true;
2967 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002968
2969 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2970 false /*updateInputWindows*/)) {
2971 assignWindowLayers(false /* setLayoutNeeded */);
2972 }
2973
Arthur Hung95b38a92018-07-20 18:56:12 +08002974 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002975 mService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08002976 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002977 }
2978
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002979 /** Returns true if a leaked surface was destroyed */
2980 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002981 // Used to indicate that a surface was leaked.
2982 mTmpWindow = null;
2983 forAllWindows(w -> {
2984 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002985 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002986 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002987 }
2988 if (!mService.mSessions.contains(wsa.mSession)) {
2989 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002990 + w + " surface=" + wsa.mSurfaceController
2991 + " token=" + w.mToken
2992 + " pid=" + w.mSession.mPid
2993 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002994 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002995 mService.mForceRemoves.add(w);
2996 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002997 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002998 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002999 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003000 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003001 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003002 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003003 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003004 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003005 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003006
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003007 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003008 }
3009
3010 /**
lumark90120a82018-08-15 00:33:03 +08003011 * Set input method window for the display.
3012 * @param win Set when window added or Null when destroyed.
3013 */
3014 void setInputMethodWindowLocked(WindowState win) {
3015 mInputMethodWindow = win;
lumark70865a82018-09-17 16:56:26 +08003016 // Update display configuration for IME process.
3017 if (mInputMethodWindow != null) {
3018 final int imePid = mInputMethodWindow.mSession.mPid;
3019 mService.mAtmInternal.onImeWindowSetOnDisplay(imePid,
3020 mInputMethodWindow.getDisplayId());
3021 }
lumark90120a82018-08-15 00:33:03 +08003022 computeImeTarget(true /* updateImeTarget */);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003023 mInsetsStateController.getSourceProvider(TYPE_IME).setWindow(win,
3024 null /* frameProvider */);
lumark90120a82018-08-15 00:33:03 +08003025 }
3026
3027 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003028 * Determine and return the window that should be the IME target.
3029 * @param updateImeTarget If true the system IME target will be updated to match what we found.
3030 * @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 +00003031 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003032 WindowState computeImeTarget(boolean updateImeTarget) {
lumark90120a82018-08-15 00:33:03 +08003033 if (mInputMethodWindow == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003034 // There isn't an IME so there shouldn't be a target...That was easy!
3035 if (updateImeTarget) {
3036 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
lumarkff0ab692018-11-05 20:32:30 +08003037 + mInputMethodTarget + " to null since mInputMethodWindow is null");
3038 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003039 }
3040 return null;
3041 }
3042
lumarkff0ab692018-11-05 20:32:30 +08003043 final WindowState curTarget = mInputMethodTarget;
Chavi Weingarten3a748552018-05-14 17:32:42 +00003044 if (!canUpdateImeTarget()) {
3045 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
3046 return curTarget;
3047 }
3048
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003049 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
3050 // same display. Or even when the current IME/target are not on the same screen as the next
3051 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08003052 mUpdateImeTarget = updateImeTarget;
3053 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003054
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003055
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003056 // Yet more tricksyness! If this window is a "starting" window, we do actually want
3057 // to be on top of it, but it is not -really- where input will go. So look down below
3058 // for a real window to target...
3059 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
3060 final AppWindowToken token = target.mAppToken;
3061 if (token != null) {
3062 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
3063 if (betterTarget != null) {
3064 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003065 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003066 }
3067 }
3068
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003069 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
lumarkff0ab692018-11-05 20:32:30 +08003070 "Proposed new IME target: " + target + " for display: " + getDisplayId());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003071
chaviw1c13ad32018-06-12 16:44:23 -07003072 // Now, a special case -- if the last target's window is in the process of exiting, but
3073 // not removed, and the new target is home, keep on the last target to avoid flicker.
3074 // Home is a special case since its above other stacks in the ordering list, but layed
3075 // out below the others.
3076 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
3077 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07003078 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00003079 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003080 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003081 }
3082
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003083 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
3084 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003085
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003086 if (target == null) {
3087 if (updateImeTarget) {
3088 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
3089 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
3090 + Debug.getCallers(4) : ""));
lumarkff0ab692018-11-05 20:32:30 +08003091 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003092 }
3093
3094 return null;
3095 }
3096
3097 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003098 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
3099 if (token != null) {
3100
3101 // Now some fun for dealing with window animations that modify the Z order. We need
3102 // to look at all windows below the current target that are in this app, finding the
3103 // highest visible one in layering.
3104 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003105 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003106 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003107 }
3108
3109 if (highestTarget != null) {
lumark588a3e82018-07-20 18:53:54 +08003110 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, mAppTransition + " " + highestTarget
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003111 + " animating=" + highestTarget.isAnimating());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003112
lumark588a3e82018-07-20 18:53:54 +08003113 if (mAppTransition.isTransitionSet()) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003114 // If we are currently setting up for an animation, hold everything until we
3115 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003116 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003117 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003118 }
3119 }
3120 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003121
3122 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
3123 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003124 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003125 }
3126
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003127 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003128 }
3129
lumarkff0ab692018-11-05 20:32:30 +08003130 /**
3131 * Calling {@link #computeImeTarget(boolean)} to update the input method target window in
3132 * the candidate app window token if needed.
3133 */
3134 void computeImeTargetIfNeeded(AppWindowToken candidate) {
3135 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == candidate) {
3136 computeImeTarget(true /* updateImeTarget */);
3137 }
3138 }
3139
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003140 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
lumarkff0ab692018-11-05 20:32:30 +08003141 if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003142 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003143 }
3144
lumarkff0ab692018-11-05 20:32:30 +08003145 mInputMethodTarget = target;
3146 mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003147 assignWindowLayers(false /* setLayoutNeeded */);
3148 }
3149
3150 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
3151 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3152 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
3153 }
3154
3155 // Used to indicate we have reached the first window in the range we are interested in.
3156 mTmpWindow = null;
3157
3158 // TODO: Figure-out a more efficient way to do this.
3159 final WindowState candidate = getWindow(w -> {
3160 if (w == top) {
3161 // Reached the first window in the range we are interested in.
3162 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003163 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003164 if (mTmpWindow == null) {
3165 return false;
3166 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003167
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003168 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3169 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003170 }
3171 // If we reached the bottom of the range of windows we are considering,
3172 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003173 if (w == bottom) {
3174 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003175 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003176 return false;
3177 });
3178
3179 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003180 }
3181
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003182 void setLayoutNeeded() {
3183 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
3184 mLayoutNeeded = true;
3185 }
3186
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003187 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003188 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
3189 mLayoutNeeded = false;
3190 }
3191
3192 boolean isLayoutNeeded() {
3193 return mLayoutNeeded;
3194 }
3195
Wale Ogunwale02319a62016-09-26 15:21:22 -07003196 void dumpTokens(PrintWriter pw, boolean dumpAll) {
3197 if (mTokenMap.isEmpty()) {
3198 return;
3199 }
3200 pw.println(" Display #" + mDisplayId);
3201 final Iterator<WindowToken> it = mTokenMap.values().iterator();
3202 while (it.hasNext()) {
3203 final WindowToken token = it.next();
3204 pw.print(" ");
3205 pw.print(token);
3206 if (dumpAll) {
3207 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003208 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07003209 } else {
3210 pw.println();
3211 }
3212 }
lumark588a3e82018-07-20 18:53:54 +08003213
3214 if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty()) {
3215 pw.println();
3216 if (mOpeningApps.size() > 0) {
3217 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
3218 }
3219 if (mClosingApps.size() > 0) {
3220 pw.print(" mClosingApps="); pw.println(mClosingApps);
3221 }
3222 }
3223
3224 mUnknownAppVisibilityController.dump(pw, " ");
Wale Ogunwale02319a62016-09-26 15:21:22 -07003225 }
3226
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003227 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003228 final int[] index = new int[1];
3229 forAllWindows(w -> {
3230 final WindowStateAnimator wAnim = w.mWinAnimator;
3231 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
3232 index[0] = index[0] + 1;
3233 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003234 }
3235
Jorim Jaggife762342016-10-13 14:33:27 +02003236 /**
3237 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
3238 */
3239 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
3240 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003241 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02003242 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
3243 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01003244 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02003245 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003246 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02003247 }
3248
Wale Ogunwale494009b82016-10-21 09:01:38 -07003249 boolean checkWaitingForWindows() {
3250
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003251 mHaveBootMsg = false;
3252 mHaveApp = false;
3253 mHaveWallpaper = false;
3254 mHaveKeyguard = true;
3255
3256 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003257 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
3258 return true;
3259 }
3260 if (w.isDrawnLw()) {
3261 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003262 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003263 } else if (w.mAttrs.type == TYPE_APPLICATION
3264 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003265 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003266 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003267 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003268 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003269 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003270 }
3271 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003272 return false;
3273 });
3274
3275 if (visibleWindow != null) {
3276 // We have a visible window.
3277 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003278 }
3279
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003280 // if the wallpaper service is disabled on the device, we're never going to have
3281 // wallpaper, don't bother waiting for it
3282 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
3283 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09003284 && mService.mContext.getResources().getBoolean(
3285 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003286 && !mService.mOnlyCore;
3287
Wale Ogunwale494009b82016-10-21 09:01:38 -07003288 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
3289 "******** booted=" + mService.mSystemBooted
3290 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003291 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
3292 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
3293 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003294
3295 // If we are turning on the screen to show the boot message, don't do it until the boot
3296 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003297 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003298 return true;
3299 }
3300
3301 // If we are turning on the screen after the boot is completed normally, don't do so until
3302 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003303 if (mService.mSystemBooted
3304 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003305 return true;
3306 }
3307
3308 return false;
3309 }
3310
Jorim Jaggi8f520872018-08-14 17:00:20 +02003311 void updateWindowsForAnimator() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003312 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003313 }
3314
Jorim Jaggi8f520872018-08-14 17:00:20 +02003315 /**
3316 * Updates the {@link TaskStack#setAnimationBackground} for all windows.
3317 */
3318 void updateBackgroundForAnimator() {
Jorim Jaggi7156b652016-10-25 08:31:58 -07003319 resetAnimationBackgroundAnimator();
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003320 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003321 }
3322
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003323 boolean isInputMethodClientFocus(int uid, int pid) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003324 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003325 if (imFocus == null) {
3326 return false;
3327 }
3328
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003329 if (DEBUG_INPUT_METHOD) {
3330 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003331 Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
3332 Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003333 }
3334
Wale Ogunwale494009b82016-10-21 09:01:38 -07003335 if (DEBUG_INPUT_METHOD) {
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003336 Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
3337 + "/" + imFocus.mSession.mPid);
3338 Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003339 }
3340
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003341 return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003342 }
3343
3344 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003345 final WindowState win = getWindow(
3346 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
3347 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003348 }
3349
Tiger Huang7c610aa2018-10-27 00:01:01 +08003350 void statusBarVisibilityChanged(int visibility) {
3351 mLastStatusBarVisibility = visibility;
3352 visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility);
3353 updateStatusBarVisibilityLocked(visibility);
3354 }
3355
3356 private boolean updateStatusBarVisibilityLocked(int visibility) {
3357 if (mLastDispatchedSystemUiVisibility == visibility) {
3358 return false;
3359 }
3360 final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility)
3361 // We are only interested in differences of one of the
3362 // clearable flags...
3363 & View.SYSTEM_UI_CLEARABLE_FLAGS
3364 // ...if it has actually been cleared.
3365 & ~visibility;
3366
3367 mLastDispatchedSystemUiVisibility = visibility;
3368 if (isDefaultDisplay) {
3369 mService.mInputManager.setSystemUiVisibility(visibility);
3370 }
3371 updateSystemUiVisibility(visibility, globalDiff);
3372 return true;
3373 }
3374
Wale Ogunwale494009b82016-10-21 09:01:38 -07003375 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003376 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003377 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003378 final int curValue = w.mSystemUiVisibility;
3379 final int diff = (curValue ^ visibility) & globalDiff;
3380 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003381 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003382 w.mSeq++;
3383 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003384 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003385 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
3386 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07003387 visibility, newValue, diff);
3388 }
3389 } catch (RemoteException e) {
3390 // so sorry
3391 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003392 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003393 }
3394
Tiger Huang7c610aa2018-10-27 00:01:01 +08003395 void reevaluateStatusBarVisibility() {
3396 int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility);
3397 if (updateStatusBarVisibilityLocked(visibility)) {
3398 mService.mWindowPlacerLocked.requestTraversal();
3399 }
3400 }
3401
Wale Ogunwale494009b82016-10-21 09:01:38 -07003402 void onWindowFreezeTimeout() {
3403 Slog.w(TAG_WM, "Window freeze timeout expired.");
3404 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003405
3406 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003407 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003408 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003409 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07003410 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003411 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3412 - mService.mDisplayFreezeTime);
3413 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003414 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003415 mService.mWindowPlacerLocked.performSurfacePlacement();
3416 }
3417
3418 void waitForAllWindowsDrawn() {
3419 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003420 forAllWindows(w -> {
3421 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3422 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3423 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003424 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07003425 w.resetLastContentInsets();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003426 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003427 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003428 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003429 }
3430
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003431 // TODO: Super crazy long method that should be broken down...
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003432 void applySurfaceChangesTransaction(boolean recoveringMemory) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003433 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
3434
3435 mTmpUpdateAllDrawn.clear();
3436
3437 int repeats = 0;
3438 do {
3439 repeats++;
3440 if (repeats > 6) {
3441 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3442 clearLayoutNeeded();
3443 break;
3444 }
3445
3446 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3447 pendingLayoutChanges);
3448
wilsonshihc32538e2018-11-07 17:27:34 +08003449 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
3450 mWallpaperController.adjustWallpaperWindows();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003451 }
3452
Riddle Hsu654a6f92018-07-13 22:59:36 +08003453 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003454 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Riddle Hsu4e611772018-10-31 18:58:28 +08003455 if (updateOrientationFromAppTokens()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003456 setLayoutNeeded();
Riddle Hsu4e611772018-10-31 18:58:28 +08003457 sendNewConfiguration();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003458 }
3459 }
3460
3461 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3462 setLayoutNeeded();
3463 }
3464
3465 // FIRST LOOP: Perform a layout, if needed.
3466 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3467 performLayout(repeats == 1, false /* updateInputWindows */);
3468 } else {
3469 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3470 }
3471
3472 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3473 pendingLayoutChanges = 0;
3474
Tiger Huang7c610aa2018-10-27 00:01:01 +08003475 mDisplayPolicy.beginPostLayoutPolicyLw();
3476 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
3477 pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw();
3478 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3479 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003480 mInsetsStateController.onPostLayout();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003481 } while (pendingLayoutChanges != 0);
3482
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003483 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003484
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003485 mTmpRecoveringMemory = recoveringMemory;
3486 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003487 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003488
Jorim Jaggif1292892018-09-10 11:58:13 +02003489 mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003490 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggif1292892018-09-10 11:58:13 +02003491 mLastHasContent,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003492 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3493 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003494 true /* inTraversal, must call performTraversalInTrans... below */);
3495
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003496 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3497 if (wallpaperVisible != mLastWallpaperVisible) {
3498 mLastWallpaperVisible = wallpaperVisible;
3499 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
3500 }
3501
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003502 while (!mTmpUpdateAllDrawn.isEmpty()) {
3503 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3504 // See if any windows have been drawn, so they (and others associated with them)
3505 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003506 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003507 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003508 }
3509
Bryce Leef3c6a472017-11-14 14:53:06 -08003510 private void updateBounds() {
Evan Rosky39b6f232018-10-30 18:35:41 -07003511 calculateBounds(mDisplayInfo, mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08003512 setBounds(mTmpBounds);
3513 }
3514
3515 // Determines the current display bounds based on the current state
Evan Rosky39b6f232018-10-30 18:35:41 -07003516 private void calculateBounds(DisplayInfo displayInfo, Rect out) {
Bryce Leef3c6a472017-11-14 14:53:06 -08003517 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Evan Rosky39b6f232018-10-30 18:35:41 -07003518 final int rotation = displayInfo.rotation;
3519 boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Bryce Leef3c6a472017-11-14 14:53:06 -08003520 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3521 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Evan Rosky39b6f232018-10-30 18:35:41 -07003522 int width = displayInfo.logicalWidth;
Bryce Leef3c6a472017-11-14 14:53:06 -08003523 int left = (physWidth - width) / 2;
Evan Rosky39b6f232018-10-30 18:35:41 -07003524 int height = displayInfo.logicalHeight;
Bryce Leef3c6a472017-11-14 14:53:06 -08003525 int top = (physHeight - height) / 2;
3526 out.set(left, top, left + width, top + height);
3527 }
3528
3529 @Override
3530 public void getBounds(Rect out) {
Evan Rosky39b6f232018-10-30 18:35:41 -07003531 calculateBounds(mDisplayInfo, out);
Bryce Leef3c6a472017-11-14 14:53:06 -08003532 }
3533
3534 private void getBounds(Rect out, int orientation) {
3535 getBounds(out);
3536
3537 // Rotate the Rect if needed.
3538 final int currentRotation = mDisplayInfo.rotation;
3539 final int rotationDelta = deltaRotation(currentRotation, orientation);
3540 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3541 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3542 mTmpRectF.set(out);
3543 mTmpMatrix.mapRect(mTmpRectF);
3544 mTmpRectF.round(out);
3545 }
3546 }
3547
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003548 void performLayout(boolean initial, boolean updateInputWindows) {
3549 if (!isLayoutNeeded()) {
3550 return;
3551 }
3552 clearLayoutNeeded();
3553
3554 final int dw = mDisplayInfo.logicalWidth;
3555 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003556 if (DEBUG_LAYOUT) {
3557 Slog.v(TAG, "-------------------------------------");
3558 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3559 }
3560
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003561 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3562 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003563 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3564 // display info above...
3565 mDisplayFrames.mRotation = mRotation;
Tiger Huang7c610aa2018-10-27 00:01:01 +08003566 mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003567
Adrian Roos5251b1d2018-03-23 18:57:43 +01003568 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003569 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003570 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003571
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003572 // Used to indicate that we have processed the dream window and all additional windows are
3573 // behind it.
3574 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003575 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003576
3577 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003578 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003579
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003580 // Used to indicate that we have processed the dream window and all additional attached
3581 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003582 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003583 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003584
3585 // Now perform layout of attached windows, which usually depend on the position of the
3586 // window they are attached to. XXX does not deal with windows that are attached to windows
3587 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003588 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003589
3590 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003591 mInputMonitor.layoutInputConsumers(dw, dh);
3592 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003593 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003594 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003595 }
3596
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003597 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
3598 }
3599
3600 /**
3601 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3602 * In portrait mode, it grabs the full screenshot.
3603 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003604 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003605 */
chaviw0315a1a2018-03-05 15:28:35 -08003606 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
3607 if (!mService.mPolicy.isScreenOn()) {
3608 if (DEBUG_SCREENSHOT) {
3609 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003610 }
chaviw0315a1a2018-03-05 15:28:35 -08003611 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003612 }
chaviwfbe47df2017-11-10 16:14:49 -08003613
chaviw0315a1a2018-03-05 15:28:35 -08003614 int dw = mDisplayInfo.logicalWidth;
3615 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003616
chaviw0315a1a2018-03-05 15:28:35 -08003617 if (dw <= 0 || dh <= 0) {
3618 return null;
3619 }
chaviwfbe47df2017-11-10 16:14:49 -08003620
chaviw0315a1a2018-03-05 15:28:35 -08003621 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003622
chaviw0315a1a2018-03-05 15:28:35 -08003623 // The screenshot API does not apply the current screen rotation.
3624 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003625
chaviw0315a1a2018-03-05 15:28:35 -08003626 if (rot == ROTATION_90 || rot == ROTATION_270) {
3627 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3628 }
chaviwfbe47df2017-11-10 16:14:49 -08003629
chaviw0315a1a2018-03-05 15:28:35 -08003630 // SurfaceFlinger is not aware of orientation, so convert our logical
3631 // crop to SurfaceFlinger's portrait orientation.
3632 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3633
3634 final ScreenRotationAnimation screenRotationAnimation =
3635 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3636 final boolean inRotation = screenRotationAnimation != null &&
3637 screenRotationAnimation.isAnimating();
3638 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3639
3640 // TODO(b/68392460): We should screenshot Task controls directly
3641 // but it's difficult at the moment as the Task doesn't have the
3642 // correct size set.
chaviw08520a02018-09-10 16:44:56 -07003643 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot);
chaviw0315a1a2018-03-05 15:28:35 -08003644 if (bitmap == null) {
3645 Slog.w(TAG_WM, "Failed to take screenshot");
3646 return null;
3647 }
3648
3649 // Create a copy of the screenshot that is immutable and backed in ashmem.
3650 // This greatly reduces the overhead of passing the bitmap between processes.
3651 final Bitmap ret = bitmap.createAshmemBitmap(config);
3652 bitmap.recycle();
3653 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003654 }
3655
3656 // TODO: Can this use createRotationMatrix()?
3657 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3658 if (rot == Surface.ROTATION_90) {
3659 final int tmp = crop.top;
3660 crop.top = dw - crop.right;
3661 crop.right = crop.bottom;
3662 crop.bottom = dw - crop.left;
3663 crop.left = tmp;
3664 } else if (rot == Surface.ROTATION_180) {
3665 int tmp = crop.top;
3666 crop.top = dh - crop.bottom;
3667 crop.bottom = dh - tmp;
3668 tmp = crop.right;
3669 crop.right = dw - crop.left;
3670 crop.left = dw - tmp;
3671 } else if (rot == Surface.ROTATION_270) {
3672 final int tmp = crop.top;
3673 crop.top = crop.left;
3674 crop.left = dh - crop.bottom;
3675 crop.bottom = crop.right;
3676 crop.right = dh - tmp;
3677 }
3678 }
3679
3680 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003681 // Used to indicate the layout is needed.
3682 mTmpWindow = null;
3683
3684 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003685 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003686 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003687 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003688 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003689 w.setDisplayLayoutNeeded();
Vishnu Nairba183352018-11-21 11:16:49 -08003690 w.finishSeamlessRotation(true /* timeout */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003691 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003692 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003693
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003694 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003695 mService.mWindowPlacerLocked.performSurfacePlacement();
3696 }
3697 }
3698
Wale Ogunwale1666e312016-12-16 11:27:18 -08003699 void setExitingTokensHasVisible(boolean hasVisible) {
3700 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3701 mExitingTokens.get(i).hasVisible = hasVisible;
3702 }
3703
3704 // Initialize state of exiting applications.
3705 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3706 }
3707
3708 void removeExistingTokensIfPossible() {
3709 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3710 final WindowToken token = mExitingTokens.get(i);
3711 if (!token.hasVisible) {
3712 mExitingTokens.remove(i);
3713 }
3714 }
3715
3716 // Time to remove any exiting applications?
3717 mTaskStackContainers.removeExistingAppTokensIfPossible();
3718 }
3719
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003720 @Override
3721 void onDescendantOverrideConfigurationChanged() {
3722 setLayoutNeeded();
3723 mService.requestTraversal();
3724 }
3725
David Stevens9440dc82017-03-16 19:00:20 -07003726 boolean okToDisplay() {
3727 if (mDisplayId == DEFAULT_DISPLAY) {
3728 return !mService.mDisplayFrozen
3729 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3730 }
3731 return mDisplayInfo.state == Display.STATE_ON;
3732 }
3733
3734 boolean okToAnimate() {
3735 return okToDisplay() &&
3736 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3737 }
3738
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003739 static final class TaskForResizePointSearchResult {
3740 boolean searchDone;
3741 Task taskForResize;
3742
3743 void reset() {
3744 searchDone = false;
3745 taskForResize = null;
3746 }
3747 }
Robert Carr3b716242016-08-16 16:02:21 -07003748
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003749 private static final class ApplySurfaceChangesTransactionState {
3750 boolean displayHasContent;
3751 boolean obscured;
3752 boolean syswin;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003753 float preferredRefreshRate;
3754 int preferredModeId;
3755
3756 void reset() {
3757 displayHasContent = false;
3758 obscured = false;
3759 syswin = false;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003760 preferredRefreshRate = 0;
3761 preferredModeId = 0;
3762 }
3763 }
3764
3765 private static final class ScreenshotApplicationState {
3766 WindowState appWin;
3767 int maxLayer;
3768 int minLayer;
3769 boolean screenshotReady;
3770
3771 void reset(boolean screenshotReady) {
3772 appWin = null;
3773 maxLayer = 0;
3774 minLayer = 0;
3775 this.screenshotReady = screenshotReady;
3776 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3777 }
3778 }
3779
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003780 /**
3781 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3782 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3783 * homogeneous children type which is currently required by sub-classes of
3784 * {@link WindowContainer} class.
3785 */
3786 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3787
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003788 DisplayChildWindowContainer(WindowManagerService service) {
3789 super(service);
3790 }
3791
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003792 @Override
3793 boolean fillsParent() {
3794 return true;
3795 }
3796
3797 @Override
3798 boolean isVisible() {
3799 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003800 }
3801 }
3802
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003803 /**
3804 * Window container class that contains all containers on this display relating to Apps.
3805 * I.e Activities.
3806 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003807 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003808 /**
3809 * A control placed at the appropriate level for transitions to occur.
3810 */
chaviw23ee71c2017-12-18 11:29:41 -08003811 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003812 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003813 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003814
Robert Carrf7a7ca82017-12-06 13:17:07 -08003815 /**
3816 * Given that the split-screen divider does not have an AppWindowToken, it
3817 * will have to live inside of a "NonAppWindowContainer", in particular
3818 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3819 * it will need to be interleaved with some of our children, appearing on top of
3820 * both docked stacks but underneath any assistant stacks.
3821 *
3822 * To solve this problem we have this anchor control, which will always exist so
3823 * we can always assign it the correct value in our {@link #assignChildLayers}.
3824 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3825 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3826 * events between the two containers.
3827 */
3828 SurfaceControl mSplitScreenDividerAnchor = null;
3829
Wale Ogunwale61911492017-10-11 08:50:50 -07003830 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3831 // through the list to find them.
3832 private TaskStack mHomeStack = null;
3833 private TaskStack mPinnedStack = null;
3834 private TaskStack mSplitScreenPrimaryStack = null;
3835
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003836 TaskStackContainers(WindowManagerService service) {
3837 super(service);
3838 }
3839
Wale Ogunwale61911492017-10-11 08:50:50 -07003840 /**
3841 * Returns the topmost stack on the display that is compatible with the input windowing mode
3842 * and activity type. Null is no compatible stack on the display.
3843 */
3844 TaskStack getStack(int windowingMode, int activityType) {
3845 if (activityType == ACTIVITY_TYPE_HOME) {
3846 return mHomeStack;
3847 }
3848 if (windowingMode == WINDOWING_MODE_PINNED) {
3849 return mPinnedStack;
3850 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3851 return mSplitScreenPrimaryStack;
3852 }
3853 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3854 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003855 if (activityType == ACTIVITY_TYPE_UNDEFINED
3856 && windowingMode == stack.getWindowingMode()) {
3857 // Passing in undefined type means we want to match the topmost stack with the
3858 // windowing mode.
3859 return stack;
3860 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003861 if (stack.isCompatible(windowingMode, activityType)) {
3862 return stack;
3863 }
3864 }
3865 return null;
3866 }
3867
3868 @VisibleForTesting
3869 TaskStack getTopStack() {
3870 return mTaskStackContainers.getChildCount() > 0
3871 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3872 }
3873
3874 TaskStack getHomeStack() {
3875 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3876 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3877 }
3878 return mHomeStack;
3879 }
3880
3881 TaskStack getPinnedStack() {
3882 return mPinnedStack;
3883 }
3884
Matthew Ng64e77cf2017-10-31 14:01:31 -07003885 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003886 return mSplitScreenPrimaryStack;
3887 }
3888
Winson Chunge2d72172018-01-25 17:46:20 +00003889 ArrayList<Task> getVisibleTasks() {
3890 final ArrayList<Task> visibleTasks = new ArrayList<>();
3891 forAllTasks(task -> {
3892 if (task.isVisible()) {
3893 visibleTasks.add(task);
3894 }
3895 });
3896 return visibleTasks;
3897 }
3898
Andrii Kulian839def92016-11-02 10:58:58 -07003899 /**
3900 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003901 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003902 */
3903 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003904 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003905 addChild(stack, onTop);
3906 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003907 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003908
Wale Ogunwale61911492017-10-11 08:50:50 -07003909 void onStackWindowingModeChanged(TaskStack stack) {
3910 removeStackReferenceIfNeeded(stack);
3911 addStackReferenceIfNeeded(stack);
3912 if (stack == mPinnedStack && getTopStack() != stack) {
3913 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3914 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3915 }
3916 }
3917
3918 private void addStackReferenceIfNeeded(TaskStack stack) {
3919 if (stack.isActivityTypeHome()) {
3920 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003921 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003922 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003923
Wale Ogunwale61911492017-10-11 08:50:50 -07003924 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003925 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003926 }
3927 final int windowingMode = stack.getWindowingMode();
3928 if (windowingMode == WINDOWING_MODE_PINNED) {
3929 if (mPinnedStack != null) {
3930 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3931 + mPinnedStack + " already exist on display=" + this
3932 + " stack=" + stack);
3933 }
3934 mPinnedStack = stack;
3935 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3936 if (mSplitScreenPrimaryStack != null) {
3937 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3938 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3939 + " already exist on display=" + this + " stack=" + stack);
3940 }
3941 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003942 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003943 }
3944 }
3945
3946 private void removeStackReferenceIfNeeded(TaskStack stack) {
3947 if (stack == mHomeStack) {
3948 mHomeStack = null;
3949 } else if (stack == mPinnedStack) {
3950 mPinnedStack = null;
3951 } else if (stack == mSplitScreenPrimaryStack) {
3952 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003953 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3954 mService.setDockedStackCreateStateLocked(
3955 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3956 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003957 }
Andrii Kulian839def92016-11-02 10:58:58 -07003958 }
3959
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003960 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003961 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3962 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003963 addChild(stack, addIndex);
3964 setLayoutNeeded();
3965 }
3966
Wale Ogunwale61911492017-10-11 08:50:50 -07003967 @Override
3968 protected void removeChild(TaskStack stack) {
3969 super.removeChild(stack);
3970 removeStackReferenceIfNeeded(stack);
3971 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003972
3973 @Override
3974 boolean isOnTop() {
3975 // Considered always on top
3976 return true;
3977 }
3978
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003979 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003980 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003981 if (child.getWindowConfiguration().isAlwaysOnTop()
3982 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003983 // This stack is always-on-top, override the default behavior.
3984 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3985
3986 // Moving to its current position, as we must call super but we don't want to
3987 // perform any meaningful action.
3988 final int currentPosition = mChildren.indexOf(child);
3989 super.positionChildAt(currentPosition, child, false /* includingParents */);
3990 return;
3991 }
3992
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003993 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3994 super.positionChildAt(targetPosition, child, includingParents);
3995
Riddle Hsu2f6e1742018-08-23 22:44:36 +08003996 if (includingParents) {
3997 // We still want to move the display of this stack container to top because even the
3998 // target position is adjusted to non-top, the intention of the condition is to have
3999 // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front
4000 // in a non-top display which is using picture-in-picture mode).
4001 final int topChildPosition = getChildCount() - 1;
4002 if (targetPosition < topChildPosition && position >= topChildPosition) {
4003 getParent().positionChildAt(POSITION_TOP, this /* child */,
4004 true /* includingParents */);
4005 }
4006 }
4007
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004008 setLayoutNeeded();
4009 }
4010
4011 /**
4012 * When stack is added or repositioned, find a proper position for it.
4013 * This will make sure that pinned stack always stays on top.
4014 * @param requestedPosition Position requested by caller.
4015 * @param stack Stack to be added or positioned.
4016 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
4017 * @return The proper position for the stack.
4018 */
4019 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004020 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09004021 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09004022 }
4023
Kazuki Takisef85197b2018-06-18 18:18:36 +09004024 final int topChildPosition = mChildren.size() - 1;
4025 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
4026 for (int i = topChildPosition; i >= 0; --i) {
4027 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
4028 belowAlwaysOnTopPosition = i;
4029 break;
4030 }
4031 }
4032
4033 // The max possible position we can insert the stack at.
4034 int maxPosition = POSITION_TOP;
4035 // The min possible position we can insert the stack at.
4036 int minPosition = POSITION_BOTTOM;
4037
4038 if (stack.isAlwaysOnTop()) {
4039 if (hasPinnedStack()) {
4040 // Always-on-top stacks go below the pinned stack.
4041 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
4042 }
4043 // Always-on-top stacks need to be above all other stacks.
4044 minPosition = belowAlwaysOnTopPosition !=
4045 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
4046 } else {
4047 // Other stacks need to be below the always-on-top stacks.
4048 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08004049 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09004050 }
4051
4052 int targetPosition = requestedPosition;
4053 targetPosition = Math.min(targetPosition, maxPosition);
4054 targetPosition = Math.max(targetPosition, minPosition);
4055
4056 int prevPosition = getStacks().indexOf(stack);
4057 // The positions we calculated above (maxPosition, minPosition) do not take into
4058 // consideration the following edge cases.
4059 // 1) We need to adjust the position depending on the value "adding".
4060 // 2) When we are moving a stack to another position, we also need to adjust the
4061 // position depending on whether the stack is moving to a higher or lower position.
4062 if ((targetPosition != requestedPosition) &&
4063 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004064 targetPosition++;
4065 }
4066
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004067 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08004068 }
4069
4070 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004071 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
4072 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004073 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004074 if (super.forAllWindows(callback, traverseTopToBottom)) {
4075 return true;
4076 }
4077 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4078 return true;
4079 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004080 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004081 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4082 return true;
4083 }
4084 if (super.forAllWindows(callback, traverseTopToBottom)) {
4085 return true;
4086 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004087 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004088 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004089 }
4090
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004091 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004092 boolean traverseTopToBottom) {
4093 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
4094 // app tokens.
4095 // TODO: Investigate if we need to continue to do this or if we can just process them
4096 // in-order.
4097 if (traverseTopToBottom) {
4098 for (int i = mChildren.size() - 1; i >= 0; --i) {
4099 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4100 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004101 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4102 traverseTopToBottom)) {
4103 return true;
4104 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004105 }
4106 }
4107 } else {
4108 final int count = mChildren.size();
4109 for (int i = 0; i < count; ++i) {
4110 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4111 final int appTokensCount = appTokens.size();
4112 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004113 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4114 traverseTopToBottom)) {
4115 return true;
4116 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004117 }
4118 }
4119 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004120 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004121 }
4122
Wale Ogunwale1666e312016-12-16 11:27:18 -08004123 void setExitingTokensHasVisible(boolean hasVisible) {
4124 for (int i = mChildren.size() - 1; i >= 0; --i) {
4125 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4126 for (int j = appTokens.size() - 1; j >= 0; --j) {
4127 appTokens.get(j).hasVisible = hasVisible;
4128 }
4129 }
4130 }
4131
4132 void removeExistingAppTokensIfPossible() {
4133 for (int i = mChildren.size() - 1; i >= 0; --i) {
4134 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4135 for (int j = appTokens.size() - 1; j >= 0; --j) {
4136 final AppWindowToken token = appTokens.get(j);
lumark588a3e82018-07-20 18:53:54 +08004137 if (!token.hasVisible && !mClosingApps.contains(token)
Wale Ogunwale1666e312016-12-16 11:27:18 -08004138 && (!token.mIsExiting || token.isEmpty())) {
4139 // Make sure there is no animation running on this token, so any windows
4140 // associated with it will be removed as soon as their animations are
4141 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02004142 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08004143 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4144 "performLayout: App token exiting now removed" + token);
4145 token.removeIfPossible();
4146 }
4147 }
4148 }
4149 }
4150
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004151 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004152 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004153 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
4154 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004155 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07004156 // docked or freeform stack is visible...except for the home stack if the docked
4157 // stack is minimized and it actually set something and the bounds is different from
4158 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004159 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004160 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004161 && !(mDividerControllerLocked.isHomeStackResizable()
4162 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004163 final int orientation = mHomeStack.getOrientation();
4164 if (orientation != SCREEN_ORIENTATION_UNSET) {
4165 return orientation;
4166 }
4167 }
4168 return SCREEN_ORIENTATION_UNSPECIFIED;
4169 }
4170
4171 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07004172 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
4173 PackageManager.FEATURE_AUTOMOTIVE);
4174 if (isCar) {
4175 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
4176 // allow anything but the default orientation.
4177 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004178 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
4179 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07004180 return SCREEN_ORIENTATION_UNSPECIFIED;
4181 }
4182
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004183 if (orientation != SCREEN_ORIENTATION_UNSET
4184 && orientation != SCREEN_ORIENTATION_BEHIND) {
4185 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004186 "App is requesting an orientation, return " + orientation
4187 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004188 return orientation;
4189 }
4190
4191 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004192 "No app is requesting an orientation, return " + mLastOrientation
4193 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004194 // The next app has not been requested to be visible, so we keep the current orientation
4195 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08004196 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004197 }
Robert Carrb1579c82017-09-05 14:54:47 -07004198
4199 @Override
4200 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004201 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004202
Robert Carr2f8aa392018-01-31 14:46:51 -08004203 for (int i = 0; i < mChildren.size(); i++) {
4204 final TaskStack s = mChildren.get(i);
4205 s.assignChildLayers(t);
4206 }
4207 }
4208
4209 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02004210
Robert Carrf7a7ca82017-12-06 13:17:07 -08004211 final int HOME_STACK_STATE = 0;
4212 final int NORMAL_STACK_STATE = 1;
4213 final int ALWAYS_ON_TOP_STATE = 2;
4214
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004215 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004216 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02004217 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02004218 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004219
Robert Carrf7a7ca82017-12-06 13:17:07 -08004220 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
4221 for (int i = 0; i < mChildren.size(); i++) {
4222 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08004223 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
4224 continue;
4225 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
4226 || s.isAlwaysOnTop())) {
4227 continue;
4228 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
4229 continue;
4230 }
4231 s.assignLayer(t, layer++);
4232 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
4233 t.setLayer(mSplitScreenDividerAnchor, layer++);
4234 }
Winson Chungd41f71d2018-03-16 15:26:07 -07004235 if ((s.isTaskAnimating() || s.isAppAnimating())
4236 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004237 // Ensure the animation layer ends up above the
4238 // highest animating stack and no higher.
4239 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004240 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004241 if (state != ALWAYS_ON_TOP_STATE) {
4242 layerForBoostedAnimationLayer = layer++;
4243 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08004244 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004245 if (state == HOME_STACK_STATE) {
4246 layerForHomeAnimationLayer = layer++;
4247 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004248 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004249 if (mAppAnimationLayer != null) {
4250 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004251 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004252 if (mBoostedAppAnimationLayer != null) {
4253 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
4254 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004255 if (mHomeAppAnimationLayer != null) {
4256 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
4257 }
Robert Carrb1579c82017-09-05 14:54:47 -07004258 }
4259
4260 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02004261 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
4262 switch (animationLayer) {
4263 case ANIMATION_LAYER_BOOSTED:
4264 return mBoostedAppAnimationLayer;
4265 case ANIMATION_LAYER_HOME:
4266 return mHomeAppAnimationLayer;
4267 case ANIMATION_LAYER_STANDARD:
4268 default:
4269 return mAppAnimationLayer;
4270 }
chaviw23ee71c2017-12-18 11:29:41 -08004271 }
4272
Robert Carrf7a7ca82017-12-06 13:17:07 -08004273 SurfaceControl getSplitScreenDividerAnchor() {
4274 return mSplitScreenDividerAnchor;
4275 }
4276
chaviw23ee71c2017-12-18 11:29:41 -08004277 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004278 void onParentSet() {
4279 super.onParentSet();
4280 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08004281 mAppAnimationLayer = makeChildSurface(null)
4282 .setName("animationLayer")
4283 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02004284 mBoostedAppAnimationLayer = makeChildSurface(null)
4285 .setName("boostedAnimationLayer")
4286 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02004287 mHomeAppAnimationLayer = makeChildSurface(null)
4288 .setName("homeAnimationLayer")
4289 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08004290 mSplitScreenDividerAnchor = makeChildSurface(null)
4291 .setName("splitScreenDividerAnchor")
4292 .build();
4293 getPendingTransaction()
4294 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02004295 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02004296 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08004297 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08004298 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07004299 } else {
chaviw23ee71c2017-12-18 11:29:41 -08004300 mAppAnimationLayer.destroy();
4301 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02004302 mBoostedAppAnimationLayer.destroy();
4303 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02004304 mHomeAppAnimationLayer.destroy();
4305 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004306 mSplitScreenDividerAnchor.destroy();
4307 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07004308 }
4309 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004310 }
4311
Robert Carree4d4b92017-11-22 12:21:46 -08004312 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004313 AboveAppWindowContainers(String name, WindowManagerService service) {
4314 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08004315 }
4316
Robert Carrb9506032018-02-13 13:54:00 -08004317 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07004318 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
4319 final SurfaceControl.Builder builder = super.makeChildSurface(child);
4320 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
4321 // To draw above the ColorFade layer during the screen off transition, the
4322 // rounded corner overlays need to be at the root of the surface hierarchy.
4323 // TODO: move the ColorLayer into the display overlay layer such that this is not
4324 // necessary anymore.
4325 builder.setParent(null);
4326 }
4327 return builder;
4328 }
4329
4330 @Override
Robert Carrb9506032018-02-13 13:54:00 -08004331 void assignChildLayers(SurfaceControl.Transaction t) {
4332 assignChildLayers(t, null /* imeContainer */);
4333 }
4334
Robert Carree4d4b92017-11-22 12:21:46 -08004335 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
4336 boolean needAssignIme = imeContainer != null
4337 && imeContainer.getSurfaceControl() != null;
4338 for (int j = 0; j < mChildren.size(); ++j) {
4339 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004340
4341 // See {@link mSplitScreenDividerAnchor}
4342 if (wt.windowType == TYPE_DOCK_DIVIDER) {
4343 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
4344 continue;
4345 }
Vishnu Nair83537a72018-07-19 21:27:48 -07004346 if (wt.mRoundedCornerOverlay) {
4347 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
4348 continue;
4349 }
Robert Carree4d4b92017-11-22 12:21:46 -08004350 wt.assignLayer(t, j);
4351 wt.assignChildLayers(t);
4352
4353 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
4354 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08004355
4356 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
4357 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004358 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08004359 needAssignIme = false;
4360 }
4361 }
4362 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004363 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08004364 }
4365 }
4366 }
4367
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004368 /**
4369 * Window container class that contains all containers on this display that are not related to
4370 * Apps. E.g. status bar.
4371 */
Robert Carree4d4b92017-11-22 12:21:46 -08004372 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07004373 /**
4374 * Compares two child window tokens returns -1 if the first is lesser than the second in
4375 * terms of z-order and 1 otherwise.
4376 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004377 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07004378 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004379 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
4380 token1.mOwnerCanManageAppTokens)
4381 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
4382 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004383
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004384 private final Predicate<WindowState> mGetOrientingWindow = w -> {
4385 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
4386 return false;
4387 }
4388 final int req = w.mAttrs.screenOrientation;
4389 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
4390 || req == SCREEN_ORIENTATION_UNSET) {
4391 return false;
4392 }
4393 return true;
4394 };
4395
Wale Ogunwale3a931692016-11-02 16:49:48 -07004396 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08004397 private final Dimmer mDimmer = new Dimmer(this);
4398 private final Rect mTmpDimBoundsRect = new Rect();
4399
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004400 NonAppWindowContainers(String name, WindowManagerService service) {
4401 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07004402 mName = name;
4403 }
4404
4405 void addChild(WindowToken token) {
4406 addChild(token, mWindowComparator);
4407 }
4408
4409 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004410 int getOrientation() {
4411 final WindowManagerPolicy policy = mService.mPolicy;
4412 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004413 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004414
4415 if (win != null) {
4416 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004417 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004418 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004419 if (mService.mKeyguardGoingAway) {
4420 // Keyguard can't affect the orientation if it is going away...
4421 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4422 return SCREEN_ORIENTATION_UNSET;
4423 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004424 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004425 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4426 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004427 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004428 }
4429
Andrii Kulian8ee72852017-03-10 10:36:45 -08004430 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004431
Jorim Jaggi1c530592018-04-06 15:11:47 +02004432 // Only allow force setting the orientation when all unknown visibilities have been
4433 // resolved, as otherwise we just may be starting another occluding activity.
4434 final boolean isUnoccluding =
lumark588a3e82018-07-20 18:53:54 +08004435 mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4436 && mUnknownAppVisibilityController.allResolved();
Jorim Jaggi1c530592018-04-06 15:11:47 +02004437 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004438 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004439 }
4440
4441 return SCREEN_ORIENTATION_UNSET;
4442 }
4443
4444 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004445 String getName() {
4446 return mName;
4447 }
chaviwf29223e2018-01-31 13:23:51 -08004448
4449 @Override
4450 Dimmer getDimmer() {
4451 return mDimmer;
4452 }
4453
4454 @Override
4455 void prepareSurfaces() {
4456 mDimmer.resetDimStates();
4457 super.prepareSurfaces();
4458 getBounds(mTmpDimBoundsRect);
4459
4460 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4461 scheduleAnimation();
4462 }
4463 }
Robert Carr3b716242016-08-16 16:02:21 -07004464 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004465
Robert Carr9034d962018-01-04 18:27:42 -08004466 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4467 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4468 super(name, service);
4469 }
4470
4471 @Override
4472 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4473 }
4474 };
4475
Robert Carrb1579c82017-09-05 14:54:47 -07004476 SurfaceControl.Builder makeSurface(SurfaceSession s) {
4477 return mService.makeSurfaceBuilder(s)
4478 .setParent(mWindowingLayer);
4479 }
4480
4481 @Override
4482 SurfaceSession getSession() {
4483 return mSession;
4484 }
4485
4486 @Override
4487 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004488 SurfaceSession s = child != null ? child.getSession() : getSession();
4489 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004490 if (child == null) {
4491 return b;
4492 }
4493
Robert Carree4d4b92017-11-22 12:21:46 -08004494 return b.setName(child.getName())
4495 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004496 }
4497
4498 /**
4499 * The makeSurface variants are for use by the window-container
4500 * hierarchy. makeOverlay here is a function for various non windowing
4501 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4502 * and other potpourii.
4503 */
4504 SurfaceControl.Builder makeOverlay() {
4505 return mService.makeSurfaceBuilder(mSession)
4506 .setParent(mOverlayLayer);
4507 }
4508
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004509 /**
4510 * Reparents the given surface to mOverlayLayer.
4511 */
4512 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4513 transaction.reparent(surface, mOverlayLayer.getHandle());
4514 }
4515
Robert Carrb1579c82017-09-05 14:54:47 -07004516 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004517 if (spec.scale != 1.0) {
4518 mMagnificationSpec = spec;
4519 } else {
4520 mMagnificationSpec = null;
4521 }
4522
Robert Carrf59b8dd2017-10-02 18:58:36 -07004523 applyMagnificationSpec(getPendingTransaction(), spec);
4524 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004525 }
4526
Robert Carr24be9ab2018-04-30 17:54:53 -07004527 void reapplyMagnificationSpec() {
4528 if (mMagnificationSpec != null) {
4529 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4530 }
4531 }
4532
Robert Carrb1579c82017-09-05 14:54:47 -07004533 @Override
4534 void onParentSet() {
4535 // Since we are the top of the SurfaceControl hierarchy here
4536 // we create the root surfaces explicitly rather than chaining
4537 // up as the default implementation in onParentSet does. So we
4538 // explicitly do NOT call super here.
4539 }
4540
4541 @Override
4542 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004543
4544 // These are layers as children of "mWindowingLayer"
4545 mBelowAppWindowsContainers.assignLayer(t, 0);
4546 mTaskStackContainers.assignLayer(t, 1);
4547 mAboveAppWindowsContainers.assignLayer(t, 2);
4548
lumarkff0ab692018-11-05 20:32:30 +08004549 final WindowState imeTarget = mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004550 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004551
Robert Carree4d4b92017-11-22 12:21:46 -08004552 // In the case where we have an IME target that is not in split-screen
4553 // mode IME assignment is easy. We just need the IME to go directly above
4554 // the target. This way children of the target will naturally go above the IME
4555 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004556 //
Robert Carree4d4b92017-11-22 12:21:46 -08004557 // In the case of split-screen windowing mode, we need to elevate the IME above the
4558 // docked divider while keeping the app itself below the docked divider, so instead
4559 // we use relative layering of the IME targets child windows, and place the
4560 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004561 //
Robert Carr234b6332018-03-20 13:38:16 -07004562 // In the case the IME target is animating, the animation Z order may be different
4563 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4564 // IME target. In this case we just layer the IME over all transitions by placing it in the
4565 // above applications layer.
4566 //
Robert Carree4d4b92017-11-22 12:21:46 -08004567 // In the case where we have no IME target we assign it where it's base layer would
4568 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004569 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4570 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004571 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004572 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004573 // TODO: We need to use an extra level on the app surface to ensure
4574 // this is always above SurfaceView but always below attached window.
4575 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004576 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004577 }
4578
4579 // Above we have assigned layers to our children, now we ask them to assign
4580 // layers to their children.
4581 mBelowAppWindowsContainers.assignChildLayers(t);
4582 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004583 mAboveAppWindowsContainers.assignChildLayers(t,
4584 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004585 mImeWindowsContainers.assignChildLayers(t);
4586 }
4587
4588 /**
4589 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4590 * that the IME target is one of the docked applications. We'd like the docked divider to be
4591 * above both of the applications, and we'd like the IME to be above the docked divider.
4592 * However we need child windows of the applications to be above the IME (Text drag handles).
4593 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4594 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
Tiger Huang7c610aa2018-10-27 00:01:01 +08004595 * with {@link WindowState#assignLayer}
Robert Carrb1579c82017-09-05 14:54:47 -07004596 */
4597 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004598 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004599 }
4600
4601 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004602 void prepareSurfaces() {
4603 final ScreenRotationAnimation screenRotationAnimation =
4604 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
4605 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4606 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4607 mPendingTransaction.setMatrix(mWindowingLayer,
4608 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4609 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4610 mPendingTransaction.setPosition(mWindowingLayer,
4611 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4612 mPendingTransaction.setAlpha(mWindowingLayer,
4613 screenRotationAnimation.getEnterTransformation().getAlpha());
4614 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004615
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004616 super.prepareSurfaces();
4617 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004618
Jorim Jaggibe418292018-03-26 16:14:12 +02004619 void assignStackOrdering() {
4620 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004621 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004622
4623 /**
4624 * Increment the deferral count to determine whether to update the IME target.
4625 */
4626 void deferUpdateImeTarget() {
4627 mDeferUpdateImeTargetCount++;
4628 }
4629
4630 /**
4631 * Decrement the deferral count to determine whether to update the IME target. If the count
4632 * reaches 0, a new ime target will get computed.
4633 */
4634 void continueUpdateImeTarget() {
4635 if (mDeferUpdateImeTargetCount == 0) {
4636 return;
4637 }
4638
4639 mDeferUpdateImeTargetCount--;
4640 if (mDeferUpdateImeTargetCount == 0) {
4641 computeImeTarget(true /* updateImeTarget */);
4642 }
4643 }
4644
4645 /**
4646 * @return Whether a new IME target should be computed.
4647 */
4648 private boolean canUpdateImeTarget() {
4649 return mDeferUpdateImeTargetCount == 0;
4650 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004651
4652 InputMonitor getInputMonitor() {
4653 return mInputMonitor;
4654 }
Jorim Jaggif1292892018-09-10 11:58:13 +02004655
4656 /**
4657 * @return Cached value whether we told display manager that we have content.
4658 */
4659 boolean getLastHasContent() {
4660 return mLastHasContent;
4661 }
Arthur Hungbe5ce212018-09-13 18:41:56 +08004662
4663 void registerPointerEventListener(@NonNull PointerEventListener listener) {
4664 if (mPointerEventDispatcher != null) {
4665 mPointerEventDispatcher.registerInputEventListener(listener);
4666 }
4667 }
4668
4669 void unregisterPointerEventListener(@NonNull PointerEventListener listener) {
4670 if (mPointerEventDispatcher != null) {
4671 mPointerEventDispatcher.unregisterInputEventListener(listener);
4672 }
4673 }
lumark588a3e82018-07-20 18:53:54 +08004674
4675 void prepareAppTransition(@WindowManager.TransitionType int transit,
4676 boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags,
4677 boolean forceOverride) {
4678 final boolean prepared = mAppTransition.prepareAppTransitionLocked(
4679 transit, alwaysKeepCurrent, flags, forceOverride);
4680 if (prepared && okToAnimate()) {
4681 mSkipAppTransitionAnimation = false;
4682 }
4683 }
4684
4685 void executeAppTransition() {
4686 if (mAppTransition.isTransitionSet()) {
4687 if (DEBUG_APP_TRANSITIONS) {
4688 Slog.w(TAG_WM, "Execute app transition: " + mAppTransition + ", displayId: "
4689 + mDisplayId + " Callers=" + Debug.getCallers(5));
4690 }
4691 mAppTransition.setReady();
4692 mService.mWindowPlacerLocked.requestTraversal();
4693 }
4694 }
4695
4696 /**
4697 * Update pendingLayoutChanges after app transition has finished.
4698 */
4699 void handleAnimatingStoppedAndTransition() {
4700 int changes = 0;
4701
4702 mAppTransition.setIdle();
4703
4704 for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) {
4705 final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i);
4706 mAppTransition.notifyAppTransitionFinishedLocked(token);
4707 }
4708 mNoAnimationNotifyOnTransitionFinished.clear();
4709
4710 mWallpaperController.hideDeferredWallpapersIfNeeded();
4711
4712 onAppTransitionDone();
4713
4714 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4715 if (DEBUG_WALLPAPER_LIGHT) {
4716 Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout");
4717 }
4718 computeImeTarget(true /* updateImeTarget */);
wilsonshihc32538e2018-11-07 17:27:34 +08004719 mWallpaperMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004720 // Since the window list has been rebuilt, focus might have to be recomputed since the
4721 // actual order of windows might have changed again.
4722 mService.mFocusMayChange = true;
4723
4724 pendingLayoutChanges |= changes;
4725 }
Andrii Kulian15cfb422018-11-07 13:38:49 -08004726
4727 /**
4728 * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
4729 */
4730 boolean supportsSystemDecorations() {
4731 // TODO(b/114338689): Read the setting from DisplaySettings.
4732 return mDisplay.supportsSystemDecorations()
4733 // TODO (b/111363427): Remove this and set the new FLAG_SHOULD_SHOW_LAUNCHER flag
4734 // (b/114338689) whenever vr 2d display id is set.
4735 || mDisplayId == mService.mVr2dDisplayId
4736 || mService.mForceDesktopModeOnExternalDisplays;
4737 }
chaviwff2e7d82018-11-02 11:11:27 -07004738
4739 /**
4740 * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and
4741 * {@link #mOverlayLayer} to the specified surfaceControl.
4742 *
4743 * @param surfaceControlHandle The handle for the new SurfaceControl, where the DisplayContent's
4744 * surfaces will be re-parented to.
4745 */
4746 void reparentDisplayContent(IBinder surfaceControlHandle) {
4747 mPendingTransaction.reparent(mWindowingLayer, surfaceControlHandle)
4748 .reparent(mOverlayLayer, surfaceControlHandle);
4749 }
Craig Mautner59c00972012-07-30 12:10:24 -07004750}