blob: 49638a91662c3480b69f3038716c0d55aa4c26f5 [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale65ebd952018-04-25 15:41:44 -070019import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale61911492017-10-11 08:50:50 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070021import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
24import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
27import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070028import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
29import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070030import static android.view.Display.DEFAULT_DISPLAY;
31import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070032import static android.view.Surface.ROTATION_0;
33import static android.view.Surface.ROTATION_180;
34import static android.view.Surface.ROTATION_270;
35import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070036import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070037import static android.view.WindowManager.DOCKED_BOTTOM;
38import static android.view.WindowManager.DOCKED_INVALID;
39import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080040import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
41import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070043import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070044import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070045import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
46import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070047import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070048import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070050import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080051import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070052import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070053import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070054import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
55import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070056import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070057import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
58import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070059import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070060import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080061import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
62
Adrian Roose99bc052017-11-20 17:55:31 +010063import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
64import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
66import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080067import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
68import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
69import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
70import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
71import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
72import static com.android.server.wm.DisplayContentProto.DPI;
73import static com.android.server.wm.DisplayContentProto.ID;
74import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
75import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
76import static com.android.server.wm.DisplayContentProto.ROTATION;
77import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
78import static com.android.server.wm.DisplayContentProto.STACKS;
79import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070085import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070095import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070096import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070097import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080098import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070099import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700100import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
101import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700102import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700103import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700104import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
105import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700106import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700107import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700108import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700109import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700110import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700111import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700112import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700113import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700114import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700115import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800116import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700117
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700118import android.annotation.CallSuper;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700119import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700120import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700121import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700122import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700123import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700124import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800125import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700126import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700127import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100128import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700129import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700130import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700131import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700132import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700133import android.os.RemoteException;
134import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100135import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800136import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700137import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700138import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700139import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700140import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100141import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700142import android.view.DisplayInfo;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800143import android.view.Gravity;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700144import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700145import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700146import android.view.Surface;
147import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100148import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700149import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700150
Bryce Lee48f4b572017-04-10 10:54:15 -0700151import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800152import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700153import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100154import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100155import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100156import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700157
158import java.io.PrintWriter;
159import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700160import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700161import java.util.HashMap;
162import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700163import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700164import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100165import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800166import java.util.function.Consumer;
167import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700168
Craig Mautner59c00972012-07-30 12:10:24 -0700169/**
170 * Utility class for keeping track of the WindowStates and other pertinent contents of a
171 * particular Display.
172 *
173 * IMPORTANT: No method from this class should ever be used without holding
174 * WindowManagerService.mWindowMap.
175 */
Riddle Hsuad256a12018-07-18 16:11:30 +0800176class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
177 implements WindowManagerPolicy.DisplayContentInfo {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700178 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700179
180 /** Unique identifier of this stack. */
181 private final int mDisplayId;
182
Wale Ogunwale3a931692016-11-02 16:49:48 -0700183 /** The containers below are the only child containers the display can have. */
184 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100185 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700186 // Contains all non-app window containers that should be displayed above the app containers
187 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800188 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100189 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700190 // Contains all non-app window containers that should be displayed below the app containers
191 // (e.g. Wallpaper).
192 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100193 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700194 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
195 // 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 -0800196 // window containers together and move them in-sync if/when needed. We use a subclass of
197 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
198 private final NonMagnifiableWindowContainers mImeWindowsContainers =
199 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700200
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000201 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800202 private WindowState mTmpWindow2;
203 private WindowAnimator mTmpWindowAnimator;
204 private boolean mTmpRecoveringMemory;
205 private boolean mUpdateImeTarget;
206 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700207 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700208
Wale Ogunwale02319a62016-09-26 15:21:22 -0700209 // Mapping from a token IBinder to a WindowToken object on this display.
210 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
211
Andrii Kuliancd097992017-03-23 18:31:59 -0700212 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700213 int mInitialDisplayWidth = 0;
214 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700215 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700216
Adrian Roos1cf585052018-01-03 18:43:27 +0100217 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100218 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100219 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100220
Andrii Kuliancd097992017-03-23 18:31:59 -0700221 /**
222 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
223 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
224 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
225 */
Craig Mautner59c00972012-07-30 12:10:24 -0700226 int mBaseDisplayWidth = 0;
227 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700228 /**
229 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
230 * but can be set from Settings or via shell command "adb shell wm density".
231 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
232 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700233 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700234 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700235 private final DisplayInfo mDisplayInfo = new DisplayInfo();
236 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700237 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800238 private final DisplayPolicy mDisplayPolicy;
239 private DisplayRotation mDisplayRotation;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000240 DisplayFrames mDisplayFrames;
241
Andrii Kulian06d07d62017-03-14 11:11:47 -0700242 /**
243 * For default display it contains real metrics, empty for others.
244 * @see WindowManagerService#createWatermarkInTransaction()
245 */
246 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
247 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
248 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700249
Andrii Kulian06d07d62017-03-14 11:11:47 -0700250 /**
251 * Compat metrics computed based on {@link #mDisplayMetrics}.
252 * @see #updateDisplayAndOrientation(int)
253 */
254 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
255
256 /** The desired scaling factor for compatible apps. */
257 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700258
Andrii Kulian8ee72852017-03-10 10:36:45 -0800259 /**
260 * Current rotation of the display.
261 * Constants as per {@link android.view.Surface.Rotation}.
262 *
Robert Carrae606b42018-02-15 15:36:23 -0800263 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800264 */
265 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700266
Andrii Kulian8ee72852017-03-10 10:36:45 -0800267 /**
268 * Last applied orientation of the display.
269 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
270 *
271 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
272 */
273 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700274
Andrii Kulian8ee72852017-03-10 10:36:45 -0800275 /**
276 * Flag indicating that the application is receiving an orientation that has different metrics
277 * than it expected. E.g. Portrait instead of Landscape.
278 *
Robert Carrae606b42018-02-15 15:36:23 -0800279 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800280 */
281 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700282
Andrii Kulian8ee72852017-03-10 10:36:45 -0800283 /**
284 * Orientation forced by some window. If there is no visible window that specifies orientation
285 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
286 *
287 * @see NonAppWindowContainers#getOrientation()
288 */
289 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700290
Andrii Kulian8ee72852017-03-10 10:36:45 -0800291 /**
292 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
293 * occluded.
294 *
295 * @see NonAppWindowContainers#getOrientation()
296 */
297 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
298
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700299 /**
300 * Keep track of wallpaper visibility to notify changes.
301 */
302 private boolean mLastWallpaperVisible = false;
303
Andrii Kulian06d07d62017-03-14 11:11:47 -0700304 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700305
Craig Mautner39834192012-09-02 07:47:24 -0700306 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700307 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700308 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800309 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800310
Andrii Kulian839def92016-11-02 10:58:58 -0700311 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800312 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800313 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800314
Andrii Kulianf0379de2018-03-14 16:24:07 -0700315 /**
316 * Flag indicating whether WindowManager should override info for this display in
317 * DisplayManager.
318 */
319 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700320
Craig Mautnerdc548482014-02-05 13:35:24 -0800321 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700322 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800323
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700324 /** Detect user tapping outside of current focused task bounds .*/
325 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700326
Craig Mautner6601b7b2013-04-29 10:29:11 -0700327 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700328 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700329
Craig Mautner6601b7b2013-04-29 10:29:11 -0700330 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800331 private final Rect mTmpRect = new Rect();
332 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700333 private final RectF mTmpRectF = new RectF();
334 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800335 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700336
Bryce Leef3c6a472017-11-14 14:53:06 -0800337 /** Used for handing back size of display */
338 private final Rect mTmpBounds = new Rect();
339
Craig Mautner95da1082014-02-24 17:54:35 -0800340 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800342
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700343 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700344 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700345
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800346 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800347 /** A collection of windows that provide tap exclude regions inside of them. */
348 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800349
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000350 private boolean mHaveBootMsg = false;
351 private boolean mHaveApp = false;
352 private boolean mHaveWallpaper = false;
353 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700354
355 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
356
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700357 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
358 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000359 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
360 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700361
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700362 // True if this display is in the process of being removed. Used to determine if the removal of
363 // the display's direct children should be allowed.
364 private boolean mRemovingDisplay = false;
365
Bryce Leed1871262017-06-12 14:12:29 -0700366 // {@code false} if this display is in the processing of being created.
367 private boolean mDisplayReady = false;
368
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800369 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700370
Robert Carrb1579c82017-09-05 14:54:47 -0700371 private final SurfaceSession mSession = new SurfaceSession();
372
373 /**
374 * We organize all top-level Surfaces in to the following layers.
375 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800376 * and omitted from Screen-Magnification, for example the strict mode flash or
377 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700378 * {@link #mWindowingLayer} contains everything else.
379 */
380 private SurfaceControl mOverlayLayer;
381
382 /**
383 * See {@link #mOverlayLayer}
384 */
385 private SurfaceControl mWindowingLayer;
386
387 /**
388 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
389 * <p>
390 * For these surfaces currently we use a surface based on the larger of width or height so we
391 * don't have to resize when rotating the display.
392 */
393 private int mSurfaceSize;
394
Adrian Roos5251b1d2018-03-23 18:57:43 +0100395 /**
396 * Sequence number for the current layout pass.
397 */
398 int mLayoutSeq = 0;
399
Chavi Weingarten3a748552018-05-14 17:32:42 +0000400 /**
401 * Specifies the count to determine whether to defer updating the IME target until ready.
402 */
403 private int mDeferUpdateImeTargetCount;
404
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100405 /** Temporary float array to retrieve 3x3 matrix values. */
406 private final float[] mTmpFloats = new float[9];
407
Robert Carr24be9ab2018-04-30 17:54:53 -0700408 private MagnificationSpec mMagnificationSpec;
409
Arthur Hung95b38a92018-07-20 18:56:12 +0800410 private InputMonitor mInputMonitor;
411
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800412 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
413 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800414 final AppWindowToken atoken = w.mAppToken;
415 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200416 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800417 if (w.performShowLocked()) {
418 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
419 if (DEBUG_LAYOUT_REPEATS) {
420 mService.mWindowPlacerLocked.debugLayoutRepeats(
421 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
422 }
423 }
424 }
425 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800426 };
427
428 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
429 final WindowStateAnimator winAnimator = w.mWinAnimator;
430 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
431 return;
432 }
433
434 final int flags = w.mAttrs.flags;
435
436 // If this window is animating, make a note that we have an animating window and take
437 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100438 if (winAnimator.isAnimationSet()) {
439 final AnimationAdapter anim = w.getAnimation();
440 if (anim != null) {
441 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800442 mTmpWindow = w;
443 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100444 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800445 if (color != 0) {
446 final TaskStack stack = w.getStack();
447 if (stack != null) {
448 stack.setAnimationBackground(winAnimator, color);
449 }
450 }
451 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800452 }
453
454 // If this window's app token is running a detached wallpaper animation, make a note so
455 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200456 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
457 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
458 if (animation != null) {
459 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800460 mTmpWindow = w;
461 }
462
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200463 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800464 if (color != 0) {
465 final TaskStack stack = w.getStack();
466 if (stack != null) {
467 stack.setAnimationBackground(winAnimator, color);
468 }
469 }
470 }
471 };
472
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800473 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
474 final int lostFocusUid = mTmpWindow.mOwnerUid;
475 final Handler handler = mService.mH;
476 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
477 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
478 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
479 w.mAttrs.hideTimeoutMilliseconds);
480 }
481 }
482 };
483
484 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
485 final AppWindowToken focusedApp = mService.mFocusedApp;
486 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
487 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
488
489 if (!w.canReceiveKeys()) {
490 return false;
491 }
492
493 final AppWindowToken wtoken = w.mAppToken;
494
495 // If this window's application has been removed, just skip it.
496 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
497 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
498 + (wtoken.removed ? "removed" : "sendingToBottom"));
499 return false;
500 }
501
502 if (focusedApp == null) {
503 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
504 + " using new focus @ " + w);
505 mTmpWindow = w;
506 return true;
507 }
508
509 if (!focusedApp.windowsAreFocusable()) {
510 // Current focused app windows aren't focusable...
511 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
512 + " focusable using new focus @ " + w);
513 mTmpWindow = w;
514 return true;
515 }
516
517 // Descend through all of the app tokens and find the first that either matches
518 // win.mAppToken (return win) or mFocusedApp (return null).
519 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
520 if (focusedApp.compareTo(wtoken) > 0) {
521 // App stack below focused app stack. No focus for you!!!
522 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
523 "findFocusedWindow: Reached focused app=" + focusedApp);
524 mTmpWindow = null;
525 return true;
526 }
527 }
528
529 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
530 mTmpWindow = w;
531 return true;
532 };
533
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800534 private final Consumer<WindowState> mPerformLayout = w -> {
535 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
536 // wasting time and funky changes while a window is animating away.
537 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
538 || w.isGoneForLayoutLw();
539
540 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
541 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
542 + " mLayoutAttached=" + w.mLayoutAttached
543 + " screen changed=" + w.isConfigChanged());
544 final AppWindowToken atoken = w.mAppToken;
545 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200546 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800547 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
548 + " parentHidden=" + w.isParentWindowHidden());
549 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200550 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800551 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
552 + " parentHidden=" + w.isParentWindowHidden());
553 }
554
555 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
556 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
557 // since that means "perform layout as normal, just don't display").
558 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
559 || ((w.isConfigChanged() || w.setReportResizeHints())
560 && !w.isGoneForLayoutLw() &&
561 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
562 (w.mHasSurface && w.mAppToken != null &&
563 w.mAppToken.layoutConfigChanges)))) {
564 if (!w.mLayoutAttached) {
565 if (mTmpInitial) {
566 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
567 w.mContentChanged = false;
568 }
569 if (w.mAttrs.type == TYPE_DREAM) {
570 // Don't layout windows behind a dream, so that if it does stuff like hide
571 // the status bar we won't get a bad transition when it goes away.
572 mTmpWindow = w;
573 }
574 w.mLayoutNeeded = false;
575 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200576 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000577 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100578 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800579
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200580 // If this is the first layout, we need to initialize the last inset values as
581 // otherwise we'd immediately cause an unnecessary resize.
582 if (firstLayout) {
583 w.updateLastInsetValues();
584 }
585
Adrian Roos23df3a32018-03-15 15:41:13 +0100586 if (w.mAppToken != null) {
587 w.mAppToken.layoutLetterbox(w);
588 }
589
chaviw492139a2018-07-16 16:07:35 -0700590 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700591 + " mContainingFrame=" + w.getContainingFrame()
592 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800593 }
594 }
595 };
596
597 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
598 if (w.mLayoutAttached) {
599 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
600 + " mViewVisibility=" + w.mViewVisibility
601 + " mRelayoutCalled=" + w.mRelayoutCalled);
602 // If this view is GONE, then skip it -- keep the current frame, and let the caller
603 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
604 // windows, since that means "perform layout as normal, just don't display").
605 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
606 return;
607 }
608 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
609 || w.mLayoutNeeded) {
610 if (mTmpInitial) {
611 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
612 w.mContentChanged = false;
613 }
614 w.mLayoutNeeded = false;
615 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000616 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100617 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700618 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700619 + " mContainingFrame=" + w.getContainingFrame()
620 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800621 }
622 } else if (w.mAttrs.type == TYPE_DREAM) {
623 // Don't layout windows behind a dream, so that if it does stuff like hide the
624 // status bar we won't get a bad transition when it goes away.
625 mTmpWindow = mTmpWindow2;
626 }
627 };
628
629 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
630 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
631 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
632 return w.canBeImeTarget();
633 };
634
635 private final Consumer<WindowState> mApplyPostLayoutPolicy =
636 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
637 mService.mInputMethodTarget);
638
639 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
640 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
641 final boolean obscuredChanged = w.mObscured !=
642 mTmpApplySurfaceChangesTransactionState.obscured;
643 final RootWindowContainer root = mService.mRoot;
644 // Only used if default window
645 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
646
647 // Update effect.
648 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
649 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
650 final boolean isDisplayed = w.isDisplayedLw();
651
652 if (isDisplayed && w.isObscuringDisplay()) {
653 // This window completely covers everything behind it, so we want to leave all
654 // of them as undimmed (for performance reasons).
655 root.mObscuringWindow = w;
656 mTmpApplySurfaceChangesTransactionState.obscured = true;
657 }
658
659 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
660 root.handleNotObscuredLocked(w,
661 mTmpApplySurfaceChangesTransactionState.obscured,
662 mTmpApplySurfaceChangesTransactionState.syswin);
663
664 if (w.mHasSurface && isDisplayed) {
665 final int type = w.mAttrs.type;
666 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
667 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
668 mTmpApplySurfaceChangesTransactionState.syswin = true;
669 }
670 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
671 && w.mAttrs.preferredRefreshRate != 0) {
672 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
673 = w.mAttrs.preferredRefreshRate;
674 }
675 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
676 && w.mAttrs.preferredDisplayModeId != 0) {
677 mTmpApplySurfaceChangesTransactionState.preferredModeId
678 = w.mAttrs.preferredDisplayModeId;
679 }
680 }
681 }
682
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800683 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
684 && mWallpaperController.isWallpaperTarget(w)) {
685 // This is the wallpaper target and its obscured state changed... make sure the
686 // current wallpaper's visibility has been updated accordingly.
687 mWallpaperController.updateWallpaperVisibility();
688 }
689
chaviw161ea3e2018-01-31 12:01:12 -0800690 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800691
692 final WindowStateAnimator winAnimator = w.mWinAnimator;
693
694 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
695 w.mContentChanged = false;
696
697 // Moved from updateWindowsAndWallpaperLocked().
698 if (w.mHasSurface) {
699 // Take care of the window being ready to display.
700 final boolean committed = winAnimator.commitFinishDrawingLocked();
701 if (isDefaultDisplay && committed) {
702 if (w.mAttrs.type == TYPE_DREAM) {
703 // HACK: When a dream is shown, it may at that point hide the lock screen.
704 // So we need to redo the layout to let the phone window manager make this
705 // happen.
706 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
707 if (DEBUG_LAYOUT_REPEATS) {
708 surfacePlacer.debugLayoutRepeats(
709 "dream and commitFinishDrawingLocked true",
710 pendingLayoutChanges);
711 }
712 }
713 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
714 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
715 "First draw done in potential wallpaper target " + w);
716 root.mWallpaperMayChange = true;
717 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
718 if (DEBUG_LAYOUT_REPEATS) {
719 surfacePlacer.debugLayoutRepeats(
720 "wallpaper and commitFinishDrawingLocked true",
721 pendingLayoutChanges);
722 }
723 }
724 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800725 }
726
727 final AppWindowToken atoken = w.mAppToken;
728 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100729 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800730 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
731 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
732 mTmpUpdateAllDrawn.add(atoken);
733 }
734 }
735
736 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
737 && w.isDisplayedLw()) {
738 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
739 }
740
741 w.updateResizingWindowIfNeeded();
742 };
743
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800744 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800745 * Create new {@link DisplayContent} instance, add itself to the root window container and
746 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700747 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800748 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700749 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
750 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700751 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700752 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800753 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100754 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800755 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800756 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
757 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
758 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
759 + " new=" + display);
760 }
761
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700762 mDisplay = display;
763 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700764 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700765 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700766 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700767 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100768 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
769 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700770 initializeDisplayBaseInfo();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800771 mDisplayPolicy = new DisplayPolicy(service);
772 mDisplayRotation = new DisplayRotation(service, this);
773 if (isDefaultDisplay) {
774 // The policy may be invoked right after here, so it requires the necessary default
775 // fields of this display content.
776 mService.mPolicy.setDefaultDisplay(this);
777 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800778 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700779 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700780
Robert Carr74a66a22018-02-23 12:17:51 -0800781 // We use this as our arbitrary surface size for buffer-less parents
782 // that don't impose cropping on their children. It may need to be larger
783 // than the display size because fullscreen windows can be shifted offscreen
784 // due to surfaceInsets. 2 times the largest display dimension feels like an
785 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
786 // layers the ability to match their parent sizes and be able to skip
787 // such arbitrary size settings.
788 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700789
790 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
791 .setSize(mSurfaceSize, mSurfaceSize)
792 .setOpaque(true);
793 mWindowingLayer = b.setName("Display Root").build();
794 mOverlayLayer = b.setName("Display Overlays").build();
795
Robert Carrf59b8dd2017-10-02 18:58:36 -0700796 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700797 .setLayerStack(mWindowingLayer, mDisplayId)
798 .show(mWindowingLayer)
799 .setLayer(mOverlayLayer, 1)
800 .setLayerStack(mOverlayLayer, mDisplayId)
801 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700802 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700803
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700804 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700805 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700806 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700807 super.addChild(mAboveAppWindowsContainers, null);
808 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800809
810 // Add itself as a child to the root container.
811 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700812
813 // TODO(b/62541591): evaluate whether this is the best spot to declare the
814 // {@link DisplayContent} ready for use.
815 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800816
Siarhei Vishniakou96283082018-08-13 18:55:55 +0000817 // TODO(b/112081256): Use independent InputMonitor.
818 mInputMonitor = isDefaultDisplay ? new InputMonitor(service, mDisplayId)
819 : mService.getDefaultDisplayContentLocked().mInputMonitor;
Bryce Leed1871262017-06-12 14:12:29 -0700820 }
821
822 boolean isReady() {
823 // The display is ready when the system and the individual display are both ready.
824 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700825 }
826
827 int getDisplayId() {
828 return mDisplayId;
829 }
830
Wale Ogunwale02319a62016-09-26 15:21:22 -0700831 WindowToken getWindowToken(IBinder binder) {
832 return mTokenMap.get(binder);
833 }
834
835 AppWindowToken getAppWindowToken(IBinder binder) {
836 final WindowToken token = getWindowToken(binder);
837 if (token == null) {
838 return null;
839 }
840 return token.asAppWindowToken();
841 }
842
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700843 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700844 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
845 if (dc != null) {
846 // We currently don't support adding a window token to the display if the display
847 // already has the binder mapped to another token. If there is a use case for supporting
848 // this moving forward we will either need to merge the WindowTokens some how or have
849 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700850 throw new IllegalArgumentException("Can't map token=" + token + " to display="
851 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700852 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700853 if (binder == null) {
854 throw new IllegalArgumentException("Can't map token=" + token + " to display="
855 + getName() + " binder is null");
856 }
857 if (token == null) {
858 throw new IllegalArgumentException("Can't map null token to display="
859 + getName() + " binder=" + binder);
860 }
861
Wale Ogunwale02319a62016-09-26 15:21:22 -0700862 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700863
864 if (token.asAppWindowToken() == null) {
865 // Add non-app token to container hierarchy on the display. App tokens are added through
866 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700867 switch (token.windowType) {
868 case TYPE_WALLPAPER:
869 mBelowAppWindowsContainers.addChild(token);
870 break;
871 case TYPE_INPUT_METHOD:
872 case TYPE_INPUT_METHOD_DIALOG:
873 mImeWindowsContainers.addChild(token);
874 break;
875 default:
876 mAboveAppWindowsContainers.addChild(token);
877 break;
878 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700879 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700880 }
881
882 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700883 final WindowToken token = mTokenMap.remove(binder);
884 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800885 token.setExiting();
886 }
887 return token;
888 }
889
890 /** Changes the display the input window token is housed on to this one. */
891 void reParentWindowToken(WindowToken token) {
892 final DisplayContent prevDc = token.getDisplayContent();
893 if (prevDc == this) {
894 return;
895 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800896 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
897 && token.asAppWindowToken() == null) {
898 // Removed the token from the map, but made sure it's not an app token before removing
899 // from parent.
900 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700901 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800902
903 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700904 }
905
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700906 void removeAppToken(IBinder binder) {
907 final WindowToken token = removeWindowToken(binder);
908 if (token == null) {
909 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
910 return;
911 }
912
913 final AppWindowToken appToken = token.asAppWindowToken();
914
915 if (appToken == null) {
916 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
917 return;
918 }
919
920 appToken.onRemovedFromDisplay();
921 }
922
Riddle Hsuad256a12018-07-18 16:11:30 +0800923 @Override
924 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700925 return mDisplay;
926 }
927
Craig Mautner59c00972012-07-30 12:10:24 -0700928 DisplayInfo getDisplayInfo() {
929 return mDisplayInfo;
930 }
931
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700932 DisplayMetrics getDisplayMetrics() {
933 return mDisplayMetrics;
934 }
935
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800936 DisplayPolicy getDisplayPolicy() {
937 return mDisplayPolicy;
938 }
939
Riddle Hsuad256a12018-07-18 16:11:30 +0800940 @Override
941 public DisplayRotation getDisplayRotation() {
942 return mDisplayRotation;
943 }
944
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800945 @VisibleForTesting
946 void setDisplayRotation(DisplayRotation displayRotation) {
947 mDisplayRotation = displayRotation;
948 }
949
Andrii Kulian8ee72852017-03-10 10:36:45 -0800950 int getRotation() {
951 return mRotation;
952 }
953
Andrii Kulianef5ce1c2018-03-20 19:27:24 -0700954 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -0800955 void setRotation(int newRotation) {
956 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +0800957 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -0800958 }
959
960 int getLastOrientation() {
961 return mLastOrientation;
962 }
963
964 void setLastOrientation(int orientation) {
965 mLastOrientation = orientation;
966 }
967
968 boolean getAltOrientation() {
969 return mAltOrientation;
970 }
971
972 void setAltOrientation(boolean altOrientation) {
973 mAltOrientation = altOrientation;
974 }
975
976 int getLastWindowForcedOrientation() {
977 return mLastWindowForcedOrientation;
978 }
979
Andrii Kulian06d07d62017-03-14 11:11:47 -0700980 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +0800981 * Temporarily pauses rotation changes until resumed.
982 *
983 * This can be used to prevent rotation changes from occurring while the user is
984 * performing certain operations, such as drag and drop.
985 *
986 * This call nests and must be matched by an equal number of calls to
987 * {@link #resumeRotationLocked}.
988 */
989 void pauseRotationLocked() {
990 mDeferredRotationPauseCount++;
991 }
992
993 /**
994 * Resumes normal rotation changes after being paused.
995 */
996 void resumeRotationLocked() {
997 if (mDeferredRotationPauseCount <= 0) {
998 return;
999 }
1000
1001 mDeferredRotationPauseCount--;
1002 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001003 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001004 }
1005 }
1006
1007 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001008 * If this is true we have updated our desired orientation, but not yet changed the real
1009 * orientation our applied our screen rotation animation. For example, because a previous
1010 * screen rotation was in progress.
1011 *
1012 * @return {@code true} if the there is an ongoing rotation change.
1013 */
1014 boolean rotationNeedsUpdate() {
1015 final int lastOrientation = getLastOrientation();
1016 final int oldRotation = getRotation();
1017 final boolean oldAltOrientation = getAltOrientation();
1018
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001019 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001020 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1021 lastOrientation, rotation);
1022 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1023 return false;
1024 }
1025 return true;
1026 }
1027
1028 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001029 * Update rotation of the display and send configuration if the rotation is changed.
1030 *
1031 * @return {@code true} if the rotation has been changed and the new config is sent.
1032 */
1033 boolean updateRotationAndSendNewConfigIfNeeded() {
1034 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1035 if (changed) {
1036 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
1037 }
1038 return changed;
1039 }
1040
1041 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001042 * Update rotation of the display.
1043 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001044 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1045 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001046 */
Robert Carrae606b42018-02-15 15:36:23 -08001047 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001048 return updateRotationUnchecked(false /* forceUpdate */);
1049 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001050
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001051 /**
1052 * Update rotation of the display with an option to force the update.
1053 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1054 * orientation because we're waiting for some rotation to finish or display
1055 * to unfreeze, which results in configuration of the previously visible
1056 * activity being applied to a newly visible one. Forcing the rotation
1057 * update allows to workaround this issue.
1058 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1059 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
1060 */
1061 boolean updateRotationUnchecked(boolean forceUpdate) {
1062 ScreenRotationAnimation screenRotationAnimation;
1063 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001064 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001065 // Rotation updates have been paused temporarily. Defer the update until
1066 // updates have been resumed.
1067 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1068 return false;
1069 }
1070
1071 screenRotationAnimation =
1072 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
1073 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1074 // Rotation updates cannot be performed while the previous rotation change
1075 // animation is still in progress. Skip this update. We will try updating
1076 // again after the animation is finished and the display is unfrozen.
1077 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1078 return false;
1079 }
1080 if (mService.mDisplayFrozen) {
1081 // Even if the screen rotation animation has finished (e.g. isAnimating
1082 // returns false), there is still some time where we haven't yet unfrozen
1083 // the display. We also need to abort rotation here.
1084 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1085 "Deferring rotation, still finishing previous rotation");
1086 return false;
1087 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001088 }
1089
1090 if (!mService.mDisplayEnabled) {
1091 // No point choosing a rotation if the display is not enabled.
1092 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1093 return false;
1094 }
1095
1096 final int oldRotation = mRotation;
1097 final int lastOrientation = mLastOrientation;
1098 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001099 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001100 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1101 + mDisplayId + " based on lastOrientation=" + lastOrientation
1102 + " and oldRotation=" + oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001103 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(mDisplayRotation,
1104 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001105
Robert Carr0e007272017-10-02 13:00:55 -07001106 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001107 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001108 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001109 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1110 // to complete (that is, waiting for windows to redraw). It's tempting to check
1111 // w.mSeamlessRotationCount but that could be incorrect in the case of
1112 // window-removal.
1113 return false;
1114 }
Robert Carr0e007272017-10-02 13:00:55 -07001115
1116 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001117 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001118 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001119 mayRotateSeamlessly = false;
1120 }
1121 for (int i = 0; i < mService.mSessions.size(); i++) {
1122 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1123 mayRotateSeamlessly = false;
1124 break;
1125 }
1126 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001127 }
Robert Carr0e007272017-10-02 13:00:55 -07001128 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001129
1130 // TODO: Implement forced rotation changes.
1131 // Set mAltOrientation to indicate that the application is receiving
1132 // an orientation that has different metrics than it expected.
1133 // eg. Portrait instead of Landscape.
1134
Riddle Hsuad256a12018-07-18 16:11:30 +08001135 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001136 lastOrientation, rotation);
1137
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001138 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1139 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001140 + ", got rotation " + rotation + " which has "
1141 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1142
1143 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1144 // No change.
1145 return false;
1146 }
1147
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001148 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1149 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001150 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1151 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1152
1153 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1154 mService.mWaitingForConfig = true;
1155 }
1156
Riddle Hsuad256a12018-07-18 16:11:30 +08001157 setRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001158 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001159
1160 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
Riddle Hsu654a6f92018-07-13 22:59:36 +08001161 mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1162 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001163
1164 setLayoutNeeded();
1165 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001166 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001167
1168 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001169 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001170 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1171 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1172 mDisplayId);
1173 } else {
1174 // The screen rotation animation uses a screenshot to freeze the screen
1175 // while windows resize underneath.
1176 // When we are rotating seamlessly, we allow the elements to transition
1177 // to their rotated state independently and without a freeze required.
1178 screenRotationAnimation = null;
1179
Robert Carrefc75702018-02-16 11:46:16 -08001180 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001181 }
1182
1183 // We need to update our screen size information to match the new rotation. If the rotation
1184 // has actually changed then this method will return true and, according to the comment at
1185 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1186 // By updating the Display info here it will be available to
1187 // #computeScreenConfiguration() later.
1188 updateDisplayAndOrientation(getConfiguration().uiMode);
1189
Robert Carrae606b42018-02-15 15:36:23 -08001190 // NOTE: We disable the rotation in the emulator because
1191 // it doesn't support hardware OpenGL emulation yet.
1192 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1193 && screenRotationAnimation.hasScreenshot()) {
1194 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1195 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1196 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1197 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001198 }
1199 }
1200
Vishnu Nair83537a72018-07-19 21:27:48 -07001201 forAllWindows(w -> {
1202 w.forceSeamlesslyRotateIfAllowed(oldRotation, rotation);
1203 }, true /* traverseTopToBottom */);
1204
1205 // TODO(b/111504081): Consolidate seamless rotation logic.
Robert Carrae606b42018-02-15 15:36:23 -08001206 if (rotateSeamlessly) {
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001207 seamlesslyRotate(getPendingTransaction(), oldRotation, rotation);
Robert Carrae606b42018-02-15 15:36:23 -08001208 }
1209
1210 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1211 scheduleAnimation();
1212
Andrii Kulian06d07d62017-03-14 11:11:47 -07001213 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001214 if (w.mHasSurface && !rotateSeamlessly) {
1215 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001216 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001217 mService.mRoot.mOrientationChangeComplete = false;
1218 w.mLastFreezeDuration = 0;
1219 }
1220 w.mReportOrientationChanged = true;
1221 }, true /* traverseTopToBottom */);
1222
1223 if (rotateSeamlessly) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001224 mService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1225 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001226 }
1227
1228 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1229 final WindowManagerService.RotationWatcher rotationWatcher
1230 = mService.mRotationWatchers.get(i);
1231 if (rotationWatcher.mDisplayId == mDisplayId) {
1232 try {
1233 rotationWatcher.mWatcher.onRotationChanged(rotation);
1234 } catch (RemoteException e) {
1235 // Ignore
1236 }
1237 }
1238 }
1239
1240 // TODO (multi-display): Magnification is supported only for the default display.
1241 // Announce rotation only if we will not animate as we already have the
1242 // windows in final state. Otherwise, we make this call at the rotation end.
1243 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1244 && isDefaultDisplay) {
1245 mService.mAccessibilityController.onRotationChangedLocked(this);
1246 }
1247
1248 return true;
1249 }
1250
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001251 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001252 final int width = mBaseDisplayWidth;
1253 final int height = mBaseDisplayHeight;
1254 final int shortSize;
1255 final int longSize;
1256 if (width > height) {
1257 shortSize = height;
1258 longSize = width;
1259 } else {
1260 shortSize = width;
1261 longSize = height;
1262 }
1263
1264 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1265 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1266
1267 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1268 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001269
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001270 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1271 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001272 }
1273
Andrii Kulian06d07d62017-03-14 11:11:47 -07001274 /**
1275 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1276 * changed.
1277 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1278 */
1279 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1280 // Use the effective "visual" dimensions based on current rotation
1281 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1282 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1283 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1284 int dw = realdw;
1285 int dh = realdh;
1286
1287 if (mAltOrientation) {
1288 if (realdw > realdh) {
1289 // Turn landscape into portrait.
1290 int maxw = (int)(realdh/1.3f);
1291 if (maxw < realdw) {
1292 dw = maxw;
1293 }
1294 } else {
1295 // Turn portrait into landscape.
1296 int maxh = (int)(realdw/1.3f);
1297 if (maxh < realdh) {
1298 dh = maxh;
1299 }
1300 }
1301 }
1302
1303 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001304 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1305 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1306
Andrii Kulian06d07d62017-03-14 11:11:47 -07001307 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001308 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001309 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001310 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001311 mDisplayInfo.rotation = mRotation;
1312 mDisplayInfo.logicalWidth = dw;
1313 mDisplayInfo.logicalHeight = dh;
1314 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1315 mDisplayInfo.appWidth = appWidth;
1316 mDisplayInfo.appHeight = appHeight;
1317 if (isDefaultDisplay) {
1318 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1319 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1320 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001321 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001322 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1323 if (mDisplayScalingDisabled) {
1324 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1325 } else {
1326 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1327 }
1328
Andrii Kulianf0379de2018-03-14 16:24:07 -07001329 // We usually set the override info in DisplayManager so that we get consistent display
1330 // metrics values when displays are changing and don't send out new values until WM is aware
1331 // of them. However, we don't do this for displays that serve as containers for ActivityView
1332 // because we don't want letter-/pillar-boxing during resize.
1333 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1334 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001335 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001336 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001337
1338 mBaseDisplayRect.set(0, 0, dw, dh);
1339
1340 if (isDefaultDisplay) {
1341 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1342 mCompatDisplayMetrics);
1343 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001344
1345 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001346 return mDisplayInfo;
1347 }
1348
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001349 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001350 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1351 }
1352
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001353 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001354 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001355 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001356 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001357 }
Adrian Roos11c25582018-02-19 18:06:36 +01001358 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001359 return WmDisplayCutout.computeSafeInsets(
1360 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001361 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001362 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Jorim Jaggi60640512018-06-29 01:14:31 +02001363 final List<Rect> bounds = WmDisplayCutout.computeSafeInsets(
1364 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
1365 .getDisplayCutout().getBoundingRects();
Adrian Roos11c25582018-02-19 18:06:36 +01001366 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1367 mTmpMatrix);
Jorim Jaggi60640512018-06-29 01:14:31 +02001368 final Region region = Region.obtain();
1369 for (int i = 0; i < bounds.size(); i++) {
1370 final Rect rect = bounds.get(i);
1371 final RectF rectF = new RectF(bounds.get(i));
1372 mTmpMatrix.mapRect(rectF);
1373 rectF.round(rect);
1374 region.op(rect, Op.UNION);
1375 }
1376
1377 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(region),
Adrian Roos24264212018-02-19 16:26:15 +01001378 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1379 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001380 }
1381
Andrii Kulian06d07d62017-03-14 11:11:47 -07001382 /**
1383 * Compute display configuration based on display properties and policy settings.
1384 * Do not call if mDisplayReady == false.
1385 */
1386 void computeScreenConfiguration(Configuration config) {
1387 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1388
1389 final int dw = displayInfo.logicalWidth;
1390 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001391 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001392 config.windowConfiguration.setWindowingMode(getWindowingMode());
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001393
Adrian Roos11c25582018-02-19 18:06:36 +01001394 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001395 config.screenWidthDp =
1396 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001397 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001398 config.screenHeightDp =
1399 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001400 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001401
Adrian Roos11c25582018-02-19 18:06:36 +01001402 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1403 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001404 final int leftInset = mTmpRect.left;
1405 final int topInset = mTmpRect.top;
1406 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001407 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1408 leftInset + displayInfo.appWidth /* right */,
1409 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001410 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1411 || displayInfo.rotation == Surface.ROTATION_270);
1412
1413 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001414 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001415
1416 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1417 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1418 ? Configuration.SCREENLAYOUT_ROUND_YES
1419 : Configuration.SCREENLAYOUT_ROUND_NO);
1420
1421 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1422 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1423 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1424 dh, mDisplayId);
1425 config.densityDpi = displayInfo.logicalDensityDpi;
1426
1427 config.colorMode =
1428 (displayInfo.isHdr()
1429 ? Configuration.COLOR_MODE_HDR_YES
1430 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001431 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001432 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1433 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1434
1435 // Update the configuration based on available input devices, lid switch,
1436 // and platform configuration.
1437 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1438 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1439 config.navigation = Configuration.NAVIGATION_NONAV;
1440
1441 int keyboardPresence = 0;
1442 int navigationPresence = 0;
1443 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1444 final int len = devices != null ? devices.length : 0;
1445 for (int i = 0; i < len; i++) {
1446 InputDevice device = devices[i];
1447 if (!device.isVirtual()) {
1448 final int sources = device.getSources();
1449 final int presenceFlag = device.isExternal() ?
1450 WindowManagerPolicy.PRESENCE_EXTERNAL :
1451 WindowManagerPolicy.PRESENCE_INTERNAL;
1452
1453 // TODO(multi-display): Configure on per-display basis.
1454 if (mService.mIsTouchDevice) {
1455 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1456 InputDevice.SOURCE_TOUCHSCREEN) {
1457 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1458 }
1459 } else {
1460 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1461 }
1462
1463 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1464 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1465 navigationPresence |= presenceFlag;
1466 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1467 && config.navigation == Configuration.NAVIGATION_NONAV) {
1468 config.navigation = Configuration.NAVIGATION_DPAD;
1469 navigationPresence |= presenceFlag;
1470 }
1471
1472 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1473 config.keyboard = Configuration.KEYBOARD_QWERTY;
1474 keyboardPresence |= presenceFlag;
1475 }
1476 }
1477 }
1478
1479 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1480 config.navigation = Configuration.NAVIGATION_DPAD;
1481 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1482 }
1483
1484 // Determine whether a hard keyboard is available and enabled.
1485 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1486 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1487 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1488 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1489 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1490 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1491 }
1492
1493 // Let the policy update hidden states.
1494 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1495 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1496 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1497 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1498 }
1499
1500 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1501 int displayId) {
1502 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1503 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1504 final int unrotDw, unrotDh;
1505 if (rotated) {
1506 unrotDw = dh;
1507 unrotDh = dw;
1508 } else {
1509 unrotDw = dw;
1510 unrotDh = dh;
1511 }
1512 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1513 displayId);
1514 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1515 displayId);
1516 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1517 displayId);
1518 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1519 displayId);
1520 return sw;
1521 }
1522
1523 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1524 DisplayMetrics dm, int dw, int dh, int displayId) {
1525 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001526 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001527 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001528 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001529 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1530 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1531 if (curSize == 0 || size < curSize) {
1532 curSize = size;
1533 }
1534 return curSize;
1535 }
1536
1537 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1538 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1539
1540 // We need to determine the smallest width that will occur under normal
1541 // operation. To this, start with the base screen size and compute the
1542 // width under the different possible rotations. We need to un-rotate
1543 // the current screen dimensions before doing this.
1544 int unrotDw, unrotDh;
1545 if (rotated) {
1546 unrotDw = dh;
1547 unrotDh = dw;
1548 } else {
1549 unrotDw = dw;
1550 unrotDh = dh;
1551 }
1552 displayInfo.smallestNominalAppWidth = 1<<30;
1553 displayInfo.smallestNominalAppHeight = 1<<30;
1554 displayInfo.largestNominalAppWidth = 0;
1555 displayInfo.largestNominalAppHeight = 0;
1556 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1557 unrotDh);
1558 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1559 unrotDw);
1560 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1561 unrotDh);
1562 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1563 unrotDw);
1564 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1565 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1566 displayId);
1567 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1568 displayId);
1569 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1570 displayId);
1571 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1572 displayId);
1573 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1574 outConfig.screenLayout = sl;
1575 }
1576
1577 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1578 int uiMode, int displayId) {
1579 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001580 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1581 mDisplayInfo.displayCutout);
1582 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1583 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001584
1585 // Compute the screen layout size class for this rotation.
1586 int longSize = w;
1587 int shortSize = h;
1588 if (longSize < shortSize) {
1589 int tmp = longSize;
1590 longSize = shortSize;
1591 shortSize = tmp;
1592 }
1593 longSize = (int)(longSize/density);
1594 shortSize = (int)(shortSize/density);
1595 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1596 }
1597
1598 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1599 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001600 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1601 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001602 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001603 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001604 if (width < displayInfo.smallestNominalAppWidth) {
1605 displayInfo.smallestNominalAppWidth = width;
1606 }
1607 if (width > displayInfo.largestNominalAppWidth) {
1608 displayInfo.largestNominalAppWidth = width;
1609 }
1610 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001611 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001612 if (height < displayInfo.smallestNominalAppHeight) {
1613 displayInfo.smallestNominalAppHeight = height;
1614 }
1615 if (height > displayInfo.largestNominalAppHeight) {
1616 displayInfo.largestNominalAppHeight = height;
1617 }
1618 }
1619
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001620 /**
1621 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1622 * theme attribute) on devices that feature a physical options menu key attempt to position
1623 * their menu panel window along the edge of the screen nearest the physical menu key.
1624 * This lowers the travel distance between invoking the menu panel and selecting
1625 * a menu option.
1626 *
1627 * This method helps control where that menu is placed. Its current implementation makes
1628 * assumptions about the menu key and its relationship to the screen based on whether
1629 * the device's natural orientation is portrait (width < height) or landscape.
1630 *
1631 * The menu key is assumed to be located along the bottom edge of natural-portrait
1632 * devices and along the right edge of natural-landscape devices. If these assumptions
1633 * do not hold for the target device, this method should be changed to reflect that.
1634 *
1635 * @return A {@link Gravity} value for placing the options menu window.
1636 */
1637 int getPreferredOptionsPanelGravity() {
1638 final int rotation = getRotation();
1639 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1640 // On devices with a natural orientation of portrait.
1641 switch (rotation) {
1642 default:
1643 case Surface.ROTATION_0:
1644 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1645 case Surface.ROTATION_90:
1646 return Gravity.RIGHT | Gravity.BOTTOM;
1647 case Surface.ROTATION_180:
1648 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1649 case Surface.ROTATION_270:
1650 return Gravity.START | Gravity.BOTTOM;
1651 }
1652 }
1653
1654 // On devices with a natural orientation of landscape.
1655 switch (rotation) {
1656 default:
1657 case Surface.ROTATION_0:
1658 return Gravity.RIGHT | Gravity.BOTTOM;
1659 case Surface.ROTATION_90:
1660 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1661 case Surface.ROTATION_180:
1662 return Gravity.START | Gravity.BOTTOM;
1663 case Surface.ROTATION_270:
1664 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1665 }
1666 }
1667
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001668 DockedStackDividerController getDockedDividerController() {
1669 return mDividerControllerLocked;
1670 }
1671
Winson Chung655332c2016-10-31 13:14:28 -07001672 PinnedStackController getPinnedStackController() {
1673 return mPinnedStackControllerLocked;
1674 }
1675
Jeff Browna506a6e2013-06-04 00:02:38 -07001676 /**
1677 * Returns true if the specified UID has access to this display.
1678 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001679 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001680 return mDisplay.hasAccess(uid);
1681 }
1682
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001683 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001684 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001685 }
1686
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001687 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001688 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001689 }
1690
Wale Ogunwale61911492017-10-11 08:50:50 -07001691 /**
1692 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1693 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001694 TaskStack getSplitScreenPrimaryStack() {
1695 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001696 return (stack != null && stack.isVisible()) ? stack : null;
1697 }
1698
Robert Carr9785cf32018-04-25 15:06:07 -07001699 boolean hasSplitScreenPrimaryStack() {
1700 return getSplitScreenPrimaryStack() != null;
1701 }
1702
Wale Ogunwale61911492017-10-11 08:50:50 -07001703 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001704 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001705 * not visible.
1706 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001707 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1708 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001709 }
1710
1711 TaskStack getPinnedStack() {
1712 return mTaskStackContainers.getPinnedStack();
1713 }
1714
1715 private boolean hasPinnedStack() {
1716 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001717 }
1718
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001719 /**
1720 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1721 * Null is no compatible stack on the display.
1722 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001723 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001724 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1725 }
1726
1727 /**
1728 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1729 * activity type. Null is no compatible stack on the display.
1730 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001731 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001732 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001733 }
1734
Bryce Lee48f4b572017-04-10 10:54:15 -07001735 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001736 WindowList<TaskStack> getStacks() {
1737 return mTaskStackContainers.mChildren;
1738 }
1739
1740 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001741 TaskStack getTopStack() {
1742 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001743 }
1744
Winson Chunge2d72172018-01-25 17:46:20 +00001745 ArrayList<Task> getVisibleTasks() {
1746 return mTaskStackContainers.getVisibleTasks();
1747 }
1748
Wale Ogunwale61911492017-10-11 08:50:50 -07001749 void onStackWindowingModeChanged(TaskStack stack) {
1750 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001751 }
1752
Andrii Kulian441e4492016-09-29 15:25:00 -07001753 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001754 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001755 super.onConfigurationChanged(newParentConfig);
1756
Andrii Kulian3a507b52016-09-19 18:14:12 -07001757 // The display size information is heavily dependent on the resources in the current
1758 // configuration, so we need to reconfigure it every time the configuration changes.
1759 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1760 mService.reconfigureDisplayLocked(this);
1761
Bryce Leef3c6a472017-11-14 14:53:06 -08001762 final DockedStackDividerController dividerController = getDockedDividerController();
1763
1764 if (dividerController != null) {
1765 getDockedDividerController().onConfigurationChanged();
1766 }
1767
1768 final PinnedStackController pinnedStackController = getPinnedStackController();
1769
1770 if (pinnedStackController != null) {
1771 getPinnedStackController().onConfigurationChanged();
1772 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001773 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001774
Andrii Kulian441e4492016-09-29 15:25:00 -07001775 /**
1776 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1777 * bounds were updated.
1778 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001779 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001780 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1781 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001782 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001783 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001784 }
1785 }
Winson Chung32c566f2017-04-11 18:31:21 -07001786
1787 // If there was no pinned stack, we still need to notify the controller of the display info
1788 // update as a result of the config change. We do this here to consolidate the flow between
1789 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001790 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001791 mPinnedStackControllerLocked.onDisplayInfoChanged();
1792 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001793 }
1794
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001795 @Override
1796 boolean fillsParent() {
1797 return true;
1798 }
1799
1800 @Override
1801 boolean isVisible() {
1802 return true;
1803 }
1804
1805 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001806 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001807 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001808 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001809 }
1810
Robert Carr9785cf32018-04-25 15:06:07 -07001811 /**
1812 * In split-screen mode we process the IME containers above the docked divider
1813 * rather than directly above their target.
1814 */
1815 private boolean skipTraverseChild(WindowContainer child) {
1816 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null
1817 && !hasSplitScreenPrimaryStack()) {
1818 return true;
1819 }
1820 return false;
1821 }
1822
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001823 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001824 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1825 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1826 // target, or here in order if there isn't an IME target.
1827 if (traverseTopToBottom) {
1828 for (int i = mChildren.size() - 1; i >= 0; --i) {
1829 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001830 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001831 continue;
1832 }
Robert Carr9785cf32018-04-25 15:06:07 -07001833
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001834 if (child.forAllWindows(callback, traverseTopToBottom)) {
1835 return true;
1836 }
1837 }
1838 } else {
1839 final int count = mChildren.size();
1840 for (int i = 0; i < count; i++) {
1841 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001842 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001843 continue;
1844 }
Robert Carr9785cf32018-04-25 15:06:07 -07001845
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001846 if (child.forAllWindows(callback, traverseTopToBottom)) {
1847 return true;
1848 }
1849 }
1850 }
1851 return false;
1852 }
1853
1854 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1855 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1856 }
1857
Wale Ogunwale399c8692017-05-08 14:22:42 -07001858 @Override
1859 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001860 final WindowManagerPolicy policy = mService.mPolicy;
1861
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001862 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001863 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001864 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1865 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001866 // If the display is frozen, some activities may be in the middle of restarting, and
1867 // thus have removed their old window. If the window has the flag to hide the lock
1868 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1869 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001870 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001871 } else if (policy.isKeyguardLocked()) {
1872 // Use the last orientation the while the display is frozen with the keyguard
1873 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1874 // window. We don't want to check the show when locked window directly though as
1875 // things aren't stable while the display is frozen, for example the window could be
1876 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001877 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1878 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001879 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001880 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001881 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001882 final int orientation = mAboveAppWindowsContainers.getOrientation();
1883 if (orientation != SCREEN_ORIENTATION_UNSET) {
1884 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001885 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001886 }
1887
Wale Ogunwale399c8692017-05-08 14:22:42 -07001888 // Top system windows are not requesting an orientation. Start searching from apps.
1889 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001890 }
1891
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001892 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001893 // Check if display metrics changed and update base values if needed.
1894 updateBaseDisplayMetricsIfNeeded();
1895
Craig Mautner722285e2012-09-07 13:55:58 -07001896 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001897 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001898
Wale Ogunwale61911492017-10-11 08:50:50 -07001899 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1900 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001901 }
Craig Mautner722285e2012-09-07 13:55:58 -07001902 }
1903
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001904 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001905 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1906 if (displayManagerInternal != null) {
1907 // Bootstrap the default logical display from the display manager.
1908 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1909 if (newDisplayInfo != null) {
1910 mDisplayInfo.copyFrom(newDisplayInfo);
1911 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001912 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001913
Andrii Kuliancd097992017-03-23 18:31:59 -07001914 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1915 mDisplayInfo.logicalDensityDpi);
1916 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1917 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1918 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001919 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001920 }
1921
Andrii Kuliancd097992017-03-23 18:31:59 -07001922 /**
1923 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1924 * values.
1925 */
1926 private void updateBaseDisplayMetricsIfNeeded() {
1927 // Get real display metrics without overrides from WM.
1928 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1929 final int orientation = mDisplayInfo.rotation;
1930 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1931 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1932 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1933 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001934 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001935
1936 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1937 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001938 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1939 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001940
1941 if (displayMetricsChanged) {
1942 // Check if display size or density is forced.
1943 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1944 || mBaseDisplayHeight != mInitialDisplayHeight;
1945 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1946
1947 // If there is an override set for base values - use it, otherwise use new values.
1948 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1949 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1950 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1951
1952 // Real display metrics changed, so we should also update initial values.
1953 mInitialDisplayWidth = newWidth;
1954 mInitialDisplayHeight = newHeight;
1955 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001956 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001957 mService.reconfigureDisplayLocked(this);
1958 }
1959 }
1960
Bryce Lee27cec322017-03-21 09:41:37 -07001961 /** Sets the maximum width the screen resolution can be */
1962 void setMaxUiWidth(int width) {
1963 if (DEBUG_DISPLAY) {
1964 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1965 }
1966
1967 mMaxUiWidth = width;
1968
1969 // Update existing metrics.
1970 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1971 }
1972
1973 /** Update base (override) display metrics. */
1974 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1975 mBaseDisplayWidth = baseWidth;
1976 mBaseDisplayHeight = baseHeight;
1977 mBaseDisplayDensity = baseDensity;
1978
1979 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1980 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1981 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1982 mBaseDisplayWidth = mMaxUiWidth;
1983
1984 if (DEBUG_DISPLAY) {
1985 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1986 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1987 + " on display:" + getDisplayId());
1988 }
1989 }
1990
1991 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001992
1993 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001994 }
1995
Wale Ogunwaledb506192017-12-08 10:57:32 -08001996 void getStableRect(Rect out) {
1997 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001998 }
1999
Wale Ogunwale61911492017-10-11 08:50:50 -07002000 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002001 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
2002 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07002003
Wale Ogunwale61911492017-10-11 08:50:50 -07002004 final TaskStack stack = new TaskStack(mService, stackId, controller);
2005 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08002006 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07002007 }
2008
Andrii Kulian51c1b672017-04-07 18:39:32 -07002009 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002010 final DisplayContent prevDc = stack.getDisplayContent();
2011 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002012 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2013 + " which is not currently attached to any display");
2014 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002015 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002016 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2017 + " to its current displayId=" + mDisplayId);
2018 }
2019
Wale Ogunwale61911492017-10-11 08:50:50 -07002020 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002021 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002022 }
2023
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002024 @Override
2025 protected void addChild(DisplayChildWindowContainer child,
2026 Comparator<DisplayChildWindowContainer> comparator) {
2027 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2028 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002029
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002030 @Override
2031 protected void addChild(DisplayChildWindowContainer child, int index) {
2032 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2033 }
2034
2035 @Override
2036 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002037 // Only allow removal of direct children from this display if the display is in the process
2038 // of been removed.
2039 if (mRemovingDisplay) {
2040 super.removeChild(child);
2041 return;
2042 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002043 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002044 }
2045
Andrii Kuliand2765632016-12-12 22:26:34 -08002046 @Override
2047 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2048 // Children of the display are statically ordered, so the real intention here is to perform
2049 // the operation on the display and not the static direct children.
2050 getParent().positionChildAt(position, this, includingParents);
2051 }
2052
Riddle Hsu57831b52018-07-27 00:31:48 +08002053 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2054 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002055 layoutAndAssignWindowLayersIfNeeded();
2056 }
2057
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002058 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002059 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2060 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002061 final int taskId = stack.taskIdFromPoint(x, y);
2062 if (taskId != -1) {
2063 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002064 }
2065 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002066 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002067 }
2068
Chong Zhang8e89b312015-09-09 15:09:30 -07002069 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002070 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002071 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002072 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002073 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002074 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002075 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002076 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2077 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002078 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002079 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002080 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002081
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002082 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2083 if (mTmpTaskForResizePointSearchResult.searchDone) {
2084 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002085 }
2086 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002087 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002088 }
2089
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002090 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08002091 // The provided task is the task on this display with focus, so if WindowManagerService's
2092 // focused app is not on this display, focusedTask will be null.
2093 if (focusedTask == null) {
2094 mTouchExcludeRegion.setEmpty();
2095 } else {
2096 mTouchExcludeRegion.set(mBaseDisplayRect);
2097 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2098 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07002099 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2100 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002101 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2102 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002103 }
2104 // If we removed the focused task above, add it back and only leave its
2105 // outside touch area in the exclusion. TapDectector is not interested in
2106 // any touch inside the focused task itself.
2107 if (!mTmpRect2.isEmpty()) {
2108 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2109 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002110 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002111 final WindowState inputMethod = mService.mInputMethodWindow;
2112 if (inputMethod != null && inputMethod.isVisibleLw()) {
2113 // If the input method is visible and the user is typing, we don't want these touch
2114 // events to be intercepted and used to change focus. This would likely cause a
2115 // disappearance of the input method.
2116 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07002117 if (inputMethod.getDisplayId() == mDisplayId) {
2118 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2119 } else {
2120 // IME is on a different display, so we need to update its tap detector.
2121 // TODO(multidisplay): Remove when IME will always appear on same display.
2122 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
2123 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002124 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002125 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002126 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002127 win.getTouchableRegion(mTmpRegion);
2128 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2129 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002130 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2131 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2132 win.amendTapExcludeRegion(mTouchExcludeRegion);
2133 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002134 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002135 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002136 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002137 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002138 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2139 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002140 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002141 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002142 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002143 }
2144
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002145 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002146 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002147 super.switchUser();
2148 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002149 }
2150
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002151 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002152 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2153 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002154 }
2155 }
2156
Wale Ogunwale10124582016-09-15 20:25:50 -07002157 @Override
2158 void removeIfPossible() {
2159 if (isAnimating()) {
2160 mDeferredRemoval = true;
2161 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002162 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002163 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002164 }
2165
Wale Ogunwale10124582016-09-15 20:25:50 -07002166 @Override
2167 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002168 mRemovingDisplay = true;
2169 try {
2170 super.removeImmediately();
2171 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07002172 if (mService.canDispatchPointerEvents()) {
2173 if (mTapDetector != null) {
2174 mService.unregisterPointerEventListener(mTapDetector);
2175 }
2176 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
2177 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
2178 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002179 }
Jorim Jaggia3844032018-01-03 15:54:43 +01002180 mService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002181 mWindowingLayer.release();
2182 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002183 } finally {
2184 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002185 }
Bryce Leef19cbe22018-02-02 15:09:21 -08002186
2187 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08002188 }
2189
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002190 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002191 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002192 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002193 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2194
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002195 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002196 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002197 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002198 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002199 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002200 }
2201
Andrii Kulian0214ed92017-05-16 13:44:05 -07002202 /** @return 'true' if removal of this display content is deferred due to active animation. */
2203 boolean isRemovalDeferred() {
2204 return mDeferredRemoval;
2205 }
2206
Wale Ogunwale10124582016-09-15 20:25:50 -07002207 boolean animateForIme(float interpolatedValue, float animationTarget,
2208 float dividerAnimationTarget) {
2209 boolean updated = false;
2210
Wale Ogunwale61911492017-10-11 08:50:50 -07002211 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2212 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002213 if (stack == null || !stack.isAdjustedForIme()) {
2214 continue;
2215 }
2216
2217 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2218 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2219 updated = true;
2220 } else {
2221 mDividerControllerLocked.mLastAnimationProgress =
2222 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2223 mDividerControllerLocked.mLastDividerProgress =
2224 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2225 updated |= stack.updateAdjustForIme(
2226 mDividerControllerLocked.mLastAnimationProgress,
2227 mDividerControllerLocked.mLastDividerProgress,
2228 false /* force */);
2229 }
2230 if (interpolatedValue >= 1f) {
2231 stack.endImeAdjustAnimation();
2232 }
2233 }
2234
2235 return updated;
2236 }
2237
2238 boolean clearImeAdjustAnimation() {
2239 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002240 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2241 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002242 if (stack != null && stack.isAdjustedForIme()) {
2243 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2244 changed = true;
2245 }
2246 }
2247 return changed;
2248 }
2249
2250 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002251 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2252 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002253 if (stack.isVisible() && stack.isAdjustedForIme()) {
2254 stack.beginImeAdjustAnimation();
2255 }
2256 }
2257 }
2258
2259 void adjustForImeIfNeeded() {
2260 final WindowState imeWin = mService.mInputMethodWindow;
2261 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2262 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002263 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002264 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2265 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2266 imeTargetStack.getDockSide() : DOCKED_INVALID;
2267 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2268 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2269 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002270 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002271 final boolean imeHeightChanged = imeVisible &&
2272 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2273
2274 // The divider could be adjusted for IME position, or be thinner than usual,
2275 // or both. There are three possible cases:
2276 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2277 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2278 // - If IME is not visible, divider is not moved and is normal width.
2279
2280 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002281 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2282 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002283 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002284 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2285 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002286 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2287 } else {
2288 stack.resetAdjustedForIme(false);
2289 }
2290 }
2291 mDividerControllerLocked.setAdjustedForIme(
2292 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2293 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002294 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2295 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002296 stack.resetAdjustedForIme(!dockVisible);
2297 }
2298 mDividerControllerLocked.setAdjustedForIme(
2299 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2300 }
Winson Chung655332c2016-10-31 13:14:28 -07002301 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002302 }
2303
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002304 /**
2305 * If a window that has an animation specifying a colored background and the current wallpaper
2306 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2307 * suddenly disappear.
2308 */
2309 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002310 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2311 w -> w.mIsWallpaper && w.isVisibleNow());
2312
2313 if (visibleWallpaper != null) {
2314 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002315 }
2316 return winAnimator.mAnimLayer;
2317 }
2318
Wale Ogunwale10124582016-09-15 20:25:50 -07002319 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002320 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2321 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002322 stack.prepareFreezingTaskBounds();
2323 }
2324 }
2325
Wale Ogunwale94744212015-09-21 19:01:47 -07002326 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002327 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002328
2329 // Compute a transform matrix to undo the coordinate space transformation,
2330 // and present the window at the same physical position it previously occupied.
2331 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2332 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2333
2334 mTmpRectF.set(bounds);
2335 mTmpMatrix.mapRect(mTmpRectF);
2336 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002337 }
2338
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002339 static int deltaRotation(int oldRotation, int newRotation) {
2340 int delta = newRotation - oldRotation;
2341 if (delta < 0) delta += 4;
2342 return delta;
2343 }
2344
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002345 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002346 Matrix outMatrix) {
2347 // For rotations without Z-ordering we don't need the target rectangle's position.
2348 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2349 displayHeight, outMatrix);
2350 }
2351
2352 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2353 float displayWidth, float displayHeight, Matrix outMatrix) {
2354 switch (rotation) {
2355 case ROTATION_0:
2356 outMatrix.reset();
2357 break;
2358 case ROTATION_270:
2359 outMatrix.setRotate(270, 0, 0);
2360 outMatrix.postTranslate(0, displayHeight);
2361 outMatrix.postTranslate(rectTop, 0);
2362 break;
2363 case ROTATION_180:
2364 outMatrix.reset();
2365 break;
2366 case ROTATION_90:
2367 outMatrix.setRotate(90, 0, 0);
2368 outMatrix.postTranslate(displayWidth, 0);
2369 outMatrix.postTranslate(-rectTop, rectLeft);
2370 break;
2371 }
2372 }
2373
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002374 @CallSuper
2375 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002376 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002377 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002378 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002379 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002380 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2381 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002382 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002383 }
2384 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2385 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002386 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2387 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002388 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002389 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002390 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2391 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002392 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002393 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002394 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2395 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002396 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002397 }
2398 proto.write(DPI, mBaseDisplayDensity);
2399 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002400 proto.write(ROTATION, mRotation);
2401 final ScreenRotationAnimation screenRotationAnimation =
2402 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2403 if (screenRotationAnimation != null) {
2404 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2405 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002406 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002407 proto.end(token);
2408 }
2409
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002410 @Override
2411 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2412 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002413 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2414 final String subPrefix = " " + prefix;
2415 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2416 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2417 pw.print("dpi");
2418 if (mInitialDisplayWidth != mBaseDisplayWidth
2419 || mInitialDisplayHeight != mBaseDisplayHeight
2420 || mInitialDisplayDensity != mBaseDisplayDensity) {
2421 pw.print(" base=");
2422 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2423 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2424 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002425 if (mDisplayScalingDisabled) {
2426 pw.println(" noscale");
2427 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002428 pw.print(" cur=");
2429 pw.print(mDisplayInfo.logicalWidth);
2430 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2431 pw.print(" app=");
2432 pw.print(mDisplayInfo.appWidth);
2433 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2434 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2435 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2436 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2437 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002438 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002439 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002440 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002441
Craig Mautnerdc548482014-02-05 13:35:24 -08002442 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002443 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002444 pw.print(prefix);
2445 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002446
2447 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002448 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002449 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2450 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002451 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002452 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002453
Craig Mautnerdc548482014-02-05 13:35:24 -08002454 pw.println();
2455 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002456 pw.println();
2457 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002458 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002459 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002460 pw.print(" Exiting #"); pw.print(i);
2461 pw.print(' '); pw.print(token);
2462 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002463 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002464 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002465 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002466
Jorim Jaggi31f71702016-05-04 16:43:04 -07002467 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002468
2469 // Dump stack references
2470 final TaskStack homeStack = getHomeStack();
2471 if (homeStack != null) {
2472 pw.println(prefix + "homeStack=" + homeStack.getName());
2473 }
2474 final TaskStack pinnedStack = getPinnedStack();
2475 if (pinnedStack != null) {
2476 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2477 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002478 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002479 if (splitScreenPrimaryStack != null) {
2480 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2481 }
2482
2483 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002484 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002485 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002486 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002487
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002488 pw.println();
2489 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002490 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002491 mDisplayPolicy.dump(prefix, pw);
2492 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002493 mDisplayRotation.dump(prefix, pw);
2494 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002495 mInputMonitor.dump(pw, " ");
Craig Mautner59c00972012-07-30 12:10:24 -07002496 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002497
2498 @Override
2499 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002500 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002501 }
2502
2503 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002504 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002505 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002506
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002507 /** Returns true if the stack in the windowing mode is visible. */
2508 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002509 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002510 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002511 }
2512
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002513 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002514 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002515 final int x = (int) xf;
2516 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002517 final WindowState touchedWin = getWindow(w -> {
2518 final int flags = w.mAttrs.flags;
2519 if (!w.isVisibleLw()) {
2520 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002521 }
2522 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002523 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002524 }
2525
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002526 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002527 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002528 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002529 }
2530
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002531 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002532
2533 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002534 return mTmpRegion.contains(x, y) || touchFlags == 0;
2535 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002536
2537 return touchedWin;
2538 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002539
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002540 boolean canAddToastWindowForUid(int uid) {
2541 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002542 // Also if the app is focused adding more than one toast at
2543 // a time for better backwards compatibility.
2544 final WindowState focusedWindowForUid = getWindow(w ->
2545 w.mOwnerUid == uid && w.isFocused());
2546 if (focusedWindowForUid != null) {
2547 return true;
2548 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002549 final WindowState win = getWindow(w ->
2550 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2551 && !w.mWindowRemovalAllowed);
2552 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002553 }
2554
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002555 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002556 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2557 return;
2558 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002559
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002560 // Used to communicate the old focus to the callback method.
2561 mTmpWindow = oldFocus;
2562
2563 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002564 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002565
2566 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002567 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002568
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002569 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002570
2571 if (mTmpWindow == null) {
2572 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2573 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002574 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002575 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002576 }
2577
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002578 /** Updates the layer assignment of windows on this display. */
2579 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002580 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002581 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002582 if (setLayoutNeeded) {
2583 setLayoutNeeded();
2584 }
Robert Carrb1579c82017-09-05 14:54:47 -07002585
Robert Carrf59b8dd2017-10-02 18:58:36 -07002586 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002587 // the application of this transaction until the animation pass triggers
2588 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2589 // the hiding and showing of surfaces.
2590 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002591 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002592 }
2593
Wale Ogunwale1666e312016-12-16 11:27:18 -08002594 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2595 // moving containers or resizing them. Need to investigate the best way to have it automatically
2596 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002597 void layoutAndAssignWindowLayersIfNeeded() {
2598 mService.mWindowsChanged = true;
2599 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002600
2601 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2602 false /*updateInputWindows*/)) {
2603 assignWindowLayers(false /* setLayoutNeeded */);
2604 }
2605
Arthur Hung95b38a92018-07-20 18:56:12 +08002606 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002607 mService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08002608 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002609 }
2610
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002611 /** Returns true if a leaked surface was destroyed */
2612 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002613 // Used to indicate that a surface was leaked.
2614 mTmpWindow = null;
2615 forAllWindows(w -> {
2616 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002617 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002618 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002619 }
2620 if (!mService.mSessions.contains(wsa.mSession)) {
2621 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002622 + w + " surface=" + wsa.mSurfaceController
2623 + " token=" + w.mToken
2624 + " pid=" + w.mSession.mPid
2625 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002626 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002627 mService.mForceRemoves.add(w);
2628 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002629 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002630 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002631 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002632 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002633 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002634 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002635 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002636 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002637 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002638
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002639 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002640 }
2641
2642 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002643 * Determine and return the window that should be the IME target.
2644 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2645 * @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 +00002646 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002647 WindowState computeImeTarget(boolean updateImeTarget) {
2648 if (mService.mInputMethodWindow == null) {
2649 // There isn't an IME so there shouldn't be a target...That was easy!
2650 if (updateImeTarget) {
2651 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2652 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002653 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002654 }
2655 return null;
2656 }
2657
Chavi Weingarten3a748552018-05-14 17:32:42 +00002658 final WindowState curTarget = mService.mInputMethodTarget;
2659 if (!canUpdateImeTarget()) {
2660 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
2661 return curTarget;
2662 }
2663
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002664 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2665 // same display. Or even when the current IME/target are not on the same screen as the next
2666 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002667 mUpdateImeTarget = updateImeTarget;
2668 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002669
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002670
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002671 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2672 // to be on top of it, but it is not -really- where input will go. So look down below
2673 // for a real window to target...
2674 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2675 final AppWindowToken token = target.mAppToken;
2676 if (token != null) {
2677 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2678 if (betterTarget != null) {
2679 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002680 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002681 }
2682 }
2683
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002684 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2685 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002686
chaviw1c13ad32018-06-12 16:44:23 -07002687 // Now, a special case -- if the last target's window is in the process of exiting, but
2688 // not removed, and the new target is home, keep on the last target to avoid flicker.
2689 // Home is a special case since its above other stacks in the ordering list, but layed
2690 // out below the others.
2691 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
2692 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07002693 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00002694 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002695 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002696 }
2697
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002698 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2699 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002700
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002701 if (target == null) {
2702 if (updateImeTarget) {
2703 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2704 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2705 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002706 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002707 }
2708
2709 return null;
2710 }
2711
2712 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002713 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2714 if (token != null) {
2715
2716 // Now some fun for dealing with window animations that modify the Z order. We need
2717 // to look at all windows below the current target that are in this app, finding the
2718 // highest visible one in layering.
2719 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002720 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002721 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002722 }
2723
2724 if (highestTarget != null) {
2725 final AppTransition appTransition = mService.mAppTransition;
2726 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2727 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2728 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002729 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002730
2731 if (appTransition.isTransitionSet()) {
2732 // If we are currently setting up for an animation, hold everything until we
2733 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002734 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002735 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002736 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002737 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002738 // If the window we are currently targeting is involved with an animation,
2739 // and it is on top of the next target we will be over, then hold off on
2740 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002741 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002742 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002743 }
2744 }
2745 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002746
2747 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2748 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002749 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002750 }
2751
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002752 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002753 }
2754
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002755 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002756 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002757 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002758 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002759 }
2760
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002761 mService.mInputMethodTarget = target;
2762 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002763 assignWindowLayers(false /* setLayoutNeeded */);
2764 }
2765
2766 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2767 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2768 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2769 }
2770
2771 // Used to indicate we have reached the first window in the range we are interested in.
2772 mTmpWindow = null;
2773
2774 // TODO: Figure-out a more efficient way to do this.
2775 final WindowState candidate = getWindow(w -> {
2776 if (w == top) {
2777 // Reached the first window in the range we are interested in.
2778 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002779 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002780 if (mTmpWindow == null) {
2781 return false;
2782 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002783
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002784 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2785 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002786 }
2787 // If we reached the bottom of the range of windows we are considering,
2788 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002789 if (w == bottom) {
2790 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002791 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002792 return false;
2793 });
2794
2795 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002796 }
2797
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002798 void setLayoutNeeded() {
2799 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2800 mLayoutNeeded = true;
2801 }
2802
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002803 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002804 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2805 mLayoutNeeded = false;
2806 }
2807
2808 boolean isLayoutNeeded() {
2809 return mLayoutNeeded;
2810 }
2811
Wale Ogunwale02319a62016-09-26 15:21:22 -07002812 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2813 if (mTokenMap.isEmpty()) {
2814 return;
2815 }
2816 pw.println(" Display #" + mDisplayId);
2817 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2818 while (it.hasNext()) {
2819 final WindowToken token = it.next();
2820 pw.print(" ");
2821 pw.print(token);
2822 if (dumpAll) {
2823 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002824 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002825 } else {
2826 pw.println();
2827 }
2828 }
2829 }
2830
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002831 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002832 final int[] index = new int[1];
2833 forAllWindows(w -> {
2834 final WindowStateAnimator wAnim = w.mWinAnimator;
2835 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2836 index[0] = index[0] + 1;
2837 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002838 }
2839
Jorim Jaggife762342016-10-13 14:33:27 +02002840 /**
2841 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2842 */
2843 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2844 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002845 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002846 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2847 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002848 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002849 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002850 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002851 }
2852
Wale Ogunwale494009b82016-10-21 09:01:38 -07002853 boolean checkWaitingForWindows() {
2854
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002855 mHaveBootMsg = false;
2856 mHaveApp = false;
2857 mHaveWallpaper = false;
2858 mHaveKeyguard = true;
2859
2860 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002861 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2862 return true;
2863 }
2864 if (w.isDrawnLw()) {
2865 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002866 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002867 } else if (w.mAttrs.type == TYPE_APPLICATION
2868 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002869 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002870 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002871 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002872 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002873 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002874 }
2875 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002876 return false;
2877 });
2878
2879 if (visibleWindow != null) {
2880 // We have a visible window.
2881 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002882 }
2883
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002884 // if the wallpaper service is disabled on the device, we're never going to have
2885 // wallpaper, don't bother waiting for it
2886 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2887 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09002888 && mService.mContext.getResources().getBoolean(
2889 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002890 && !mService.mOnlyCore;
2891
Wale Ogunwale494009b82016-10-21 09:01:38 -07002892 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2893 "******** booted=" + mService.mSystemBooted
2894 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002895 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2896 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2897 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002898
2899 // If we are turning on the screen to show the boot message, don't do it until the boot
2900 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002901 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002902 return true;
2903 }
2904
2905 // If we are turning on the screen after the boot is completed normally, don't do so until
2906 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002907 if (mService.mSystemBooted
2908 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002909 return true;
2910 }
2911
2912 return false;
2913 }
2914
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002915 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002916 mTmpWindowAnimator = animator;
2917 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002918 }
2919
2920 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002921 resetAnimationBackgroundAnimator();
2922
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002923 // Used to indicate a detached wallpaper.
2924 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002925 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002926
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002927 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002928
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002929 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002930 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002931 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2932 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002933 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2934 }
2935 }
2936
Wale Ogunwale494009b82016-10-21 09:01:38 -07002937 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002938 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002939 if (imFocus == null) {
2940 return false;
2941 }
2942
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002943 if (DEBUG_INPUT_METHOD) {
2944 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2945 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2946 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002947 }
2948
Wale Ogunwale494009b82016-10-21 09:01:38 -07002949 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2950
2951 if (DEBUG_INPUT_METHOD) {
2952 Slog.i(TAG_WM, "IM target client: " + imeClient);
2953 if (imeClient != null) {
2954 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2955 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2956 }
2957 }
2958
2959 return imeClient != null && imeClient.asBinder() == client.asBinder();
2960 }
2961
2962 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002963 final WindowState win = getWindow(
2964 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2965 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002966 }
2967
2968 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002969 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002970 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002971 final int curValue = w.mSystemUiVisibility;
2972 final int diff = (curValue ^ visibility) & globalDiff;
2973 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002974 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002975 w.mSeq++;
2976 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002977 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002978 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2979 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002980 visibility, newValue, diff);
2981 }
2982 } catch (RemoteException e) {
2983 // so sorry
2984 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002985 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002986 }
2987
2988 void onWindowFreezeTimeout() {
2989 Slog.w(TAG_WM, "Window freeze timeout expired.");
2990 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002991
2992 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002993 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002994 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002995 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002996 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002997 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2998 - mService.mDisplayFreezeTime);
2999 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003000 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003001 mService.mWindowPlacerLocked.performSurfacePlacement();
3002 }
3003
3004 void waitForAllWindowsDrawn() {
3005 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003006 forAllWindows(w -> {
3007 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3008 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3009 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003010 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003011 w.mLastContentInsets.set(-1, -1, -1, -1);
3012 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003013 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003014 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003015 }
3016
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003017 // TODO: Super crazy long method that should be broken down...
3018 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
3019
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003020 final int dw = mDisplayInfo.logicalWidth;
3021 final int dh = mDisplayInfo.logicalHeight;
3022 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
3023
3024 mTmpUpdateAllDrawn.clear();
3025
3026 int repeats = 0;
3027 do {
3028 repeats++;
3029 if (repeats > 6) {
3030 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3031 clearLayoutNeeded();
3032 break;
3033 }
3034
3035 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3036 pendingLayoutChanges);
3037
Andrii Kulian839def92016-11-02 10:58:58 -07003038 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
3039 // the wallpaper window jumping across displays.
3040 // Remove check for default display when there will be support for multiple wallpaper
3041 // targets (on different displays).
3042 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003043 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003044 }
3045
Riddle Hsu654a6f92018-07-13 22:59:36 +08003046 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003047 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08003048 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003049 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07003050 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003051 }
3052 }
3053
3054 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3055 setLayoutNeeded();
3056 }
3057
3058 // FIRST LOOP: Perform a layout, if needed.
3059 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3060 performLayout(repeats == 1, false /* updateInputWindows */);
3061 } else {
3062 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3063 }
3064
3065 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3066 pendingLayoutChanges = 0;
3067
3068 if (isDefaultDisplay) {
3069 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003070 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003071 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
3072 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3073 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
3074 }
3075 } while (pendingLayoutChanges != 0);
3076
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003077 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003078
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003079 mTmpRecoveringMemory = recoveringMemory;
3080 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003081 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003082
3083 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003084 mTmpApplySurfaceChangesTransactionState.displayHasContent,
3085 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3086 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003087 true /* inTraversal, must call performTraversalInTrans... below */);
3088
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003089 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3090 if (wallpaperVisible != mLastWallpaperVisible) {
3091 mLastWallpaperVisible = wallpaperVisible;
3092 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
3093 }
3094
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003095 while (!mTmpUpdateAllDrawn.isEmpty()) {
3096 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3097 // See if any windows have been drawn, so they (and others associated with them)
3098 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003099 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003100 }
3101
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003102 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003103 }
3104
Bryce Leef3c6a472017-11-14 14:53:06 -08003105 private void updateBounds() {
3106 calculateBounds(mTmpBounds);
3107 setBounds(mTmpBounds);
3108 }
3109
3110 // Determines the current display bounds based on the current state
3111 private void calculateBounds(Rect out) {
3112 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
3113 final int orientation = mDisplayInfo.rotation;
3114 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
3115 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3116 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
3117 int width = mDisplayInfo.logicalWidth;
3118 int left = (physWidth - width) / 2;
3119 int height = mDisplayInfo.logicalHeight;
3120 int top = (physHeight - height) / 2;
3121 out.set(left, top, left + width, top + height);
3122 }
3123
3124 @Override
3125 public void getBounds(Rect out) {
3126 calculateBounds(out);
3127 }
3128
3129 private void getBounds(Rect out, int orientation) {
3130 getBounds(out);
3131
3132 // Rotate the Rect if needed.
3133 final int currentRotation = mDisplayInfo.rotation;
3134 final int rotationDelta = deltaRotation(currentRotation, orientation);
3135 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3136 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3137 mTmpRectF.set(out);
3138 mTmpMatrix.mapRect(mTmpRectF);
3139 mTmpRectF.round(out);
3140 }
3141 }
3142
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003143 void performLayout(boolean initial, boolean updateInputWindows) {
3144 if (!isLayoutNeeded()) {
3145 return;
3146 }
3147 clearLayoutNeeded();
3148
3149 final int dw = mDisplayInfo.logicalWidth;
3150 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003151 if (DEBUG_LAYOUT) {
3152 Slog.v(TAG, "-------------------------------------");
3153 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3154 }
3155
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003156 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3157 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003158 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3159 // display info above...
3160 mDisplayFrames.mRotation = mRotation;
3161 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003162 if (isDefaultDisplay) {
3163 // Not needed on non-default displays.
3164 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
3165 mService.mScreenRect.set(0, 0, dw, dh);
3166 }
3167
Adrian Roos5251b1d2018-03-23 18:57:43 +01003168 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003169 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003170 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003171
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003172 // Used to indicate that we have processed the dream window and all additional windows are
3173 // behind it.
3174 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003175 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003176
3177 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003178 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003179
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003180 // Used to indicate that we have processed the dream window and all additional attached
3181 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003182 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003183 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003184
3185 // Now perform layout of attached windows, which usually depend on the position of the
3186 // window they are attached to. XXX does not deal with windows that are attached to windows
3187 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003188 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003189
3190 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003191 mInputMonitor.layoutInputConsumers(dw, dh);
3192 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003193 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003194 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003195 }
3196
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003197 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
3198 }
3199
3200 /**
3201 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3202 * In portrait mode, it grabs the full screenshot.
3203 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003204 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003205 */
chaviw0315a1a2018-03-05 15:28:35 -08003206 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
3207 if (!mService.mPolicy.isScreenOn()) {
3208 if (DEBUG_SCREENSHOT) {
3209 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003210 }
chaviw0315a1a2018-03-05 15:28:35 -08003211 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003212 }
chaviwfbe47df2017-11-10 16:14:49 -08003213
chaviw0315a1a2018-03-05 15:28:35 -08003214 int dw = mDisplayInfo.logicalWidth;
3215 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003216
chaviw0315a1a2018-03-05 15:28:35 -08003217 if (dw <= 0 || dh <= 0) {
3218 return null;
3219 }
chaviwfbe47df2017-11-10 16:14:49 -08003220
chaviw0315a1a2018-03-05 15:28:35 -08003221 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003222
chaviw0315a1a2018-03-05 15:28:35 -08003223 // The screenshot API does not apply the current screen rotation.
3224 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003225
chaviw0315a1a2018-03-05 15:28:35 -08003226 if (rot == ROTATION_90 || rot == ROTATION_270) {
3227 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3228 }
chaviwfbe47df2017-11-10 16:14:49 -08003229
chaviw0315a1a2018-03-05 15:28:35 -08003230 // SurfaceFlinger is not aware of orientation, so convert our logical
3231 // crop to SurfaceFlinger's portrait orientation.
3232 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3233
3234 final ScreenRotationAnimation screenRotationAnimation =
3235 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3236 final boolean inRotation = screenRotationAnimation != null &&
3237 screenRotationAnimation.isAnimating();
3238 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3239
3240 // TODO(b/68392460): We should screenshot Task controls directly
3241 // but it's difficult at the moment as the Task doesn't have the
3242 // correct size set.
3243 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3244 if (bitmap == null) {
3245 Slog.w(TAG_WM, "Failed to take screenshot");
3246 return null;
3247 }
3248
3249 // Create a copy of the screenshot that is immutable and backed in ashmem.
3250 // This greatly reduces the overhead of passing the bitmap between processes.
3251 final Bitmap ret = bitmap.createAshmemBitmap(config);
3252 bitmap.recycle();
3253 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003254 }
3255
3256 // TODO: Can this use createRotationMatrix()?
3257 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3258 if (rot == Surface.ROTATION_90) {
3259 final int tmp = crop.top;
3260 crop.top = dw - crop.right;
3261 crop.right = crop.bottom;
3262 crop.bottom = dw - crop.left;
3263 crop.left = tmp;
3264 } else if (rot == Surface.ROTATION_180) {
3265 int tmp = crop.top;
3266 crop.top = dh - crop.bottom;
3267 crop.bottom = dh - tmp;
3268 tmp = crop.right;
3269 crop.right = dw - crop.left;
3270 crop.left = dw - tmp;
3271 } else if (rot == Surface.ROTATION_270) {
3272 final int tmp = crop.top;
3273 crop.top = crop.left;
3274 crop.left = dh - crop.bottom;
3275 crop.bottom = crop.right;
3276 crop.right = dh - tmp;
3277 }
3278 }
3279
3280 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003281 // Used to indicate the layout is needed.
3282 mTmpWindow = null;
3283
3284 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003285 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003286 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003287 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003288 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003289 w.setDisplayLayoutNeeded();
3290 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003291 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003292
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003293 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003294 mService.mWindowPlacerLocked.performSurfacePlacement();
3295 }
3296 }
3297
Wale Ogunwale1666e312016-12-16 11:27:18 -08003298 void setExitingTokensHasVisible(boolean hasVisible) {
3299 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3300 mExitingTokens.get(i).hasVisible = hasVisible;
3301 }
3302
3303 // Initialize state of exiting applications.
3304 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3305 }
3306
3307 void removeExistingTokensIfPossible() {
3308 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3309 final WindowToken token = mExitingTokens.get(i);
3310 if (!token.hasVisible) {
3311 mExitingTokens.remove(i);
3312 }
3313 }
3314
3315 // Time to remove any exiting applications?
3316 mTaskStackContainers.removeExistingAppTokensIfPossible();
3317 }
3318
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003319 @Override
3320 void onDescendantOverrideConfigurationChanged() {
3321 setLayoutNeeded();
3322 mService.requestTraversal();
3323 }
3324
David Stevens9440dc82017-03-16 19:00:20 -07003325 boolean okToDisplay() {
3326 if (mDisplayId == DEFAULT_DISPLAY) {
3327 return !mService.mDisplayFrozen
3328 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3329 }
3330 return mDisplayInfo.state == Display.STATE_ON;
3331 }
3332
3333 boolean okToAnimate() {
3334 return okToDisplay() &&
3335 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3336 }
3337
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003338 static final class TaskForResizePointSearchResult {
3339 boolean searchDone;
3340 Task taskForResize;
3341
3342 void reset() {
3343 searchDone = false;
3344 taskForResize = null;
3345 }
3346 }
Robert Carr3b716242016-08-16 16:02:21 -07003347
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003348 private static final class ApplySurfaceChangesTransactionState {
3349 boolean displayHasContent;
3350 boolean obscured;
3351 boolean syswin;
3352 boolean focusDisplayed;
3353 float preferredRefreshRate;
3354 int preferredModeId;
3355
3356 void reset() {
3357 displayHasContent = false;
3358 obscured = false;
3359 syswin = false;
3360 focusDisplayed = false;
3361 preferredRefreshRate = 0;
3362 preferredModeId = 0;
3363 }
3364 }
3365
3366 private static final class ScreenshotApplicationState {
3367 WindowState appWin;
3368 int maxLayer;
3369 int minLayer;
3370 boolean screenshotReady;
3371
3372 void reset(boolean screenshotReady) {
3373 appWin = null;
3374 maxLayer = 0;
3375 minLayer = 0;
3376 this.screenshotReady = screenshotReady;
3377 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3378 }
3379 }
3380
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003381 /**
3382 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3383 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3384 * homogeneous children type which is currently required by sub-classes of
3385 * {@link WindowContainer} class.
3386 */
3387 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3388
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003389 DisplayChildWindowContainer(WindowManagerService service) {
3390 super(service);
3391 }
3392
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003393 @Override
3394 boolean fillsParent() {
3395 return true;
3396 }
3397
3398 @Override
3399 boolean isVisible() {
3400 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003401 }
3402 }
3403
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003404 /**
3405 * Window container class that contains all containers on this display relating to Apps.
3406 * I.e Activities.
3407 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003408 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003409 /**
3410 * A control placed at the appropriate level for transitions to occur.
3411 */
chaviw23ee71c2017-12-18 11:29:41 -08003412 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003413 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003414 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003415
Robert Carrf7a7ca82017-12-06 13:17:07 -08003416 /**
3417 * Given that the split-screen divider does not have an AppWindowToken, it
3418 * will have to live inside of a "NonAppWindowContainer", in particular
3419 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3420 * it will need to be interleaved with some of our children, appearing on top of
3421 * both docked stacks but underneath any assistant stacks.
3422 *
3423 * To solve this problem we have this anchor control, which will always exist so
3424 * we can always assign it the correct value in our {@link #assignChildLayers}.
3425 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3426 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3427 * events between the two containers.
3428 */
3429 SurfaceControl mSplitScreenDividerAnchor = null;
3430
Wale Ogunwale61911492017-10-11 08:50:50 -07003431 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3432 // through the list to find them.
3433 private TaskStack mHomeStack = null;
3434 private TaskStack mPinnedStack = null;
3435 private TaskStack mSplitScreenPrimaryStack = null;
3436
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003437 TaskStackContainers(WindowManagerService service) {
3438 super(service);
3439 }
3440
Wale Ogunwale61911492017-10-11 08:50:50 -07003441 /**
3442 * Returns the topmost stack on the display that is compatible with the input windowing mode
3443 * and activity type. Null is no compatible stack on the display.
3444 */
3445 TaskStack getStack(int windowingMode, int activityType) {
3446 if (activityType == ACTIVITY_TYPE_HOME) {
3447 return mHomeStack;
3448 }
3449 if (windowingMode == WINDOWING_MODE_PINNED) {
3450 return mPinnedStack;
3451 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3452 return mSplitScreenPrimaryStack;
3453 }
3454 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3455 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003456 if (activityType == ACTIVITY_TYPE_UNDEFINED
3457 && windowingMode == stack.getWindowingMode()) {
3458 // Passing in undefined type means we want to match the topmost stack with the
3459 // windowing mode.
3460 return stack;
3461 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003462 if (stack.isCompatible(windowingMode, activityType)) {
3463 return stack;
3464 }
3465 }
3466 return null;
3467 }
3468
3469 @VisibleForTesting
3470 TaskStack getTopStack() {
3471 return mTaskStackContainers.getChildCount() > 0
3472 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3473 }
3474
3475 TaskStack getHomeStack() {
3476 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3477 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3478 }
3479 return mHomeStack;
3480 }
3481
3482 TaskStack getPinnedStack() {
3483 return mPinnedStack;
3484 }
3485
Matthew Ng64e77cf2017-10-31 14:01:31 -07003486 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003487 return mSplitScreenPrimaryStack;
3488 }
3489
Winson Chunge2d72172018-01-25 17:46:20 +00003490 ArrayList<Task> getVisibleTasks() {
3491 final ArrayList<Task> visibleTasks = new ArrayList<>();
3492 forAllTasks(task -> {
3493 if (task.isVisible()) {
3494 visibleTasks.add(task);
3495 }
3496 });
3497 return visibleTasks;
3498 }
3499
Andrii Kulian839def92016-11-02 10:58:58 -07003500 /**
3501 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003502 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003503 */
3504 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003505 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003506 addChild(stack, onTop);
3507 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003508 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003509
Wale Ogunwale61911492017-10-11 08:50:50 -07003510 void onStackWindowingModeChanged(TaskStack stack) {
3511 removeStackReferenceIfNeeded(stack);
3512 addStackReferenceIfNeeded(stack);
3513 if (stack == mPinnedStack && getTopStack() != stack) {
3514 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3515 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3516 }
3517 }
3518
3519 private void addStackReferenceIfNeeded(TaskStack stack) {
3520 if (stack.isActivityTypeHome()) {
Louis Chang6322c422018-07-18 18:37:28 +08003521 // TODO(b/111363427) Rollback to throws exceptions once we figure out how to
3522 // properly deal with home type stack when external display removed
Wale Ogunwale61911492017-10-11 08:50:50 -07003523 if (mHomeStack != null) {
Louis Chang6322c422018-07-18 18:37:28 +08003524 // throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3525 // + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3526 Slog.e(TAG, "addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003527 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang6322c422018-07-18 18:37:28 +08003528 } else {
3529 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003530 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003531 }
3532 final int windowingMode = stack.getWindowingMode();
3533 if (windowingMode == WINDOWING_MODE_PINNED) {
3534 if (mPinnedStack != null) {
3535 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3536 + mPinnedStack + " already exist on display=" + this
3537 + " stack=" + stack);
3538 }
3539 mPinnedStack = stack;
3540 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3541 if (mSplitScreenPrimaryStack != null) {
3542 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3543 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3544 + " already exist on display=" + this + " stack=" + stack);
3545 }
3546 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003547 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003548 }
3549 }
3550
3551 private void removeStackReferenceIfNeeded(TaskStack stack) {
3552 if (stack == mHomeStack) {
3553 mHomeStack = null;
3554 } else if (stack == mPinnedStack) {
3555 mPinnedStack = null;
3556 } else if (stack == mSplitScreenPrimaryStack) {
3557 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003558 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3559 mService.setDockedStackCreateStateLocked(
3560 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3561 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003562 }
Andrii Kulian839def92016-11-02 10:58:58 -07003563 }
3564
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003565 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003566 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3567 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003568 addChild(stack, addIndex);
3569 setLayoutNeeded();
3570 }
3571
Wale Ogunwale61911492017-10-11 08:50:50 -07003572 @Override
3573 protected void removeChild(TaskStack stack) {
3574 super.removeChild(stack);
3575 removeStackReferenceIfNeeded(stack);
3576 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003577
3578 @Override
3579 boolean isOnTop() {
3580 // Considered always on top
3581 return true;
3582 }
3583
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003584 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003585 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003586 if (child.getWindowConfiguration().isAlwaysOnTop()
3587 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003588 // This stack is always-on-top, override the default behavior.
3589 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3590
3591 // Moving to its current position, as we must call super but we don't want to
3592 // perform any meaningful action.
3593 final int currentPosition = mChildren.indexOf(child);
3594 super.positionChildAt(currentPosition, child, false /* includingParents */);
3595 return;
3596 }
3597
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003598 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3599 super.positionChildAt(targetPosition, child, includingParents);
3600
3601 setLayoutNeeded();
3602 }
3603
3604 /**
3605 * When stack is added or repositioned, find a proper position for it.
3606 * This will make sure that pinned stack always stays on top.
3607 * @param requestedPosition Position requested by caller.
3608 * @param stack Stack to be added or positioned.
3609 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3610 * @return The proper position for the stack.
3611 */
3612 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003613 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09003614 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09003615 }
3616
Kazuki Takisef85197b2018-06-18 18:18:36 +09003617 final int topChildPosition = mChildren.size() - 1;
3618 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
3619 for (int i = topChildPosition; i >= 0; --i) {
3620 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
3621 belowAlwaysOnTopPosition = i;
3622 break;
3623 }
3624 }
3625
3626 // The max possible position we can insert the stack at.
3627 int maxPosition = POSITION_TOP;
3628 // The min possible position we can insert the stack at.
3629 int minPosition = POSITION_BOTTOM;
3630
3631 if (stack.isAlwaysOnTop()) {
3632 if (hasPinnedStack()) {
3633 // Always-on-top stacks go below the pinned stack.
3634 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
3635 }
3636 // Always-on-top stacks need to be above all other stacks.
3637 minPosition = belowAlwaysOnTopPosition !=
3638 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
3639 } else {
3640 // Other stacks need to be below the always-on-top stacks.
3641 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08003642 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09003643 }
3644
3645 int targetPosition = requestedPosition;
3646 targetPosition = Math.min(targetPosition, maxPosition);
3647 targetPosition = Math.max(targetPosition, minPosition);
3648
3649 int prevPosition = getStacks().indexOf(stack);
3650 // The positions we calculated above (maxPosition, minPosition) do not take into
3651 // consideration the following edge cases.
3652 // 1) We need to adjust the position depending on the value "adding".
3653 // 2) When we are moving a stack to another position, we also need to adjust the
3654 // position depending on whether the stack is moving to a higher or lower position.
3655 if ((targetPosition != requestedPosition) &&
3656 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003657 targetPosition++;
3658 }
3659
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003660 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003661 }
3662
3663 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003664 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3665 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003666 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003667 if (super.forAllWindows(callback, traverseTopToBottom)) {
3668 return true;
3669 }
3670 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3671 return true;
3672 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003673 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003674 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3675 return true;
3676 }
3677 if (super.forAllWindows(callback, traverseTopToBottom)) {
3678 return true;
3679 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003680 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003681 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003682 }
3683
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003684 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003685 boolean traverseTopToBottom) {
3686 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3687 // app tokens.
3688 // TODO: Investigate if we need to continue to do this or if we can just process them
3689 // in-order.
3690 if (traverseTopToBottom) {
3691 for (int i = mChildren.size() - 1; i >= 0; --i) {
3692 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3693 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003694 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3695 traverseTopToBottom)) {
3696 return true;
3697 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003698 }
3699 }
3700 } else {
3701 final int count = mChildren.size();
3702 for (int i = 0; i < count; ++i) {
3703 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3704 final int appTokensCount = appTokens.size();
3705 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003706 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3707 traverseTopToBottom)) {
3708 return true;
3709 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003710 }
3711 }
3712 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003713 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003714 }
3715
Wale Ogunwale1666e312016-12-16 11:27:18 -08003716 void setExitingTokensHasVisible(boolean hasVisible) {
3717 for (int i = mChildren.size() - 1; i >= 0; --i) {
3718 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3719 for (int j = appTokens.size() - 1; j >= 0; --j) {
3720 appTokens.get(j).hasVisible = hasVisible;
3721 }
3722 }
3723 }
3724
3725 void removeExistingAppTokensIfPossible() {
3726 for (int i = mChildren.size() - 1; i >= 0; --i) {
3727 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3728 for (int j = appTokens.size() - 1; j >= 0; --j) {
3729 final AppWindowToken token = appTokens.get(j);
3730 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3731 && (!token.mIsExiting || token.isEmpty())) {
3732 // Make sure there is no animation running on this token, so any windows
3733 // associated with it will be removed as soon as their animations are
3734 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003735 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003736 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3737 "performLayout: App token exiting now removed" + token);
3738 token.removeIfPossible();
3739 }
3740 }
3741 }
3742 }
3743
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003744 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003745 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003746 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3747 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003748 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07003749 // docked or freeform stack is visible...except for the home stack if the docked
3750 // stack is minimized and it actually set something and the bounds is different from
3751 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003752 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003753 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003754 && !(mDividerControllerLocked.isHomeStackResizable()
3755 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003756 final int orientation = mHomeStack.getOrientation();
3757 if (orientation != SCREEN_ORIENTATION_UNSET) {
3758 return orientation;
3759 }
3760 }
3761 return SCREEN_ORIENTATION_UNSPECIFIED;
3762 }
3763
3764 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003765 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3766 PackageManager.FEATURE_AUTOMOTIVE);
3767 if (isCar) {
3768 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3769 // allow anything but the default orientation.
3770 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003771 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
3772 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07003773 return SCREEN_ORIENTATION_UNSPECIFIED;
3774 }
3775
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003776 if (orientation != SCREEN_ORIENTATION_UNSET
3777 && orientation != SCREEN_ORIENTATION_BEHIND) {
3778 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003779 "App is requesting an orientation, return " + orientation
3780 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003781 return orientation;
3782 }
3783
3784 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003785 "No app is requesting an orientation, return " + mLastOrientation
3786 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003787 // The next app has not been requested to be visible, so we keep the current orientation
3788 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003789 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003790 }
Robert Carrb1579c82017-09-05 14:54:47 -07003791
3792 @Override
3793 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003794 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003795
Robert Carr2f8aa392018-01-31 14:46:51 -08003796 for (int i = 0; i < mChildren.size(); i++) {
3797 final TaskStack s = mChildren.get(i);
3798 s.assignChildLayers(t);
3799 }
3800 }
3801
3802 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02003803
Robert Carrf7a7ca82017-12-06 13:17:07 -08003804 final int HOME_STACK_STATE = 0;
3805 final int NORMAL_STACK_STATE = 1;
3806 final int ALWAYS_ON_TOP_STATE = 2;
3807
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003808 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003809 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02003810 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02003811 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003812
Robert Carrf7a7ca82017-12-06 13:17:07 -08003813 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3814 for (int i = 0; i < mChildren.size(); i++) {
3815 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003816 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3817 continue;
3818 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3819 || s.isAlwaysOnTop())) {
3820 continue;
3821 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3822 continue;
3823 }
3824 s.assignLayer(t, layer++);
3825 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3826 t.setLayer(mSplitScreenDividerAnchor, layer++);
3827 }
Winson Chungd41f71d2018-03-16 15:26:07 -07003828 if ((s.isTaskAnimating() || s.isAppAnimating())
3829 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003830 // Ensure the animation layer ends up above the
3831 // highest animating stack and no higher.
3832 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003833 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003834 if (state != ALWAYS_ON_TOP_STATE) {
3835 layerForBoostedAnimationLayer = layer++;
3836 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08003837 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003838 if (state == HOME_STACK_STATE) {
3839 layerForHomeAnimationLayer = layer++;
3840 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003841 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003842 if (mAppAnimationLayer != null) {
3843 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003844 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003845 if (mBoostedAppAnimationLayer != null) {
3846 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
3847 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003848 if (mHomeAppAnimationLayer != null) {
3849 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
3850 }
Robert Carrb1579c82017-09-05 14:54:47 -07003851 }
3852
3853 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02003854 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
3855 switch (animationLayer) {
3856 case ANIMATION_LAYER_BOOSTED:
3857 return mBoostedAppAnimationLayer;
3858 case ANIMATION_LAYER_HOME:
3859 return mHomeAppAnimationLayer;
3860 case ANIMATION_LAYER_STANDARD:
3861 default:
3862 return mAppAnimationLayer;
3863 }
chaviw23ee71c2017-12-18 11:29:41 -08003864 }
3865
Robert Carrf7a7ca82017-12-06 13:17:07 -08003866 SurfaceControl getSplitScreenDividerAnchor() {
3867 return mSplitScreenDividerAnchor;
3868 }
3869
chaviw23ee71c2017-12-18 11:29:41 -08003870 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003871 void onParentSet() {
3872 super.onParentSet();
3873 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003874 mAppAnimationLayer = makeChildSurface(null)
3875 .setName("animationLayer")
3876 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02003877 mBoostedAppAnimationLayer = makeChildSurface(null)
3878 .setName("boostedAnimationLayer")
3879 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02003880 mHomeAppAnimationLayer = makeChildSurface(null)
3881 .setName("homeAnimationLayer")
3882 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003883 mSplitScreenDividerAnchor = makeChildSurface(null)
3884 .setName("splitScreenDividerAnchor")
3885 .build();
3886 getPendingTransaction()
3887 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02003888 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02003889 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08003890 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003891 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003892 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003893 mAppAnimationLayer.destroy();
3894 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003895 mBoostedAppAnimationLayer.destroy();
3896 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003897 mHomeAppAnimationLayer.destroy();
3898 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003899 mSplitScreenDividerAnchor.destroy();
3900 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003901 }
3902 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003903 }
3904
Robert Carree4d4b92017-11-22 12:21:46 -08003905 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003906 AboveAppWindowContainers(String name, WindowManagerService service) {
3907 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003908 }
3909
Robert Carrb9506032018-02-13 13:54:00 -08003910 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07003911 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
3912 final SurfaceControl.Builder builder = super.makeChildSurface(child);
3913 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
3914 // To draw above the ColorFade layer during the screen off transition, the
3915 // rounded corner overlays need to be at the root of the surface hierarchy.
3916 // TODO: move the ColorLayer into the display overlay layer such that this is not
3917 // necessary anymore.
3918 builder.setParent(null);
3919 }
3920 return builder;
3921 }
3922
3923 @Override
Robert Carrb9506032018-02-13 13:54:00 -08003924 void assignChildLayers(SurfaceControl.Transaction t) {
3925 assignChildLayers(t, null /* imeContainer */);
3926 }
3927
Robert Carree4d4b92017-11-22 12:21:46 -08003928 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3929 boolean needAssignIme = imeContainer != null
3930 && imeContainer.getSurfaceControl() != null;
3931 for (int j = 0; j < mChildren.size(); ++j) {
3932 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003933
3934 // See {@link mSplitScreenDividerAnchor}
3935 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3936 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3937 continue;
3938 }
Vishnu Nair83537a72018-07-19 21:27:48 -07003939 if (wt.mRoundedCornerOverlay) {
3940 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
3941 continue;
3942 }
Robert Carree4d4b92017-11-22 12:21:46 -08003943 wt.assignLayer(t, j);
3944 wt.assignChildLayers(t);
3945
3946 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3947 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003948
3949 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3950 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003951 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003952 needAssignIme = false;
3953 }
3954 }
3955 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003956 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003957 }
3958 }
3959 }
3960
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003961 /**
3962 * Window container class that contains all containers on this display that are not related to
3963 * Apps. E.g. status bar.
3964 */
Robert Carree4d4b92017-11-22 12:21:46 -08003965 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003966 /**
3967 * Compares two child window tokens returns -1 if the first is lesser than the second in
3968 * terms of z-order and 1 otherwise.
3969 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003970 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003971 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003972 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3973 token1.mOwnerCanManageAppTokens)
3974 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3975 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003976
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003977 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3978 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3979 return false;
3980 }
3981 final int req = w.mAttrs.screenOrientation;
3982 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3983 || req == SCREEN_ORIENTATION_UNSET) {
3984 return false;
3985 }
3986 return true;
3987 };
3988
Wale Ogunwale3a931692016-11-02 16:49:48 -07003989 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003990 private final Dimmer mDimmer = new Dimmer(this);
3991 private final Rect mTmpDimBoundsRect = new Rect();
3992
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003993 NonAppWindowContainers(String name, WindowManagerService service) {
3994 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003995 mName = name;
3996 }
3997
3998 void addChild(WindowToken token) {
3999 addChild(token, mWindowComparator);
4000 }
4001
4002 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004003 int getOrientation() {
4004 final WindowManagerPolicy policy = mService.mPolicy;
4005 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004006 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004007
4008 if (win != null) {
4009 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004010 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004011 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004012 if (mService.mKeyguardGoingAway) {
4013 // Keyguard can't affect the orientation if it is going away...
4014 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4015 return SCREEN_ORIENTATION_UNSET;
4016 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004017 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004018 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4019 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004020 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004021 }
4022
Andrii Kulian8ee72852017-03-10 10:36:45 -08004023 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004024
Jorim Jaggi1c530592018-04-06 15:11:47 +02004025 // Only allow force setting the orientation when all unknown visibilities have been
4026 // resolved, as otherwise we just may be starting another occluding activity.
4027 final boolean isUnoccluding =
4028 mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4029 && mService.mUnknownAppVisibilityController.allResolved();
4030 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004031 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004032 }
4033
4034 return SCREEN_ORIENTATION_UNSET;
4035 }
4036
4037 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004038 String getName() {
4039 return mName;
4040 }
chaviwf29223e2018-01-31 13:23:51 -08004041
4042 @Override
4043 Dimmer getDimmer() {
4044 return mDimmer;
4045 }
4046
4047 @Override
4048 void prepareSurfaces() {
4049 mDimmer.resetDimStates();
4050 super.prepareSurfaces();
4051 getBounds(mTmpDimBoundsRect);
4052
4053 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4054 scheduleAnimation();
4055 }
4056 }
Robert Carr3b716242016-08-16 16:02:21 -07004057 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004058
Robert Carr9034d962018-01-04 18:27:42 -08004059 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4060 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4061 super(name, service);
4062 }
4063
4064 @Override
4065 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4066 }
4067 };
4068
Robert Carrb1579c82017-09-05 14:54:47 -07004069 SurfaceControl.Builder makeSurface(SurfaceSession s) {
4070 return mService.makeSurfaceBuilder(s)
4071 .setParent(mWindowingLayer);
4072 }
4073
4074 @Override
4075 SurfaceSession getSession() {
4076 return mSession;
4077 }
4078
4079 @Override
4080 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004081 SurfaceSession s = child != null ? child.getSession() : getSession();
4082 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07004083 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004084
4085 if (child == null) {
4086 return b;
4087 }
4088
Robert Carree4d4b92017-11-22 12:21:46 -08004089 return b.setName(child.getName())
4090 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004091 }
4092
4093 /**
4094 * The makeSurface variants are for use by the window-container
4095 * hierarchy. makeOverlay here is a function for various non windowing
4096 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4097 * and other potpourii.
4098 */
4099 SurfaceControl.Builder makeOverlay() {
4100 return mService.makeSurfaceBuilder(mSession)
4101 .setParent(mOverlayLayer);
4102 }
4103
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004104 /**
4105 * Reparents the given surface to mOverlayLayer.
4106 */
4107 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4108 transaction.reparent(surface, mOverlayLayer.getHandle());
4109 }
4110
Robert Carrb1579c82017-09-05 14:54:47 -07004111 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004112 if (spec.scale != 1.0) {
4113 mMagnificationSpec = spec;
4114 } else {
4115 mMagnificationSpec = null;
4116 }
4117
Robert Carrf59b8dd2017-10-02 18:58:36 -07004118 applyMagnificationSpec(getPendingTransaction(), spec);
4119 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004120 }
4121
Robert Carr24be9ab2018-04-30 17:54:53 -07004122 void reapplyMagnificationSpec() {
4123 if (mMagnificationSpec != null) {
4124 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4125 }
4126 }
4127
Robert Carrb1579c82017-09-05 14:54:47 -07004128 @Override
4129 void onParentSet() {
4130 // Since we are the top of the SurfaceControl hierarchy here
4131 // we create the root surfaces explicitly rather than chaining
4132 // up as the default implementation in onParentSet does. So we
4133 // explicitly do NOT call super here.
4134 }
4135
4136 @Override
4137 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004138
4139 // These are layers as children of "mWindowingLayer"
4140 mBelowAppWindowsContainers.assignLayer(t, 0);
4141 mTaskStackContainers.assignLayer(t, 1);
4142 mAboveAppWindowsContainers.assignLayer(t, 2);
4143
4144 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004145 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004146
Robert Carree4d4b92017-11-22 12:21:46 -08004147 // In the case where we have an IME target that is not in split-screen
4148 // mode IME assignment is easy. We just need the IME to go directly above
4149 // the target. This way children of the target will naturally go above the IME
4150 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004151 //
Robert Carree4d4b92017-11-22 12:21:46 -08004152 // In the case of split-screen windowing mode, we need to elevate the IME above the
4153 // docked divider while keeping the app itself below the docked divider, so instead
4154 // we use relative layering of the IME targets child windows, and place the
4155 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004156 //
Robert Carr234b6332018-03-20 13:38:16 -07004157 // In the case the IME target is animating, the animation Z order may be different
4158 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4159 // IME target. In this case we just layer the IME over all transitions by placing it in the
4160 // above applications layer.
4161 //
Robert Carree4d4b92017-11-22 12:21:46 -08004162 // In the case where we have no IME target we assign it where it's base layer would
4163 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004164 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4165 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004166 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004167 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004168 // TODO: We need to use an extra level on the app surface to ensure
4169 // this is always above SurfaceView but always below attached window.
4170 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004171 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004172 }
4173
4174 // Above we have assigned layers to our children, now we ask them to assign
4175 // layers to their children.
4176 mBelowAppWindowsContainers.assignChildLayers(t);
4177 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004178 mAboveAppWindowsContainers.assignChildLayers(t,
4179 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004180 mImeWindowsContainers.assignChildLayers(t);
4181 }
4182
4183 /**
4184 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4185 * that the IME target is one of the docked applications. We'd like the docked divider to be
4186 * above both of the applications, and we'd like the IME to be above the docked divider.
4187 * However we need child windows of the applications to be above the IME (Text drag handles).
4188 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4189 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
4190 * with {@link #WindowState#assignLayer}
4191 */
4192 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004193 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004194 }
4195
4196 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004197 void prepareSurfaces() {
4198 final ScreenRotationAnimation screenRotationAnimation =
4199 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
4200 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4201 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4202 mPendingTransaction.setMatrix(mWindowingLayer,
4203 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4204 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4205 mPendingTransaction.setPosition(mWindowingLayer,
4206 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4207 mPendingTransaction.setAlpha(mWindowingLayer,
4208 screenRotationAnimation.getEnterTransformation().getAlpha());
4209 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004210
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004211 super.prepareSurfaces();
4212 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004213
Jorim Jaggibe418292018-03-26 16:14:12 +02004214 void assignStackOrdering() {
4215 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004216 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004217
4218 /**
4219 * Increment the deferral count to determine whether to update the IME target.
4220 */
4221 void deferUpdateImeTarget() {
4222 mDeferUpdateImeTargetCount++;
4223 }
4224
4225 /**
4226 * Decrement the deferral count to determine whether to update the IME target. If the count
4227 * reaches 0, a new ime target will get computed.
4228 */
4229 void continueUpdateImeTarget() {
4230 if (mDeferUpdateImeTargetCount == 0) {
4231 return;
4232 }
4233
4234 mDeferUpdateImeTargetCount--;
4235 if (mDeferUpdateImeTargetCount == 0) {
4236 computeImeTarget(true /* updateImeTarget */);
4237 }
4238 }
4239
4240 /**
4241 * @return Whether a new IME target should be computed.
4242 */
4243 private boolean canUpdateImeTarget() {
4244 return mDeferUpdateImeTargetCount == 0;
4245 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004246
4247 InputMonitor getInputMonitor() {
4248 return mInputMonitor;
4249 }
Craig Mautner59c00972012-07-30 12:10:24 -07004250}