blob: 2f4c5cab2559be43e5ab89c937f64bc4b3cfd8ea [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;
Wale Ogunwale3a256e62018-12-06 14:41:18 -080062import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080063import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
64
Wale Ogunwale3a256e62018-12-06 14:41:18 -080065import static android.view.WindowManager.TRANSIT_TASK_OPEN;
66import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
Adrian Roose99bc052017-11-20 17:55:31 +010067import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
68import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
69import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
70import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080071import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
lumark588a3e82018-07-20 18:53:54 +080072import static com.android.server.wm.DisplayContentProto.APP_TRANSITION;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080073import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
74import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
75import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
76import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
77import static com.android.server.wm.DisplayContentProto.DPI;
Tiger Huang1e5b10a2018-07-30 20:19:51 +080078import static com.android.server.wm.DisplayContentProto.FOCUSED_APP;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080079import static com.android.server.wm.DisplayContentProto.ID;
80import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
81import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
82import static com.android.server.wm.DisplayContentProto.ROTATION;
83import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
84import static com.android.server.wm.DisplayContentProto.STACKS;
85import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
lumark588a3e82018-07-20 18:53:54 +080087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwale494009b82016-10-21 09:01:38 -070088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070096import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070098import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080099import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -0700101import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700102import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700103import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800104import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700105import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800106import static com.android.server.wm.WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800107import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700108import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
109import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700110import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700111import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700112import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
113import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800114import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
115import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
116import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_ASSIGN_LAYERS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700117import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700118import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700119import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700120import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700121import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700122import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700123import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700124import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700125import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700126
lumark588a3e82018-07-20 18:53:54 +0800127import android.animation.AnimationHandler;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700128import android.annotation.CallSuper;
Riddle Hsuf53da812018-08-15 22:00:27 +0800129import android.annotation.IntDef;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700130import android.annotation.NonNull;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200131import android.annotation.Nullable;
Dean Harding3e5a1522017-10-06 09:19:01 -0700132import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700133import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700134import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700135import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700136import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800137import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700138import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700139import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100140import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700141import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700142import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700143import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700144import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700145import android.os.RemoteException;
146import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100147import android.os.Trace;
Riddle Hsuf53da812018-08-15 22:00:27 +0800148import android.os.UserHandle;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800149import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700150import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700151import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700152import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700153import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100154import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700155import android.view.DisplayInfo;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800156import android.view.Gravity;
Arthur Hungbe5ce212018-09-13 18:41:56 +0800157import android.view.InputChannel;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700158import android.view.InputDevice;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200159import android.view.InsetsState.InternalInsetType;
Robert Carrb1579c82017-09-05 14:54:47 -0700160import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700161import android.view.Surface;
162import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100163import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700164import android.view.SurfaceSession;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800165import android.view.View;
lumark588a3e82018-07-20 18:53:54 +0800166import android.view.WindowManager;
Evan Rosky39b6f232018-10-30 18:35:41 -0700167import android.view.WindowManagerPolicyConstants.PointerEventListener;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700168
Bryce Lee48f4b572017-04-10 10:54:15 -0700169import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800170import com.android.internal.util.ToBooleanFunction;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200171import com.android.internal.util.function.TriConsumer;
Adrian Roose99bc052017-11-20 17:55:31 +0100172import com.android.server.policy.WindowManagerPolicy;
Issei Suzuki43190bd2018-08-20 17:28:41 +0200173import com.android.server.wm.utils.DisplayRotationUtil;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100174import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100175import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700176
177import java.io.PrintWriter;
Riddle Hsuf53da812018-08-15 22:00:27 +0800178import java.lang.annotation.Retention;
179import java.lang.annotation.RetentionPolicy;
Craig Mautner59c00972012-07-30 12:10:24 -0700180import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700181import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700182import java.util.HashMap;
183import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700184import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700185import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100186import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800187import java.util.function.Consumer;
188import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700189
Craig Mautner59c00972012-07-30 12:10:24 -0700190/**
191 * Utility class for keeping track of the WindowStates and other pertinent contents of a
192 * particular Display.
Craig Mautner59c00972012-07-30 12:10:24 -0700193 */
Riddle Hsuad256a12018-07-18 16:11:30 +0800194class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
195 implements WindowManagerPolicy.DisplayContentInfo {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700196 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700197
Riddle Hsuf53da812018-08-15 22:00:27 +0800198 /** The default scaling mode that scales content automatically. */
199 static final int FORCE_SCALING_MODE_AUTO = 0;
200 /** For {@link #setForcedScalingMode} to apply flag {@link Display#FLAG_SCALING_DISABLED}. */
201 static final int FORCE_SCALING_MODE_DISABLED = 1;
202
203 @IntDef(prefix = { "FORCE_SCALING_MODE_" }, value = {
204 FORCE_SCALING_MODE_AUTO,
205 FORCE_SCALING_MODE_DISABLED
206 })
207 @Retention(RetentionPolicy.SOURCE)
208 @interface ForceScalingMode {}
209
Craig Mautner59c00972012-07-30 12:10:24 -0700210 /** Unique identifier of this stack. */
211 private final int mDisplayId;
212
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800213 // TODO: Remove once unification is complete.
214 ActivityDisplay mAcitvityDisplay;
215
Wale Ogunwale3a931692016-11-02 16:49:48 -0700216 /** The containers below are the only child containers the display can have. */
217 // Contains all window containers that are related to apps (Activities)
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800218 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700219 // Contains all non-app window containers that should be displayed above the app containers
220 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800221 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800222 new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700223 // Contains all non-app window containers that should be displayed below the app containers
224 // (e.g. Wallpaper).
225 private final NonAppWindowContainers mBelowAppWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800226 new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700227 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
228 // 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 -0800229 // window containers together and move them in-sync if/when needed. We use a subclass of
230 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
231 private final NonMagnifiableWindowContainers mImeWindowsContainers =
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800232 new NonMagnifiableWindowContainers("mImeWindowsContainers", mWmService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700233
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000234 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800235 private WindowState mTmpWindow2;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800236 private boolean mTmpRecoveringMemory;
237 private boolean mUpdateImeTarget;
238 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700239 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700240
lumark588a3e82018-07-20 18:53:54 +0800241 final AppTransition mAppTransition;
242 final AppTransitionController mAppTransitionController;
243 boolean mSkipAppTransitionAnimation = false;
244
245 final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>();
246 final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>();
247 final UnknownAppVisibilityController mUnknownAppVisibilityController;
248 BoundsAnimationController mBoundsAnimationController;
249
250 /**
251 * List of clients without a transtiton animation that we notify once we are done
252 * transitioning since they won't be notified through the app window animator.
253 */
254 final List<IBinder> mNoAnimationNotifyOnTransitionFinished = new ArrayList<>();
255
Wale Ogunwale02319a62016-09-26 15:21:22 -0700256 // Mapping from a token IBinder to a WindowToken object on this display.
257 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
258
Andrii Kuliancd097992017-03-23 18:31:59 -0700259 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700260 int mInitialDisplayWidth = 0;
261 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700262 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700263
Adrian Roos1cf585052018-01-03 18:43:27 +0100264 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100265 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100266 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100267
Andrii Kuliancd097992017-03-23 18:31:59 -0700268 /**
269 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
270 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
271 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
272 */
Craig Mautner59c00972012-07-30 12:10:24 -0700273 int mBaseDisplayWidth = 0;
274 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700275 /**
276 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
277 * but can be set from Settings or via shell command "adb shell wm density".
278 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
279 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700280 int mBaseDisplayDensity = 0;
Riddle Hsuf53da812018-08-15 22:00:27 +0800281
282 /**
283 * Whether to disable display scaling. This can be set via shell command "adb shell wm scaling".
284 * @see WindowManagerService#setForcedDisplayScalingMode(int, int)
285 */
Jeff Brownd46747a2015-04-15 19:02:36 -0700286 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700287 private final DisplayInfo mDisplayInfo = new DisplayInfo();
288 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700289 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800290 private final DisplayPolicy mDisplayPolicy;
291 private DisplayRotation mDisplayRotation;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000292 DisplayFrames mDisplayFrames;
293
Andrii Kulian06d07d62017-03-14 11:11:47 -0700294 /**
295 * For default display it contains real metrics, empty for others.
296 * @see WindowManagerService#createWatermarkInTransaction()
297 */
298 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800299
300 /** @see #computeCompatSmallestWidth(boolean, int, int, int, DisplayCutout) */
Andrii Kulian06d07d62017-03-14 11:11:47 -0700301 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700302
Andrii Kulian06d07d62017-03-14 11:11:47 -0700303 /**
304 * Compat metrics computed based on {@link #mDisplayMetrics}.
305 * @see #updateDisplayAndOrientation(int)
306 */
307 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
308
309 /** The desired scaling factor for compatible apps. */
310 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700311
Andrii Kulian8ee72852017-03-10 10:36:45 -0800312 /**
313 * Current rotation of the display.
314 * Constants as per {@link android.view.Surface.Rotation}.
315 *
Robert Carrae606b42018-02-15 15:36:23 -0800316 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800317 */
318 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700319
Andrii Kulian8ee72852017-03-10 10:36:45 -0800320 /**
321 * Last applied orientation of the display.
322 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
323 *
Riddle Hsu4e611772018-10-31 18:58:28 +0800324 * @see #updateOrientationFromAppTokens()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800325 */
326 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700327
Andrii Kulian8ee72852017-03-10 10:36:45 -0800328 /**
329 * Flag indicating that the application is receiving an orientation that has different metrics
330 * than it expected. E.g. Portrait instead of Landscape.
331 *
Robert Carrae606b42018-02-15 15:36:23 -0800332 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800333 */
334 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700335
Andrii Kulian8ee72852017-03-10 10:36:45 -0800336 /**
337 * Orientation forced by some window. If there is no visible window that specifies orientation
338 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
339 *
340 * @see NonAppWindowContainers#getOrientation()
341 */
342 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700343
Andrii Kulian8ee72852017-03-10 10:36:45 -0800344 /**
345 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
346 * occluded.
347 *
348 * @see NonAppWindowContainers#getOrientation()
349 */
350 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
351
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700352 /**
353 * Keep track of wallpaper visibility to notify changes.
354 */
355 private boolean mLastWallpaperVisible = false;
356
Andrii Kulian06d07d62017-03-14 11:11:47 -0700357 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700358
Craig Mautner39834192012-09-02 07:47:24 -0700359 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700360 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700361 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800362 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800363
Vishnu Nairba183352018-11-21 11:16:49 -0800364 /**
365 * Used to gate application window layout until we have sent the complete configuration.
366 * TODO: There are still scenarios where we may be out of sync with the client. Ideally
367 * we want to replace this flag with a mechanism that will confirm the configuration
368 * applied by the client is the one expected by the system server.
369 */
370 boolean mWaitingForConfig;
371
Andrii Kulian839def92016-11-02 10:58:58 -0700372 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800373 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800374 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800375
Andrii Kulianf0379de2018-03-14 16:24:07 -0700376 /**
377 * Flag indicating whether WindowManager should override info for this display in
378 * DisplayManager.
379 */
380 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700381
Craig Mautnerdc548482014-02-05 13:35:24 -0800382 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700383 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800384
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700385 /** Detect user tapping outside of current focused task bounds .*/
386 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700387
Craig Mautner6601b7b2013-04-29 10:29:11 -0700388 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700389 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700390
Craig Mautner6601b7b2013-04-29 10:29:11 -0700391 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800392 private final Rect mTmpRect = new Rect();
393 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700394 private final RectF mTmpRectF = new RectF();
395 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800396 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700397
Issei Suzuki43190bd2018-08-20 17:28:41 +0200398
Bryce Leef3c6a472017-11-14 14:53:06 -0800399 /** Used for handing back size of display */
400 private final Rect mTmpBounds = new Rect();
401
Craig Mautner95da1082014-02-24 17:54:35 -0800402 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700403 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800404
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700405 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700406 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700407
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800408 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800409 /** A collection of windows that provide tap exclude regions inside of them. */
410 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800411
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000412 private boolean mHaveBootMsg = false;
413 private boolean mHaveApp = false;
414 private boolean mHaveWallpaper = false;
415 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700416
417 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
418
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700419 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
420 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000421 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
422 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700423
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700424 // True if this display is in the process of being removed. Used to determine if the removal of
425 // the display's direct children should be allowed.
426 private boolean mRemovingDisplay = false;
427
Bryce Leed1871262017-06-12 14:12:29 -0700428 // {@code false} if this display is in the processing of being created.
429 private boolean mDisplayReady = false;
430
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800431 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700432
wilsonshihc32538e2018-11-07 17:27:34 +0800433 boolean mWallpaperMayChange = false;
434
Robert Carrb1579c82017-09-05 14:54:47 -0700435 private final SurfaceSession mSession = new SurfaceSession();
436
437 /**
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800438 * Window that is currently interacting with the user. This window is responsible for receiving
439 * key events and pointer events from the user.
440 */
441 WindowState mCurrentFocus = null;
442
443 /**
444 * The last focused window that we've notified the client that the focus is changed.
445 */
446 WindowState mLastFocus = null;
447
448 /**
449 * Windows that have lost input focus and are waiting for the new focus window to be displayed
450 * before they are told about this.
451 */
452 ArrayList<WindowState> mLosingFocus = new ArrayList<>();
453
454 /**
455 * The foreground app of this display. Windows below this app cannot be the focused window. If
456 * the user taps on the area outside of the task of the focused app, we will notify AM about the
457 * new task the user wants to interact with.
458 */
459 AppWindowToken mFocusedApp = null;
460
461 /** Windows added since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
462 final ArrayList<WindowState> mWinAddedSinceNullFocus = new ArrayList<>();
463
464 /** Windows removed since {@link #mCurrentFocus} was set to null. Used for ANR blaming. */
465 final ArrayList<WindowState> mWinRemovedSinceNullFocus = new ArrayList<>();
466
467 /**
Robert Carrb1579c82017-09-05 14:54:47 -0700468 * We organize all top-level Surfaces in to the following layers.
469 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800470 * and omitted from Screen-Magnification, for example the strict mode flash or
471 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700472 * {@link #mWindowingLayer} contains everything else.
473 */
474 private SurfaceControl mOverlayLayer;
475
476 /**
477 * See {@link #mOverlayLayer}
478 */
479 private SurfaceControl mWindowingLayer;
480
481 /**
Adrian Roos5251b1d2018-03-23 18:57:43 +0100482 * Sequence number for the current layout pass.
483 */
484 int mLayoutSeq = 0;
485
Chavi Weingarten3a748552018-05-14 17:32:42 +0000486 /**
487 * Specifies the count to determine whether to defer updating the IME target until ready.
488 */
489 private int mDeferUpdateImeTargetCount;
490
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100491 /** Temporary float array to retrieve 3x3 matrix values. */
492 private final float[] mTmpFloats = new float[9];
493
Robert Carr24be9ab2018-04-30 17:54:53 -0700494 private MagnificationSpec mMagnificationSpec;
495
Arthur Hung95b38a92018-07-20 18:56:12 +0800496 private InputMonitor mInputMonitor;
497
Jorim Jaggif1292892018-09-10 11:58:13 +0200498 /** Caches the value whether told display manager that we have content. */
499 private boolean mLastHasContent;
500
Issei Suzuki43190bd2018-08-20 17:28:41 +0200501 private DisplayRotationUtil mRotationUtil = new DisplayRotationUtil();
502
lumark90120a82018-08-15 00:33:03 +0800503 /**
504 * The input method window for this display.
505 */
506 WindowState mInputMethodWindow;
507
lumarkff0ab692018-11-05 20:32:30 +0800508 /**
509 * This just indicates the window the input method is on top of, not
510 * necessarily the window its input is going to.
511 */
512 WindowState mInputMethodTarget;
513
514 /** If true hold off on modifying the animation layer of mInputMethodTarget */
515 boolean mInputMethodTargetWaitingAnim;
516
Arthur Hungbe5ce212018-09-13 18:41:56 +0800517 private final PointerEventDispatcher mPointerEventDispatcher;
518
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200519 private final InsetsStateController mInsetsStateController;
520
Tiger Huang7c610aa2018-10-27 00:01:01 +0800521 // Last systemUiVisibility we received from status bar.
522 private int mLastStatusBarVisibility = 0;
523 // Last systemUiVisibility we dispatched to windows.
524 private int mLastDispatchedSystemUiVisibility = 0;
525
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800526 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
527 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800528 final AppWindowToken atoken = w.mAppToken;
529 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200530 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800531 if (w.performShowLocked()) {
532 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
533 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800534 mWmService.mWindowPlacerLocked.debugLayoutRepeats(
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800535 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
536 }
537 }
538 }
539 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800540 };
541
542 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
543 final WindowStateAnimator winAnimator = w.mWinAnimator;
544 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
545 return;
546 }
547
Jorim Jaggi8f520872018-08-14 17:00:20 +0200548 // If this window is animating, ensure the animation background is set.
549 final AnimationAdapter anim = w.mAppToken != null
550 ? w.mAppToken.getAnimation()
551 : w.getAnimation();
552 if (anim != null) {
553 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800554 if (color != 0) {
555 final TaskStack stack = w.getStack();
556 if (stack != null) {
557 stack.setAnimationBackground(winAnimator, color);
558 }
559 }
560 }
561 };
562
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800563 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
564 final int lostFocusUid = mTmpWindow.mOwnerUid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800565 final Handler handler = mWmService.mH;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800566 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
567 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
568 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
569 w.mAttrs.hideTimeoutMilliseconds);
570 }
571 }
572 };
573
574 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800575 final AppWindowToken focusedApp = mFocusedApp;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800576 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
577 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
578
579 if (!w.canReceiveKeys()) {
580 return false;
581 }
582
583 final AppWindowToken wtoken = w.mAppToken;
584
585 // If this window's application has been removed, just skip it.
586 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
587 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
588 + (wtoken.removed ? "removed" : "sendingToBottom"));
589 return false;
590 }
591
592 if (focusedApp == null) {
593 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
594 + " using new focus @ " + w);
595 mTmpWindow = w;
596 return true;
597 }
598
599 if (!focusedApp.windowsAreFocusable()) {
600 // Current focused app windows aren't focusable...
601 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
602 + " focusable using new focus @ " + w);
603 mTmpWindow = w;
604 return true;
605 }
606
607 // Descend through all of the app tokens and find the first that either matches
608 // win.mAppToken (return win) or mFocusedApp (return null).
609 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
610 if (focusedApp.compareTo(wtoken) > 0) {
611 // App stack below focused app stack. No focus for you!!!
612 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
613 "findFocusedWindow: Reached focused app=" + focusedApp);
614 mTmpWindow = null;
615 return true;
616 }
617 }
618
619 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
620 mTmpWindow = w;
621 return true;
622 };
623
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800624 private final Consumer<WindowState> mPerformLayout = w -> {
625 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
626 // wasting time and funky changes while a window is animating away.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800627 final boolean gone = (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w))
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800628 || w.isGoneForLayoutLw();
629
630 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
631 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
632 + " mLayoutAttached=" + w.mLayoutAttached
633 + " screen changed=" + w.isConfigChanged());
634 final AppWindowToken atoken = w.mAppToken;
635 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200636 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800637 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
638 + " parentHidden=" + w.isParentWindowHidden());
639 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200640 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800641 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
642 + " parentHidden=" + w.isParentWindowHidden());
643 }
644
645 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
646 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
647 // since that means "perform layout as normal, just don't display").
648 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
649 || ((w.isConfigChanged() || w.setReportResizeHints())
650 && !w.isGoneForLayoutLw() &&
651 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
652 (w.mHasSurface && w.mAppToken != null &&
653 w.mAppToken.layoutConfigChanges)))) {
654 if (!w.mLayoutAttached) {
655 if (mTmpInitial) {
656 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700657 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800658 }
659 if (w.mAttrs.type == TYPE_DREAM) {
660 // Don't layout windows behind a dream, so that if it does stuff like hide
661 // the status bar we won't get a bad transition when it goes away.
662 mTmpWindow = w;
663 }
664 w.mLayoutNeeded = false;
665 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200666 final boolean firstLayout = !w.isLaidOut();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800667 getDisplayPolicy().layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100668 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800669
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200670 // If this is the first layout, we need to initialize the last inset values as
671 // otherwise we'd immediately cause an unnecessary resize.
672 if (firstLayout) {
673 w.updateLastInsetValues();
674 }
675
Adrian Roos23df3a32018-03-15 15:41:13 +0100676 if (w.mAppToken != null) {
677 w.mAppToken.layoutLetterbox(w);
678 }
679
chaviw492139a2018-07-16 16:07:35 -0700680 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700681 + " mContainingFrame=" + w.getContainingFrame()
682 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800683 }
684 }
685 };
686
687 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
688 if (w.mLayoutAttached) {
689 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
690 + " mViewVisibility=" + w.mViewVisibility
691 + " mRelayoutCalled=" + w.mRelayoutCalled);
692 // If this view is GONE, then skip it -- keep the current frame, and let the caller
693 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
694 // windows, since that means "perform layout as normal, just don't display").
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800695 if (mTmpWindow != null && mWmService.mPolicy.canBeHiddenByKeyguardLw(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800696 return;
697 }
698 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
699 || w.mLayoutNeeded) {
700 if (mTmpInitial) {
701 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700702 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800703 }
704 w.mLayoutNeeded = false;
705 w.prelayout();
Tiger Huang7c610aa2018-10-27 00:01:01 +0800706 getDisplayPolicy().layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100707 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700708 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700709 + " mContainingFrame=" + w.getContainingFrame()
710 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800711 }
712 } else if (w.mAttrs.type == TYPE_DREAM) {
713 // Don't layout windows behind a dream, so that if it does stuff like hide the
714 // status bar we won't get a bad transition when it goes away.
715 mTmpWindow = mTmpWindow2;
716 }
717 };
718
719 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
720 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
721 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
722 return w.canBeImeTarget();
723 };
724
725 private final Consumer<WindowState> mApplyPostLayoutPolicy =
Tiger Huang7c610aa2018-10-27 00:01:01 +0800726 w -> getDisplayPolicy().applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
lumarkff0ab692018-11-05 20:32:30 +0800727 mInputMethodTarget);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800728
729 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800730 final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800731 final boolean obscuredChanged = w.mObscured !=
732 mTmpApplySurfaceChangesTransactionState.obscured;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800733 final RootWindowContainer root = mWmService.mRoot;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800734
735 // Update effect.
736 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
737 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
738 final boolean isDisplayed = w.isDisplayedLw();
739
740 if (isDisplayed && w.isObscuringDisplay()) {
741 // This window completely covers everything behind it, so we want to leave all
742 // of them as undimmed (for performance reasons).
743 root.mObscuringWindow = w;
744 mTmpApplySurfaceChangesTransactionState.obscured = true;
745 }
746
747 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
748 root.handleNotObscuredLocked(w,
749 mTmpApplySurfaceChangesTransactionState.obscured,
750 mTmpApplySurfaceChangesTransactionState.syswin);
751
752 if (w.mHasSurface && isDisplayed) {
753 final int type = w.mAttrs.type;
754 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
755 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
756 mTmpApplySurfaceChangesTransactionState.syswin = true;
757 }
758 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
759 && w.mAttrs.preferredRefreshRate != 0) {
760 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
761 = w.mAttrs.preferredRefreshRate;
762 }
763 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
764 && w.mAttrs.preferredDisplayModeId != 0) {
765 mTmpApplySurfaceChangesTransactionState.preferredModeId
766 = w.mAttrs.preferredDisplayModeId;
767 }
768 }
769 }
770
wilsonshihc32538e2018-11-07 17:27:34 +0800771 if (obscuredChanged && w.isVisibleLw() && mWallpaperController.isWallpaperTarget(w)) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800772 // This is the wallpaper target and its obscured state changed... make sure the
773 // current wallpaper's visibility has been updated accordingly.
774 mWallpaperController.updateWallpaperVisibility();
775 }
776
chaviw161ea3e2018-01-31 12:01:12 -0800777 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800778
779 final WindowStateAnimator winAnimator = w.mWinAnimator;
780
781 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
chaviw1454b392018-08-06 09:54:04 -0700782 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800783
784 // Moved from updateWindowsAndWallpaperLocked().
785 if (w.mHasSurface) {
786 // Take care of the window being ready to display.
787 final boolean committed = winAnimator.commitFinishDrawingLocked();
788 if (isDefaultDisplay && committed) {
789 if (w.mAttrs.type == TYPE_DREAM) {
790 // HACK: When a dream is shown, it may at that point hide the lock screen.
791 // So we need to redo the layout to let the phone window manager make this
792 // happen.
793 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
794 if (DEBUG_LAYOUT_REPEATS) {
795 surfacePlacer.debugLayoutRepeats(
796 "dream and commitFinishDrawingLocked true",
797 pendingLayoutChanges);
798 }
799 }
800 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
801 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
802 "First draw done in potential wallpaper target " + w);
wilsonshihc32538e2018-11-07 17:27:34 +0800803 mWallpaperMayChange = true;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800804 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
805 if (DEBUG_LAYOUT_REPEATS) {
806 surfacePlacer.debugLayoutRepeats(
807 "wallpaper and commitFinishDrawingLocked true",
808 pendingLayoutChanges);
809 }
810 }
811 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800812 }
813
814 final AppWindowToken atoken = w.mAppToken;
815 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100816 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800817 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
818 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
819 mTmpUpdateAllDrawn.add(atoken);
820 }
821 }
822
Tiger Huang1e5b10a2018-07-30 20:19:51 +0800823 if (!mLosingFocus.isEmpty() && w.isFocused() && w.isDisplayedLw()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800824 mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800825 }
826
827 w.updateResizingWindowIfNeeded();
828 };
829
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800830 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800831 * Create new {@link DisplayContent} instance, add itself to the root window container and
832 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700833 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800834 * @param service You know.
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800835 * @param activityDisplay The ActivityDisplay for the display container.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700836 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700837 DisplayContent(Display display, WindowManagerService service,
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800838 ActivityDisplay activityDisplay) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100839 super(service);
Wale Ogunwale3a256e62018-12-06 14:41:18 -0800840 mAcitvityDisplay = activityDisplay;
Wale Ogunwale1666e312016-12-16 11:27:18 -0800841 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
842 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
843 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
844 + " new=" + display);
845 }
846
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700847 mDisplay = display;
848 mDisplayId = display.getDisplayId();
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800849 mWallpaperController = new WallpaperController(mWmService, this);
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700850 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700851 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700852 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100853 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
854 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700855 initializeDisplayBaseInfo();
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700856
lumark588a3e82018-07-20 18:53:54 +0800857 mAppTransition = new AppTransition(service.mContext, service, this);
858 mAppTransition.registerListenerLocked(service.mActivityManagerAppTransitionNotifier);
859 mAppTransitionController = new AppTransitionController(service, this);
860 mUnknownAppVisibilityController = new UnknownAppVisibilityController(service, this);
861
862 AnimationHandler animationHandler = new AnimationHandler();
863 mBoundsAnimationController = new BoundsAnimationController(service.mContext,
864 mAppTransition, SurfaceAnimationThread.getHandler(), animationHandler);
865
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800866 if (mWmService.mInputManager != null) {
867 final InputChannel inputChannel = mWmService.mInputManager.monitorInput("Display "
Tiger Huang7c610aa2018-10-27 00:01:01 +0800868 + mDisplayId, mDisplayId);
869 mPointerEventDispatcher = inputChannel != null
870 ? new PointerEventDispatcher(inputChannel) : null;
871 } else {
872 mPointerEventDispatcher = null;
873 }
874 mDisplayPolicy = new DisplayPolicy(service, this);
875 mDisplayRotation = new DisplayRotation(service, this);
876 if (isDefaultDisplay) {
877 // The policy may be invoked right after here, so it requires the necessary default
878 // fields of this display content.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800879 mWmService.mPolicy.setDefaultDisplay(this);
Tiger Huang7c610aa2018-10-27 00:01:01 +0800880 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800881 if (mWmService.mDisplayReady) {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800882 mDisplayPolicy.onConfigurationChanged();
883 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800884 if (mWmService.mSystemReady) {
Tiger Huang7c610aa2018-10-27 00:01:01 +0800885 mDisplayPolicy.systemReady();
886 }
887 mDividerControllerLocked = new DockedStackDividerController(service, this);
888 mPinnedStackControllerLocked = new PinnedStackController(service, this);
889
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800890 final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(mSession).setOpaque(true);
Robert Carrb1579c82017-09-05 14:54:47 -0700891 mWindowingLayer = b.setName("Display Root").build();
892 mOverlayLayer = b.setName("Display Overlays").build();
893
Robert Carrf59b8dd2017-10-02 18:58:36 -0700894 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700895 .setLayerStack(mWindowingLayer, mDisplayId)
896 .show(mWindowingLayer)
897 .setLayer(mOverlayLayer, 1)
898 .setLayerStack(mOverlayLayer, mDisplayId)
899 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700900 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700901
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700902 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700903 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700904 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700905 super.addChild(mAboveAppWindowsContainers, null);
906 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800907
908 // Add itself as a child to the root container.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800909 mWmService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700910
911 // TODO(b/62541591): evaluate whether this is the best spot to declare the
912 // {@link DisplayContent} ready for use.
913 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800914
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800915 mWmService.mAnimator.addDisplayLocked(mDisplayId);
Arthur Hung39134b22018-08-14 11:58:28 +0800916 mInputMonitor = new InputMonitor(service, mDisplayId);
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200917 mInsetsStateController = new InsetsStateController(this);
Bryce Leed1871262017-06-12 14:12:29 -0700918 }
919
920 boolean isReady() {
921 // The display is ready when the system and the individual display are both ready.
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800922 return mWmService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700923 }
924
925 int getDisplayId() {
926 return mDisplayId;
927 }
928
Wale Ogunwale02319a62016-09-26 15:21:22 -0700929 WindowToken getWindowToken(IBinder binder) {
930 return mTokenMap.get(binder);
931 }
932
933 AppWindowToken getAppWindowToken(IBinder binder) {
934 final WindowToken token = getWindowToken(binder);
935 if (token == null) {
936 return null;
937 }
938 return token.asAppWindowToken();
939 }
940
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700941 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800942 final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700943 if (dc != null) {
944 // We currently don't support adding a window token to the display if the display
945 // already has the binder mapped to another token. If there is a use case for supporting
946 // this moving forward we will either need to merge the WindowTokens some how or have
947 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700948 throw new IllegalArgumentException("Can't map token=" + token + " to display="
949 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700950 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700951 if (binder == null) {
952 throw new IllegalArgumentException("Can't map token=" + token + " to display="
953 + getName() + " binder is null");
954 }
955 if (token == null) {
956 throw new IllegalArgumentException("Can't map null token to display="
957 + getName() + " binder=" + binder);
958 }
959
Wale Ogunwale02319a62016-09-26 15:21:22 -0700960 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700961
962 if (token.asAppWindowToken() == null) {
963 // Add non-app token to container hierarchy on the display. App tokens are added through
964 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700965 switch (token.windowType) {
966 case TYPE_WALLPAPER:
967 mBelowAppWindowsContainers.addChild(token);
968 break;
969 case TYPE_INPUT_METHOD:
970 case TYPE_INPUT_METHOD_DIALOG:
971 mImeWindowsContainers.addChild(token);
972 break;
973 default:
974 mAboveAppWindowsContainers.addChild(token);
975 break;
976 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700977 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700978 }
979
980 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700981 final WindowToken token = mTokenMap.remove(binder);
982 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800983 token.setExiting();
984 }
985 return token;
986 }
987
988 /** Changes the display the input window token is housed on to this one. */
989 void reParentWindowToken(WindowToken token) {
990 final DisplayContent prevDc = token.getDisplayContent();
991 if (prevDc == this) {
992 return;
993 }
Riddle Hsu85bd04b2018-11-17 00:34:36 +0800994 if (prevDc != null) {
995 if (prevDc.mTokenMap.remove(token.token) != null && token.asAppWindowToken() == null) {
996 // Removed the token from the map, but made sure it's not an app token before
997 // removing from parent.
998 token.getParent().removeChild(token);
999 }
1000 if (prevDc.mLastFocus == mCurrentFocus) {
1001 // The window has become the focus of this display, so it should not be notified
1002 // that it lost focus from the previous display.
1003 prevDc.mLastFocus = null;
1004 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001005 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -08001006
1007 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -07001008 }
1009
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001010 void removeAppToken(IBinder binder) {
1011 final WindowToken token = removeWindowToken(binder);
1012 if (token == null) {
1013 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
1014 return;
1015 }
1016
1017 final AppWindowToken appToken = token.asAppWindowToken();
1018
1019 if (appToken == null) {
1020 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
1021 return;
1022 }
1023
1024 appToken.onRemovedFromDisplay();
1025 }
1026
Riddle Hsuad256a12018-07-18 16:11:30 +08001027 @Override
1028 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -07001029 return mDisplay;
1030 }
1031
Craig Mautner59c00972012-07-30 12:10:24 -07001032 DisplayInfo getDisplayInfo() {
1033 return mDisplayInfo;
1034 }
1035
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001036 DisplayMetrics getDisplayMetrics() {
1037 return mDisplayMetrics;
1038 }
1039
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001040 DisplayPolicy getDisplayPolicy() {
1041 return mDisplayPolicy;
1042 }
1043
Riddle Hsuad256a12018-07-18 16:11:30 +08001044 @Override
1045 public DisplayRotation getDisplayRotation() {
1046 return mDisplayRotation;
1047 }
1048
Jorim Jaggif96c90a2018-09-26 16:55:15 +02001049 /**
1050 * Marks a window as providing insets for the rest of the windows in the system.
1051 *
1052 * @param type The type of inset this window provides.
1053 * @param win The window.
1054 * @param frameProvider Function to compute the frame, or {@code null} if the just the frame of
1055 * the window should be taken.
1056 */
1057 void setInsetProvider(@InternalInsetType int type, WindowState win,
1058 @Nullable TriConsumer<DisplayFrames, WindowState, Rect> frameProvider) {
1059 mInsetsStateController.getSourceProvider(type).setWindow(win, frameProvider);
1060 }
1061
1062 InsetsStateController getInsetsStateController() {
1063 return mInsetsStateController;
1064 }
1065
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001066 @VisibleForTesting
1067 void setDisplayRotation(DisplayRotation displayRotation) {
1068 mDisplayRotation = displayRotation;
1069 }
1070
Andrii Kulian8ee72852017-03-10 10:36:45 -08001071 int getRotation() {
1072 return mRotation;
1073 }
1074
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001075 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -08001076 void setRotation(int newRotation) {
1077 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +08001078 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001079 }
1080
1081 int getLastOrientation() {
1082 return mLastOrientation;
1083 }
1084
Andrii Kulian8ee72852017-03-10 10:36:45 -08001085 boolean getAltOrientation() {
1086 return mAltOrientation;
1087 }
1088
Andrii Kulian8ee72852017-03-10 10:36:45 -08001089 int getLastWindowForcedOrientation() {
1090 return mLastWindowForcedOrientation;
1091 }
1092
Andrii Kulian06d07d62017-03-14 11:11:47 -07001093 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +08001094 * Temporarily pauses rotation changes until resumed.
1095 *
1096 * This can be used to prevent rotation changes from occurring while the user is
1097 * performing certain operations, such as drag and drop.
1098 *
1099 * This call nests and must be matched by an equal number of calls to
1100 * {@link #resumeRotationLocked}.
1101 */
1102 void pauseRotationLocked() {
1103 mDeferredRotationPauseCount++;
1104 }
1105
1106 /**
1107 * Resumes normal rotation changes after being paused.
1108 */
1109 void resumeRotationLocked() {
1110 if (mDeferredRotationPauseCount <= 0) {
1111 return;
1112 }
1113
1114 mDeferredRotationPauseCount--;
1115 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001116 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001117 }
1118 }
1119
1120 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001121 * If this is true we have updated our desired orientation, but not yet changed the real
1122 * orientation our applied our screen rotation animation. For example, because a previous
1123 * screen rotation was in progress.
1124 *
1125 * @return {@code true} if the there is an ongoing rotation change.
1126 */
1127 boolean rotationNeedsUpdate() {
1128 final int lastOrientation = getLastOrientation();
1129 final int oldRotation = getRotation();
1130 final boolean oldAltOrientation = getAltOrientation();
1131
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001132 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001133 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1134 lastOrientation, rotation);
1135 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1136 return false;
1137 }
1138 return true;
1139 }
1140
Wale Ogunwale3a256e62018-12-06 14:41:18 -08001141 /**
1142 * The display content may have configuration set from {@link #DisplayWindowSettings}. This
1143 * callback let the owner of container know there is existing configuration to prevent the
1144 * values from being replaced by the initializing {@link #ActivityDisplay}.
1145 */
1146 void initializeDisplayOverrideConfiguration() {
1147 if (mAcitvityDisplay != null) {
1148 mAcitvityDisplay.onInitializeOverrideConfiguration(getRequestedOverrideConfiguration());
1149 }
1150 }
1151
Riddle Hsu4e611772018-10-31 18:58:28 +08001152 /** Notify the configuration change of this display. */
1153 void sendNewConfiguration() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001154 mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget();
Riddle Hsu4e611772018-10-31 18:58:28 +08001155 }
1156
1157 /**
1158 * Determine the new desired orientation of this display.
1159 *
1160 * The orientation is computed from non-application windows first. If none of the
1161 * non-application windows specify orientation, the orientation is computed from application
1162 * tokens.
1163 *
1164 * @return {@code true} if the orientation is changed.
1165 */
1166 boolean updateOrientationFromAppTokens() {
1167 return updateOrientationFromAppTokens(false /* forceUpdate */);
1168 }
1169
1170 boolean updateOrientationFromAppTokens(boolean forceUpdate) {
1171 final int req = getOrientation();
1172 if (req != mLastOrientation || forceUpdate) {
1173 mLastOrientation = req;
1174 mDisplayRotation.setCurrentOrientation(req);
1175 return updateRotationUnchecked(forceUpdate);
1176 }
1177 return false;
1178 }
1179
Riddle Hsuad256a12018-07-18 16:11:30 +08001180 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001181 * Update rotation of the display and send configuration if the rotation is changed.
1182 *
1183 * @return {@code true} if the rotation has been changed and the new config is sent.
1184 */
1185 boolean updateRotationAndSendNewConfigIfNeeded() {
1186 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1187 if (changed) {
Riddle Hsu4e611772018-10-31 18:58:28 +08001188 sendNewConfiguration();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001189 }
1190 return changed;
1191 }
1192
1193 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001194 * Update rotation of the display.
1195 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001196 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1197 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001198 */
Robert Carrae606b42018-02-15 15:36:23 -08001199 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001200 return updateRotationUnchecked(false /* forceUpdate */);
1201 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001202
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001203 /**
Evan Roskye747c3e2018-10-30 20:06:41 -07001204 * Update rotation of the DisplayContent with an option to force the update. This updates
1205 * the container's perception of rotation and, depending on the top activities, will freeze
1206 * the screen or start seamless rotation. The display itself gets rotated in
1207 * {@link #applyRotationLocked} during {@link WindowManagerService#sendNewConfiguration}.
1208 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001209 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1210 * orientation because we're waiting for some rotation to finish or display
1211 * to unfreeze, which results in configuration of the previously visible
1212 * activity being applied to a newly visible one. Forcing the rotation
1213 * update allows to workaround this issue.
1214 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
Evan Roskye747c3e2018-10-30 20:06:41 -07001215 * {@link WindowManagerService#sendNewConfiguration(int)} TO COMPLETE THE ROTATION AND
1216 * UNFREEZE THE SCREEN.
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001217 */
1218 boolean updateRotationUnchecked(boolean forceUpdate) {
1219 ScreenRotationAnimation screenRotationAnimation;
1220 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001221 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001222 // Rotation updates have been paused temporarily. Defer the update until
1223 // updates have been resumed.
1224 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1225 return false;
1226 }
1227
1228 screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001229 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001230 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1231 // Rotation updates cannot be performed while the previous rotation change
1232 // animation is still in progress. Skip this update. We will try updating
1233 // again after the animation is finished and the display is unfrozen.
1234 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1235 return false;
1236 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001237 if (mWmService.mDisplayFrozen) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001238 // Even if the screen rotation animation has finished (e.g. isAnimating
1239 // returns false), there is still some time where we haven't yet unfrozen
1240 // the display. We also need to abort rotation here.
1241 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1242 "Deferring rotation, still finishing previous rotation");
1243 return false;
1244 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001245 }
1246
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001247 if (!mWmService.mDisplayEnabled) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001248 // No point choosing a rotation if the display is not enabled.
1249 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1250 return false;
1251 }
1252
1253 final int oldRotation = mRotation;
1254 final int lastOrientation = mLastOrientation;
1255 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001256 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001257 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1258 + mDisplayId + " based on lastOrientation=" + lastOrientation
1259 + " and oldRotation=" + oldRotation);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001260 boolean mayRotateSeamlessly = mDisplayPolicy.shouldRotateSeamlessly(mDisplayRotation,
Riddle Hsuad256a12018-07-18 16:11:30 +08001261 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001262
Robert Carr0e007272017-10-02 13:00:55 -07001263 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001264 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001265 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001266 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1267 // to complete (that is, waiting for windows to redraw). It's tempting to check
1268 // w.mSeamlessRotationCount but that could be incorrect in the case of
1269 // window-removal.
1270 return false;
1271 }
Robert Carr0e007272017-10-02 13:00:55 -07001272
1273 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001274 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001275 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001276 mayRotateSeamlessly = false;
1277 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001278 for (int i = 0; i < mWmService.mSessions.size(); i++) {
1279 if (mWmService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
Robert Carr0e007272017-10-02 13:00:55 -07001280 mayRotateSeamlessly = false;
1281 break;
1282 }
1283 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001284 }
Robert Carr0e007272017-10-02 13:00:55 -07001285 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001286
1287 // TODO: Implement forced rotation changes.
1288 // Set mAltOrientation to indicate that the application is receiving
1289 // an orientation that has different metrics than it expected.
1290 // eg. Portrait instead of Landscape.
1291
Riddle Hsuad256a12018-07-18 16:11:30 +08001292 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001293 lastOrientation, rotation);
1294
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001295 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1296 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001297 + ", got rotation " + rotation + " which has "
1298 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1299
1300 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1301 // No change.
1302 return false;
1303 }
1304
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001305 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1306 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001307 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1308 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1309
1310 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
Vishnu Nairba183352018-11-21 11:16:49 -08001311 mWaitingForConfig = true;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001312 }
1313
Evan Roskye747c3e2018-10-30 20:06:41 -07001314 mRotation = rotation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001315 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001316
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001317 mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1318 mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
Riddle Hsu654a6f92018-07-13 22:59:36 +08001319 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001320
1321 setLayoutNeeded();
1322 final int[] anim = new int[2];
Tiger Huang7c610aa2018-10-27 00:01:01 +08001323 mDisplayPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001324
1325 if (!rotateSeamlessly) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001326 mWmService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001327 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001328 } else {
1329 // The screen rotation animation uses a screenshot to freeze the screen
1330 // while windows resize underneath.
1331 // When we are rotating seamlessly, we allow the elements to transition
1332 // to their rotated state independently and without a freeze required.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001333 mWmService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001334 }
1335
Evan Roskye747c3e2018-10-30 20:06:41 -07001336 return true;
1337 }
1338
1339 /**
1340 * Applies the rotation transaction. This must be called after {@link #updateRotationUnchecked}
1341 * (if it returned {@code true}) to actually finish the rotation.
1342 *
1343 * @param oldRotation the rotation we are coming from.
1344 * @param rotation the rotation to apply.
1345 */
1346 void applyRotationLocked(final int oldRotation, final int rotation) {
1347 mDisplayRotation.setRotation(rotation);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001348 final boolean rotateSeamlessly = mWmService.isRotatingSeamlessly();
Evan Roskye747c3e2018-10-30 20:06:41 -07001349 ScreenRotationAnimation screenRotationAnimation = rotateSeamlessly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001350 ? null : mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001351 // We need to update our screen size information to match the new rotation. If the rotation
1352 // has actually changed then this method will return true and, according to the comment at
1353 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1354 // By updating the Display info here it will be available to
1355 // #computeScreenConfiguration() later.
1356 updateDisplayAndOrientation(getConfiguration().uiMode);
1357
Robert Carrae606b42018-02-15 15:36:23 -08001358 // NOTE: We disable the rotation in the emulator because
1359 // it doesn't support hardware OpenGL emulation yet.
1360 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1361 && screenRotationAnimation.hasScreenshot()) {
1362 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001363 MAX_ANIMATION_DURATION, mWmService.getTransitionAnimationScaleLocked(),
Robert Carrae606b42018-02-15 15:36:23 -08001364 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001365 mWmService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001366 }
1367 }
1368
Vishnu Nair83537a72018-07-19 21:27:48 -07001369 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001370 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1371 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001372 }, true /* traverseTopToBottom */);
1373
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001374 mWmService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
Robert Carrae606b42018-02-15 15:36:23 -08001375 scheduleAnimation();
1376
Andrii Kulian06d07d62017-03-14 11:11:47 -07001377 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001378 if (w.mHasSurface && !rotateSeamlessly) {
1379 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001380 w.setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001381 mWmService.mRoot.mOrientationChangeComplete = false;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001382 w.mLastFreezeDuration = 0;
1383 }
1384 w.mReportOrientationChanged = true;
1385 }, true /* traverseTopToBottom */);
1386
1387 if (rotateSeamlessly) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001388 mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
Riddle Hsu654a6f92018-07-13 22:59:36 +08001389 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001390 }
1391
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001392 for (int i = mWmService.mRotationWatchers.size() - 1; i >= 0; i--) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001393 final WindowManagerService.RotationWatcher rotationWatcher
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001394 = mWmService.mRotationWatchers.get(i);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001395 if (rotationWatcher.mDisplayId == mDisplayId) {
1396 try {
1397 rotationWatcher.mWatcher.onRotationChanged(rotation);
1398 } catch (RemoteException e) {
1399 // Ignore
1400 }
1401 }
1402 }
1403
1404 // TODO (multi-display): Magnification is supported only for the default display.
1405 // Announce rotation only if we will not animate as we already have the
1406 // windows in final state. Otherwise, we make this call at the rotation end.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001407 if (screenRotationAnimation == null && mWmService.mAccessibilityController != null
Andrii Kulian06d07d62017-03-14 11:11:47 -07001408 && isDefaultDisplay) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001409 mWmService.mAccessibilityController.onRotationChangedLocked(this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001410 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001411 }
1412
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001413 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001414 final int width = mBaseDisplayWidth;
1415 final int height = mBaseDisplayHeight;
1416 final int shortSize;
1417 final int longSize;
1418 if (width > height) {
1419 shortSize = height;
1420 longSize = width;
1421 } else {
1422 shortSize = width;
1423 longSize = height;
1424 }
1425
1426 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1427 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1428
1429 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1430 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001431
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001432 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1433 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Arthur Hungbe5ce212018-09-13 18:41:56 +08001434
1435 // Tap Listeners are supported for:
1436 // 1. All physical displays (multi-display).
1437 // 2. VirtualDisplays on VR, AA (and everything else).
1438 if (mPointerEventDispatcher != null && mTapDetector == null) {
1439 if (DEBUG_DISPLAY) {
1440 Slog.d(TAG,
1441 "Registering PointerEventListener for DisplayId: " + mDisplayId);
1442 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001443 mTapDetector = new TaskTapPointerEventListener(mWmService, this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08001444 registerPointerEventListener(mTapDetector);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001445 registerPointerEventListener(mWmService.mMousePositionTracker);
Arthur Hungbe5ce212018-09-13 18:41:56 +08001446 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001447 }
1448
Andrii Kulian06d07d62017-03-14 11:11:47 -07001449 /**
1450 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1451 * changed.
1452 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1453 */
1454 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1455 // Use the effective "visual" dimensions based on current rotation
1456 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1457 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1458 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1459 int dw = realdw;
1460 int dh = realdh;
1461
1462 if (mAltOrientation) {
1463 if (realdw > realdh) {
1464 // Turn landscape into portrait.
1465 int maxw = (int)(realdh/1.3f);
1466 if (maxw < realdw) {
1467 dw = maxw;
1468 }
1469 } else {
1470 // Turn portrait into landscape.
1471 int maxh = (int)(realdw/1.3f);
1472 if (maxh < realdh) {
1473 dh = maxh;
1474 }
1475 }
1476 }
1477
1478 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001479 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1480 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1481
Tiger Huang7c610aa2018-10-27 00:01:01 +08001482 final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1483 displayCutout);
1484 final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1485 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001486 mDisplayInfo.rotation = mRotation;
1487 mDisplayInfo.logicalWidth = dw;
1488 mDisplayInfo.logicalHeight = dh;
1489 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1490 mDisplayInfo.appWidth = appWidth;
1491 mDisplayInfo.appHeight = appHeight;
1492 if (isDefaultDisplay) {
1493 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1494 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1495 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001496 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001497 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1498 if (mDisplayScalingDisabled) {
1499 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1500 } else {
1501 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1502 }
1503
Andrii Kulianf0379de2018-03-14 16:24:07 -07001504 // We usually set the override info in DisplayManager so that we get consistent display
1505 // metrics values when displays are changing and don't send out new values until WM is aware
1506 // of them. However, we don't do this for displays that serve as containers for ActivityView
1507 // because we don't want letter-/pillar-boxing during resize.
1508 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1509 ? mDisplayInfo : null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001510 mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001511 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001512
1513 mBaseDisplayRect.set(0, 0, dw, dh);
1514
1515 if (isDefaultDisplay) {
1516 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1517 mCompatDisplayMetrics);
1518 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001519
Andrii Kulian06d07d62017-03-14 11:11:47 -07001520 return mDisplayInfo;
1521 }
1522
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001523 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001524 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1525 }
1526
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001527 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001528 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001529 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001530 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001531 }
Adrian Roos11c25582018-02-19 18:06:36 +01001532 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001533 return WmDisplayCutout.computeSafeInsets(
1534 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001535 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001536 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Issei Suzuki43190bd2018-08-20 17:28:41 +02001537 final Rect[] newBounds = mRotationUtil.getRotatedBounds(
1538 WmDisplayCutout.computeSafeInsets(
Jorim Jaggi60640512018-06-29 01:14:31 +02001539 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
Issei Suzuki43190bd2018-08-20 17:28:41 +02001540 .getDisplayCutout().getBoundingRectsAll(),
1541 rotation, mInitialDisplayWidth, mInitialDisplayHeight);
1542 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(newBounds),
Adrian Roos24264212018-02-19 16:26:15 +01001543 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1544 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001545 }
1546
Andrii Kulian06d07d62017-03-14 11:11:47 -07001547 /**
1548 * Compute display configuration based on display properties and policy settings.
1549 * Do not call if mDisplayReady == false.
1550 */
1551 void computeScreenConfiguration(Configuration config) {
1552 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
Evan Roskye747c3e2018-10-30 20:06:41 -07001553 calculateBounds(displayInfo, mTmpBounds);
1554 config.windowConfiguration.setBounds(mTmpBounds);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001555
1556 final int dw = displayInfo.logicalWidth;
1557 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001558 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001559 config.windowConfiguration.setWindowingMode(getWindowingMode());
Yunfan Chen7daa6ac2018-11-29 18:16:44 -08001560 config.windowConfiguration.setDisplayWindowingMode(getWindowingMode());
Evan Roskye747c3e2018-10-30 20:06:41 -07001561 config.windowConfiguration.setRotation(displayInfo.rotation);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001562
Adrian Roos11c25582018-02-19 18:06:36 +01001563 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001564 config.screenWidthDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001565 (int)(mDisplayPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1566 config.uiMode, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001567 config.screenHeightDp =
Tiger Huang7c610aa2018-10-27 00:01:01 +08001568 (int)(mDisplayPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1569 config.uiMode, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001570
Tiger Huang7c610aa2018-10-27 00:01:01 +08001571 mDisplayPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001572 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001573 final int leftInset = mTmpRect.left;
1574 final int topInset = mTmpRect.top;
1575 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001576 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1577 leftInset + displayInfo.appWidth /* right */,
1578 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001579 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1580 || displayInfo.rotation == Surface.ROTATION_270);
1581
Tiger Huang7c610aa2018-10-27 00:01:01 +08001582 computeSizeRangesAndScreenLayout(displayInfo, rotated, config.uiMode, dw, dh, density,
1583 config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001584
1585 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1586 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1587 ? Configuration.SCREENLAYOUT_ROUND_YES
1588 : Configuration.SCREENLAYOUT_ROUND_NO);
1589
1590 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1591 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1592 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001593 dh, displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001594 config.densityDpi = displayInfo.logicalDensityDpi;
1595
1596 config.colorMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001597 ((displayInfo.isHdr() && mWmService.hasHdrSupport())
Andrii Kulian06d07d62017-03-14 11:11:47 -07001598 ? Configuration.COLOR_MODE_HDR_YES
1599 : Configuration.COLOR_MODE_HDR_NO)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001600 | (displayInfo.isWideColorGamut() && mWmService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001601 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1602 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1603
1604 // Update the configuration based on available input devices, lid switch,
1605 // and platform configuration.
1606 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1607 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1608 config.navigation = Configuration.NAVIGATION_NONAV;
1609
1610 int keyboardPresence = 0;
1611 int navigationPresence = 0;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001612 final InputDevice[] devices = mWmService.mInputManager.getInputDevices();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001613 final int len = devices != null ? devices.length : 0;
1614 for (int i = 0; i < len; i++) {
1615 InputDevice device = devices[i];
1616 if (!device.isVirtual()) {
1617 final int sources = device.getSources();
1618 final int presenceFlag = device.isExternal() ?
1619 WindowManagerPolicy.PRESENCE_EXTERNAL :
1620 WindowManagerPolicy.PRESENCE_INTERNAL;
1621
1622 // TODO(multi-display): Configure on per-display basis.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001623 if (mWmService.mIsTouchDevice) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001624 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1625 InputDevice.SOURCE_TOUCHSCREEN) {
1626 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1627 }
1628 } else {
1629 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1630 }
1631
1632 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1633 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1634 navigationPresence |= presenceFlag;
1635 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1636 && config.navigation == Configuration.NAVIGATION_NONAV) {
1637 config.navigation = Configuration.NAVIGATION_DPAD;
1638 navigationPresence |= presenceFlag;
1639 }
1640
1641 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1642 config.keyboard = Configuration.KEYBOARD_QWERTY;
1643 keyboardPresence |= presenceFlag;
1644 }
1645 }
1646 }
1647
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001648 if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001649 config.navigation = Configuration.NAVIGATION_DPAD;
1650 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1651 }
1652
1653 // Determine whether a hard keyboard is available and enabled.
1654 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1655 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001656 if (hardKeyboardAvailable != mWmService.mHardKeyboardAvailable) {
1657 mWmService.mHardKeyboardAvailable = hardKeyboardAvailable;
1658 mWmService.mH.removeMessages(REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1659 mWmService.mH.sendEmptyMessage(REPORT_HARD_KEYBOARD_STATUS_CHANGE);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001660 }
1661
Tiger Huang7c610aa2018-10-27 00:01:01 +08001662 mDisplayPolicy.updateConfigurationDependentBehaviors();
1663
Andrii Kulian06d07d62017-03-14 11:11:47 -07001664 // Let the policy update hidden states.
1665 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1666 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1667 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001668 mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001669 }
1670
1671 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001672 DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001673 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1674 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1675 final int unrotDw, unrotDh;
1676 if (rotated) {
1677 unrotDw = dh;
1678 unrotDh = dw;
1679 } else {
1680 unrotDw = dw;
1681 unrotDh = dh;
1682 }
1683 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001684 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001685 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001686 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001687 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001688 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001689 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001690 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001691 return sw;
1692 }
1693
1694 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001695 DisplayMetrics dm, int dw, int dh, DisplayCutout displayCutout) {
1696 dm.noncompatWidthPixels = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1697 displayCutout);
1698 dm.noncompatHeightPixels = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode,
1699 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001700 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1701 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1702 if (curSize == 0 || size < curSize) {
1703 curSize = size;
1704 }
1705 return curSize;
1706 }
1707
Tiger Huang7c610aa2018-10-27 00:01:01 +08001708 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
1709 int uiMode, int dw, int dh, float density, Configuration outConfig) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001710
1711 // We need to determine the smallest width that will occur under normal
1712 // operation. To this, start with the base screen size and compute the
1713 // width under the different possible rotations. We need to un-rotate
1714 // the current screen dimensions before doing this.
1715 int unrotDw, unrotDh;
1716 if (rotated) {
1717 unrotDw = dh;
1718 unrotDh = dw;
1719 } else {
1720 unrotDw = dw;
1721 unrotDh = dh;
1722 }
1723 displayInfo.smallestNominalAppWidth = 1<<30;
1724 displayInfo.smallestNominalAppHeight = 1<<30;
1725 displayInfo.largestNominalAppWidth = 0;
1726 displayInfo.largestNominalAppHeight = 0;
Tiger Huang7c610aa2018-10-27 00:01:01 +08001727 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_0, uiMode, unrotDw, unrotDh);
1728 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_90, uiMode, unrotDh, unrotDw);
1729 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_180, uiMode, unrotDw, unrotDh);
1730 adjustDisplaySizeRanges(displayInfo, Surface.ROTATION_270, uiMode, unrotDh, unrotDw);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001731 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1732 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001733 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001734 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001735 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001736 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001737 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001738 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001739 displayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001740 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1741 outConfig.screenLayout = sl;
1742 }
1743
1744 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
Tiger Huang7c610aa2018-10-27 00:01:01 +08001745 int uiMode, DisplayCutout displayCutout) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001746 // Get the app screen size at this rotation.
Tiger Huang7c610aa2018-10-27 00:01:01 +08001747 int w = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayCutout);
1748 int h = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001749
1750 // Compute the screen layout size class for this rotation.
1751 int longSize = w;
1752 int shortSize = h;
1753 if (longSize < shortSize) {
1754 int tmp = longSize;
1755 longSize = shortSize;
1756 shortSize = tmp;
1757 }
1758 longSize = (int)(longSize/density);
1759 shortSize = (int)(shortSize/density);
1760 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1761 }
1762
Tiger Huang7c610aa2018-10-27 00:01:01 +08001763 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001764 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001765 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1766 rotation).getDisplayCutout();
Tiger Huang7c610aa2018-10-27 00:01:01 +08001767 final int width = mDisplayPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1768 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001769 if (width < displayInfo.smallestNominalAppWidth) {
1770 displayInfo.smallestNominalAppWidth = width;
1771 }
1772 if (width > displayInfo.largestNominalAppWidth) {
1773 displayInfo.largestNominalAppWidth = width;
1774 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001775 final int height = mDisplayPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1776 displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001777 if (height < displayInfo.smallestNominalAppHeight) {
1778 displayInfo.smallestNominalAppHeight = height;
1779 }
1780 if (height > displayInfo.largestNominalAppHeight) {
1781 displayInfo.largestNominalAppHeight = height;
1782 }
1783 }
1784
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001785 /**
1786 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1787 * theme attribute) on devices that feature a physical options menu key attempt to position
1788 * their menu panel window along the edge of the screen nearest the physical menu key.
1789 * This lowers the travel distance between invoking the menu panel and selecting
1790 * a menu option.
1791 *
1792 * This method helps control where that menu is placed. Its current implementation makes
1793 * assumptions about the menu key and its relationship to the screen based on whether
1794 * the device's natural orientation is portrait (width < height) or landscape.
1795 *
1796 * The menu key is assumed to be located along the bottom edge of natural-portrait
1797 * devices and along the right edge of natural-landscape devices. If these assumptions
1798 * do not hold for the target device, this method should be changed to reflect that.
1799 *
1800 * @return A {@link Gravity} value for placing the options menu window.
1801 */
1802 int getPreferredOptionsPanelGravity() {
1803 final int rotation = getRotation();
1804 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1805 // On devices with a natural orientation of portrait.
1806 switch (rotation) {
1807 default:
1808 case Surface.ROTATION_0:
1809 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1810 case Surface.ROTATION_90:
1811 return Gravity.RIGHT | Gravity.BOTTOM;
1812 case Surface.ROTATION_180:
1813 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1814 case Surface.ROTATION_270:
1815 return Gravity.START | Gravity.BOTTOM;
1816 }
1817 }
1818
1819 // On devices with a natural orientation of landscape.
1820 switch (rotation) {
1821 default:
1822 case Surface.ROTATION_0:
1823 return Gravity.RIGHT | Gravity.BOTTOM;
1824 case Surface.ROTATION_90:
1825 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1826 case Surface.ROTATION_180:
1827 return Gravity.START | Gravity.BOTTOM;
1828 case Surface.ROTATION_270:
1829 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1830 }
1831 }
1832
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001833 DockedStackDividerController getDockedDividerController() {
1834 return mDividerControllerLocked;
1835 }
1836
Winson Chung655332c2016-10-31 13:14:28 -07001837 PinnedStackController getPinnedStackController() {
1838 return mPinnedStackControllerLocked;
1839 }
1840
Jeff Browna506a6e2013-06-04 00:02:38 -07001841 /**
1842 * Returns true if the specified UID has access to this display.
1843 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001844 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001845 return mDisplay.hasAccess(uid);
1846 }
1847
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001848 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001849 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001850 }
1851
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001852 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001853 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001854 }
1855
Wale Ogunwale61911492017-10-11 08:50:50 -07001856 /**
1857 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1858 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001859 TaskStack getSplitScreenPrimaryStack() {
1860 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001861 return (stack != null && stack.isVisible()) ? stack : null;
1862 }
1863
Robert Carr9785cf32018-04-25 15:06:07 -07001864 boolean hasSplitScreenPrimaryStack() {
1865 return getSplitScreenPrimaryStack() != null;
1866 }
1867
Wale Ogunwale61911492017-10-11 08:50:50 -07001868 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001869 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001870 * not visible.
1871 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001872 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1873 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001874 }
1875
1876 TaskStack getPinnedStack() {
1877 return mTaskStackContainers.getPinnedStack();
1878 }
1879
1880 private boolean hasPinnedStack() {
1881 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001882 }
1883
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001884 /**
1885 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1886 * Null is no compatible stack on the display.
1887 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001888 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001889 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1890 }
1891
1892 /**
1893 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1894 * activity type. Null is no compatible stack on the display.
1895 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001896 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001897 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001898 }
1899
Bryce Lee48f4b572017-04-10 10:54:15 -07001900 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001901 WindowList<TaskStack> getStacks() {
1902 return mTaskStackContainers.mChildren;
1903 }
1904
1905 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001906 TaskStack getTopStack() {
1907 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001908 }
1909
Winson Chunge2d72172018-01-25 17:46:20 +00001910 ArrayList<Task> getVisibleTasks() {
1911 return mTaskStackContainers.getVisibleTasks();
1912 }
1913
Wale Ogunwale61911492017-10-11 08:50:50 -07001914 void onStackWindowingModeChanged(TaskStack stack) {
1915 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001916 }
1917
Andrii Kulian441e4492016-09-29 15:25:00 -07001918 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001919 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001920 super.onConfigurationChanged(newParentConfig);
Tiger Huang7c610aa2018-10-27 00:01:01 +08001921 if (mDisplayPolicy != null) {
1922 mDisplayPolicy.onConfigurationChanged();
1923 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001924
Evan Roskye747c3e2018-10-30 20:06:41 -07001925 // If there was no pinned stack, we still need to notify the controller of the display info
1926 // update as a result of the config change.
1927 if (mPinnedStackControllerLocked != null && !hasPinnedStack()) {
1928 mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo());
1929 }
Evan Roskye747c3e2018-10-30 20:06:41 -07001930 }
1931
1932 /**
1933 * Updates the resources used by docked/pinned controllers. This needs to be called at the
1934 * beginning of a configuration update cascade since the metrics from these resources are used
1935 * for bounds calculations. Since ActivityDisplay initiates the configuration update, this
1936 * should be called from there instead of DisplayContent's onConfigurationChanged.
1937 */
1938 void preOnConfigurationChanged() {
Bryce Leef3c6a472017-11-14 14:53:06 -08001939 final DockedStackDividerController dividerController = getDockedDividerController();
1940
1941 if (dividerController != null) {
1942 getDockedDividerController().onConfigurationChanged();
1943 }
1944
1945 final PinnedStackController pinnedStackController = getPinnedStackController();
1946
1947 if (pinnedStackController != null) {
1948 getPinnedStackController().onConfigurationChanged();
1949 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001950 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001951
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001952 @Override
1953 boolean fillsParent() {
1954 return true;
1955 }
1956
1957 @Override
1958 boolean isVisible() {
1959 return true;
1960 }
1961
1962 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001963 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001964 super.onAppTransitionDone();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001965 mWmService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001966 }
1967
Yunfan Chen7daa6ac2018-11-29 18:16:44 -08001968 @Override
1969 public void setWindowingMode(int windowingMode) {
1970 super.setWindowingMode(windowingMode);
1971 super.setDisplayWindowingMode(windowingMode);
1972 }
1973
1974 @Override
1975 void setDisplayWindowingMode(int windowingMode) {
1976 setWindowingMode(windowingMode);
1977 }
1978
Robert Carr9785cf32018-04-25 15:06:07 -07001979 /**
1980 * In split-screen mode we process the IME containers above the docked divider
1981 * rather than directly above their target.
1982 */
1983 private boolean skipTraverseChild(WindowContainer child) {
lumarkff0ab692018-11-05 20:32:30 +08001984 if (child == mImeWindowsContainers && mInputMethodTarget != null
Robert Carr9785cf32018-04-25 15:06:07 -07001985 && !hasSplitScreenPrimaryStack()) {
1986 return true;
1987 }
1988 return false;
1989 }
1990
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001991 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001992 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1993 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1994 // target, or here in order if there isn't an IME target.
1995 if (traverseTopToBottom) {
1996 for (int i = mChildren.size() - 1; i >= 0; --i) {
1997 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001998 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001999 continue;
2000 }
Robert Carr9785cf32018-04-25 15:06:07 -07002001
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002002 if (child.forAllWindows(callback, traverseTopToBottom)) {
2003 return true;
2004 }
2005 }
2006 } else {
2007 final int count = mChildren.size();
2008 for (int i = 0; i < count; i++) {
2009 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07002010 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002011 continue;
2012 }
Robert Carr9785cf32018-04-25 15:06:07 -07002013
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08002014 if (child.forAllWindows(callback, traverseTopToBottom)) {
2015 return true;
2016 }
2017 }
2018 }
2019 return false;
2020 }
2021
2022 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
2023 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
2024 }
2025
Wale Ogunwale399c8692017-05-08 14:22:42 -07002026 @Override
2027 int getOrientation() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002028 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002029
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002030 if (mWmService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08002031 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002032 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2033 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002034 // If the display is frozen, some activities may be in the middle of restarting, and
2035 // thus have removed their old window. If the window has the flag to hide the lock
2036 // screen, then the lock screen can re-appear and inflict its own orientation on us.
2037 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002038 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002039 } else if (policy.isKeyguardLocked()) {
2040 // Use the last orientation the while the display is frozen with the keyguard
2041 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
2042 // window. We don't want to check the show when locked window directly though as
2043 // things aren't stable while the display is frozen, for example the window could be
2044 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07002045 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
2046 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08002047 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07002048 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002049 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002050 final int orientation = mAboveAppWindowsContainers.getOrientation();
2051 if (orientation != SCREEN_ORIENTATION_UNSET) {
2052 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07002053 }
Wale Ogunwale51362492016-09-08 17:49:17 -07002054 }
2055
Wale Ogunwale399c8692017-05-08 14:22:42 -07002056 // Top system windows are not requesting an orientation. Start searching from apps.
2057 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07002058 }
2059
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002060 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07002061 // Check if display metrics changed and update base values if needed.
2062 updateBaseDisplayMetricsIfNeeded();
2063
Craig Mautner722285e2012-09-07 13:55:58 -07002064 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07002065 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07002066
Garfield Tan2f145f22018-11-01 15:27:03 -07002067 onDisplayChanged(this);
Craig Mautner722285e2012-09-07 13:55:58 -07002068 }
2069
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002070 void initializeDisplayBaseInfo() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002071 final DisplayManagerInternal displayManagerInternal = mWmService.mDisplayManagerInternal;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002072 if (displayManagerInternal != null) {
2073 // Bootstrap the default logical display from the display manager.
2074 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
2075 if (newDisplayInfo != null) {
2076 mDisplayInfo.copyFrom(newDisplayInfo);
2077 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002078 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07002079
Andrii Kuliancd097992017-03-23 18:31:59 -07002080 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
2081 mDisplayInfo.logicalDensityDpi);
2082 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
2083 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
2084 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002085 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07002086 }
2087
Andrii Kuliancd097992017-03-23 18:31:59 -07002088 /**
2089 * If display metrics changed, overrides are not set and it's not just a rotation - update base
2090 * values.
2091 */
2092 private void updateBaseDisplayMetricsIfNeeded() {
2093 // Get real display metrics without overrides from WM.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002094 mWmService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
Andrii Kuliancd097992017-03-23 18:31:59 -07002095 final int orientation = mDisplayInfo.rotation;
2096 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2097 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
2098 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
2099 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01002100 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07002101
2102 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
2103 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01002104 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
2105 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07002106
2107 if (displayMetricsChanged) {
2108 // Check if display size or density is forced.
2109 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
2110 || mBaseDisplayHeight != mInitialDisplayHeight;
2111 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
2112
2113 // If there is an override set for base values - use it, otherwise use new values.
2114 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
2115 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
2116 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
2117
2118 // Real display metrics changed, so we should also update initial values.
2119 mInitialDisplayWidth = newWidth;
2120 mInitialDisplayHeight = newHeight;
2121 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01002122 mInitialDisplayCutout = newCutout;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002123 mWmService.reconfigureDisplayLocked(this);
Andrii Kuliancd097992017-03-23 18:31:59 -07002124 }
2125 }
2126
Bryce Lee27cec322017-03-21 09:41:37 -07002127 /** Sets the maximum width the screen resolution can be */
2128 void setMaxUiWidth(int width) {
2129 if (DEBUG_DISPLAY) {
2130 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
2131 }
2132
2133 mMaxUiWidth = width;
2134
2135 // Update existing metrics.
2136 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
2137 }
2138
2139 /** Update base (override) display metrics. */
2140 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
2141 mBaseDisplayWidth = baseWidth;
2142 mBaseDisplayHeight = baseHeight;
2143 mBaseDisplayDensity = baseDensity;
2144
2145 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
2146 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
2147 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
2148 mBaseDisplayWidth = mMaxUiWidth;
2149
2150 if (DEBUG_DISPLAY) {
2151 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
2152 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
2153 + " on display:" + getDisplayId());
2154 }
2155 }
2156
2157 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08002158
2159 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07002160 }
2161
Riddle Hsuf53da812018-08-15 22:00:27 +08002162 /**
2163 * Forces this display to use the specified density.
2164 *
2165 * @param density The density in DPI to use. If the value equals to initial density, the setting
2166 * will be cleared.
2167 * @param userId The target user to apply. Only meaningful when this is default display. If the
2168 * user id is {@link UserHandle#USER_CURRENT}, it means to apply current settings
2169 * so only need to configure display.
2170 */
2171 void setForcedDensity(int density, int userId) {
2172 final boolean clear = density == mInitialDisplayDensity;
2173 final boolean updateCurrent = userId == UserHandle.USER_CURRENT;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002174 if (mWmService.mCurrentUserId == userId || updateCurrent) {
Riddle Hsuf53da812018-08-15 22:00:27 +08002175 mBaseDisplayDensity = density;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002176 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002177 }
2178 if (updateCurrent) {
2179 // We are applying existing settings so no need to save it again.
2180 return;
2181 }
2182
2183 if (density == mInitialDisplayDensity) {
2184 density = 0;
2185 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002186 mWmService.mDisplayWindowSettings.setForcedDensity(this, density, userId);
Riddle Hsuf53da812018-08-15 22:00:27 +08002187 }
2188
2189 /** @param mode {@link #FORCE_SCALING_MODE_AUTO} or {@link #FORCE_SCALING_MODE_DISABLED}. */
2190 void setForcedScalingMode(@ForceScalingMode int mode) {
2191 if (mode != FORCE_SCALING_MODE_DISABLED) {
2192 mode = FORCE_SCALING_MODE_AUTO;
2193 }
2194
2195 mDisplayScalingDisabled = (mode != FORCE_SCALING_MODE_AUTO);
2196 Slog.i(TAG_WM, "Using display scaling mode: " + (mDisplayScalingDisabled ? "off" : "auto"));
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002197 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002198
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002199 mWmService.mDisplayWindowSettings.setForcedScalingMode(this, mode);
Riddle Hsuf53da812018-08-15 22:00:27 +08002200 }
2201
2202 /** If the given width and height equal to initial size, the setting will be cleared. */
2203 void setForcedSize(int width, int height) {
2204 final boolean clear = mInitialDisplayWidth == width && mInitialDisplayHeight == height;
2205 if (!clear) {
2206 // Set some sort of reasonable bounds on the size of the display that we will try
2207 // to emulate.
2208 final int minSize = 200;
2209 final int maxScale = 2;
2210 width = Math.min(Math.max(width, minSize), mInitialDisplayWidth * maxScale);
2211 height = Math.min(Math.max(height, minSize), mInitialDisplayHeight * maxScale);
2212 }
2213
2214 Slog.i(TAG_WM, "Using new display size: " + width + "x" + height);
2215 updateBaseDisplayMetrics(width, height, mBaseDisplayDensity);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002216 mWmService.reconfigureDisplayLocked(this);
Riddle Hsuf53da812018-08-15 22:00:27 +08002217
2218 if (clear) {
2219 width = height = 0;
2220 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002221 mWmService.mDisplayWindowSettings.setForcedSize(this, width, height);
Riddle Hsuf53da812018-08-15 22:00:27 +08002222 }
2223
Wale Ogunwaledb506192017-12-08 10:57:32 -08002224 void getStableRect(Rect out) {
2225 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08002226 }
2227
Wale Ogunwale61911492017-10-11 08:50:50 -07002228 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002229 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
2230 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07002231
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002232 final TaskStack stack = new TaskStack(mWmService, stackId, controller);
Wale Ogunwale61911492017-10-11 08:50:50 -07002233 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08002234 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07002235 }
2236
Andrii Kulian51c1b672017-04-07 18:39:32 -07002237 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002238 final DisplayContent prevDc = stack.getDisplayContent();
2239 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002240 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2241 + " which is not currently attached to any display");
2242 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002243 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002244 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2245 + " to its current displayId=" + mDisplayId);
2246 }
2247
lumark588a3e82018-07-20 18:53:54 +08002248 // Clean up all pending transitions when stack reparent to another display.
2249 stack.forAllAppWindows(AppWindowToken::removeFromPendingTransition);
2250
Wale Ogunwale61911492017-10-11 08:50:50 -07002251 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002252 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002253 }
2254
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002255 @Override
2256 protected void addChild(DisplayChildWindowContainer child,
2257 Comparator<DisplayChildWindowContainer> comparator) {
2258 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2259 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002260
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002261 @Override
2262 protected void addChild(DisplayChildWindowContainer child, int index) {
2263 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2264 }
2265
2266 @Override
2267 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002268 // Only allow removal of direct children from this display if the display is in the process
2269 // of been removed.
2270 if (mRemovingDisplay) {
2271 super.removeChild(child);
2272 return;
2273 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002274 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002275 }
2276
Andrii Kuliand2765632016-12-12 22:26:34 -08002277 @Override
2278 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2279 // Children of the display are statically ordered, so the real intention here is to perform
2280 // the operation on the display and not the static direct children.
2281 getParent().positionChildAt(position, this, includingParents);
2282 }
2283
Riddle Hsu57831b52018-07-27 00:31:48 +08002284 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2285 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002286 layoutAndAssignWindowLayersIfNeeded();
2287 }
2288
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002289 /**
2290 * Used to obtain task ID when user taps on coordinate (x, y) in this display, and outside
2291 * current task in focus.
2292 *
2293 * This returns the task ID of the foremost task at (x, y) if the task is not home. Otherwise it
2294 * returns -1.
2295 *
2296 * @param x horizontal coordinate of the tap position
2297 * @param y vertical coordinate of the tap position
2298 * @return the task ID if a non-home task is found; -1 if not
2299 */
2300 int taskForTapOutside(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002301 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2302 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002303 if (stack.isActivityTypeHome() && !stack.inMultiWindowMode()) {
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002304 // We skip not only home stack, but also everything behind home because user can't
Garfield Tanf2e0a9e2018-10-16 09:42:02 -07002305 // see them when home stack is isn't in multi-window mode.
Garfield Tan4f71c5a2018-10-10 10:12:02 -07002306 break;
2307 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002308 final int taskId = stack.taskIdFromPoint(x, y);
2309 if (taskId != -1) {
2310 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002311 }
2312 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002313 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002314 }
2315
Chong Zhang8e89b312015-09-09 15:09:30 -07002316 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002317 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002318 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002319 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002320 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002321 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002322 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002323 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2324 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002325 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002326 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002327 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002328
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002329 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2330 if (mTmpTaskForResizePointSearchResult.searchDone) {
2331 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002332 }
2333 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002334 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002335 }
2336
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002337 void updateTouchExcludeRegion() {
2338 final Task focusedTask = (mFocusedApp != null ? mFocusedApp.getTask() : null);
David Stevensee9e2772017-02-09 16:30:27 -08002339 if (focusedTask == null) {
2340 mTouchExcludeRegion.setEmpty();
2341 } else {
2342 mTouchExcludeRegion.set(mBaseDisplayRect);
2343 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2344 mTmpRect2.setEmpty();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002345 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0;
2346 --stackNdx) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002347 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002348 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2349 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002350 }
2351 // If we removed the focused task above, add it back and only leave its
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002352 // outside touch area in the exclusion. TapDetector is not interested in
David Stevensee9e2772017-02-09 16:30:27 -08002353 // any touch inside the focused task itself.
2354 if (!mTmpRect2.isEmpty()) {
2355 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2356 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002357 }
lumark90120a82018-08-15 00:33:03 +08002358 if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) {
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002359 // If the input method is visible and the user is typing, we don't want these touch
2360 // events to be intercepted and used to change focus. This would likely cause a
2361 // disappearance of the input method.
lumark90120a82018-08-15 00:33:03 +08002362 mInputMethodWindow.getTouchableRegion(mTmpRegion);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002363 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002364 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002365 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002366 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002367 win.getTouchableRegion(mTmpRegion);
2368 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2369 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002370 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2371 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2372 win.amendTapExcludeRegion(mTouchExcludeRegion);
2373 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002374 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002375 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002376 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002377 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002378 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2379 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002380 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002381 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002382 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002383 }
2384
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002385 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002386 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002387 super.switchUser();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002388 mWmService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002389 }
2390
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002391 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002392 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2393 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002394 }
2395 }
2396
Wale Ogunwale10124582016-09-15 20:25:50 -07002397 @Override
2398 void removeIfPossible() {
2399 if (isAnimating()) {
2400 mDeferredRemoval = true;
2401 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002402 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002403 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002404 }
2405
Wale Ogunwale10124582016-09-15 20:25:50 -07002406 @Override
2407 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002408 mRemovingDisplay = true;
2409 try {
lumark588a3e82018-07-20 18:53:54 +08002410 // Clear all transitions & screen frozen states when removing display.
2411 mOpeningApps.clear();
2412 mClosingApps.clear();
2413 mUnknownAppVisibilityController.clear();
2414 mAppTransition.removeAppTransitionTimeoutCallbacks();
2415 handleAnimatingStoppedAndTransition();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002416 mWmService.stopFreezingDisplayLocked();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002417 super.removeImmediately();
2418 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002419 if (mPointerEventDispatcher != null && mTapDetector != null) {
2420 unregisterPointerEventListener(mTapDetector);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002421 unregisterPointerEventListener(mWmService.mMousePositionTracker);
Arthur Hungbe5ce212018-09-13 18:41:56 +08002422 mTapDetector = null;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002423 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002424 mWmService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002425 mWindowingLayer.release();
2426 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002427 } finally {
Riddle Hsu4e611772018-10-31 18:58:28 +08002428 mDisplayReady = false;
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002429 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002430 }
Robert Carr679ccb02018-08-08 15:32:35 -07002431
Tiger Huang7c610aa2018-10-27 00:01:01 +08002432 mDisplayPolicy.onDisplayRemoved();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002433 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautner95da1082014-02-24 17:54:35 -08002434 }
2435
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002436 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002437 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002438 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002439 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2440
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002441 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002442 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002443 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002444 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002445 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002446 }
2447
Andrii Kulian0214ed92017-05-16 13:44:05 -07002448 /** @return 'true' if removal of this display content is deferred due to active animation. */
2449 boolean isRemovalDeferred() {
2450 return mDeferredRemoval;
2451 }
2452
Wale Ogunwale10124582016-09-15 20:25:50 -07002453 boolean animateForIme(float interpolatedValue, float animationTarget,
2454 float dividerAnimationTarget) {
2455 boolean updated = false;
2456
Wale Ogunwale61911492017-10-11 08:50:50 -07002457 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2458 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002459 if (stack == null || !stack.isAdjustedForIme()) {
2460 continue;
2461 }
2462
2463 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2464 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2465 updated = true;
2466 } else {
2467 mDividerControllerLocked.mLastAnimationProgress =
2468 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2469 mDividerControllerLocked.mLastDividerProgress =
2470 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2471 updated |= stack.updateAdjustForIme(
2472 mDividerControllerLocked.mLastAnimationProgress,
2473 mDividerControllerLocked.mLastDividerProgress,
2474 false /* force */);
2475 }
2476 if (interpolatedValue >= 1f) {
2477 stack.endImeAdjustAnimation();
2478 }
2479 }
2480
2481 return updated;
2482 }
2483
2484 boolean clearImeAdjustAnimation() {
2485 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002486 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2487 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002488 if (stack != null && stack.isAdjustedForIme()) {
2489 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2490 changed = true;
2491 }
2492 }
2493 return changed;
2494 }
2495
2496 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002497 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2498 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002499 if (stack.isVisible() && stack.isAdjustedForIme()) {
2500 stack.beginImeAdjustAnimation();
2501 }
2502 }
2503 }
2504
2505 void adjustForImeIfNeeded() {
lumark90120a82018-08-15 00:33:03 +08002506 final WindowState imeWin = mInputMethodWindow;
Wale Ogunwale10124582016-09-15 20:25:50 -07002507 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2508 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002509 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002510 final TaskStack imeTargetStack = mWmService.getImeFocusStackLocked();
Wale Ogunwale10124582016-09-15 20:25:50 -07002511 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2512 imeTargetStack.getDockSide() : DOCKED_INVALID;
2513 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2514 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2515 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002516 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002517 final boolean imeHeightChanged = imeVisible &&
2518 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2519
2520 // The divider could be adjusted for IME position, or be thinner than usual,
2521 // or both. There are three possible cases:
2522 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2523 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2524 // - If IME is not visible, divider is not moved and is normal width.
2525
2526 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002527 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2528 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002529 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002530 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2531 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002532 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2533 } else {
2534 stack.resetAdjustedForIme(false);
2535 }
2536 }
2537 mDividerControllerLocked.setAdjustedForIme(
2538 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2539 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002540 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2541 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002542 stack.resetAdjustedForIme(!dockVisible);
2543 }
2544 mDividerControllerLocked.setAdjustedForIme(
2545 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2546 }
Winson Chung655332c2016-10-31 13:14:28 -07002547 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002548 }
2549
2550 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002551 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2552 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002553 stack.prepareFreezingTaskBounds();
2554 }
2555 }
2556
Wale Ogunwale94744212015-09-21 19:01:47 -07002557 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002558 getBounds(mTmpRect, newRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002559 rotateBounds(mTmpRect, oldRotation, newRotation, bounds);
2560 }
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002561
Evan Rosky39b6f232018-10-30 18:35:41 -07002562 void rotateBounds(Rect parentBounds, int oldRotation, int newRotation, Rect bounds) {
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002563 // Compute a transform matrix to undo the coordinate space transformation,
2564 // and present the window at the same physical position it previously occupied.
2565 final int deltaRotation = deltaRotation(newRotation, oldRotation);
Evan Rosky39b6f232018-10-30 18:35:41 -07002566 createRotationMatrix(
2567 deltaRotation, parentBounds.width(), parentBounds.height(), mTmpMatrix);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002568
2569 mTmpRectF.set(bounds);
2570 mTmpMatrix.mapRect(mTmpRectF);
2571 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002572 }
2573
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002574 static int deltaRotation(int oldRotation, int newRotation) {
2575 int delta = newRotation - oldRotation;
2576 if (delta < 0) delta += 4;
2577 return delta;
2578 }
2579
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002580 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002581 Matrix outMatrix) {
2582 // For rotations without Z-ordering we don't need the target rectangle's position.
2583 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2584 displayHeight, outMatrix);
2585 }
2586
2587 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2588 float displayWidth, float displayHeight, Matrix outMatrix) {
2589 switch (rotation) {
2590 case ROTATION_0:
2591 outMatrix.reset();
2592 break;
2593 case ROTATION_270:
2594 outMatrix.setRotate(270, 0, 0);
2595 outMatrix.postTranslate(0, displayHeight);
2596 outMatrix.postTranslate(rectTop, 0);
2597 break;
2598 case ROTATION_180:
2599 outMatrix.reset();
2600 break;
2601 case ROTATION_90:
2602 outMatrix.setRotate(90, 0, 0);
2603 outMatrix.postTranslate(displayWidth, 0);
2604 outMatrix.postTranslate(-rectTop, rectLeft);
2605 break;
2606 }
2607 }
2608
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002609 @CallSuper
2610 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002611 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002612 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002613 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002614 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002615 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2616 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002617 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002618 }
2619 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2620 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002621 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2622 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002623 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002624 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002625 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2626 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002627 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002628 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002629 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2630 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002631 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002632 }
2633 proto.write(DPI, mBaseDisplayDensity);
2634 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002635 proto.write(ROTATION, mRotation);
2636 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002637 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002638 if (screenRotationAnimation != null) {
2639 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2640 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002641 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
lumark588a3e82018-07-20 18:53:54 +08002642 mAppTransition.writeToProto(proto, APP_TRANSITION);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002643 if (mFocusedApp != null) {
2644 mFocusedApp.writeNameToProto(proto, FOCUSED_APP);
2645 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002646 proto.end(token);
2647 }
2648
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002649 @Override
2650 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2651 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002652 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2653 final String subPrefix = " " + prefix;
2654 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2655 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2656 pw.print("dpi");
2657 if (mInitialDisplayWidth != mBaseDisplayWidth
2658 || mInitialDisplayHeight != mBaseDisplayHeight
2659 || mInitialDisplayDensity != mBaseDisplayDensity) {
2660 pw.print(" base=");
2661 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2662 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2663 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002664 if (mDisplayScalingDisabled) {
2665 pw.println(" noscale");
2666 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002667 pw.print(" cur=");
2668 pw.print(mDisplayInfo.logicalWidth);
2669 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2670 pw.print(" app=");
2671 pw.print(mDisplayInfo.appWidth);
2672 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2673 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2674 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2675 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2676 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002677 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002678 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002679 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002680
Craig Mautnerdc548482014-02-05 13:35:24 -08002681 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002682 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002683 pw.print(prefix);
2684 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002685
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002686 pw.print(" mCurrentFocus="); pw.println(mCurrentFocus);
2687 if (mLastFocus != mCurrentFocus) {
2688 pw.print(" mLastFocus="); pw.println(mLastFocus);
2689 }
2690 if (mLosingFocus.size() > 0) {
2691 pw.println();
2692 pw.println(" Windows losing focus:");
2693 for (int i = mLosingFocus.size() - 1; i >= 0; i--) {
2694 final WindowState w = mLosingFocus.get(i);
2695 pw.print(" Losing #"); pw.print(i); pw.print(' ');
2696 pw.print(w);
2697 if (dumpAll) {
2698 pw.println(":");
2699 w.dump(pw, " ", true);
2700 } else {
2701 pw.println();
2702 }
2703 }
2704 }
2705 pw.print(" mFocusedApp="); pw.println(mFocusedApp);
Tiger Huang7c610aa2018-10-27 00:01:01 +08002706 if (mLastStatusBarVisibility != 0) {
2707 pw.print(" mLastStatusBarVisibility=0x");
2708 pw.println(Integer.toHexString(mLastStatusBarVisibility));
2709 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002710
Adrian Roos5251b1d2018-03-23 18:57:43 +01002711 pw.println();
wilsonshihc32538e2018-11-07 17:27:34 +08002712 mWallpaperController.dump(pw, " ");
2713
2714 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002715 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002716 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2717 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002718 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002719 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002720
Craig Mautnerdc548482014-02-05 13:35:24 -08002721 pw.println();
2722 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002723 pw.println();
2724 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002725 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002726 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002727 pw.print(" Exiting #"); pw.print(i);
2728 pw.print(' '); pw.print(token);
2729 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002730 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002731 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002732 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002733
Jorim Jaggi31f71702016-05-04 16:43:04 -07002734 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002735
2736 // Dump stack references
2737 final TaskStack homeStack = getHomeStack();
2738 if (homeStack != null) {
2739 pw.println(prefix + "homeStack=" + homeStack.getName());
2740 }
2741 final TaskStack pinnedStack = getPinnedStack();
2742 if (pinnedStack != null) {
2743 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2744 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002745 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002746 if (splitScreenPrimaryStack != null) {
2747 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2748 }
2749
2750 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002751 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002752 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002753 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002754
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002755 pw.println();
2756 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002757 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002758 mDisplayPolicy.dump(prefix, pw);
2759 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002760 mDisplayRotation.dump(prefix, pw);
2761 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002762 mInputMonitor.dump(pw, " ");
Jorim Jaggif96c90a2018-09-26 16:55:15 +02002763 pw.println();
2764 mInsetsStateController.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002765 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002766
2767 @Override
2768 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002769 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002770 }
2771
2772 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002773 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002774 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002775
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002776 /** Returns true if the stack in the windowing mode is visible. */
2777 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002778 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002779 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002780 }
2781
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002782 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002783 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002784 final int x = (int) xf;
2785 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002786 final WindowState touchedWin = getWindow(w -> {
2787 final int flags = w.mAttrs.flags;
2788 if (!w.isVisibleLw()) {
2789 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002790 }
2791 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002792 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002793 }
2794
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002795 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002796 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002797 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002798 }
2799
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002800 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002801
2802 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002803 return mTmpRegion.contains(x, y) || touchFlags == 0;
2804 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002805
2806 return touchedWin;
2807 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002808
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002809 boolean canAddToastWindowForUid(int uid) {
2810 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002811 // Also if the app is focused adding more than one toast at
2812 // a time for better backwards compatibility.
2813 final WindowState focusedWindowForUid = getWindow(w ->
2814 w.mOwnerUid == uid && w.isFocused());
2815 if (focusedWindowForUid != null) {
2816 return true;
2817 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002818 final WindowState win = getWindow(w ->
2819 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2820 && !w.mWindowRemovalAllowed);
2821 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002822 }
2823
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002824 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002825 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2826 return;
2827 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002828
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002829 // Used to communicate the old focus to the callback method.
2830 mTmpWindow = oldFocus;
2831
2832 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002833 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002834
2835 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002836 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002837
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002838 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002839
2840 if (mTmpWindow == null) {
2841 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2842 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002843 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002844 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002845 }
2846
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002847
2848 /**
2849 * Update the focused window and make some adjustments if the focus has changed.
2850 *
2851 * @param mode Indicates the situation we are in. Possible modes are:
2852 * {@link WindowManagerService#UPDATE_FOCUS_NORMAL},
2853 * {@link WindowManagerService#UPDATE_FOCUS_PLACING_SURFACES},
2854 * {@link WindowManagerService#UPDATE_FOCUS_WILL_PLACE_SURFACES},
2855 * {@link WindowManagerService#UPDATE_FOCUS_REMOVING_FOCUS}
2856 * @param updateInputWindows Whether to sync the window information to the input module.
2857 * @return {@code true} if the focused window has changed.
2858 */
2859 boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows, boolean focusFound) {
2860 final WindowState newFocus = findFocusedWindow();
2861 if (mCurrentFocus == newFocus) {
2862 return false;
2863 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002864 boolean imWindowChanged = false;
2865 // TODO (b/111080190): Multi-Session IME
2866 if (!focusFound) {
2867 final WindowState imWindow = mInputMethodWindow;
2868 if (imWindow != null) {
lumarkff0ab692018-11-05 20:32:30 +08002869 final WindowState prevTarget = mInputMethodTarget;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002870
2871 final WindowState newTarget = computeImeTarget(true /* updateImeTarget*/);
2872 imWindowChanged = prevTarget != newTarget;
2873
2874 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
2875 && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2876 assignWindowLayers(false /* setLayoutNeeded */);
2877 }
2878 }
2879 }
2880
2881 if (imWindowChanged) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002882 mWmService.mWindowsChanged = true;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002883 setLayoutNeeded();
2884 }
2885
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002886 if (DEBUG_FOCUS_LIGHT || mWmService.localLOGV) Slog.v(TAG_WM, "Changing focus from "
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002887 + mCurrentFocus + " to " + newFocus + " displayId=" + getDisplayId()
2888 + " Callers=" + Debug.getCallers(4));
2889 final WindowState oldFocus = mCurrentFocus;
2890 mCurrentFocus = newFocus;
2891 mLosingFocus.remove(newFocus);
2892
2893 if (newFocus != null) {
2894 mWinAddedSinceNullFocus.clear();
2895 mWinRemovedSinceNullFocus.clear();
2896
2897 if (newFocus.canReceiveKeys()) {
2898 // Displaying a window implicitly causes dispatching to be unpaused.
2899 // This is to protect against bugs if someone pauses dispatching but
2900 // forgets to resume.
2901 newFocus.mToken.paused = false;
2902 }
2903 }
2904
Tiger Huang7c610aa2018-10-27 00:01:01 +08002905 int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002906
2907 if (imWindowChanged && oldFocus != mInputMethodWindow) {
2908 // Focus of the input method window changed. Perform layout if needed.
2909 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2910 performLayout(true /*initial*/, updateInputWindows);
2911 focusChanged &= ~FINISH_LAYOUT_REDO_LAYOUT;
2912 } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
2913 // Client will do the layout, but we need to assign layers
2914 // for handleNewWindowLocked() below.
2915 assignWindowLayers(false /* setLayoutNeeded */);
2916 }
2917 }
2918
2919 if ((focusChanged & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2920 // The change in focus caused us to need to do a layout. Okay.
2921 setLayoutNeeded();
2922 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2923 performLayout(true /*initial*/, updateInputWindows);
2924 } else if (mode == UPDATE_FOCUS_REMOVING_FOCUS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002925 mWmService.mRoot.performSurfacePlacement(false);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002926 }
2927 }
2928
2929 if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
2930 // If we defer assigning layers, then the caller is responsible for doing this part.
2931 getInputMonitor().setInputFocusLw(newFocus, updateInputWindows);
2932 }
2933
2934 adjustForImeIfNeeded();
2935
2936 // We may need to schedule some toast windows to be removed. The toasts for an app that
2937 // does not have input focus are removed within a timeout to prevent apps to redress
2938 // other apps' UI.
2939 scheduleToastWindowsTimeoutIfNeededLocked(oldFocus, newFocus);
2940
2941 if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
2942 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
2943 }
2944 return true;
2945 }
2946
2947 /**
2948 * Set the new focused app to this display.
2949 *
2950 * @param newFocus the new focused AppWindowToken.
2951 * @return true if the focused app is changed.
2952 */
2953 boolean setFocusedApp(AppWindowToken newFocus) {
2954 if (newFocus != null) {
2955 final DisplayContent appDisplay = newFocus.getDisplayContent();
2956 if (appDisplay != this) {
2957 throw new IllegalStateException(newFocus + " is not on " + getName()
2958 + " but " + ((appDisplay != null) ? appDisplay.getName() : "none"));
2959 }
2960 }
2961 if (mFocusedApp == newFocus) {
2962 return false;
2963 }
2964 mFocusedApp = newFocus;
2965 getInputMonitor().setFocusedAppLw(newFocus);
2966 updateTouchExcludeRegion();
2967 return true;
2968 }
2969
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002970 /** Updates the layer assignment of windows on this display. */
2971 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002972 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002973 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002974 if (setLayoutNeeded) {
2975 setLayoutNeeded();
2976 }
Robert Carrb1579c82017-09-05 14:54:47 -07002977
Robert Carrf59b8dd2017-10-02 18:58:36 -07002978 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002979 // the application of this transaction until the animation pass triggers
2980 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2981 // the hiding and showing of surfaces.
2982 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002983 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002984 }
2985
Wale Ogunwale1666e312016-12-16 11:27:18 -08002986 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2987 // moving containers or resizing them. Need to investigate the best way to have it automatically
2988 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002989 void layoutAndAssignWindowLayersIfNeeded() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002990 mWmService.mWindowsChanged = true;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002991 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002992
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002993 if (!mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002994 false /*updateInputWindows*/)) {
2995 assignWindowLayers(false /* setLayoutNeeded */);
2996 }
2997
Arthur Hung95b38a92018-07-20 18:56:12 +08002998 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002999 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08003000 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003001 }
3002
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003003 /** Returns true if a leaked surface was destroyed */
3004 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003005 // Used to indicate that a surface was leaked.
3006 mTmpWindow = null;
3007 forAllWindows(w -> {
3008 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003009 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003010 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003011 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003012 if (!mWmService.mSessions.contains(wsa.mSession)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003013 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003014 + w + " surface=" + wsa.mSurfaceController
3015 + " token=" + w.mToken
3016 + " pid=" + w.mSession.mPid
3017 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003018 wsa.destroySurface();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003019 mWmService.mForceRemoves.add(w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003020 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07003021 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003022 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003023 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003024 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003025 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003026 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003027 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003028 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003029 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003030
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003031 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003032 }
3033
3034 /**
lumark90120a82018-08-15 00:33:03 +08003035 * Set input method window for the display.
3036 * @param win Set when window added or Null when destroyed.
3037 */
3038 void setInputMethodWindowLocked(WindowState win) {
3039 mInputMethodWindow = win;
lumark70865a82018-09-17 16:56:26 +08003040 // Update display configuration for IME process.
3041 if (mInputMethodWindow != null) {
3042 final int imePid = mInputMethodWindow.mSession.mPid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003043 mWmService.mAtmInternal.onImeWindowSetOnDisplay(imePid,
lumark70865a82018-09-17 16:56:26 +08003044 mInputMethodWindow.getDisplayId());
3045 }
lumark90120a82018-08-15 00:33:03 +08003046 computeImeTarget(true /* updateImeTarget */);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003047 mInsetsStateController.getSourceProvider(TYPE_IME).setWindow(win,
3048 null /* frameProvider */);
lumark90120a82018-08-15 00:33:03 +08003049 }
3050
3051 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003052 * Determine and return the window that should be the IME target.
3053 * @param updateImeTarget If true the system IME target will be updated to match what we found.
3054 * @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 +00003055 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003056 WindowState computeImeTarget(boolean updateImeTarget) {
lumark90120a82018-08-15 00:33:03 +08003057 if (mInputMethodWindow == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003058 // There isn't an IME so there shouldn't be a target...That was easy!
3059 if (updateImeTarget) {
3060 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
lumarkff0ab692018-11-05 20:32:30 +08003061 + mInputMethodTarget + " to null since mInputMethodWindow is null");
3062 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003063 }
3064 return null;
3065 }
3066
lumarkff0ab692018-11-05 20:32:30 +08003067 final WindowState curTarget = mInputMethodTarget;
Chavi Weingarten3a748552018-05-14 17:32:42 +00003068 if (!canUpdateImeTarget()) {
3069 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
3070 return curTarget;
3071 }
3072
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003073 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
3074 // same display. Or even when the current IME/target are not on the same screen as the next
3075 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08003076 mUpdateImeTarget = updateImeTarget;
3077 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003078
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003079
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003080 // Yet more tricksyness! If this window is a "starting" window, we do actually want
3081 // to be on top of it, but it is not -really- where input will go. So look down below
3082 // for a real window to target...
3083 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
3084 final AppWindowToken token = target.mAppToken;
3085 if (token != null) {
3086 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
3087 if (betterTarget != null) {
3088 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003089 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003090 }
3091 }
3092
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003093 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
lumarkff0ab692018-11-05 20:32:30 +08003094 "Proposed new IME target: " + target + " for display: " + getDisplayId());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003095
chaviw1c13ad32018-06-12 16:44:23 -07003096 // Now, a special case -- if the last target's window is in the process of exiting, but
3097 // not removed, and the new target is home, keep on the last target to avoid flicker.
3098 // Home is a special case since its above other stacks in the ordering list, but layed
3099 // out below the others.
3100 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
3101 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07003102 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00003103 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003104 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003105 }
3106
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003107 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
3108 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003109
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003110 if (target == null) {
3111 if (updateImeTarget) {
3112 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
3113 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
3114 + Debug.getCallers(4) : ""));
lumarkff0ab692018-11-05 20:32:30 +08003115 setInputMethodTarget(null, mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003116 }
3117
3118 return null;
3119 }
3120
3121 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003122 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
3123 if (token != null) {
3124
3125 // Now some fun for dealing with window animations that modify the Z order. We need
3126 // to look at all windows below the current target that are in this app, finding the
3127 // highest visible one in layering.
3128 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003129 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003130 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003131 }
3132
3133 if (highestTarget != null) {
lumark588a3e82018-07-20 18:53:54 +08003134 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, mAppTransition + " " + highestTarget
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003135 + " animating=" + highestTarget.isAnimating());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003136
lumark588a3e82018-07-20 18:53:54 +08003137 if (mAppTransition.isTransitionSet()) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003138 // If we are currently setting up for an animation, hold everything until we
3139 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003140 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003141 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003142 }
3143 }
3144 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003145
3146 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
3147 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003148 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003149 }
3150
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003151 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003152 }
3153
lumarkff0ab692018-11-05 20:32:30 +08003154 /**
3155 * Calling {@link #computeImeTarget(boolean)} to update the input method target window in
3156 * the candidate app window token if needed.
3157 */
3158 void computeImeTargetIfNeeded(AppWindowToken candidate) {
3159 if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == candidate) {
3160 computeImeTarget(true /* updateImeTarget */);
3161 }
3162 }
3163
Jorim Jaggib0fc8172017-11-23 17:04:08 +00003164 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
lumarkff0ab692018-11-05 20:32:30 +08003165 if (target == mInputMethodTarget && mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003166 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003167 }
3168
lumarkff0ab692018-11-05 20:32:30 +08003169 mInputMethodTarget = target;
3170 mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003171 assignWindowLayers(false /* setLayoutNeeded */);
3172 }
3173
3174 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
3175 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3176 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
3177 }
3178
3179 // Used to indicate we have reached the first window in the range we are interested in.
3180 mTmpWindow = null;
3181
3182 // TODO: Figure-out a more efficient way to do this.
3183 final WindowState candidate = getWindow(w -> {
3184 if (w == top) {
3185 // Reached the first window in the range we are interested in.
3186 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003187 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003188 if (mTmpWindow == null) {
3189 return false;
3190 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003191
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003192 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
3193 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003194 }
3195 // If we reached the bottom of the range of windows we are considering,
3196 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003197 if (w == bottom) {
3198 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003199 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003200 return false;
3201 });
3202
3203 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003204 }
3205
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003206 void setLayoutNeeded() {
3207 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
3208 mLayoutNeeded = true;
3209 }
3210
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003211 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003212 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
3213 mLayoutNeeded = false;
3214 }
3215
3216 boolean isLayoutNeeded() {
3217 return mLayoutNeeded;
3218 }
3219
Wale Ogunwale02319a62016-09-26 15:21:22 -07003220 void dumpTokens(PrintWriter pw, boolean dumpAll) {
3221 if (mTokenMap.isEmpty()) {
3222 return;
3223 }
3224 pw.println(" Display #" + mDisplayId);
3225 final Iterator<WindowToken> it = mTokenMap.values().iterator();
3226 while (it.hasNext()) {
3227 final WindowToken token = it.next();
3228 pw.print(" ");
3229 pw.print(token);
3230 if (dumpAll) {
3231 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003232 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07003233 } else {
3234 pw.println();
3235 }
3236 }
lumark588a3e82018-07-20 18:53:54 +08003237
3238 if (!mOpeningApps.isEmpty() || !mClosingApps.isEmpty()) {
3239 pw.println();
3240 if (mOpeningApps.size() > 0) {
3241 pw.print(" mOpeningApps="); pw.println(mOpeningApps);
3242 }
3243 if (mClosingApps.size() > 0) {
3244 pw.print(" mClosingApps="); pw.println(mClosingApps);
3245 }
3246 }
3247
3248 mUnknownAppVisibilityController.dump(pw, " ");
Wale Ogunwale02319a62016-09-26 15:21:22 -07003249 }
3250
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003251 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003252 final int[] index = new int[1];
3253 forAllWindows(w -> {
3254 final WindowStateAnimator wAnim = w.mWinAnimator;
3255 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
3256 index[0] = index[0] + 1;
3257 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003258 }
3259
Jorim Jaggife762342016-10-13 14:33:27 +02003260 /**
3261 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
3262 */
3263 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003264 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003265 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02003266 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
3267 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01003268 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02003269 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003270 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02003271 }
3272
Wale Ogunwale494009b82016-10-21 09:01:38 -07003273 boolean checkWaitingForWindows() {
3274
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003275 mHaveBootMsg = false;
3276 mHaveApp = false;
3277 mHaveWallpaper = false;
3278 mHaveKeyguard = true;
3279
3280 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003281 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
3282 return true;
3283 }
3284 if (w.isDrawnLw()) {
3285 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003286 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003287 } else if (w.mAttrs.type == TYPE_APPLICATION
3288 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003289 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003290 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003291 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003292 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003293 mHaveKeyguard = mWmService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003294 }
3295 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003296 return false;
3297 });
3298
3299 if (visibleWindow != null) {
3300 // We have a visible window.
3301 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003302 }
3303
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003304 // if the wallpaper service is disabled on the device, we're never going to have
3305 // wallpaper, don't bother waiting for it
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003306 boolean wallpaperEnabled = mWmService.mContext.getResources().getBoolean(
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003307 com.android.internal.R.bool.config_enableWallpaperService)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003308 && mWmService.mContext.getResources().getBoolean(
Daichi Hironoc1432222018-03-29 13:06:07 +09003309 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003310 && !mWmService.mOnlyCore;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003311
Wale Ogunwale494009b82016-10-21 09:01:38 -07003312 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003313 "******** booted=" + mWmService.mSystemBooted
3314 + " msg=" + mWmService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003315 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
3316 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
3317 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003318
3319 // If we are turning on the screen to show the boot message, don't do it until the boot
3320 // message is actually displayed.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003321 if (!mWmService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003322 return true;
3323 }
3324
3325 // If we are turning on the screen after the boot is completed normally, don't do so until
3326 // we have the application and wallpaper.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003327 if (mWmService.mSystemBooted
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003328 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003329 return true;
3330 }
3331
3332 return false;
3333 }
3334
Jorim Jaggi8f520872018-08-14 17:00:20 +02003335 void updateWindowsForAnimator() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003336 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003337 }
3338
Jorim Jaggi8f520872018-08-14 17:00:20 +02003339 /**
3340 * Updates the {@link TaskStack#setAnimationBackground} for all windows.
3341 */
3342 void updateBackgroundForAnimator() {
Jorim Jaggi7156b652016-10-25 08:31:58 -07003343 resetAnimationBackgroundAnimator();
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003344 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07003345 }
3346
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003347 boolean isInputMethodClientFocus(int uid, int pid) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003348 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003349 if (imFocus == null) {
3350 return false;
3351 }
3352
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003353 if (DEBUG_INPUT_METHOD) {
3354 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003355 Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
3356 Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00003357 }
3358
Wale Ogunwale494009b82016-10-21 09:01:38 -07003359 if (DEBUG_INPUT_METHOD) {
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003360 Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
3361 + "/" + imFocus.mSession.mPid);
3362 Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003363 }
3364
Yohei Yukawa41f89c32018-09-19 14:30:04 -07003365 return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003366 }
3367
3368 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003369 final WindowState win = getWindow(
3370 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
3371 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003372 }
3373
Tiger Huang7c610aa2018-10-27 00:01:01 +08003374 void statusBarVisibilityChanged(int visibility) {
3375 mLastStatusBarVisibility = visibility;
3376 visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(visibility);
3377 updateStatusBarVisibilityLocked(visibility);
3378 }
3379
3380 private boolean updateStatusBarVisibilityLocked(int visibility) {
3381 if (mLastDispatchedSystemUiVisibility == visibility) {
3382 return false;
3383 }
3384 final int globalDiff = (visibility ^ mLastDispatchedSystemUiVisibility)
3385 // We are only interested in differences of one of the
3386 // clearable flags...
3387 & View.SYSTEM_UI_CLEARABLE_FLAGS
3388 // ...if it has actually been cleared.
3389 & ~visibility;
3390
3391 mLastDispatchedSystemUiVisibility = visibility;
3392 if (isDefaultDisplay) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003393 mWmService.mInputManager.setSystemUiVisibility(visibility);
Tiger Huang7c610aa2018-10-27 00:01:01 +08003394 }
3395 updateSystemUiVisibility(visibility, globalDiff);
3396 return true;
3397 }
3398
Wale Ogunwale494009b82016-10-21 09:01:38 -07003399 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003400 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07003401 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003402 final int curValue = w.mSystemUiVisibility;
3403 final int diff = (curValue ^ visibility) & globalDiff;
3404 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003405 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003406 w.mSeq++;
3407 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003408 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003409 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
3410 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07003411 visibility, newValue, diff);
3412 }
3413 } catch (RemoteException e) {
3414 // so sorry
3415 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003416 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003417 }
3418
Tiger Huang7c610aa2018-10-27 00:01:01 +08003419 void reevaluateStatusBarVisibility() {
3420 int visibility = getDisplayPolicy().adjustSystemUiVisibilityLw(mLastStatusBarVisibility);
3421 if (updateStatusBarVisibilityLocked(visibility)) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003422 mWmService.mWindowPlacerLocked.requestTraversal();
Tiger Huang7c610aa2018-10-27 00:01:01 +08003423 }
3424 }
3425
Wale Ogunwale494009b82016-10-21 09:01:38 -07003426 void onWindowFreezeTimeout() {
3427 Slog.w(TAG_WM, "Window freeze timeout expired.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003428 mWmService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003429
3430 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003431 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003432 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003433 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07003434 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003435 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003436 - mWmService.mDisplayFreezeTime);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003437 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003438 }, true /* traverseTopToBottom */);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003439 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale494009b82016-10-21 09:01:38 -07003440 }
3441
3442 void waitForAllWindowsDrawn() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003443 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003444 forAllWindows(w -> {
3445 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3446 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3447 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003448 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07003449 w.resetLastContentInsets();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003450 mWmService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003451 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003452 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003453 }
3454
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003455 // TODO: Super crazy long method that should be broken down...
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003456 void applySurfaceChangesTransaction(boolean recoveringMemory) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003457 final WindowSurfacePlacer surfacePlacer = mWmService.mWindowPlacerLocked;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003458
3459 mTmpUpdateAllDrawn.clear();
3460
3461 int repeats = 0;
3462 do {
3463 repeats++;
3464 if (repeats > 6) {
3465 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3466 clearLayoutNeeded();
3467 break;
3468 }
3469
3470 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3471 pendingLayoutChanges);
3472
wilsonshihc32538e2018-11-07 17:27:34 +08003473 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
3474 mWallpaperController.adjustWallpaperWindows();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003475 }
3476
Riddle Hsu654a6f92018-07-13 22:59:36 +08003477 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003478 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Riddle Hsu4e611772018-10-31 18:58:28 +08003479 if (updateOrientationFromAppTokens()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003480 setLayoutNeeded();
Riddle Hsu4e611772018-10-31 18:58:28 +08003481 sendNewConfiguration();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003482 }
3483 }
3484
3485 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3486 setLayoutNeeded();
3487 }
3488
3489 // FIRST LOOP: Perform a layout, if needed.
3490 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3491 performLayout(repeats == 1, false /* updateInputWindows */);
3492 } else {
3493 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3494 }
3495
3496 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3497 pendingLayoutChanges = 0;
3498
Tiger Huang7c610aa2018-10-27 00:01:01 +08003499 mDisplayPolicy.beginPostLayoutPolicyLw();
3500 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
3501 pendingLayoutChanges |= mDisplayPolicy.finishPostLayoutPolicyLw();
3502 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3503 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003504 mInsetsStateController.onPostLayout();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003505 } while (pendingLayoutChanges != 0);
3506
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003507 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003508
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003509 mTmpRecoveringMemory = recoveringMemory;
3510 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003511 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003512
Jorim Jaggif1292892018-09-10 11:58:13 +02003513 mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003514 mWmService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggif1292892018-09-10 11:58:13 +02003515 mLastHasContent,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003516 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3517 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003518 true /* inTraversal, must call performTraversalInTrans... below */);
3519
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003520 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3521 if (wallpaperVisible != mLastWallpaperVisible) {
3522 mLastWallpaperVisible = wallpaperVisible;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003523 mWmService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003524 }
3525
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003526 while (!mTmpUpdateAllDrawn.isEmpty()) {
3527 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3528 // See if any windows have been drawn, so they (and others associated with them)
3529 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003530 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003531 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003532 }
3533
Bryce Leef3c6a472017-11-14 14:53:06 -08003534 private void updateBounds() {
Evan Rosky39b6f232018-10-30 18:35:41 -07003535 calculateBounds(mDisplayInfo, mTmpBounds);
Bryce Leef3c6a472017-11-14 14:53:06 -08003536 setBounds(mTmpBounds);
3537 }
3538
3539 // Determines the current display bounds based on the current state
Evan Rosky39b6f232018-10-30 18:35:41 -07003540 private void calculateBounds(DisplayInfo displayInfo, Rect out) {
Bryce Leef3c6a472017-11-14 14:53:06 -08003541 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
Evan Rosky39b6f232018-10-30 18:35:41 -07003542 final int rotation = displayInfo.rotation;
3543 boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Bryce Leef3c6a472017-11-14 14:53:06 -08003544 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3545 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
Evan Rosky39b6f232018-10-30 18:35:41 -07003546 int width = displayInfo.logicalWidth;
Bryce Leef3c6a472017-11-14 14:53:06 -08003547 int left = (physWidth - width) / 2;
Evan Rosky39b6f232018-10-30 18:35:41 -07003548 int height = displayInfo.logicalHeight;
Bryce Leef3c6a472017-11-14 14:53:06 -08003549 int top = (physHeight - height) / 2;
3550 out.set(left, top, left + width, top + height);
3551 }
3552
3553 @Override
3554 public void getBounds(Rect out) {
Evan Rosky39b6f232018-10-30 18:35:41 -07003555 calculateBounds(mDisplayInfo, out);
Bryce Leef3c6a472017-11-14 14:53:06 -08003556 }
3557
3558 private void getBounds(Rect out, int orientation) {
3559 getBounds(out);
3560
3561 // Rotate the Rect if needed.
3562 final int currentRotation = mDisplayInfo.rotation;
3563 final int rotationDelta = deltaRotation(currentRotation, orientation);
3564 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3565 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3566 mTmpRectF.set(out);
3567 mTmpMatrix.mapRect(mTmpRectF);
3568 mTmpRectF.round(out);
3569 }
3570 }
3571
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003572 void performLayout(boolean initial, boolean updateInputWindows) {
3573 if (!isLayoutNeeded()) {
3574 return;
3575 }
3576 clearLayoutNeeded();
3577
3578 final int dw = mDisplayInfo.logicalWidth;
3579 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003580 if (DEBUG_LAYOUT) {
3581 Slog.v(TAG, "-------------------------------------");
3582 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3583 }
3584
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003585 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3586 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003587 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3588 // display info above...
3589 mDisplayFrames.mRotation = mRotation;
Tiger Huang7c610aa2018-10-27 00:01:01 +08003590 mDisplayPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003591
Adrian Roos5251b1d2018-03-23 18:57:43 +01003592 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003593 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003594 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003595
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003596 // Used to indicate that we have processed the dream window and all additional windows are
3597 // behind it.
3598 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003599 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003600
3601 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003602 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003603
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003604 // Used to indicate that we have processed the dream window and all additional attached
3605 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003606 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003607 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003608
3609 // Now perform layout of attached windows, which usually depend on the position of the
3610 // window they are attached to. XXX does not deal with windows that are attached to windows
3611 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003612 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003613
3614 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003615 mInputMonitor.layoutInputConsumers(dw, dh);
3616 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003617 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003618 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003619 }
3620
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003621 mWmService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003622 }
3623
3624 /**
3625 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3626 * In portrait mode, it grabs the full screenshot.
3627 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003628 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003629 */
chaviw0315a1a2018-03-05 15:28:35 -08003630 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003631 if (!mWmService.mPolicy.isScreenOn()) {
chaviw0315a1a2018-03-05 15:28:35 -08003632 if (DEBUG_SCREENSHOT) {
3633 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003634 }
chaviw0315a1a2018-03-05 15:28:35 -08003635 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003636 }
chaviwfbe47df2017-11-10 16:14:49 -08003637
chaviw0315a1a2018-03-05 15:28:35 -08003638 int dw = mDisplayInfo.logicalWidth;
3639 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003640
chaviw0315a1a2018-03-05 15:28:35 -08003641 if (dw <= 0 || dh <= 0) {
3642 return null;
3643 }
chaviwfbe47df2017-11-10 16:14:49 -08003644
chaviw0315a1a2018-03-05 15:28:35 -08003645 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003646
chaviw0315a1a2018-03-05 15:28:35 -08003647 // The screenshot API does not apply the current screen rotation.
3648 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003649
chaviw0315a1a2018-03-05 15:28:35 -08003650 if (rot == ROTATION_90 || rot == ROTATION_270) {
3651 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3652 }
chaviwfbe47df2017-11-10 16:14:49 -08003653
chaviw0315a1a2018-03-05 15:28:35 -08003654 // SurfaceFlinger is not aware of orientation, so convert our logical
3655 // crop to SurfaceFlinger's portrait orientation.
3656 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3657
3658 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003659 mWmService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
chaviw0315a1a2018-03-05 15:28:35 -08003660 final boolean inRotation = screenRotationAnimation != null &&
3661 screenRotationAnimation.isAnimating();
3662 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3663
3664 // TODO(b/68392460): We should screenshot Task controls directly
3665 // but it's difficult at the moment as the Task doesn't have the
3666 // correct size set.
chaviw08520a02018-09-10 16:44:56 -07003667 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot);
chaviw0315a1a2018-03-05 15:28:35 -08003668 if (bitmap == null) {
3669 Slog.w(TAG_WM, "Failed to take screenshot");
3670 return null;
3671 }
3672
3673 // Create a copy of the screenshot that is immutable and backed in ashmem.
3674 // This greatly reduces the overhead of passing the bitmap between processes.
3675 final Bitmap ret = bitmap.createAshmemBitmap(config);
3676 bitmap.recycle();
3677 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003678 }
3679
3680 // TODO: Can this use createRotationMatrix()?
3681 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3682 if (rot == Surface.ROTATION_90) {
3683 final int tmp = crop.top;
3684 crop.top = dw - crop.right;
3685 crop.right = crop.bottom;
3686 crop.bottom = dw - crop.left;
3687 crop.left = tmp;
3688 } else if (rot == Surface.ROTATION_180) {
3689 int tmp = crop.top;
3690 crop.top = dh - crop.bottom;
3691 crop.bottom = dh - tmp;
3692 tmp = crop.right;
3693 crop.right = dw - crop.left;
3694 crop.left = dw - tmp;
3695 } else if (rot == Surface.ROTATION_270) {
3696 final int tmp = crop.top;
3697 crop.top = crop.left;
3698 crop.left = dh - crop.bottom;
3699 crop.bottom = crop.right;
3700 crop.right = dh - tmp;
3701 }
3702 }
3703
3704 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003705 // Used to indicate the layout is needed.
3706 mTmpWindow = null;
3707
3708 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003709 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003710 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003711 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003712 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003713 w.setDisplayLayoutNeeded();
Vishnu Nairba183352018-11-21 11:16:49 -08003714 w.finishSeamlessRotation(true /* timeout */);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003715 mWmService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003716 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003717
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003718 if (mTmpWindow != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003719 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003720 }
3721 }
3722
Wale Ogunwale1666e312016-12-16 11:27:18 -08003723 void setExitingTokensHasVisible(boolean hasVisible) {
3724 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3725 mExitingTokens.get(i).hasVisible = hasVisible;
3726 }
3727
3728 // Initialize state of exiting applications.
3729 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3730 }
3731
3732 void removeExistingTokensIfPossible() {
3733 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3734 final WindowToken token = mExitingTokens.get(i);
3735 if (!token.hasVisible) {
3736 mExitingTokens.remove(i);
3737 }
3738 }
3739
3740 // Time to remove any exiting applications?
3741 mTaskStackContainers.removeExistingAppTokensIfPossible();
3742 }
3743
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003744 @Override
3745 void onDescendantOverrideConfigurationChanged() {
3746 setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003747 mWmService.requestTraversal();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003748 }
3749
David Stevens9440dc82017-03-16 19:00:20 -07003750 boolean okToDisplay() {
3751 if (mDisplayId == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003752 return !mWmService.mDisplayFrozen
3753 && mWmService.mDisplayEnabled && mWmService.mPolicy.isScreenOn();
David Stevens9440dc82017-03-16 19:00:20 -07003754 }
3755 return mDisplayInfo.state == Display.STATE_ON;
3756 }
3757
3758 boolean okToAnimate() {
3759 return okToDisplay() &&
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003760 (mDisplayId != DEFAULT_DISPLAY || mWmService.mPolicy.okToAnimate());
David Stevens9440dc82017-03-16 19:00:20 -07003761 }
3762
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003763 static final class TaskForResizePointSearchResult {
3764 boolean searchDone;
3765 Task taskForResize;
3766
3767 void reset() {
3768 searchDone = false;
3769 taskForResize = null;
3770 }
3771 }
Robert Carr3b716242016-08-16 16:02:21 -07003772
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003773 private static final class ApplySurfaceChangesTransactionState {
3774 boolean displayHasContent;
3775 boolean obscured;
3776 boolean syswin;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003777 float preferredRefreshRate;
3778 int preferredModeId;
3779
3780 void reset() {
3781 displayHasContent = false;
3782 obscured = false;
3783 syswin = false;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003784 preferredRefreshRate = 0;
3785 preferredModeId = 0;
3786 }
3787 }
3788
3789 private static final class ScreenshotApplicationState {
3790 WindowState appWin;
3791 int maxLayer;
3792 int minLayer;
3793 boolean screenshotReady;
3794
3795 void reset(boolean screenshotReady) {
3796 appWin = null;
3797 maxLayer = 0;
3798 minLayer = 0;
3799 this.screenshotReady = screenshotReady;
3800 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3801 }
3802 }
3803
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003804 /**
3805 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3806 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3807 * homogeneous children type which is currently required by sub-classes of
3808 * {@link WindowContainer} class.
3809 */
3810 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3811
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003812 DisplayChildWindowContainer(WindowManagerService service) {
3813 super(service);
3814 }
3815
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003816 @Override
3817 boolean fillsParent() {
3818 return true;
3819 }
3820
3821 @Override
3822 boolean isVisible() {
3823 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003824 }
3825 }
3826
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003827 /**
3828 * Window container class that contains all containers on this display relating to Apps.
3829 * I.e Activities.
3830 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003831 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003832 /**
3833 * A control placed at the appropriate level for transitions to occur.
3834 */
chaviw23ee71c2017-12-18 11:29:41 -08003835 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003836 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003837 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003838
Robert Carrf7a7ca82017-12-06 13:17:07 -08003839 /**
3840 * Given that the split-screen divider does not have an AppWindowToken, it
3841 * will have to live inside of a "NonAppWindowContainer", in particular
3842 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3843 * it will need to be interleaved with some of our children, appearing on top of
3844 * both docked stacks but underneath any assistant stacks.
3845 *
3846 * To solve this problem we have this anchor control, which will always exist so
3847 * we can always assign it the correct value in our {@link #assignChildLayers}.
3848 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3849 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3850 * events between the two containers.
3851 */
3852 SurfaceControl mSplitScreenDividerAnchor = null;
3853
Wale Ogunwale61911492017-10-11 08:50:50 -07003854 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3855 // through the list to find them.
3856 private TaskStack mHomeStack = null;
3857 private TaskStack mPinnedStack = null;
3858 private TaskStack mSplitScreenPrimaryStack = null;
3859
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003860 TaskStackContainers(WindowManagerService service) {
3861 super(service);
3862 }
3863
Wale Ogunwale61911492017-10-11 08:50:50 -07003864 /**
3865 * Returns the topmost stack on the display that is compatible with the input windowing mode
3866 * and activity type. Null is no compatible stack on the display.
3867 */
3868 TaskStack getStack(int windowingMode, int activityType) {
3869 if (activityType == ACTIVITY_TYPE_HOME) {
3870 return mHomeStack;
3871 }
3872 if (windowingMode == WINDOWING_MODE_PINNED) {
3873 return mPinnedStack;
3874 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3875 return mSplitScreenPrimaryStack;
3876 }
3877 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3878 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003879 if (activityType == ACTIVITY_TYPE_UNDEFINED
3880 && windowingMode == stack.getWindowingMode()) {
3881 // Passing in undefined type means we want to match the topmost stack with the
3882 // windowing mode.
3883 return stack;
3884 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003885 if (stack.isCompatible(windowingMode, activityType)) {
3886 return stack;
3887 }
3888 }
3889 return null;
3890 }
3891
3892 @VisibleForTesting
3893 TaskStack getTopStack() {
3894 return mTaskStackContainers.getChildCount() > 0
3895 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3896 }
3897
3898 TaskStack getHomeStack() {
3899 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3900 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3901 }
3902 return mHomeStack;
3903 }
3904
3905 TaskStack getPinnedStack() {
3906 return mPinnedStack;
3907 }
3908
Matthew Ng64e77cf2017-10-31 14:01:31 -07003909 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003910 return mSplitScreenPrimaryStack;
3911 }
3912
Winson Chunge2d72172018-01-25 17:46:20 +00003913 ArrayList<Task> getVisibleTasks() {
3914 final ArrayList<Task> visibleTasks = new ArrayList<>();
3915 forAllTasks(task -> {
3916 if (task.isVisible()) {
3917 visibleTasks.add(task);
3918 }
3919 });
3920 return visibleTasks;
3921 }
3922
Andrii Kulian839def92016-11-02 10:58:58 -07003923 /**
3924 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003925 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003926 */
3927 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003928 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003929 addChild(stack, onTop);
3930 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003931 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003932
Wale Ogunwale61911492017-10-11 08:50:50 -07003933 void onStackWindowingModeChanged(TaskStack stack) {
3934 removeStackReferenceIfNeeded(stack);
3935 addStackReferenceIfNeeded(stack);
3936 if (stack == mPinnedStack && getTopStack() != stack) {
3937 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3938 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3939 }
3940 }
3941
3942 private void addStackReferenceIfNeeded(TaskStack stack) {
3943 if (stack.isActivityTypeHome()) {
3944 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003945 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003946 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003947
Wale Ogunwale61911492017-10-11 08:50:50 -07003948 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003949 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003950 }
3951 final int windowingMode = stack.getWindowingMode();
3952 if (windowingMode == WINDOWING_MODE_PINNED) {
3953 if (mPinnedStack != null) {
3954 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3955 + mPinnedStack + " already exist on display=" + this
3956 + " stack=" + stack);
3957 }
3958 mPinnedStack = stack;
3959 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3960 if (mSplitScreenPrimaryStack != null) {
3961 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3962 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3963 + " already exist on display=" + this + " stack=" + stack);
3964 }
3965 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003966 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003967 }
3968 }
3969
3970 private void removeStackReferenceIfNeeded(TaskStack stack) {
3971 if (stack == mHomeStack) {
3972 mHomeStack = null;
3973 } else if (stack == mPinnedStack) {
3974 mPinnedStack = null;
3975 } else if (stack == mSplitScreenPrimaryStack) {
3976 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003977 // Re-set the split-screen create mode whenever the split-screen stack is removed.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003978 mWmService.setDockedStackCreateStateLocked(
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003979 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3980 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003981 }
Andrii Kulian839def92016-11-02 10:58:58 -07003982 }
3983
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003984 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003985 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3986 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003987 addChild(stack, addIndex);
3988 setLayoutNeeded();
3989 }
3990
Wale Ogunwale61911492017-10-11 08:50:50 -07003991 @Override
3992 protected void removeChild(TaskStack stack) {
3993 super.removeChild(stack);
3994 removeStackReferenceIfNeeded(stack);
3995 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003996
3997 @Override
3998 boolean isOnTop() {
3999 // Considered always on top
4000 return true;
4001 }
4002
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004003 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08004004 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07004005 if (child.getWindowConfiguration().isAlwaysOnTop()
4006 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08004007 // This stack is always-on-top, override the default behavior.
4008 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
4009
4010 // Moving to its current position, as we must call super but we don't want to
4011 // perform any meaningful action.
4012 final int currentPosition = mChildren.indexOf(child);
4013 super.positionChildAt(currentPosition, child, false /* includingParents */);
4014 return;
4015 }
4016
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004017 final int targetPosition = findPositionForStack(position, child, false /* adding */);
4018 super.positionChildAt(targetPosition, child, includingParents);
4019
Riddle Hsu2f6e1742018-08-23 22:44:36 +08004020 if (includingParents) {
4021 // We still want to move the display of this stack container to top because even the
4022 // target position is adjusted to non-top, the intention of the condition is to have
4023 // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front
4024 // in a non-top display which is using picture-in-picture mode).
4025 final int topChildPosition = getChildCount() - 1;
4026 if (targetPosition < topChildPosition && position >= topChildPosition) {
4027 getParent().positionChildAt(POSITION_TOP, this /* child */,
4028 true /* includingParents */);
4029 }
4030 }
4031
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004032 setLayoutNeeded();
4033 }
4034
4035 /**
4036 * When stack is added or repositioned, find a proper position for it.
4037 * This will make sure that pinned stack always stays on top.
4038 * @param requestedPosition Position requested by caller.
4039 * @param stack Stack to be added or positioned.
4040 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
4041 * @return The proper position for the stack.
4042 */
4043 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004044 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09004045 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09004046 }
4047
Kazuki Takisef85197b2018-06-18 18:18:36 +09004048 final int topChildPosition = mChildren.size() - 1;
4049 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
4050 for (int i = topChildPosition; i >= 0; --i) {
4051 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
4052 belowAlwaysOnTopPosition = i;
4053 break;
4054 }
4055 }
4056
4057 // The max possible position we can insert the stack at.
4058 int maxPosition = POSITION_TOP;
4059 // The min possible position we can insert the stack at.
4060 int minPosition = POSITION_BOTTOM;
4061
4062 if (stack.isAlwaysOnTop()) {
4063 if (hasPinnedStack()) {
4064 // Always-on-top stacks go below the pinned stack.
4065 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
4066 }
4067 // Always-on-top stacks need to be above all other stacks.
4068 minPosition = belowAlwaysOnTopPosition !=
4069 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
4070 } else {
4071 // Other stacks need to be below the always-on-top stacks.
4072 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08004073 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09004074 }
4075
4076 int targetPosition = requestedPosition;
4077 targetPosition = Math.min(targetPosition, maxPosition);
4078 targetPosition = Math.max(targetPosition, minPosition);
4079
4080 int prevPosition = getStacks().indexOf(stack);
4081 // The positions we calculated above (maxPosition, minPosition) do not take into
4082 // consideration the following edge cases.
4083 // 1) We need to adjust the position depending on the value "adding".
4084 // 2) When we are moving a stack to another position, we also need to adjust the
4085 // position depending on whether the stack is moving to a higher or lower position.
4086 if ((targetPosition != requestedPosition) &&
4087 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09004088 targetPosition++;
4089 }
4090
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08004091 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08004092 }
4093
4094 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004095 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
4096 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004097 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004098 if (super.forAllWindows(callback, traverseTopToBottom)) {
4099 return true;
4100 }
4101 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4102 return true;
4103 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004104 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004105 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
4106 return true;
4107 }
4108 if (super.forAllWindows(callback, traverseTopToBottom)) {
4109 return true;
4110 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004111 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004112 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004113 }
4114
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004115 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004116 boolean traverseTopToBottom) {
4117 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
4118 // app tokens.
4119 // TODO: Investigate if we need to continue to do this or if we can just process them
4120 // in-order.
4121 if (traverseTopToBottom) {
4122 for (int i = mChildren.size() - 1; i >= 0; --i) {
4123 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4124 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004125 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4126 traverseTopToBottom)) {
4127 return true;
4128 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004129 }
4130 }
4131 } else {
4132 final int count = mChildren.size();
4133 for (int i = 0; i < count; ++i) {
4134 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4135 final int appTokensCount = appTokens.size();
4136 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004137 if (appTokens.get(j).forAllWindowsUnchecked(callback,
4138 traverseTopToBottom)) {
4139 return true;
4140 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004141 }
4142 }
4143 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004144 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004145 }
4146
Wale Ogunwale1666e312016-12-16 11:27:18 -08004147 void setExitingTokensHasVisible(boolean hasVisible) {
4148 for (int i = mChildren.size() - 1; i >= 0; --i) {
4149 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4150 for (int j = appTokens.size() - 1; j >= 0; --j) {
4151 appTokens.get(j).hasVisible = hasVisible;
4152 }
4153 }
4154 }
4155
4156 void removeExistingAppTokensIfPossible() {
4157 for (int i = mChildren.size() - 1; i >= 0; --i) {
4158 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
4159 for (int j = appTokens.size() - 1; j >= 0; --j) {
4160 final AppWindowToken token = appTokens.get(j);
lumark588a3e82018-07-20 18:53:54 +08004161 if (!token.hasVisible && !mClosingApps.contains(token)
Wale Ogunwale1666e312016-12-16 11:27:18 -08004162 && (!token.mIsExiting || token.isEmpty())) {
4163 // Make sure there is no animation running on this token, so any windows
4164 // associated with it will be removed as soon as their animations are
4165 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02004166 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08004167 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
4168 "performLayout: App token exiting now removed" + token);
4169 token.removeIfPossible();
4170 }
4171 }
4172 }
4173 }
4174
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004175 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004176 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004177 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
4178 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004179 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07004180 // docked or freeform stack is visible...except for the home stack if the docked
4181 // stack is minimized and it actually set something and the bounds is different from
4182 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004183 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004184 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07004185 && !(mDividerControllerLocked.isHomeStackResizable()
4186 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004187 final int orientation = mHomeStack.getOrientation();
4188 if (orientation != SCREEN_ORIENTATION_UNSET) {
4189 return orientation;
4190 }
4191 }
4192 return SCREEN_ORIENTATION_UNSPECIFIED;
4193 }
4194
4195 final int orientation = super.getOrientation();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004196 boolean isCar = mWmService.mContext.getPackageManager().hasSystemFeature(
Dean Harding3e5a1522017-10-06 09:19:01 -07004197 PackageManager.FEATURE_AUTOMOTIVE);
4198 if (isCar) {
4199 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
4200 // allow anything but the default orientation.
4201 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004202 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
4203 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07004204 return SCREEN_ORIENTATION_UNSPECIFIED;
4205 }
4206
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004207 if (orientation != SCREEN_ORIENTATION_UNSET
4208 && orientation != SCREEN_ORIENTATION_BEHIND) {
4209 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004210 "App is requesting an orientation, return " + orientation
4211 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004212 return orientation;
4213 }
4214
4215 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004216 "No app is requesting an orientation, return " + mLastOrientation
4217 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004218 // The next app has not been requested to be visible, so we keep the current orientation
4219 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08004220 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07004221 }
Robert Carrb1579c82017-09-05 14:54:47 -07004222
4223 @Override
4224 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004225 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004226
Robert Carr2f8aa392018-01-31 14:46:51 -08004227 for (int i = 0; i < mChildren.size(); i++) {
4228 final TaskStack s = mChildren.get(i);
4229 s.assignChildLayers(t);
4230 }
4231 }
4232
4233 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02004234
Robert Carrf7a7ca82017-12-06 13:17:07 -08004235 final int HOME_STACK_STATE = 0;
4236 final int NORMAL_STACK_STATE = 1;
4237 final int ALWAYS_ON_TOP_STATE = 2;
4238
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004239 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004240 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02004241 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02004242 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08004243
Robert Carrf7a7ca82017-12-06 13:17:07 -08004244 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
4245 for (int i = 0; i < mChildren.size(); i++) {
4246 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08004247 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
4248 continue;
4249 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
4250 || s.isAlwaysOnTop())) {
4251 continue;
4252 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
4253 continue;
4254 }
4255 s.assignLayer(t, layer++);
4256 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
4257 t.setLayer(mSplitScreenDividerAnchor, layer++);
4258 }
Winson Chungd41f71d2018-03-16 15:26:07 -07004259 if ((s.isTaskAnimating() || s.isAppAnimating())
4260 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08004261 // Ensure the animation layer ends up above the
4262 // highest animating stack and no higher.
4263 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004264 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004265 if (state != ALWAYS_ON_TOP_STATE) {
4266 layerForBoostedAnimationLayer = layer++;
4267 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08004268 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004269 if (state == HOME_STACK_STATE) {
4270 layerForHomeAnimationLayer = layer++;
4271 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004272 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004273 if (mAppAnimationLayer != null) {
4274 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004275 }
Jorim Jaggibe418292018-03-26 16:14:12 +02004276 if (mBoostedAppAnimationLayer != null) {
4277 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
4278 }
Jorim Jaggi391790622018-04-18 15:30:44 +02004279 if (mHomeAppAnimationLayer != null) {
4280 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
4281 }
Robert Carrb1579c82017-09-05 14:54:47 -07004282 }
4283
4284 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02004285 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
4286 switch (animationLayer) {
4287 case ANIMATION_LAYER_BOOSTED:
4288 return mBoostedAppAnimationLayer;
4289 case ANIMATION_LAYER_HOME:
4290 return mHomeAppAnimationLayer;
4291 case ANIMATION_LAYER_STANDARD:
4292 default:
4293 return mAppAnimationLayer;
4294 }
chaviw23ee71c2017-12-18 11:29:41 -08004295 }
4296
Robert Carrf7a7ca82017-12-06 13:17:07 -08004297 SurfaceControl getSplitScreenDividerAnchor() {
4298 return mSplitScreenDividerAnchor;
4299 }
4300
chaviw23ee71c2017-12-18 11:29:41 -08004301 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004302 void onParentSet() {
4303 super.onParentSet();
4304 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08004305 mAppAnimationLayer = makeChildSurface(null)
4306 .setName("animationLayer")
4307 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02004308 mBoostedAppAnimationLayer = makeChildSurface(null)
4309 .setName("boostedAnimationLayer")
4310 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02004311 mHomeAppAnimationLayer = makeChildSurface(null)
4312 .setName("homeAnimationLayer")
4313 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08004314 mSplitScreenDividerAnchor = makeChildSurface(null)
4315 .setName("splitScreenDividerAnchor")
4316 .build();
4317 getPendingTransaction()
4318 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02004319 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02004320 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08004321 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08004322 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07004323 } else {
chaviw23ee71c2017-12-18 11:29:41 -08004324 mAppAnimationLayer.destroy();
4325 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02004326 mBoostedAppAnimationLayer.destroy();
4327 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02004328 mHomeAppAnimationLayer.destroy();
4329 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08004330 mSplitScreenDividerAnchor.destroy();
4331 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07004332 }
4333 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004334 }
4335
Robert Carree4d4b92017-11-22 12:21:46 -08004336 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004337 AboveAppWindowContainers(String name, WindowManagerService service) {
4338 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08004339 }
4340
Robert Carrb9506032018-02-13 13:54:00 -08004341 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07004342 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
4343 final SurfaceControl.Builder builder = super.makeChildSurface(child);
4344 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
4345 // To draw above the ColorFade layer during the screen off transition, the
4346 // rounded corner overlays need to be at the root of the surface hierarchy.
4347 // TODO: move the ColorLayer into the display overlay layer such that this is not
4348 // necessary anymore.
4349 builder.setParent(null);
4350 }
4351 return builder;
4352 }
4353
4354 @Override
Robert Carrb9506032018-02-13 13:54:00 -08004355 void assignChildLayers(SurfaceControl.Transaction t) {
4356 assignChildLayers(t, null /* imeContainer */);
4357 }
4358
Robert Carree4d4b92017-11-22 12:21:46 -08004359 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
4360 boolean needAssignIme = imeContainer != null
4361 && imeContainer.getSurfaceControl() != null;
4362 for (int j = 0; j < mChildren.size(); ++j) {
4363 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08004364
4365 // See {@link mSplitScreenDividerAnchor}
4366 if (wt.windowType == TYPE_DOCK_DIVIDER) {
4367 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
4368 continue;
4369 }
Vishnu Nair83537a72018-07-19 21:27:48 -07004370 if (wt.mRoundedCornerOverlay) {
4371 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
4372 continue;
4373 }
Robert Carree4d4b92017-11-22 12:21:46 -08004374 wt.assignLayer(t, j);
4375 wt.assignChildLayers(t);
4376
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004377 int layer = mWmService.mPolicy.getWindowLayerFromTypeLw(
Robert Carree4d4b92017-11-22 12:21:46 -08004378 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08004379
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004380 if (needAssignIme && layer >= mWmService.mPolicy.getWindowLayerFromTypeLw(
Robert Carrb8e78fa2017-11-28 13:07:58 -08004381 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004382 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08004383 needAssignIme = false;
4384 }
4385 }
4386 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004387 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08004388 }
4389 }
4390 }
4391
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004392 /**
4393 * Window container class that contains all containers on this display that are not related to
4394 * Apps. E.g. status bar.
4395 */
Robert Carree4d4b92017-11-22 12:21:46 -08004396 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07004397 /**
4398 * Compares two child window tokens returns -1 if the first is lesser than the second in
4399 * terms of z-order and 1 otherwise.
4400 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004401 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07004402 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004403 mWmService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004404 token1.mOwnerCanManageAppTokens)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004405 < mWmService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08004406 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07004407
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004408 private final Predicate<WindowState> mGetOrientingWindow = w -> {
4409 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
4410 return false;
4411 }
4412 final int req = w.mAttrs.screenOrientation;
4413 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
4414 || req == SCREEN_ORIENTATION_UNSET) {
4415 return false;
4416 }
4417 return true;
4418 };
4419
Wale Ogunwale3a931692016-11-02 16:49:48 -07004420 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08004421 private final Dimmer mDimmer = new Dimmer(this);
4422 private final Rect mTmpDimBoundsRect = new Rect();
4423
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004424 NonAppWindowContainers(String name, WindowManagerService service) {
4425 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07004426 mName = name;
4427 }
4428
4429 void addChild(WindowToken token) {
4430 addChild(token, mWindowComparator);
4431 }
4432
4433 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004434 int getOrientation() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004435 final WindowManagerPolicy policy = mWmService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004436 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004437 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004438
4439 if (win != null) {
4440 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004441 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004442 mLastKeyguardForcedOrientation = req;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004443 if (mWmService.mKeyguardGoingAway) {
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004444 // Keyguard can't affect the orientation if it is going away...
4445 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4446 return SCREEN_ORIENTATION_UNSET;
4447 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004448 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004449 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4450 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004451 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004452 }
4453
Andrii Kulian8ee72852017-03-10 10:36:45 -08004454 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004455
Jorim Jaggi1c530592018-04-06 15:11:47 +02004456 // Only allow force setting the orientation when all unknown visibilities have been
4457 // resolved, as otherwise we just may be starting another occluding activity.
4458 final boolean isUnoccluding =
lumark588a3e82018-07-20 18:53:54 +08004459 mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4460 && mUnknownAppVisibilityController.allResolved();
Jorim Jaggi1c530592018-04-06 15:11:47 +02004461 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004462 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004463 }
4464
4465 return SCREEN_ORIENTATION_UNSET;
4466 }
4467
4468 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004469 String getName() {
4470 return mName;
4471 }
chaviwf29223e2018-01-31 13:23:51 -08004472
4473 @Override
4474 Dimmer getDimmer() {
4475 return mDimmer;
4476 }
4477
4478 @Override
4479 void prepareSurfaces() {
4480 mDimmer.resetDimStates();
4481 super.prepareSurfaces();
4482 getBounds(mTmpDimBoundsRect);
4483
4484 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4485 scheduleAnimation();
4486 }
4487 }
Robert Carr3b716242016-08-16 16:02:21 -07004488 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004489
Robert Carr9034d962018-01-04 18:27:42 -08004490 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4491 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4492 super(name, service);
4493 }
4494
4495 @Override
4496 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4497 }
4498 };
4499
Robert Carrb1579c82017-09-05 14:54:47 -07004500 SurfaceControl.Builder makeSurface(SurfaceSession s) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004501 return mWmService.makeSurfaceBuilder(s)
Robert Carrb1579c82017-09-05 14:54:47 -07004502 .setParent(mWindowingLayer);
4503 }
4504
4505 @Override
4506 SurfaceSession getSession() {
4507 return mSession;
4508 }
4509
4510 @Override
4511 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004512 SurfaceSession s = child != null ? child.getSession() : getSession();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004513 final SurfaceControl.Builder b = mWmService.makeSurfaceBuilder(s);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004514 if (child == null) {
4515 return b;
4516 }
4517
Robert Carree4d4b92017-11-22 12:21:46 -08004518 return b.setName(child.getName())
4519 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004520 }
4521
4522 /**
4523 * The makeSurface variants are for use by the window-container
4524 * hierarchy. makeOverlay here is a function for various non windowing
4525 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4526 * and other potpourii.
4527 */
4528 SurfaceControl.Builder makeOverlay() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004529 return mWmService.makeSurfaceBuilder(mSession)
Robert Carrb1579c82017-09-05 14:54:47 -07004530 .setParent(mOverlayLayer);
4531 }
4532
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004533 /**
4534 * Reparents the given surface to mOverlayLayer.
4535 */
4536 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4537 transaction.reparent(surface, mOverlayLayer.getHandle());
4538 }
4539
Robert Carrb1579c82017-09-05 14:54:47 -07004540 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004541 if (spec.scale != 1.0) {
4542 mMagnificationSpec = spec;
4543 } else {
4544 mMagnificationSpec = null;
4545 }
4546
Robert Carrf59b8dd2017-10-02 18:58:36 -07004547 applyMagnificationSpec(getPendingTransaction(), spec);
4548 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004549 }
4550
Robert Carr24be9ab2018-04-30 17:54:53 -07004551 void reapplyMagnificationSpec() {
4552 if (mMagnificationSpec != null) {
4553 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4554 }
4555 }
4556
Robert Carrb1579c82017-09-05 14:54:47 -07004557 @Override
4558 void onParentSet() {
4559 // Since we are the top of the SurfaceControl hierarchy here
4560 // we create the root surfaces explicitly rather than chaining
4561 // up as the default implementation in onParentSet does. So we
4562 // explicitly do NOT call super here.
4563 }
4564
4565 @Override
4566 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004567
4568 // These are layers as children of "mWindowingLayer"
4569 mBelowAppWindowsContainers.assignLayer(t, 0);
4570 mTaskStackContainers.assignLayer(t, 1);
4571 mAboveAppWindowsContainers.assignLayer(t, 2);
4572
lumarkff0ab692018-11-05 20:32:30 +08004573 final WindowState imeTarget = mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004574 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004575
Robert Carree4d4b92017-11-22 12:21:46 -08004576 // In the case where we have an IME target that is not in split-screen
4577 // mode IME assignment is easy. We just need the IME to go directly above
4578 // the target. This way children of the target will naturally go above the IME
4579 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004580 //
Robert Carree4d4b92017-11-22 12:21:46 -08004581 // In the case of split-screen windowing mode, we need to elevate the IME above the
4582 // docked divider while keeping the app itself below the docked divider, so instead
4583 // we use relative layering of the IME targets child windows, and place the
4584 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004585 //
Robert Carr234b6332018-03-20 13:38:16 -07004586 // In the case the IME target is animating, the animation Z order may be different
4587 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4588 // IME target. In this case we just layer the IME over all transitions by placing it in the
4589 // above applications layer.
4590 //
Robert Carree4d4b92017-11-22 12:21:46 -08004591 // In the case where we have no IME target we assign it where it's base layer would
4592 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004593 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4594 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004595 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004596 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004597 // TODO: We need to use an extra level on the app surface to ensure
4598 // this is always above SurfaceView but always below attached window.
4599 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004600 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004601 }
4602
4603 // Above we have assigned layers to our children, now we ask them to assign
4604 // layers to their children.
4605 mBelowAppWindowsContainers.assignChildLayers(t);
4606 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004607 mAboveAppWindowsContainers.assignChildLayers(t,
4608 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004609 mImeWindowsContainers.assignChildLayers(t);
4610 }
4611
4612 /**
4613 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4614 * that the IME target is one of the docked applications. We'd like the docked divider to be
4615 * above both of the applications, and we'd like the IME to be above the docked divider.
4616 * However we need child windows of the applications to be above the IME (Text drag handles).
4617 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4618 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
Tiger Huang7c610aa2018-10-27 00:01:01 +08004619 * with {@link WindowState#assignLayer}
Robert Carrb1579c82017-09-05 14:54:47 -07004620 */
4621 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004622 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004623 }
4624
4625 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004626 void prepareSurfaces() {
4627 final ScreenRotationAnimation screenRotationAnimation =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004628 mWmService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004629 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4630 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4631 mPendingTransaction.setMatrix(mWindowingLayer,
4632 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4633 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4634 mPendingTransaction.setPosition(mWindowingLayer,
4635 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4636 mPendingTransaction.setAlpha(mWindowingLayer,
4637 screenRotationAnimation.getEnterTransformation().getAlpha());
4638 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004639
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004640 super.prepareSurfaces();
4641 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004642
Jorim Jaggibe418292018-03-26 16:14:12 +02004643 void assignStackOrdering() {
4644 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004645 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004646
4647 /**
4648 * Increment the deferral count to determine whether to update the IME target.
4649 */
4650 void deferUpdateImeTarget() {
4651 mDeferUpdateImeTargetCount++;
4652 }
4653
4654 /**
4655 * Decrement the deferral count to determine whether to update the IME target. If the count
4656 * reaches 0, a new ime target will get computed.
4657 */
4658 void continueUpdateImeTarget() {
4659 if (mDeferUpdateImeTargetCount == 0) {
4660 return;
4661 }
4662
4663 mDeferUpdateImeTargetCount--;
4664 if (mDeferUpdateImeTargetCount == 0) {
4665 computeImeTarget(true /* updateImeTarget */);
4666 }
4667 }
4668
4669 /**
4670 * @return Whether a new IME target should be computed.
4671 */
4672 private boolean canUpdateImeTarget() {
4673 return mDeferUpdateImeTargetCount == 0;
4674 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004675
4676 InputMonitor getInputMonitor() {
4677 return mInputMonitor;
4678 }
Jorim Jaggif1292892018-09-10 11:58:13 +02004679
4680 /**
4681 * @return Cached value whether we told display manager that we have content.
4682 */
4683 boolean getLastHasContent() {
4684 return mLastHasContent;
4685 }
Arthur Hungbe5ce212018-09-13 18:41:56 +08004686
4687 void registerPointerEventListener(@NonNull PointerEventListener listener) {
4688 if (mPointerEventDispatcher != null) {
4689 mPointerEventDispatcher.registerInputEventListener(listener);
4690 }
4691 }
4692
4693 void unregisterPointerEventListener(@NonNull PointerEventListener listener) {
4694 if (mPointerEventDispatcher != null) {
4695 mPointerEventDispatcher.unregisterInputEventListener(listener);
4696 }
4697 }
lumark588a3e82018-07-20 18:53:54 +08004698
4699 void prepareAppTransition(@WindowManager.TransitionType int transit,
Wale Ogunwale3a256e62018-12-06 14:41:18 -08004700 boolean alwaysKeepCurrent) {
4701 prepareAppTransition(transit, alwaysKeepCurrent, 0 /* flags */, false /* forceOverride */);
4702 }
4703
4704 void prepareAppTransition(@WindowManager.TransitionType int transit,
lumark588a3e82018-07-20 18:53:54 +08004705 boolean alwaysKeepCurrent, @WindowManager.TransitionFlags int flags,
4706 boolean forceOverride) {
4707 final boolean prepared = mAppTransition.prepareAppTransitionLocked(
4708 transit, alwaysKeepCurrent, flags, forceOverride);
4709 if (prepared && okToAnimate()) {
4710 mSkipAppTransitionAnimation = false;
4711 }
4712 }
4713
4714 void executeAppTransition() {
4715 if (mAppTransition.isTransitionSet()) {
4716 if (DEBUG_APP_TRANSITIONS) {
4717 Slog.w(TAG_WM, "Execute app transition: " + mAppTransition + ", displayId: "
4718 + mDisplayId + " Callers=" + Debug.getCallers(5));
4719 }
4720 mAppTransition.setReady();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004721 mWmService.mWindowPlacerLocked.requestTraversal();
lumark588a3e82018-07-20 18:53:54 +08004722 }
4723 }
4724
4725 /**
4726 * Update pendingLayoutChanges after app transition has finished.
4727 */
4728 void handleAnimatingStoppedAndTransition() {
4729 int changes = 0;
4730
4731 mAppTransition.setIdle();
4732
4733 for (int i = mNoAnimationNotifyOnTransitionFinished.size() - 1; i >= 0; i--) {
4734 final IBinder token = mNoAnimationNotifyOnTransitionFinished.get(i);
4735 mAppTransition.notifyAppTransitionFinishedLocked(token);
4736 }
4737 mNoAnimationNotifyOnTransitionFinished.clear();
4738
4739 mWallpaperController.hideDeferredWallpapersIfNeeded();
4740
4741 onAppTransitionDone();
4742
4743 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4744 if (DEBUG_WALLPAPER_LIGHT) {
4745 Slog.v(TAG_WM, "Wallpaper layer changed: assigning layers + relayout");
4746 }
4747 computeImeTarget(true /* updateImeTarget */);
wilsonshihc32538e2018-11-07 17:27:34 +08004748 mWallpaperMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004749 // Since the window list has been rebuilt, focus might have to be recomputed since the
4750 // actual order of windows might have changed again.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004751 mWmService.mFocusMayChange = true;
lumark588a3e82018-07-20 18:53:54 +08004752
4753 pendingLayoutChanges |= changes;
4754 }
Andrii Kulian15cfb422018-11-07 13:38:49 -08004755
Wale Ogunwale3a256e62018-12-06 14:41:18 -08004756 /** Check if pending app transition is for activity / task launch. */
4757 boolean isNextTransitionForward() {
4758 final int transit = mAppTransition.getAppTransition();
4759 return transit == TRANSIT_ACTIVITY_OPEN
4760 || transit == TRANSIT_TASK_OPEN
4761 || transit == TRANSIT_TASK_TO_FRONT;
4762 }
4763
Andrii Kulian15cfb422018-11-07 13:38:49 -08004764 /**
4765 * @see Display#FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
4766 */
4767 boolean supportsSystemDecorations() {
4768 // TODO(b/114338689): Read the setting from DisplaySettings.
4769 return mDisplay.supportsSystemDecorations()
4770 // TODO (b/111363427): Remove this and set the new FLAG_SHOULD_SHOW_LAUNCHER flag
4771 // (b/114338689) whenever vr 2d display id is set.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004772 || mDisplayId == mWmService.mVr2dDisplayId
4773 || mWmService.mForceDesktopModeOnExternalDisplays;
Andrii Kulian15cfb422018-11-07 13:38:49 -08004774 }
chaviwff2e7d82018-11-02 11:11:27 -07004775
4776 /**
4777 * Re-parent the DisplayContent's top surfaces, {@link #mWindowingLayer} and
4778 * {@link #mOverlayLayer} to the specified surfaceControl.
4779 *
4780 * @param surfaceControlHandle The handle for the new SurfaceControl, where the DisplayContent's
4781 * surfaces will be re-parented to.
4782 */
4783 void reparentDisplayContent(IBinder surfaceControlHandle) {
4784 mPendingTransaction.reparent(mWindowingLayer, surfaceControlHandle)
4785 .reparent(mOverlayLayer, surfaceControlHandle);
4786 }
Craig Mautner59c00972012-07-30 12:10:24 -07004787}