blob: 1536d1833dd98efa77afddb9d074686d96278f6e [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
Riddle Hsu86cb7de2018-08-13 23:29:58 +0800924 DisplayWindowController getController() {
925 return (DisplayWindowController) super.getController();
926 }
927
928 @Override
Riddle Hsuad256a12018-07-18 16:11:30 +0800929 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700930 return mDisplay;
931 }
932
Craig Mautner59c00972012-07-30 12:10:24 -0700933 DisplayInfo getDisplayInfo() {
934 return mDisplayInfo;
935 }
936
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700937 DisplayMetrics getDisplayMetrics() {
938 return mDisplayMetrics;
939 }
940
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800941 DisplayPolicy getDisplayPolicy() {
942 return mDisplayPolicy;
943 }
944
Riddle Hsuad256a12018-07-18 16:11:30 +0800945 @Override
946 public DisplayRotation getDisplayRotation() {
947 return mDisplayRotation;
948 }
949
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800950 @VisibleForTesting
951 void setDisplayRotation(DisplayRotation displayRotation) {
952 mDisplayRotation = displayRotation;
953 }
954
Andrii Kulian8ee72852017-03-10 10:36:45 -0800955 int getRotation() {
956 return mRotation;
957 }
958
Andrii Kulianef5ce1c2018-03-20 19:27:24 -0700959 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -0800960 void setRotation(int newRotation) {
961 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +0800962 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -0800963 }
964
965 int getLastOrientation() {
966 return mLastOrientation;
967 }
968
969 void setLastOrientation(int orientation) {
970 mLastOrientation = orientation;
971 }
972
973 boolean getAltOrientation() {
974 return mAltOrientation;
975 }
976
977 void setAltOrientation(boolean altOrientation) {
978 mAltOrientation = altOrientation;
979 }
980
981 int getLastWindowForcedOrientation() {
982 return mLastWindowForcedOrientation;
983 }
984
Andrii Kulian06d07d62017-03-14 11:11:47 -0700985 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +0800986 * Temporarily pauses rotation changes until resumed.
987 *
988 * This can be used to prevent rotation changes from occurring while the user is
989 * performing certain operations, such as drag and drop.
990 *
991 * This call nests and must be matched by an equal number of calls to
992 * {@link #resumeRotationLocked}.
993 */
994 void pauseRotationLocked() {
995 mDeferredRotationPauseCount++;
996 }
997
998 /**
999 * Resumes normal rotation changes after being paused.
1000 */
1001 void resumeRotationLocked() {
1002 if (mDeferredRotationPauseCount <= 0) {
1003 return;
1004 }
1005
1006 mDeferredRotationPauseCount--;
1007 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001008 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001009 }
1010 }
1011
1012 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001013 * If this is true we have updated our desired orientation, but not yet changed the real
1014 * orientation our applied our screen rotation animation. For example, because a previous
1015 * screen rotation was in progress.
1016 *
1017 * @return {@code true} if the there is an ongoing rotation change.
1018 */
1019 boolean rotationNeedsUpdate() {
1020 final int lastOrientation = getLastOrientation();
1021 final int oldRotation = getRotation();
1022 final boolean oldAltOrientation = getAltOrientation();
1023
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001024 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001025 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1026 lastOrientation, rotation);
1027 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1028 return false;
1029 }
1030 return true;
1031 }
1032
1033 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001034 * Update rotation of the display and send configuration if the rotation is changed.
1035 *
1036 * @return {@code true} if the rotation has been changed and the new config is sent.
1037 */
1038 boolean updateRotationAndSendNewConfigIfNeeded() {
1039 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1040 if (changed) {
1041 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
1042 }
1043 return changed;
1044 }
1045
1046 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001047 * Update rotation of the display.
1048 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001049 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1050 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001051 */
Robert Carrae606b42018-02-15 15:36:23 -08001052 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001053 return updateRotationUnchecked(false /* forceUpdate */);
1054 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001055
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001056 /**
1057 * Update rotation of the display with an option to force the update.
1058 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1059 * orientation because we're waiting for some rotation to finish or display
1060 * to unfreeze, which results in configuration of the previously visible
1061 * activity being applied to a newly visible one. Forcing the rotation
1062 * update allows to workaround this issue.
1063 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1064 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
1065 */
1066 boolean updateRotationUnchecked(boolean forceUpdate) {
1067 ScreenRotationAnimation screenRotationAnimation;
1068 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001069 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001070 // Rotation updates have been paused temporarily. Defer the update until
1071 // updates have been resumed.
1072 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1073 return false;
1074 }
1075
1076 screenRotationAnimation =
1077 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
1078 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1079 // Rotation updates cannot be performed while the previous rotation change
1080 // animation is still in progress. Skip this update. We will try updating
1081 // again after the animation is finished and the display is unfrozen.
1082 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1083 return false;
1084 }
1085 if (mService.mDisplayFrozen) {
1086 // Even if the screen rotation animation has finished (e.g. isAnimating
1087 // returns false), there is still some time where we haven't yet unfrozen
1088 // the display. We also need to abort rotation here.
1089 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1090 "Deferring rotation, still finishing previous rotation");
1091 return false;
1092 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001093 }
1094
1095 if (!mService.mDisplayEnabled) {
1096 // No point choosing a rotation if the display is not enabled.
1097 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1098 return false;
1099 }
1100
1101 final int oldRotation = mRotation;
1102 final int lastOrientation = mLastOrientation;
1103 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001104 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001105 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1106 + mDisplayId + " based on lastOrientation=" + lastOrientation
1107 + " and oldRotation=" + oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001108 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(mDisplayRotation,
1109 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001110
Robert Carr0e007272017-10-02 13:00:55 -07001111 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001112 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001113 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001114 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1115 // to complete (that is, waiting for windows to redraw). It's tempting to check
1116 // w.mSeamlessRotationCount but that could be incorrect in the case of
1117 // window-removal.
1118 return false;
1119 }
Robert Carr0e007272017-10-02 13:00:55 -07001120
1121 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001122 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001123 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001124 mayRotateSeamlessly = false;
1125 }
1126 for (int i = 0; i < mService.mSessions.size(); i++) {
1127 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1128 mayRotateSeamlessly = false;
1129 break;
1130 }
1131 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001132 }
Robert Carr0e007272017-10-02 13:00:55 -07001133 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001134
1135 // TODO: Implement forced rotation changes.
1136 // Set mAltOrientation to indicate that the application is receiving
1137 // an orientation that has different metrics than it expected.
1138 // eg. Portrait instead of Landscape.
1139
Riddle Hsuad256a12018-07-18 16:11:30 +08001140 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001141 lastOrientation, rotation);
1142
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001143 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1144 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001145 + ", got rotation " + rotation + " which has "
1146 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1147
1148 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1149 // No change.
1150 return false;
1151 }
1152
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001153 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1154 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001155 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1156 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1157
1158 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1159 mService.mWaitingForConfig = true;
1160 }
1161
Riddle Hsuad256a12018-07-18 16:11:30 +08001162 setRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001163 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001164
1165 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
Riddle Hsu654a6f92018-07-13 22:59:36 +08001166 mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1167 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001168
1169 setLayoutNeeded();
1170 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001171 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001172
1173 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001174 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001175 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1176 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1177 mDisplayId);
1178 } else {
1179 // The screen rotation animation uses a screenshot to freeze the screen
1180 // while windows resize underneath.
1181 // When we are rotating seamlessly, we allow the elements to transition
1182 // to their rotated state independently and without a freeze required.
1183 screenRotationAnimation = null;
1184
Robert Carrefc75702018-02-16 11:46:16 -08001185 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001186 }
1187
1188 // We need to update our screen size information to match the new rotation. If the rotation
1189 // has actually changed then this method will return true and, according to the comment at
1190 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1191 // By updating the Display info here it will be available to
1192 // #computeScreenConfiguration() later.
1193 updateDisplayAndOrientation(getConfiguration().uiMode);
1194
Robert Carrae606b42018-02-15 15:36:23 -08001195 // NOTE: We disable the rotation in the emulator because
1196 // it doesn't support hardware OpenGL emulation yet.
1197 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1198 && screenRotationAnimation.hasScreenshot()) {
1199 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1200 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1201 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1202 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001203 }
1204 }
1205
Vishnu Nair83537a72018-07-19 21:27:48 -07001206 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001207 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1208 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001209 }, true /* traverseTopToBottom */);
1210
Robert Carrae606b42018-02-15 15:36:23 -08001211 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1212 scheduleAnimation();
1213
Andrii Kulian06d07d62017-03-14 11:11:47 -07001214 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001215 if (w.mHasSurface && !rotateSeamlessly) {
1216 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001217 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001218 mService.mRoot.mOrientationChangeComplete = false;
1219 w.mLastFreezeDuration = 0;
1220 }
1221 w.mReportOrientationChanged = true;
1222 }, true /* traverseTopToBottom */);
1223
1224 if (rotateSeamlessly) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001225 mService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1226 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001227 }
1228
1229 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1230 final WindowManagerService.RotationWatcher rotationWatcher
1231 = mService.mRotationWatchers.get(i);
1232 if (rotationWatcher.mDisplayId == mDisplayId) {
1233 try {
1234 rotationWatcher.mWatcher.onRotationChanged(rotation);
1235 } catch (RemoteException e) {
1236 // Ignore
1237 }
1238 }
1239 }
1240
1241 // TODO (multi-display): Magnification is supported only for the default display.
1242 // Announce rotation only if we will not animate as we already have the
1243 // windows in final state. Otherwise, we make this call at the rotation end.
1244 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1245 && isDefaultDisplay) {
1246 mService.mAccessibilityController.onRotationChangedLocked(this);
1247 }
1248
1249 return true;
1250 }
1251
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001252 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001253 final int width = mBaseDisplayWidth;
1254 final int height = mBaseDisplayHeight;
1255 final int shortSize;
1256 final int longSize;
1257 if (width > height) {
1258 shortSize = height;
1259 longSize = width;
1260 } else {
1261 shortSize = width;
1262 longSize = height;
1263 }
1264
1265 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1266 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1267
1268 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1269 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001270
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001271 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1272 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001273 }
1274
Andrii Kulian06d07d62017-03-14 11:11:47 -07001275 /**
1276 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1277 * changed.
1278 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1279 */
1280 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1281 // Use the effective "visual" dimensions based on current rotation
1282 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1283 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1284 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1285 int dw = realdw;
1286 int dh = realdh;
1287
1288 if (mAltOrientation) {
1289 if (realdw > realdh) {
1290 // Turn landscape into portrait.
1291 int maxw = (int)(realdh/1.3f);
1292 if (maxw < realdw) {
1293 dw = maxw;
1294 }
1295 } else {
1296 // Turn portrait into landscape.
1297 int maxh = (int)(realdw/1.3f);
1298 if (maxh < realdh) {
1299 dh = maxh;
1300 }
1301 }
1302 }
1303
1304 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001305 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1306 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1307
Andrii Kulian06d07d62017-03-14 11:11:47 -07001308 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001309 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001310 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001311 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001312 mDisplayInfo.rotation = mRotation;
1313 mDisplayInfo.logicalWidth = dw;
1314 mDisplayInfo.logicalHeight = dh;
1315 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1316 mDisplayInfo.appWidth = appWidth;
1317 mDisplayInfo.appHeight = appHeight;
1318 if (isDefaultDisplay) {
1319 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1320 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1321 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001322 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001323 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1324 if (mDisplayScalingDisabled) {
1325 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1326 } else {
1327 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1328 }
1329
Andrii Kulianf0379de2018-03-14 16:24:07 -07001330 // We usually set the override info in DisplayManager so that we get consistent display
1331 // metrics values when displays are changing and don't send out new values until WM is aware
1332 // of them. However, we don't do this for displays that serve as containers for ActivityView
1333 // because we don't want letter-/pillar-boxing during resize.
1334 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1335 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001336 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001337 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001338
1339 mBaseDisplayRect.set(0, 0, dw, dh);
1340
1341 if (isDefaultDisplay) {
1342 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1343 mCompatDisplayMetrics);
1344 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001345
1346 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001347 return mDisplayInfo;
1348 }
1349
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001350 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001351 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1352 }
1353
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001354 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001355 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001356 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001357 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001358 }
Adrian Roos11c25582018-02-19 18:06:36 +01001359 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001360 return WmDisplayCutout.computeSafeInsets(
1361 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001362 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001363 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Jorim Jaggi60640512018-06-29 01:14:31 +02001364 final List<Rect> bounds = WmDisplayCutout.computeSafeInsets(
1365 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
1366 .getDisplayCutout().getBoundingRects();
Adrian Roos11c25582018-02-19 18:06:36 +01001367 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1368 mTmpMatrix);
Jorim Jaggi60640512018-06-29 01:14:31 +02001369 final Region region = Region.obtain();
1370 for (int i = 0; i < bounds.size(); i++) {
1371 final Rect rect = bounds.get(i);
1372 final RectF rectF = new RectF(bounds.get(i));
1373 mTmpMatrix.mapRect(rectF);
1374 rectF.round(rect);
1375 region.op(rect, Op.UNION);
1376 }
1377
1378 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(region),
Adrian Roos24264212018-02-19 16:26:15 +01001379 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1380 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001381 }
1382
Andrii Kulian06d07d62017-03-14 11:11:47 -07001383 /**
1384 * Compute display configuration based on display properties and policy settings.
1385 * Do not call if mDisplayReady == false.
1386 */
1387 void computeScreenConfiguration(Configuration config) {
1388 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1389
1390 final int dw = displayInfo.logicalWidth;
1391 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001392 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001393 config.windowConfiguration.setWindowingMode(getWindowingMode());
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001394
Adrian Roos11c25582018-02-19 18:06:36 +01001395 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001396 config.screenWidthDp =
1397 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001398 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001399 config.screenHeightDp =
1400 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001401 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001402
Adrian Roos11c25582018-02-19 18:06:36 +01001403 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1404 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001405 final int leftInset = mTmpRect.left;
1406 final int topInset = mTmpRect.top;
1407 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001408 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1409 leftInset + displayInfo.appWidth /* right */,
1410 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001411 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1412 || displayInfo.rotation == Surface.ROTATION_270);
1413
1414 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001415 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001416
1417 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1418 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1419 ? Configuration.SCREENLAYOUT_ROUND_YES
1420 : Configuration.SCREENLAYOUT_ROUND_NO);
1421
1422 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1423 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1424 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1425 dh, mDisplayId);
1426 config.densityDpi = displayInfo.logicalDensityDpi;
1427
1428 config.colorMode =
1429 (displayInfo.isHdr()
1430 ? Configuration.COLOR_MODE_HDR_YES
1431 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001432 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001433 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1434 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1435
1436 // Update the configuration based on available input devices, lid switch,
1437 // and platform configuration.
1438 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1439 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1440 config.navigation = Configuration.NAVIGATION_NONAV;
1441
1442 int keyboardPresence = 0;
1443 int navigationPresence = 0;
1444 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1445 final int len = devices != null ? devices.length : 0;
1446 for (int i = 0; i < len; i++) {
1447 InputDevice device = devices[i];
1448 if (!device.isVirtual()) {
1449 final int sources = device.getSources();
1450 final int presenceFlag = device.isExternal() ?
1451 WindowManagerPolicy.PRESENCE_EXTERNAL :
1452 WindowManagerPolicy.PRESENCE_INTERNAL;
1453
1454 // TODO(multi-display): Configure on per-display basis.
1455 if (mService.mIsTouchDevice) {
1456 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1457 InputDevice.SOURCE_TOUCHSCREEN) {
1458 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1459 }
1460 } else {
1461 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1462 }
1463
1464 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1465 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1466 navigationPresence |= presenceFlag;
1467 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1468 && config.navigation == Configuration.NAVIGATION_NONAV) {
1469 config.navigation = Configuration.NAVIGATION_DPAD;
1470 navigationPresence |= presenceFlag;
1471 }
1472
1473 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1474 config.keyboard = Configuration.KEYBOARD_QWERTY;
1475 keyboardPresence |= presenceFlag;
1476 }
1477 }
1478 }
1479
1480 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1481 config.navigation = Configuration.NAVIGATION_DPAD;
1482 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1483 }
1484
1485 // Determine whether a hard keyboard is available and enabled.
1486 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1487 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1488 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1489 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1490 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1491 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1492 }
1493
1494 // Let the policy update hidden states.
1495 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1496 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1497 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1498 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1499 }
1500
1501 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1502 int displayId) {
1503 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1504 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1505 final int unrotDw, unrotDh;
1506 if (rotated) {
1507 unrotDw = dh;
1508 unrotDh = dw;
1509 } else {
1510 unrotDw = dw;
1511 unrotDh = dh;
1512 }
1513 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1514 displayId);
1515 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1516 displayId);
1517 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1518 displayId);
1519 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1520 displayId);
1521 return sw;
1522 }
1523
1524 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1525 DisplayMetrics dm, int dw, int dh, int displayId) {
1526 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001527 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001528 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001529 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001530 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1531 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1532 if (curSize == 0 || size < curSize) {
1533 curSize = size;
1534 }
1535 return curSize;
1536 }
1537
1538 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1539 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1540
1541 // We need to determine the smallest width that will occur under normal
1542 // operation. To this, start with the base screen size and compute the
1543 // width under the different possible rotations. We need to un-rotate
1544 // the current screen dimensions before doing this.
1545 int unrotDw, unrotDh;
1546 if (rotated) {
1547 unrotDw = dh;
1548 unrotDh = dw;
1549 } else {
1550 unrotDw = dw;
1551 unrotDh = dh;
1552 }
1553 displayInfo.smallestNominalAppWidth = 1<<30;
1554 displayInfo.smallestNominalAppHeight = 1<<30;
1555 displayInfo.largestNominalAppWidth = 0;
1556 displayInfo.largestNominalAppHeight = 0;
1557 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1558 unrotDh);
1559 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1560 unrotDw);
1561 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1562 unrotDh);
1563 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1564 unrotDw);
1565 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1566 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1567 displayId);
1568 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1569 displayId);
1570 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1571 displayId);
1572 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1573 displayId);
1574 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1575 outConfig.screenLayout = sl;
1576 }
1577
1578 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1579 int uiMode, int displayId) {
1580 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001581 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1582 mDisplayInfo.displayCutout);
1583 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1584 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001585
1586 // Compute the screen layout size class for this rotation.
1587 int longSize = w;
1588 int shortSize = h;
1589 if (longSize < shortSize) {
1590 int tmp = longSize;
1591 longSize = shortSize;
1592 shortSize = tmp;
1593 }
1594 longSize = (int)(longSize/density);
1595 shortSize = (int)(shortSize/density);
1596 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1597 }
1598
1599 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1600 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001601 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1602 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001603 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001604 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001605 if (width < displayInfo.smallestNominalAppWidth) {
1606 displayInfo.smallestNominalAppWidth = width;
1607 }
1608 if (width > displayInfo.largestNominalAppWidth) {
1609 displayInfo.largestNominalAppWidth = width;
1610 }
1611 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001612 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001613 if (height < displayInfo.smallestNominalAppHeight) {
1614 displayInfo.smallestNominalAppHeight = height;
1615 }
1616 if (height > displayInfo.largestNominalAppHeight) {
1617 displayInfo.largestNominalAppHeight = height;
1618 }
1619 }
1620
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001621 /**
1622 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1623 * theme attribute) on devices that feature a physical options menu key attempt to position
1624 * their menu panel window along the edge of the screen nearest the physical menu key.
1625 * This lowers the travel distance between invoking the menu panel and selecting
1626 * a menu option.
1627 *
1628 * This method helps control where that menu is placed. Its current implementation makes
1629 * assumptions about the menu key and its relationship to the screen based on whether
1630 * the device's natural orientation is portrait (width < height) or landscape.
1631 *
1632 * The menu key is assumed to be located along the bottom edge of natural-portrait
1633 * devices and along the right edge of natural-landscape devices. If these assumptions
1634 * do not hold for the target device, this method should be changed to reflect that.
1635 *
1636 * @return A {@link Gravity} value for placing the options menu window.
1637 */
1638 int getPreferredOptionsPanelGravity() {
1639 final int rotation = getRotation();
1640 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1641 // On devices with a natural orientation of portrait.
1642 switch (rotation) {
1643 default:
1644 case Surface.ROTATION_0:
1645 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1646 case Surface.ROTATION_90:
1647 return Gravity.RIGHT | Gravity.BOTTOM;
1648 case Surface.ROTATION_180:
1649 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1650 case Surface.ROTATION_270:
1651 return Gravity.START | Gravity.BOTTOM;
1652 }
1653 }
1654
1655 // On devices with a natural orientation of landscape.
1656 switch (rotation) {
1657 default:
1658 case Surface.ROTATION_0:
1659 return Gravity.RIGHT | Gravity.BOTTOM;
1660 case Surface.ROTATION_90:
1661 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1662 case Surface.ROTATION_180:
1663 return Gravity.START | Gravity.BOTTOM;
1664 case Surface.ROTATION_270:
1665 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1666 }
1667 }
1668
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001669 DockedStackDividerController getDockedDividerController() {
1670 return mDividerControllerLocked;
1671 }
1672
Winson Chung655332c2016-10-31 13:14:28 -07001673 PinnedStackController getPinnedStackController() {
1674 return mPinnedStackControllerLocked;
1675 }
1676
Jeff Browna506a6e2013-06-04 00:02:38 -07001677 /**
1678 * Returns true if the specified UID has access to this display.
1679 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001680 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001681 return mDisplay.hasAccess(uid);
1682 }
1683
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001684 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001685 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001686 }
1687
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001688 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001689 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001690 }
1691
Wale Ogunwale61911492017-10-11 08:50:50 -07001692 /**
1693 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1694 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001695 TaskStack getSplitScreenPrimaryStack() {
1696 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001697 return (stack != null && stack.isVisible()) ? stack : null;
1698 }
1699
Robert Carr9785cf32018-04-25 15:06:07 -07001700 boolean hasSplitScreenPrimaryStack() {
1701 return getSplitScreenPrimaryStack() != null;
1702 }
1703
Wale Ogunwale61911492017-10-11 08:50:50 -07001704 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001705 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001706 * not visible.
1707 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001708 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1709 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001710 }
1711
1712 TaskStack getPinnedStack() {
1713 return mTaskStackContainers.getPinnedStack();
1714 }
1715
1716 private boolean hasPinnedStack() {
1717 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001718 }
1719
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001720 /**
1721 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1722 * Null is no compatible stack on the display.
1723 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001724 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001725 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1726 }
1727
1728 /**
1729 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1730 * activity type. Null is no compatible stack on the display.
1731 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001732 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001733 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001734 }
1735
Bryce Lee48f4b572017-04-10 10:54:15 -07001736 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001737 WindowList<TaskStack> getStacks() {
1738 return mTaskStackContainers.mChildren;
1739 }
1740
1741 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001742 TaskStack getTopStack() {
1743 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001744 }
1745
Winson Chunge2d72172018-01-25 17:46:20 +00001746 ArrayList<Task> getVisibleTasks() {
1747 return mTaskStackContainers.getVisibleTasks();
1748 }
1749
Wale Ogunwale61911492017-10-11 08:50:50 -07001750 void onStackWindowingModeChanged(TaskStack stack) {
1751 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001752 }
1753
Andrii Kulian441e4492016-09-29 15:25:00 -07001754 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001755 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001756 super.onConfigurationChanged(newParentConfig);
1757
Andrii Kulian3a507b52016-09-19 18:14:12 -07001758 // The display size information is heavily dependent on the resources in the current
1759 // configuration, so we need to reconfigure it every time the configuration changes.
1760 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1761 mService.reconfigureDisplayLocked(this);
1762
Bryce Leef3c6a472017-11-14 14:53:06 -08001763 final DockedStackDividerController dividerController = getDockedDividerController();
1764
1765 if (dividerController != null) {
1766 getDockedDividerController().onConfigurationChanged();
1767 }
1768
1769 final PinnedStackController pinnedStackController = getPinnedStackController();
1770
1771 if (pinnedStackController != null) {
1772 getPinnedStackController().onConfigurationChanged();
1773 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001774 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001775
Andrii Kulian441e4492016-09-29 15:25:00 -07001776 /**
1777 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1778 * bounds were updated.
1779 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001780 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001781 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1782 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001783 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001784 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001785 }
1786 }
Winson Chung32c566f2017-04-11 18:31:21 -07001787
1788 // If there was no pinned stack, we still need to notify the controller of the display info
1789 // update as a result of the config change. We do this here to consolidate the flow between
1790 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001791 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001792 mPinnedStackControllerLocked.onDisplayInfoChanged();
1793 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001794 }
1795
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001796 @Override
1797 boolean fillsParent() {
1798 return true;
1799 }
1800
1801 @Override
1802 boolean isVisible() {
1803 return true;
1804 }
1805
1806 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001807 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001808 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001809 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001810 }
1811
Robert Carr9785cf32018-04-25 15:06:07 -07001812 /**
1813 * In split-screen mode we process the IME containers above the docked divider
1814 * rather than directly above their target.
1815 */
1816 private boolean skipTraverseChild(WindowContainer child) {
1817 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null
1818 && !hasSplitScreenPrimaryStack()) {
1819 return true;
1820 }
1821 return false;
1822 }
1823
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001824 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001825 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1826 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1827 // target, or here in order if there isn't an IME target.
1828 if (traverseTopToBottom) {
1829 for (int i = mChildren.size() - 1; i >= 0; --i) {
1830 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001831 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001832 continue;
1833 }
Robert Carr9785cf32018-04-25 15:06:07 -07001834
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001835 if (child.forAllWindows(callback, traverseTopToBottom)) {
1836 return true;
1837 }
1838 }
1839 } else {
1840 final int count = mChildren.size();
1841 for (int i = 0; i < count; i++) {
1842 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001843 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001844 continue;
1845 }
Robert Carr9785cf32018-04-25 15:06:07 -07001846
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001847 if (child.forAllWindows(callback, traverseTopToBottom)) {
1848 return true;
1849 }
1850 }
1851 }
1852 return false;
1853 }
1854
1855 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1856 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1857 }
1858
Wale Ogunwale399c8692017-05-08 14:22:42 -07001859 @Override
1860 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001861 final WindowManagerPolicy policy = mService.mPolicy;
1862
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001863 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001864 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001865 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1866 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001867 // If the display is frozen, some activities may be in the middle of restarting, and
1868 // thus have removed their old window. If the window has the flag to hide the lock
1869 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1870 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001871 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001872 } else if (policy.isKeyguardLocked()) {
1873 // Use the last orientation the while the display is frozen with the keyguard
1874 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1875 // window. We don't want to check the show when locked window directly though as
1876 // things aren't stable while the display is frozen, for example the window could be
1877 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001878 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1879 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001880 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001881 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001882 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001883 final int orientation = mAboveAppWindowsContainers.getOrientation();
1884 if (orientation != SCREEN_ORIENTATION_UNSET) {
1885 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001886 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001887 }
1888
Wale Ogunwale399c8692017-05-08 14:22:42 -07001889 // Top system windows are not requesting an orientation. Start searching from apps.
1890 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001891 }
1892
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001893 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001894 // Check if display metrics changed and update base values if needed.
1895 updateBaseDisplayMetricsIfNeeded();
1896
Craig Mautner722285e2012-09-07 13:55:58 -07001897 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001898 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001899
Wale Ogunwale61911492017-10-11 08:50:50 -07001900 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1901 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001902 }
Craig Mautner722285e2012-09-07 13:55:58 -07001903 }
1904
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001905 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001906 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1907 if (displayManagerInternal != null) {
1908 // Bootstrap the default logical display from the display manager.
1909 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1910 if (newDisplayInfo != null) {
1911 mDisplayInfo.copyFrom(newDisplayInfo);
1912 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001913 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001914
Andrii Kuliancd097992017-03-23 18:31:59 -07001915 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1916 mDisplayInfo.logicalDensityDpi);
1917 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1918 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1919 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001920 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001921 }
1922
Andrii Kuliancd097992017-03-23 18:31:59 -07001923 /**
1924 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1925 * values.
1926 */
1927 private void updateBaseDisplayMetricsIfNeeded() {
1928 // Get real display metrics without overrides from WM.
1929 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1930 final int orientation = mDisplayInfo.rotation;
1931 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1932 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1933 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1934 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001935 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001936
1937 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1938 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001939 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1940 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001941
1942 if (displayMetricsChanged) {
1943 // Check if display size or density is forced.
1944 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1945 || mBaseDisplayHeight != mInitialDisplayHeight;
1946 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1947
1948 // If there is an override set for base values - use it, otherwise use new values.
1949 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1950 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1951 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1952
1953 // Real display metrics changed, so we should also update initial values.
1954 mInitialDisplayWidth = newWidth;
1955 mInitialDisplayHeight = newHeight;
1956 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001957 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001958 mService.reconfigureDisplayLocked(this);
1959 }
1960 }
1961
Bryce Lee27cec322017-03-21 09:41:37 -07001962 /** Sets the maximum width the screen resolution can be */
1963 void setMaxUiWidth(int width) {
1964 if (DEBUG_DISPLAY) {
1965 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1966 }
1967
1968 mMaxUiWidth = width;
1969
1970 // Update existing metrics.
1971 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1972 }
1973
1974 /** Update base (override) display metrics. */
1975 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1976 mBaseDisplayWidth = baseWidth;
1977 mBaseDisplayHeight = baseHeight;
1978 mBaseDisplayDensity = baseDensity;
1979
1980 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1981 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1982 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1983 mBaseDisplayWidth = mMaxUiWidth;
1984
1985 if (DEBUG_DISPLAY) {
1986 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1987 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1988 + " on display:" + getDisplayId());
1989 }
1990 }
1991
1992 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001993
1994 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001995 }
1996
Wale Ogunwaledb506192017-12-08 10:57:32 -08001997 void getStableRect(Rect out) {
1998 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001999 }
2000
Wale Ogunwale61911492017-10-11 08:50:50 -07002001 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002002 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
2003 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07002004
Wale Ogunwale61911492017-10-11 08:50:50 -07002005 final TaskStack stack = new TaskStack(mService, stackId, controller);
2006 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08002007 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07002008 }
2009
Andrii Kulian51c1b672017-04-07 18:39:32 -07002010 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002011 final DisplayContent prevDc = stack.getDisplayContent();
2012 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07002013 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
2014 + " which is not currently attached to any display");
2015 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08002016 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07002017 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2018 + " to its current displayId=" + mDisplayId);
2019 }
2020
Wale Ogunwale61911492017-10-11 08:50:50 -07002021 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002022 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002023 }
2024
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002025 @Override
2026 protected void addChild(DisplayChildWindowContainer child,
2027 Comparator<DisplayChildWindowContainer> comparator) {
2028 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2029 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002030
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002031 @Override
2032 protected void addChild(DisplayChildWindowContainer child, int index) {
2033 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2034 }
2035
2036 @Override
2037 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002038 // Only allow removal of direct children from this display if the display is in the process
2039 // of been removed.
2040 if (mRemovingDisplay) {
2041 super.removeChild(child);
2042 return;
2043 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002044 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002045 }
2046
Andrii Kuliand2765632016-12-12 22:26:34 -08002047 @Override
2048 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2049 // Children of the display are statically ordered, so the real intention here is to perform
2050 // the operation on the display and not the static direct children.
2051 getParent().positionChildAt(position, this, includingParents);
2052 }
2053
Riddle Hsu57831b52018-07-27 00:31:48 +08002054 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2055 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002056 layoutAndAssignWindowLayersIfNeeded();
2057 }
2058
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002059 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002060 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2061 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002062 final int taskId = stack.taskIdFromPoint(x, y);
2063 if (taskId != -1) {
2064 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002065 }
2066 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002067 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002068 }
2069
Chong Zhang8e89b312015-09-09 15:09:30 -07002070 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002071 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002072 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002073 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002074 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002075 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002076 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002077 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2078 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002079 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002080 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002081 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002082
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002083 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2084 if (mTmpTaskForResizePointSearchResult.searchDone) {
2085 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002086 }
2087 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002088 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002089 }
2090
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002091 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08002092 // The provided task is the task on this display with focus, so if WindowManagerService's
2093 // focused app is not on this display, focusedTask will be null.
2094 if (focusedTask == null) {
2095 mTouchExcludeRegion.setEmpty();
2096 } else {
2097 mTouchExcludeRegion.set(mBaseDisplayRect);
2098 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2099 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07002100 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2101 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002102 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2103 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002104 }
2105 // If we removed the focused task above, add it back and only leave its
2106 // outside touch area in the exclusion. TapDectector is not interested in
2107 // any touch inside the focused task itself.
2108 if (!mTmpRect2.isEmpty()) {
2109 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2110 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002111 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002112 final WindowState inputMethod = mService.mInputMethodWindow;
2113 if (inputMethod != null && inputMethod.isVisibleLw()) {
2114 // If the input method is visible and the user is typing, we don't want these touch
2115 // events to be intercepted and used to change focus. This would likely cause a
2116 // disappearance of the input method.
2117 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07002118 if (inputMethod.getDisplayId() == mDisplayId) {
2119 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2120 } else {
2121 // IME is on a different display, so we need to update its tap detector.
2122 // TODO(multidisplay): Remove when IME will always appear on same display.
2123 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
2124 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002125 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002126 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002127 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002128 win.getTouchableRegion(mTmpRegion);
2129 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2130 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002131 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2132 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2133 win.amendTapExcludeRegion(mTouchExcludeRegion);
2134 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002135 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002136 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002137 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002138 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002139 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2140 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002141 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002142 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002143 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002144 }
2145
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002146 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002147 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002148 super.switchUser();
2149 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002150 }
2151
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002152 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002153 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2154 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002155 }
2156 }
2157
Wale Ogunwale10124582016-09-15 20:25:50 -07002158 @Override
2159 void removeIfPossible() {
2160 if (isAnimating()) {
2161 mDeferredRemoval = true;
2162 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002163 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002164 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002165 }
2166
Wale Ogunwale10124582016-09-15 20:25:50 -07002167 @Override
2168 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002169 mRemovingDisplay = true;
2170 try {
2171 super.removeImmediately();
2172 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07002173 if (mService.canDispatchPointerEvents()) {
2174 if (mTapDetector != null) {
2175 mService.unregisterPointerEventListener(mTapDetector);
2176 }
2177 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
2178 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
2179 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002180 }
Jorim Jaggia3844032018-01-03 15:54:43 +01002181 mService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002182 mWindowingLayer.release();
2183 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002184 } finally {
2185 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002186 }
Bryce Leef19cbe22018-02-02 15:09:21 -08002187
2188 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08002189 }
2190
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002191 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002192 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002193 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002194 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2195
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002196 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002197 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002198 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002199 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002200 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002201 }
2202
Andrii Kulian0214ed92017-05-16 13:44:05 -07002203 /** @return 'true' if removal of this display content is deferred due to active animation. */
2204 boolean isRemovalDeferred() {
2205 return mDeferredRemoval;
2206 }
2207
Wale Ogunwale10124582016-09-15 20:25:50 -07002208 boolean animateForIme(float interpolatedValue, float animationTarget,
2209 float dividerAnimationTarget) {
2210 boolean updated = false;
2211
Wale Ogunwale61911492017-10-11 08:50:50 -07002212 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2213 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002214 if (stack == null || !stack.isAdjustedForIme()) {
2215 continue;
2216 }
2217
2218 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2219 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2220 updated = true;
2221 } else {
2222 mDividerControllerLocked.mLastAnimationProgress =
2223 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2224 mDividerControllerLocked.mLastDividerProgress =
2225 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2226 updated |= stack.updateAdjustForIme(
2227 mDividerControllerLocked.mLastAnimationProgress,
2228 mDividerControllerLocked.mLastDividerProgress,
2229 false /* force */);
2230 }
2231 if (interpolatedValue >= 1f) {
2232 stack.endImeAdjustAnimation();
2233 }
2234 }
2235
2236 return updated;
2237 }
2238
2239 boolean clearImeAdjustAnimation() {
2240 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002241 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2242 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002243 if (stack != null && stack.isAdjustedForIme()) {
2244 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2245 changed = true;
2246 }
2247 }
2248 return changed;
2249 }
2250
2251 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002252 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2253 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002254 if (stack.isVisible() && stack.isAdjustedForIme()) {
2255 stack.beginImeAdjustAnimation();
2256 }
2257 }
2258 }
2259
2260 void adjustForImeIfNeeded() {
2261 final WindowState imeWin = mService.mInputMethodWindow;
2262 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2263 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002264 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002265 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2266 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2267 imeTargetStack.getDockSide() : DOCKED_INVALID;
2268 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2269 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2270 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002271 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002272 final boolean imeHeightChanged = imeVisible &&
2273 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2274
2275 // The divider could be adjusted for IME position, or be thinner than usual,
2276 // or both. There are three possible cases:
2277 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2278 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2279 // - If IME is not visible, divider is not moved and is normal width.
2280
2281 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002282 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2283 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002284 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002285 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2286 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002287 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2288 } else {
2289 stack.resetAdjustedForIme(false);
2290 }
2291 }
2292 mDividerControllerLocked.setAdjustedForIme(
2293 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2294 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002295 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2296 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002297 stack.resetAdjustedForIme(!dockVisible);
2298 }
2299 mDividerControllerLocked.setAdjustedForIme(
2300 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2301 }
Winson Chung655332c2016-10-31 13:14:28 -07002302 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002303 }
2304
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002305 /**
2306 * If a window that has an animation specifying a colored background and the current wallpaper
2307 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2308 * suddenly disappear.
2309 */
2310 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002311 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2312 w -> w.mIsWallpaper && w.isVisibleNow());
2313
2314 if (visibleWallpaper != null) {
2315 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002316 }
2317 return winAnimator.mAnimLayer;
2318 }
2319
Wale Ogunwale10124582016-09-15 20:25:50 -07002320 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002321 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2322 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002323 stack.prepareFreezingTaskBounds();
2324 }
2325 }
2326
Wale Ogunwale94744212015-09-21 19:01:47 -07002327 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002328 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002329
2330 // Compute a transform matrix to undo the coordinate space transformation,
2331 // and present the window at the same physical position it previously occupied.
2332 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2333 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2334
2335 mTmpRectF.set(bounds);
2336 mTmpMatrix.mapRect(mTmpRectF);
2337 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002338 }
2339
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002340 static int deltaRotation(int oldRotation, int newRotation) {
2341 int delta = newRotation - oldRotation;
2342 if (delta < 0) delta += 4;
2343 return delta;
2344 }
2345
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002346 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002347 Matrix outMatrix) {
2348 // For rotations without Z-ordering we don't need the target rectangle's position.
2349 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2350 displayHeight, outMatrix);
2351 }
2352
2353 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2354 float displayWidth, float displayHeight, Matrix outMatrix) {
2355 switch (rotation) {
2356 case ROTATION_0:
2357 outMatrix.reset();
2358 break;
2359 case ROTATION_270:
2360 outMatrix.setRotate(270, 0, 0);
2361 outMatrix.postTranslate(0, displayHeight);
2362 outMatrix.postTranslate(rectTop, 0);
2363 break;
2364 case ROTATION_180:
2365 outMatrix.reset();
2366 break;
2367 case ROTATION_90:
2368 outMatrix.setRotate(90, 0, 0);
2369 outMatrix.postTranslate(displayWidth, 0);
2370 outMatrix.postTranslate(-rectTop, rectLeft);
2371 break;
2372 }
2373 }
2374
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002375 @CallSuper
2376 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002377 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002378 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002379 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002380 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002381 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2382 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002383 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002384 }
2385 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2386 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002387 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2388 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002389 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002390 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002391 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2392 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002393 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002394 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002395 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2396 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002397 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002398 }
2399 proto.write(DPI, mBaseDisplayDensity);
2400 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002401 proto.write(ROTATION, mRotation);
2402 final ScreenRotationAnimation screenRotationAnimation =
2403 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2404 if (screenRotationAnimation != null) {
2405 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2406 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002407 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002408 proto.end(token);
2409 }
2410
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002411 @Override
2412 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2413 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002414 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2415 final String subPrefix = " " + prefix;
2416 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2417 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2418 pw.print("dpi");
2419 if (mInitialDisplayWidth != mBaseDisplayWidth
2420 || mInitialDisplayHeight != mBaseDisplayHeight
2421 || mInitialDisplayDensity != mBaseDisplayDensity) {
2422 pw.print(" base=");
2423 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2424 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2425 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002426 if (mDisplayScalingDisabled) {
2427 pw.println(" noscale");
2428 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002429 pw.print(" cur=");
2430 pw.print(mDisplayInfo.logicalWidth);
2431 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2432 pw.print(" app=");
2433 pw.print(mDisplayInfo.appWidth);
2434 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2435 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2436 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2437 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2438 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002439 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002440 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002441 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002442
Craig Mautnerdc548482014-02-05 13:35:24 -08002443 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002444 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002445 pw.print(prefix);
2446 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002447
2448 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002449 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002450 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2451 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002452 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002453 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002454
Craig Mautnerdc548482014-02-05 13:35:24 -08002455 pw.println();
2456 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002457 pw.println();
2458 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002459 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002460 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002461 pw.print(" Exiting #"); pw.print(i);
2462 pw.print(' '); pw.print(token);
2463 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002464 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002465 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002466 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002467
Jorim Jaggi31f71702016-05-04 16:43:04 -07002468 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002469
2470 // Dump stack references
2471 final TaskStack homeStack = getHomeStack();
2472 if (homeStack != null) {
2473 pw.println(prefix + "homeStack=" + homeStack.getName());
2474 }
2475 final TaskStack pinnedStack = getPinnedStack();
2476 if (pinnedStack != null) {
2477 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2478 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002479 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002480 if (splitScreenPrimaryStack != null) {
2481 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2482 }
2483
2484 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002485 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002486 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002487 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002488
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002489 pw.println();
2490 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002491 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002492 mDisplayPolicy.dump(prefix, pw);
2493 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002494 mDisplayRotation.dump(prefix, pw);
2495 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002496 mInputMonitor.dump(pw, " ");
Craig Mautner59c00972012-07-30 12:10:24 -07002497 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002498
2499 @Override
2500 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002501 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002502 }
2503
2504 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002505 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002506 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002507
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002508 /** Returns true if the stack in the windowing mode is visible. */
2509 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002510 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002511 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002512 }
2513
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002514 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002515 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002516 final int x = (int) xf;
2517 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002518 final WindowState touchedWin = getWindow(w -> {
2519 final int flags = w.mAttrs.flags;
2520 if (!w.isVisibleLw()) {
2521 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002522 }
2523 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002524 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002525 }
2526
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002527 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002528 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002529 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002530 }
2531
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002532 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002533
2534 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002535 return mTmpRegion.contains(x, y) || touchFlags == 0;
2536 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002537
2538 return touchedWin;
2539 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002540
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002541 boolean canAddToastWindowForUid(int uid) {
2542 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002543 // Also if the app is focused adding more than one toast at
2544 // a time for better backwards compatibility.
2545 final WindowState focusedWindowForUid = getWindow(w ->
2546 w.mOwnerUid == uid && w.isFocused());
2547 if (focusedWindowForUid != null) {
2548 return true;
2549 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002550 final WindowState win = getWindow(w ->
2551 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2552 && !w.mWindowRemovalAllowed);
2553 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002554 }
2555
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002556 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002557 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2558 return;
2559 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002560
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002561 // Used to communicate the old focus to the callback method.
2562 mTmpWindow = oldFocus;
2563
2564 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002565 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002566
2567 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002568 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002569
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002570 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002571
2572 if (mTmpWindow == null) {
2573 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2574 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002575 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002576 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002577 }
2578
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002579 /** Updates the layer assignment of windows on this display. */
2580 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002581 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002582 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002583 if (setLayoutNeeded) {
2584 setLayoutNeeded();
2585 }
Robert Carrb1579c82017-09-05 14:54:47 -07002586
Robert Carrf59b8dd2017-10-02 18:58:36 -07002587 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002588 // the application of this transaction until the animation pass triggers
2589 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2590 // the hiding and showing of surfaces.
2591 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002592 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002593 }
2594
Wale Ogunwale1666e312016-12-16 11:27:18 -08002595 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2596 // moving containers or resizing them. Need to investigate the best way to have it automatically
2597 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002598 void layoutAndAssignWindowLayersIfNeeded() {
2599 mService.mWindowsChanged = true;
2600 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002601
2602 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2603 false /*updateInputWindows*/)) {
2604 assignWindowLayers(false /* setLayoutNeeded */);
2605 }
2606
Arthur Hung95b38a92018-07-20 18:56:12 +08002607 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002608 mService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08002609 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002610 }
2611
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002612 /** Returns true if a leaked surface was destroyed */
2613 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002614 // Used to indicate that a surface was leaked.
2615 mTmpWindow = null;
2616 forAllWindows(w -> {
2617 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002618 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002619 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002620 }
2621 if (!mService.mSessions.contains(wsa.mSession)) {
2622 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002623 + w + " surface=" + wsa.mSurfaceController
2624 + " token=" + w.mToken
2625 + " pid=" + w.mSession.mPid
2626 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002627 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002628 mService.mForceRemoves.add(w);
2629 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002630 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002631 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002632 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002633 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002634 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002635 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002636 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002637 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002638 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002639
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002640 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002641 }
2642
2643 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002644 * Determine and return the window that should be the IME target.
2645 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2646 * @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 +00002647 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002648 WindowState computeImeTarget(boolean updateImeTarget) {
2649 if (mService.mInputMethodWindow == null) {
2650 // There isn't an IME so there shouldn't be a target...That was easy!
2651 if (updateImeTarget) {
2652 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2653 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002654 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002655 }
2656 return null;
2657 }
2658
Chavi Weingarten3a748552018-05-14 17:32:42 +00002659 final WindowState curTarget = mService.mInputMethodTarget;
2660 if (!canUpdateImeTarget()) {
2661 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
2662 return curTarget;
2663 }
2664
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002665 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2666 // same display. Or even when the current IME/target are not on the same screen as the next
2667 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002668 mUpdateImeTarget = updateImeTarget;
2669 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002670
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002671
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002672 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2673 // to be on top of it, but it is not -really- where input will go. So look down below
2674 // for a real window to target...
2675 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2676 final AppWindowToken token = target.mAppToken;
2677 if (token != null) {
2678 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2679 if (betterTarget != null) {
2680 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002681 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002682 }
2683 }
2684
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002685 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2686 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002687
chaviw1c13ad32018-06-12 16:44:23 -07002688 // Now, a special case -- if the last target's window is in the process of exiting, but
2689 // not removed, and the new target is home, keep on the last target to avoid flicker.
2690 // Home is a special case since its above other stacks in the ordering list, but layed
2691 // out below the others.
2692 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
2693 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07002694 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00002695 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002696 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002697 }
2698
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002699 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2700 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002701
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002702 if (target == null) {
2703 if (updateImeTarget) {
2704 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2705 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2706 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002707 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002708 }
2709
2710 return null;
2711 }
2712
2713 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002714 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2715 if (token != null) {
2716
2717 // Now some fun for dealing with window animations that modify the Z order. We need
2718 // to look at all windows below the current target that are in this app, finding the
2719 // highest visible one in layering.
2720 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002721 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002722 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002723 }
2724
2725 if (highestTarget != null) {
2726 final AppTransition appTransition = mService.mAppTransition;
2727 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2728 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2729 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002730 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002731
2732 if (appTransition.isTransitionSet()) {
2733 // If we are currently setting up for an animation, hold everything until we
2734 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002735 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002736 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002737 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002738 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002739 // If the window we are currently targeting is involved with an animation,
2740 // and it is on top of the next target we will be over, then hold off on
2741 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002742 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002743 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002744 }
2745 }
2746 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002747
2748 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2749 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002750 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002751 }
2752
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002753 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002754 }
2755
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002756 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002757 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002758 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002759 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002760 }
2761
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002762 mService.mInputMethodTarget = target;
2763 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002764 assignWindowLayers(false /* setLayoutNeeded */);
2765 }
2766
2767 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2768 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2769 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2770 }
2771
2772 // Used to indicate we have reached the first window in the range we are interested in.
2773 mTmpWindow = null;
2774
2775 // TODO: Figure-out a more efficient way to do this.
2776 final WindowState candidate = getWindow(w -> {
2777 if (w == top) {
2778 // Reached the first window in the range we are interested in.
2779 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002780 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002781 if (mTmpWindow == null) {
2782 return false;
2783 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002784
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002785 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2786 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002787 }
2788 // If we reached the bottom of the range of windows we are considering,
2789 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002790 if (w == bottom) {
2791 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002792 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002793 return false;
2794 });
2795
2796 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002797 }
2798
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002799 void setLayoutNeeded() {
2800 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2801 mLayoutNeeded = true;
2802 }
2803
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002804 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002805 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2806 mLayoutNeeded = false;
2807 }
2808
2809 boolean isLayoutNeeded() {
2810 return mLayoutNeeded;
2811 }
2812
Wale Ogunwale02319a62016-09-26 15:21:22 -07002813 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2814 if (mTokenMap.isEmpty()) {
2815 return;
2816 }
2817 pw.println(" Display #" + mDisplayId);
2818 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2819 while (it.hasNext()) {
2820 final WindowToken token = it.next();
2821 pw.print(" ");
2822 pw.print(token);
2823 if (dumpAll) {
2824 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002825 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002826 } else {
2827 pw.println();
2828 }
2829 }
2830 }
2831
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002832 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002833 final int[] index = new int[1];
2834 forAllWindows(w -> {
2835 final WindowStateAnimator wAnim = w.mWinAnimator;
2836 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2837 index[0] = index[0] + 1;
2838 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002839 }
2840
Jorim Jaggife762342016-10-13 14:33:27 +02002841 /**
2842 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2843 */
2844 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2845 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002846 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002847 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2848 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002849 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002850 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002851 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002852 }
2853
Wale Ogunwale494009b82016-10-21 09:01:38 -07002854 boolean checkWaitingForWindows() {
2855
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002856 mHaveBootMsg = false;
2857 mHaveApp = false;
2858 mHaveWallpaper = false;
2859 mHaveKeyguard = true;
2860
2861 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002862 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2863 return true;
2864 }
2865 if (w.isDrawnLw()) {
2866 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002867 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002868 } else if (w.mAttrs.type == TYPE_APPLICATION
2869 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002870 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002871 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002872 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002873 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002874 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002875 }
2876 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002877 return false;
2878 });
2879
2880 if (visibleWindow != null) {
2881 // We have a visible window.
2882 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002883 }
2884
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002885 // if the wallpaper service is disabled on the device, we're never going to have
2886 // wallpaper, don't bother waiting for it
2887 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2888 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09002889 && mService.mContext.getResources().getBoolean(
2890 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002891 && !mService.mOnlyCore;
2892
Wale Ogunwale494009b82016-10-21 09:01:38 -07002893 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2894 "******** booted=" + mService.mSystemBooted
2895 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002896 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2897 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2898 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002899
2900 // If we are turning on the screen to show the boot message, don't do it until the boot
2901 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002902 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002903 return true;
2904 }
2905
2906 // If we are turning on the screen after the boot is completed normally, don't do so until
2907 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002908 if (mService.mSystemBooted
2909 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002910 return true;
2911 }
2912
2913 return false;
2914 }
2915
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002916 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002917 mTmpWindowAnimator = animator;
2918 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002919 }
2920
2921 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002922 resetAnimationBackgroundAnimator();
2923
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002924 // Used to indicate a detached wallpaper.
2925 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002926 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002927
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002928 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002929
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002930 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002931 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002932 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2933 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002934 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2935 }
2936 }
2937
Wale Ogunwale494009b82016-10-21 09:01:38 -07002938 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002939 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002940 if (imFocus == null) {
2941 return false;
2942 }
2943
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002944 if (DEBUG_INPUT_METHOD) {
2945 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2946 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2947 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002948 }
2949
Wale Ogunwale494009b82016-10-21 09:01:38 -07002950 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2951
2952 if (DEBUG_INPUT_METHOD) {
2953 Slog.i(TAG_WM, "IM target client: " + imeClient);
2954 if (imeClient != null) {
2955 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2956 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2957 }
2958 }
2959
2960 return imeClient != null && imeClient.asBinder() == client.asBinder();
2961 }
2962
2963 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002964 final WindowState win = getWindow(
2965 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2966 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002967 }
2968
2969 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002970 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002971 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002972 final int curValue = w.mSystemUiVisibility;
2973 final int diff = (curValue ^ visibility) & globalDiff;
2974 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002975 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002976 w.mSeq++;
2977 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002978 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002979 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2980 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002981 visibility, newValue, diff);
2982 }
2983 } catch (RemoteException e) {
2984 // so sorry
2985 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002986 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002987 }
2988
2989 void onWindowFreezeTimeout() {
2990 Slog.w(TAG_WM, "Window freeze timeout expired.");
2991 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002992
2993 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002994 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002995 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002996 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002997 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002998 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2999 - mService.mDisplayFreezeTime);
3000 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003001 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003002 mService.mWindowPlacerLocked.performSurfacePlacement();
3003 }
3004
3005 void waitForAllWindowsDrawn() {
3006 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003007 forAllWindows(w -> {
3008 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
3009 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
3010 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07003011 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07003012 w.resetLastContentInsets();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003013 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003014 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003015 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07003016 }
3017
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003018 // TODO: Super crazy long method that should be broken down...
3019 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
3020
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003021 final int dw = mDisplayInfo.logicalWidth;
3022 final int dh = mDisplayInfo.logicalHeight;
3023 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
3024
3025 mTmpUpdateAllDrawn.clear();
3026
3027 int repeats = 0;
3028 do {
3029 repeats++;
3030 if (repeats > 6) {
3031 Slog.w(TAG, "Animation repeat aborted after too many iterations");
3032 clearLayoutNeeded();
3033 break;
3034 }
3035
3036 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
3037 pendingLayoutChanges);
3038
Andrii Kulian839def92016-11-02 10:58:58 -07003039 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
3040 // the wallpaper window jumping across displays.
3041 // Remove check for default display when there will be support for multiple wallpaper
3042 // targets (on different displays).
3043 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003044 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003045 }
3046
Riddle Hsu654a6f92018-07-13 22:59:36 +08003047 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003048 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08003049 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003050 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07003051 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003052 }
3053 }
3054
3055 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3056 setLayoutNeeded();
3057 }
3058
3059 // FIRST LOOP: Perform a layout, if needed.
3060 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3061 performLayout(repeats == 1, false /* updateInputWindows */);
3062 } else {
3063 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3064 }
3065
3066 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3067 pendingLayoutChanges = 0;
3068
3069 if (isDefaultDisplay) {
3070 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003071 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003072 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
3073 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3074 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
3075 }
3076 } while (pendingLayoutChanges != 0);
3077
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003078 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003079
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003080 mTmpRecoveringMemory = recoveringMemory;
3081 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003082 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003083
3084 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003085 mTmpApplySurfaceChangesTransactionState.displayHasContent,
3086 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3087 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003088 true /* inTraversal, must call performTraversalInTrans... below */);
3089
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003090 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3091 if (wallpaperVisible != mLastWallpaperVisible) {
3092 mLastWallpaperVisible = wallpaperVisible;
3093 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
3094 }
3095
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003096 while (!mTmpUpdateAllDrawn.isEmpty()) {
3097 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3098 // See if any windows have been drawn, so they (and others associated with them)
3099 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003100 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003101 }
3102
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003103 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003104 }
3105
Bryce Leef3c6a472017-11-14 14:53:06 -08003106 private void updateBounds() {
3107 calculateBounds(mTmpBounds);
3108 setBounds(mTmpBounds);
3109 }
3110
3111 // Determines the current display bounds based on the current state
3112 private void calculateBounds(Rect out) {
3113 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
3114 final int orientation = mDisplayInfo.rotation;
3115 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
3116 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3117 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
3118 int width = mDisplayInfo.logicalWidth;
3119 int left = (physWidth - width) / 2;
3120 int height = mDisplayInfo.logicalHeight;
3121 int top = (physHeight - height) / 2;
3122 out.set(left, top, left + width, top + height);
3123 }
3124
3125 @Override
3126 public void getBounds(Rect out) {
3127 calculateBounds(out);
3128 }
3129
3130 private void getBounds(Rect out, int orientation) {
3131 getBounds(out);
3132
3133 // Rotate the Rect if needed.
3134 final int currentRotation = mDisplayInfo.rotation;
3135 final int rotationDelta = deltaRotation(currentRotation, orientation);
3136 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3137 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3138 mTmpRectF.set(out);
3139 mTmpMatrix.mapRect(mTmpRectF);
3140 mTmpRectF.round(out);
3141 }
3142 }
3143
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003144 void performLayout(boolean initial, boolean updateInputWindows) {
3145 if (!isLayoutNeeded()) {
3146 return;
3147 }
3148 clearLayoutNeeded();
3149
3150 final int dw = mDisplayInfo.logicalWidth;
3151 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003152 if (DEBUG_LAYOUT) {
3153 Slog.v(TAG, "-------------------------------------");
3154 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3155 }
3156
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003157 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3158 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003159 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3160 // display info above...
3161 mDisplayFrames.mRotation = mRotation;
3162 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003163 if (isDefaultDisplay) {
3164 // Not needed on non-default displays.
3165 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
3166 mService.mScreenRect.set(0, 0, dw, dh);
3167 }
3168
Adrian Roos5251b1d2018-03-23 18:57:43 +01003169 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003170 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003171 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003172
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003173 // Used to indicate that we have processed the dream window and all additional windows are
3174 // behind it.
3175 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003176 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003177
3178 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003179 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003180
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003181 // Used to indicate that we have processed the dream window and all additional attached
3182 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003183 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003184 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003185
3186 // Now perform layout of attached windows, which usually depend on the position of the
3187 // window they are attached to. XXX does not deal with windows that are attached to windows
3188 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003189 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003190
3191 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003192 mInputMonitor.layoutInputConsumers(dw, dh);
3193 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003194 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003195 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003196 }
3197
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003198 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
3199 }
3200
3201 /**
3202 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3203 * In portrait mode, it grabs the full screenshot.
3204 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003205 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003206 */
chaviw0315a1a2018-03-05 15:28:35 -08003207 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
3208 if (!mService.mPolicy.isScreenOn()) {
3209 if (DEBUG_SCREENSHOT) {
3210 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003211 }
chaviw0315a1a2018-03-05 15:28:35 -08003212 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003213 }
chaviwfbe47df2017-11-10 16:14:49 -08003214
chaviw0315a1a2018-03-05 15:28:35 -08003215 int dw = mDisplayInfo.logicalWidth;
3216 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003217
chaviw0315a1a2018-03-05 15:28:35 -08003218 if (dw <= 0 || dh <= 0) {
3219 return null;
3220 }
chaviwfbe47df2017-11-10 16:14:49 -08003221
chaviw0315a1a2018-03-05 15:28:35 -08003222 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003223
chaviw0315a1a2018-03-05 15:28:35 -08003224 // The screenshot API does not apply the current screen rotation.
3225 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003226
chaviw0315a1a2018-03-05 15:28:35 -08003227 if (rot == ROTATION_90 || rot == ROTATION_270) {
3228 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3229 }
chaviwfbe47df2017-11-10 16:14:49 -08003230
chaviw0315a1a2018-03-05 15:28:35 -08003231 // SurfaceFlinger is not aware of orientation, so convert our logical
3232 // crop to SurfaceFlinger's portrait orientation.
3233 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3234
3235 final ScreenRotationAnimation screenRotationAnimation =
3236 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3237 final boolean inRotation = screenRotationAnimation != null &&
3238 screenRotationAnimation.isAnimating();
3239 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3240
3241 // TODO(b/68392460): We should screenshot Task controls directly
3242 // but it's difficult at the moment as the Task doesn't have the
3243 // correct size set.
3244 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3245 if (bitmap == null) {
3246 Slog.w(TAG_WM, "Failed to take screenshot");
3247 return null;
3248 }
3249
3250 // Create a copy of the screenshot that is immutable and backed in ashmem.
3251 // This greatly reduces the overhead of passing the bitmap between processes.
3252 final Bitmap ret = bitmap.createAshmemBitmap(config);
3253 bitmap.recycle();
3254 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003255 }
3256
3257 // TODO: Can this use createRotationMatrix()?
3258 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3259 if (rot == Surface.ROTATION_90) {
3260 final int tmp = crop.top;
3261 crop.top = dw - crop.right;
3262 crop.right = crop.bottom;
3263 crop.bottom = dw - crop.left;
3264 crop.left = tmp;
3265 } else if (rot == Surface.ROTATION_180) {
3266 int tmp = crop.top;
3267 crop.top = dh - crop.bottom;
3268 crop.bottom = dh - tmp;
3269 tmp = crop.right;
3270 crop.right = dw - crop.left;
3271 crop.left = dw - tmp;
3272 } else if (rot == Surface.ROTATION_270) {
3273 final int tmp = crop.top;
3274 crop.top = crop.left;
3275 crop.left = dh - crop.bottom;
3276 crop.bottom = crop.right;
3277 crop.right = dh - tmp;
3278 }
3279 }
3280
3281 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003282 // Used to indicate the layout is needed.
3283 mTmpWindow = null;
3284
3285 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003286 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003287 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003288 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003289 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003290 w.setDisplayLayoutNeeded();
3291 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003292 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003293
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003294 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003295 mService.mWindowPlacerLocked.performSurfacePlacement();
3296 }
3297 }
3298
Wale Ogunwale1666e312016-12-16 11:27:18 -08003299 void setExitingTokensHasVisible(boolean hasVisible) {
3300 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3301 mExitingTokens.get(i).hasVisible = hasVisible;
3302 }
3303
3304 // Initialize state of exiting applications.
3305 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3306 }
3307
3308 void removeExistingTokensIfPossible() {
3309 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3310 final WindowToken token = mExitingTokens.get(i);
3311 if (!token.hasVisible) {
3312 mExitingTokens.remove(i);
3313 }
3314 }
3315
3316 // Time to remove any exiting applications?
3317 mTaskStackContainers.removeExistingAppTokensIfPossible();
3318 }
3319
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003320 @Override
3321 void onDescendantOverrideConfigurationChanged() {
3322 setLayoutNeeded();
3323 mService.requestTraversal();
3324 }
3325
David Stevens9440dc82017-03-16 19:00:20 -07003326 boolean okToDisplay() {
3327 if (mDisplayId == DEFAULT_DISPLAY) {
3328 return !mService.mDisplayFrozen
3329 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3330 }
3331 return mDisplayInfo.state == Display.STATE_ON;
3332 }
3333
3334 boolean okToAnimate() {
3335 return okToDisplay() &&
3336 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3337 }
3338
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003339 static final class TaskForResizePointSearchResult {
3340 boolean searchDone;
3341 Task taskForResize;
3342
3343 void reset() {
3344 searchDone = false;
3345 taskForResize = null;
3346 }
3347 }
Robert Carr3b716242016-08-16 16:02:21 -07003348
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003349 private static final class ApplySurfaceChangesTransactionState {
3350 boolean displayHasContent;
3351 boolean obscured;
3352 boolean syswin;
3353 boolean focusDisplayed;
3354 float preferredRefreshRate;
3355 int preferredModeId;
3356
3357 void reset() {
3358 displayHasContent = false;
3359 obscured = false;
3360 syswin = false;
3361 focusDisplayed = false;
3362 preferredRefreshRate = 0;
3363 preferredModeId = 0;
3364 }
3365 }
3366
3367 private static final class ScreenshotApplicationState {
3368 WindowState appWin;
3369 int maxLayer;
3370 int minLayer;
3371 boolean screenshotReady;
3372
3373 void reset(boolean screenshotReady) {
3374 appWin = null;
3375 maxLayer = 0;
3376 minLayer = 0;
3377 this.screenshotReady = screenshotReady;
3378 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3379 }
3380 }
3381
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003382 /**
3383 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3384 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3385 * homogeneous children type which is currently required by sub-classes of
3386 * {@link WindowContainer} class.
3387 */
3388 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3389
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003390 DisplayChildWindowContainer(WindowManagerService service) {
3391 super(service);
3392 }
3393
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003394 @Override
3395 boolean fillsParent() {
3396 return true;
3397 }
3398
3399 @Override
3400 boolean isVisible() {
3401 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003402 }
3403 }
3404
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003405 /**
3406 * Window container class that contains all containers on this display relating to Apps.
3407 * I.e Activities.
3408 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003409 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003410 /**
3411 * A control placed at the appropriate level for transitions to occur.
3412 */
chaviw23ee71c2017-12-18 11:29:41 -08003413 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003414 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003415 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003416
Robert Carrf7a7ca82017-12-06 13:17:07 -08003417 /**
3418 * Given that the split-screen divider does not have an AppWindowToken, it
3419 * will have to live inside of a "NonAppWindowContainer", in particular
3420 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3421 * it will need to be interleaved with some of our children, appearing on top of
3422 * both docked stacks but underneath any assistant stacks.
3423 *
3424 * To solve this problem we have this anchor control, which will always exist so
3425 * we can always assign it the correct value in our {@link #assignChildLayers}.
3426 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3427 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3428 * events between the two containers.
3429 */
3430 SurfaceControl mSplitScreenDividerAnchor = null;
3431
Wale Ogunwale61911492017-10-11 08:50:50 -07003432 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3433 // through the list to find them.
3434 private TaskStack mHomeStack = null;
3435 private TaskStack mPinnedStack = null;
3436 private TaskStack mSplitScreenPrimaryStack = null;
3437
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003438 TaskStackContainers(WindowManagerService service) {
3439 super(service);
3440 }
3441
Wale Ogunwale61911492017-10-11 08:50:50 -07003442 /**
3443 * Returns the topmost stack on the display that is compatible with the input windowing mode
3444 * and activity type. Null is no compatible stack on the display.
3445 */
3446 TaskStack getStack(int windowingMode, int activityType) {
3447 if (activityType == ACTIVITY_TYPE_HOME) {
3448 return mHomeStack;
3449 }
3450 if (windowingMode == WINDOWING_MODE_PINNED) {
3451 return mPinnedStack;
3452 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3453 return mSplitScreenPrimaryStack;
3454 }
3455 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3456 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003457 if (activityType == ACTIVITY_TYPE_UNDEFINED
3458 && windowingMode == stack.getWindowingMode()) {
3459 // Passing in undefined type means we want to match the topmost stack with the
3460 // windowing mode.
3461 return stack;
3462 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003463 if (stack.isCompatible(windowingMode, activityType)) {
3464 return stack;
3465 }
3466 }
3467 return null;
3468 }
3469
3470 @VisibleForTesting
3471 TaskStack getTopStack() {
3472 return mTaskStackContainers.getChildCount() > 0
3473 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3474 }
3475
3476 TaskStack getHomeStack() {
3477 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3478 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3479 }
3480 return mHomeStack;
3481 }
3482
3483 TaskStack getPinnedStack() {
3484 return mPinnedStack;
3485 }
3486
Matthew Ng64e77cf2017-10-31 14:01:31 -07003487 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003488 return mSplitScreenPrimaryStack;
3489 }
3490
Winson Chunge2d72172018-01-25 17:46:20 +00003491 ArrayList<Task> getVisibleTasks() {
3492 final ArrayList<Task> visibleTasks = new ArrayList<>();
3493 forAllTasks(task -> {
3494 if (task.isVisible()) {
3495 visibleTasks.add(task);
3496 }
3497 });
3498 return visibleTasks;
3499 }
3500
Andrii Kulian839def92016-11-02 10:58:58 -07003501 /**
3502 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003503 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003504 */
3505 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003506 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003507 addChild(stack, onTop);
3508 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003509 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003510
Wale Ogunwale61911492017-10-11 08:50:50 -07003511 void onStackWindowingModeChanged(TaskStack stack) {
3512 removeStackReferenceIfNeeded(stack);
3513 addStackReferenceIfNeeded(stack);
3514 if (stack == mPinnedStack && getTopStack() != stack) {
3515 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3516 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3517 }
3518 }
3519
3520 private void addStackReferenceIfNeeded(TaskStack stack) {
3521 if (stack.isActivityTypeHome()) {
3522 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003523 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003524 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003525
Wale Ogunwale61911492017-10-11 08:50:50 -07003526 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003527 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003528 }
3529 final int windowingMode = stack.getWindowingMode();
3530 if (windowingMode == WINDOWING_MODE_PINNED) {
3531 if (mPinnedStack != null) {
3532 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3533 + mPinnedStack + " already exist on display=" + this
3534 + " stack=" + stack);
3535 }
3536 mPinnedStack = stack;
3537 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3538 if (mSplitScreenPrimaryStack != null) {
3539 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3540 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3541 + " already exist on display=" + this + " stack=" + stack);
3542 }
3543 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003544 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003545 }
3546 }
3547
3548 private void removeStackReferenceIfNeeded(TaskStack stack) {
3549 if (stack == mHomeStack) {
3550 mHomeStack = null;
3551 } else if (stack == mPinnedStack) {
3552 mPinnedStack = null;
3553 } else if (stack == mSplitScreenPrimaryStack) {
3554 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003555 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3556 mService.setDockedStackCreateStateLocked(
3557 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3558 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003559 }
Andrii Kulian839def92016-11-02 10:58:58 -07003560 }
3561
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003562 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003563 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3564 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003565 addChild(stack, addIndex);
3566 setLayoutNeeded();
3567 }
3568
Wale Ogunwale61911492017-10-11 08:50:50 -07003569 @Override
3570 protected void removeChild(TaskStack stack) {
3571 super.removeChild(stack);
3572 removeStackReferenceIfNeeded(stack);
3573 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003574
3575 @Override
3576 boolean isOnTop() {
3577 // Considered always on top
3578 return true;
3579 }
3580
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003581 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003582 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003583 if (child.getWindowConfiguration().isAlwaysOnTop()
3584 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003585 // This stack is always-on-top, override the default behavior.
3586 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3587
3588 // Moving to its current position, as we must call super but we don't want to
3589 // perform any meaningful action.
3590 final int currentPosition = mChildren.indexOf(child);
3591 super.positionChildAt(currentPosition, child, false /* includingParents */);
3592 return;
3593 }
3594
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003595 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3596 super.positionChildAt(targetPosition, child, includingParents);
3597
3598 setLayoutNeeded();
3599 }
3600
3601 /**
3602 * When stack is added or repositioned, find a proper position for it.
3603 * This will make sure that pinned stack always stays on top.
3604 * @param requestedPosition Position requested by caller.
3605 * @param stack Stack to be added or positioned.
3606 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3607 * @return The proper position for the stack.
3608 */
3609 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003610 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09003611 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09003612 }
3613
Kazuki Takisef85197b2018-06-18 18:18:36 +09003614 final int topChildPosition = mChildren.size() - 1;
3615 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
3616 for (int i = topChildPosition; i >= 0; --i) {
3617 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
3618 belowAlwaysOnTopPosition = i;
3619 break;
3620 }
3621 }
3622
3623 // The max possible position we can insert the stack at.
3624 int maxPosition = POSITION_TOP;
3625 // The min possible position we can insert the stack at.
3626 int minPosition = POSITION_BOTTOM;
3627
3628 if (stack.isAlwaysOnTop()) {
3629 if (hasPinnedStack()) {
3630 // Always-on-top stacks go below the pinned stack.
3631 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
3632 }
3633 // Always-on-top stacks need to be above all other stacks.
3634 minPosition = belowAlwaysOnTopPosition !=
3635 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
3636 } else {
3637 // Other stacks need to be below the always-on-top stacks.
3638 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08003639 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09003640 }
3641
3642 int targetPosition = requestedPosition;
3643 targetPosition = Math.min(targetPosition, maxPosition);
3644 targetPosition = Math.max(targetPosition, minPosition);
3645
3646 int prevPosition = getStacks().indexOf(stack);
3647 // The positions we calculated above (maxPosition, minPosition) do not take into
3648 // consideration the following edge cases.
3649 // 1) We need to adjust the position depending on the value "adding".
3650 // 2) When we are moving a stack to another position, we also need to adjust the
3651 // position depending on whether the stack is moving to a higher or lower position.
3652 if ((targetPosition != requestedPosition) &&
3653 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003654 targetPosition++;
3655 }
3656
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003657 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003658 }
3659
3660 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003661 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3662 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003663 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003664 if (super.forAllWindows(callback, traverseTopToBottom)) {
3665 return true;
3666 }
3667 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3668 return true;
3669 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003670 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003671 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3672 return true;
3673 }
3674 if (super.forAllWindows(callback, traverseTopToBottom)) {
3675 return true;
3676 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003677 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003678 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003679 }
3680
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003681 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003682 boolean traverseTopToBottom) {
3683 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3684 // app tokens.
3685 // TODO: Investigate if we need to continue to do this or if we can just process them
3686 // in-order.
3687 if (traverseTopToBottom) {
3688 for (int i = mChildren.size() - 1; i >= 0; --i) {
3689 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3690 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003691 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3692 traverseTopToBottom)) {
3693 return true;
3694 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003695 }
3696 }
3697 } else {
3698 final int count = mChildren.size();
3699 for (int i = 0; i < count; ++i) {
3700 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3701 final int appTokensCount = appTokens.size();
3702 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003703 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3704 traverseTopToBottom)) {
3705 return true;
3706 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003707 }
3708 }
3709 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003710 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003711 }
3712
Wale Ogunwale1666e312016-12-16 11:27:18 -08003713 void setExitingTokensHasVisible(boolean hasVisible) {
3714 for (int i = mChildren.size() - 1; i >= 0; --i) {
3715 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3716 for (int j = appTokens.size() - 1; j >= 0; --j) {
3717 appTokens.get(j).hasVisible = hasVisible;
3718 }
3719 }
3720 }
3721
3722 void removeExistingAppTokensIfPossible() {
3723 for (int i = mChildren.size() - 1; i >= 0; --i) {
3724 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3725 for (int j = appTokens.size() - 1; j >= 0; --j) {
3726 final AppWindowToken token = appTokens.get(j);
3727 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3728 && (!token.mIsExiting || token.isEmpty())) {
3729 // Make sure there is no animation running on this token, so any windows
3730 // associated with it will be removed as soon as their animations are
3731 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003732 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003733 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3734 "performLayout: App token exiting now removed" + token);
3735 token.removeIfPossible();
3736 }
3737 }
3738 }
3739 }
3740
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003741 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003742 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003743 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3744 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003745 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07003746 // docked or freeform stack is visible...except for the home stack if the docked
3747 // stack is minimized and it actually set something and the bounds is different from
3748 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003749 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003750 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003751 && !(mDividerControllerLocked.isHomeStackResizable()
3752 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003753 final int orientation = mHomeStack.getOrientation();
3754 if (orientation != SCREEN_ORIENTATION_UNSET) {
3755 return orientation;
3756 }
3757 }
3758 return SCREEN_ORIENTATION_UNSPECIFIED;
3759 }
3760
3761 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003762 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3763 PackageManager.FEATURE_AUTOMOTIVE);
3764 if (isCar) {
3765 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3766 // allow anything but the default orientation.
3767 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003768 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
3769 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07003770 return SCREEN_ORIENTATION_UNSPECIFIED;
3771 }
3772
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003773 if (orientation != SCREEN_ORIENTATION_UNSET
3774 && orientation != SCREEN_ORIENTATION_BEHIND) {
3775 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003776 "App is requesting an orientation, return " + orientation
3777 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003778 return orientation;
3779 }
3780
3781 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003782 "No app is requesting an orientation, return " + mLastOrientation
3783 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003784 // The next app has not been requested to be visible, so we keep the current orientation
3785 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003786 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003787 }
Robert Carrb1579c82017-09-05 14:54:47 -07003788
3789 @Override
3790 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003791 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003792
Robert Carr2f8aa392018-01-31 14:46:51 -08003793 for (int i = 0; i < mChildren.size(); i++) {
3794 final TaskStack s = mChildren.get(i);
3795 s.assignChildLayers(t);
3796 }
3797 }
3798
3799 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02003800
Robert Carrf7a7ca82017-12-06 13:17:07 -08003801 final int HOME_STACK_STATE = 0;
3802 final int NORMAL_STACK_STATE = 1;
3803 final int ALWAYS_ON_TOP_STATE = 2;
3804
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003805 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003806 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02003807 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02003808 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003809
Robert Carrf7a7ca82017-12-06 13:17:07 -08003810 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3811 for (int i = 0; i < mChildren.size(); i++) {
3812 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003813 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3814 continue;
3815 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3816 || s.isAlwaysOnTop())) {
3817 continue;
3818 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3819 continue;
3820 }
3821 s.assignLayer(t, layer++);
3822 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3823 t.setLayer(mSplitScreenDividerAnchor, layer++);
3824 }
Winson Chungd41f71d2018-03-16 15:26:07 -07003825 if ((s.isTaskAnimating() || s.isAppAnimating())
3826 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003827 // Ensure the animation layer ends up above the
3828 // highest animating stack and no higher.
3829 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003830 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003831 if (state != ALWAYS_ON_TOP_STATE) {
3832 layerForBoostedAnimationLayer = layer++;
3833 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08003834 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003835 if (state == HOME_STACK_STATE) {
3836 layerForHomeAnimationLayer = layer++;
3837 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003838 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003839 if (mAppAnimationLayer != null) {
3840 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003841 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003842 if (mBoostedAppAnimationLayer != null) {
3843 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
3844 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003845 if (mHomeAppAnimationLayer != null) {
3846 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
3847 }
Robert Carrb1579c82017-09-05 14:54:47 -07003848 }
3849
3850 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02003851 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
3852 switch (animationLayer) {
3853 case ANIMATION_LAYER_BOOSTED:
3854 return mBoostedAppAnimationLayer;
3855 case ANIMATION_LAYER_HOME:
3856 return mHomeAppAnimationLayer;
3857 case ANIMATION_LAYER_STANDARD:
3858 default:
3859 return mAppAnimationLayer;
3860 }
chaviw23ee71c2017-12-18 11:29:41 -08003861 }
3862
Robert Carrf7a7ca82017-12-06 13:17:07 -08003863 SurfaceControl getSplitScreenDividerAnchor() {
3864 return mSplitScreenDividerAnchor;
3865 }
3866
chaviw23ee71c2017-12-18 11:29:41 -08003867 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003868 void onParentSet() {
3869 super.onParentSet();
3870 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003871 mAppAnimationLayer = makeChildSurface(null)
3872 .setName("animationLayer")
3873 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02003874 mBoostedAppAnimationLayer = makeChildSurface(null)
3875 .setName("boostedAnimationLayer")
3876 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02003877 mHomeAppAnimationLayer = makeChildSurface(null)
3878 .setName("homeAnimationLayer")
3879 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003880 mSplitScreenDividerAnchor = makeChildSurface(null)
3881 .setName("splitScreenDividerAnchor")
3882 .build();
3883 getPendingTransaction()
3884 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02003885 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02003886 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08003887 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003888 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003889 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003890 mAppAnimationLayer.destroy();
3891 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003892 mBoostedAppAnimationLayer.destroy();
3893 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003894 mHomeAppAnimationLayer.destroy();
3895 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003896 mSplitScreenDividerAnchor.destroy();
3897 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003898 }
3899 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003900 }
3901
Robert Carree4d4b92017-11-22 12:21:46 -08003902 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003903 AboveAppWindowContainers(String name, WindowManagerService service) {
3904 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003905 }
3906
Robert Carrb9506032018-02-13 13:54:00 -08003907 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07003908 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
3909 final SurfaceControl.Builder builder = super.makeChildSurface(child);
3910 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
3911 // To draw above the ColorFade layer during the screen off transition, the
3912 // rounded corner overlays need to be at the root of the surface hierarchy.
3913 // TODO: move the ColorLayer into the display overlay layer such that this is not
3914 // necessary anymore.
3915 builder.setParent(null);
3916 }
3917 return builder;
3918 }
3919
3920 @Override
Robert Carrb9506032018-02-13 13:54:00 -08003921 void assignChildLayers(SurfaceControl.Transaction t) {
3922 assignChildLayers(t, null /* imeContainer */);
3923 }
3924
Robert Carree4d4b92017-11-22 12:21:46 -08003925 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3926 boolean needAssignIme = imeContainer != null
3927 && imeContainer.getSurfaceControl() != null;
3928 for (int j = 0; j < mChildren.size(); ++j) {
3929 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003930
3931 // See {@link mSplitScreenDividerAnchor}
3932 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3933 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3934 continue;
3935 }
Vishnu Nair83537a72018-07-19 21:27:48 -07003936 if (wt.mRoundedCornerOverlay) {
3937 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
3938 continue;
3939 }
Robert Carree4d4b92017-11-22 12:21:46 -08003940 wt.assignLayer(t, j);
3941 wt.assignChildLayers(t);
3942
3943 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3944 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003945
3946 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3947 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003948 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003949 needAssignIme = false;
3950 }
3951 }
3952 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003953 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003954 }
3955 }
3956 }
3957
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003958 /**
3959 * Window container class that contains all containers on this display that are not related to
3960 * Apps. E.g. status bar.
3961 */
Robert Carree4d4b92017-11-22 12:21:46 -08003962 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003963 /**
3964 * Compares two child window tokens returns -1 if the first is lesser than the second in
3965 * terms of z-order and 1 otherwise.
3966 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003967 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003968 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003969 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3970 token1.mOwnerCanManageAppTokens)
3971 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3972 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003973
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003974 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3975 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3976 return false;
3977 }
3978 final int req = w.mAttrs.screenOrientation;
3979 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3980 || req == SCREEN_ORIENTATION_UNSET) {
3981 return false;
3982 }
3983 return true;
3984 };
3985
Wale Ogunwale3a931692016-11-02 16:49:48 -07003986 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003987 private final Dimmer mDimmer = new Dimmer(this);
3988 private final Rect mTmpDimBoundsRect = new Rect();
3989
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003990 NonAppWindowContainers(String name, WindowManagerService service) {
3991 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003992 mName = name;
3993 }
3994
3995 void addChild(WindowToken token) {
3996 addChild(token, mWindowComparator);
3997 }
3998
3999 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004000 int getOrientation() {
4001 final WindowManagerPolicy policy = mService.mPolicy;
4002 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08004003 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004004
4005 if (win != null) {
4006 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004007 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004008 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07004009 if (mService.mKeyguardGoingAway) {
4010 // Keyguard can't affect the orientation if it is going away...
4011 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
4012 return SCREEN_ORIENTATION_UNSET;
4013 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004014 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07004015 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
4016 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08004017 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004018 }
4019
Andrii Kulian8ee72852017-03-10 10:36:45 -08004020 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004021
Jorim Jaggi1c530592018-04-06 15:11:47 +02004022 // Only allow force setting the orientation when all unknown visibilities have been
4023 // resolved, as otherwise we just may be starting another occluding activity.
4024 final boolean isUnoccluding =
4025 mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
4026 && mService.mUnknownAppVisibilityController.allResolved();
4027 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08004028 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00004029 }
4030
4031 return SCREEN_ORIENTATION_UNSET;
4032 }
4033
4034 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004035 String getName() {
4036 return mName;
4037 }
chaviwf29223e2018-01-31 13:23:51 -08004038
4039 @Override
4040 Dimmer getDimmer() {
4041 return mDimmer;
4042 }
4043
4044 @Override
4045 void prepareSurfaces() {
4046 mDimmer.resetDimStates();
4047 super.prepareSurfaces();
4048 getBounds(mTmpDimBoundsRect);
4049
4050 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4051 scheduleAnimation();
4052 }
4053 }
Robert Carr3b716242016-08-16 16:02:21 -07004054 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004055
Robert Carr9034d962018-01-04 18:27:42 -08004056 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4057 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4058 super(name, service);
4059 }
4060
4061 @Override
4062 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4063 }
4064 };
4065
Robert Carrb1579c82017-09-05 14:54:47 -07004066 SurfaceControl.Builder makeSurface(SurfaceSession s) {
4067 return mService.makeSurfaceBuilder(s)
4068 .setParent(mWindowingLayer);
4069 }
4070
4071 @Override
4072 SurfaceSession getSession() {
4073 return mSession;
4074 }
4075
4076 @Override
4077 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004078 SurfaceSession s = child != null ? child.getSession() : getSession();
4079 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07004080 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004081
4082 if (child == null) {
4083 return b;
4084 }
4085
Robert Carree4d4b92017-11-22 12:21:46 -08004086 return b.setName(child.getName())
4087 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004088 }
4089
4090 /**
4091 * The makeSurface variants are for use by the window-container
4092 * hierarchy. makeOverlay here is a function for various non windowing
4093 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4094 * and other potpourii.
4095 */
4096 SurfaceControl.Builder makeOverlay() {
4097 return mService.makeSurfaceBuilder(mSession)
4098 .setParent(mOverlayLayer);
4099 }
4100
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004101 /**
4102 * Reparents the given surface to mOverlayLayer.
4103 */
4104 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4105 transaction.reparent(surface, mOverlayLayer.getHandle());
4106 }
4107
Robert Carrb1579c82017-09-05 14:54:47 -07004108 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004109 if (spec.scale != 1.0) {
4110 mMagnificationSpec = spec;
4111 } else {
4112 mMagnificationSpec = null;
4113 }
4114
Robert Carrf59b8dd2017-10-02 18:58:36 -07004115 applyMagnificationSpec(getPendingTransaction(), spec);
4116 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004117 }
4118
Robert Carr24be9ab2018-04-30 17:54:53 -07004119 void reapplyMagnificationSpec() {
4120 if (mMagnificationSpec != null) {
4121 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4122 }
4123 }
4124
Robert Carrb1579c82017-09-05 14:54:47 -07004125 @Override
4126 void onParentSet() {
4127 // Since we are the top of the SurfaceControl hierarchy here
4128 // we create the root surfaces explicitly rather than chaining
4129 // up as the default implementation in onParentSet does. So we
4130 // explicitly do NOT call super here.
4131 }
4132
4133 @Override
4134 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004135
4136 // These are layers as children of "mWindowingLayer"
4137 mBelowAppWindowsContainers.assignLayer(t, 0);
4138 mTaskStackContainers.assignLayer(t, 1);
4139 mAboveAppWindowsContainers.assignLayer(t, 2);
4140
4141 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004142 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004143
Robert Carree4d4b92017-11-22 12:21:46 -08004144 // In the case where we have an IME target that is not in split-screen
4145 // mode IME assignment is easy. We just need the IME to go directly above
4146 // the target. This way children of the target will naturally go above the IME
4147 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004148 //
Robert Carree4d4b92017-11-22 12:21:46 -08004149 // In the case of split-screen windowing mode, we need to elevate the IME above the
4150 // docked divider while keeping the app itself below the docked divider, so instead
4151 // we use relative layering of the IME targets child windows, and place the
4152 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004153 //
Robert Carr234b6332018-03-20 13:38:16 -07004154 // In the case the IME target is animating, the animation Z order may be different
4155 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4156 // IME target. In this case we just layer the IME over all transitions by placing it in the
4157 // above applications layer.
4158 //
Robert Carree4d4b92017-11-22 12:21:46 -08004159 // In the case where we have no IME target we assign it where it's base layer would
4160 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004161 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4162 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004163 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004164 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004165 // TODO: We need to use an extra level on the app surface to ensure
4166 // this is always above SurfaceView but always below attached window.
4167 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004168 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004169 }
4170
4171 // Above we have assigned layers to our children, now we ask them to assign
4172 // layers to their children.
4173 mBelowAppWindowsContainers.assignChildLayers(t);
4174 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004175 mAboveAppWindowsContainers.assignChildLayers(t,
4176 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004177 mImeWindowsContainers.assignChildLayers(t);
4178 }
4179
4180 /**
4181 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4182 * that the IME target is one of the docked applications. We'd like the docked divider to be
4183 * above both of the applications, and we'd like the IME to be above the docked divider.
4184 * However we need child windows of the applications to be above the IME (Text drag handles).
4185 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4186 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
4187 * with {@link #WindowState#assignLayer}
4188 */
4189 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004190 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004191 }
4192
4193 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004194 void prepareSurfaces() {
4195 final ScreenRotationAnimation screenRotationAnimation =
4196 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
4197 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4198 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4199 mPendingTransaction.setMatrix(mWindowingLayer,
4200 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4201 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4202 mPendingTransaction.setPosition(mWindowingLayer,
4203 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4204 mPendingTransaction.setAlpha(mWindowingLayer,
4205 screenRotationAnimation.getEnterTransformation().getAlpha());
4206 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004207
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004208 super.prepareSurfaces();
4209 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004210
Jorim Jaggibe418292018-03-26 16:14:12 +02004211 void assignStackOrdering() {
4212 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004213 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004214
4215 /**
4216 * Increment the deferral count to determine whether to update the IME target.
4217 */
4218 void deferUpdateImeTarget() {
4219 mDeferUpdateImeTargetCount++;
4220 }
4221
4222 /**
4223 * Decrement the deferral count to determine whether to update the IME target. If the count
4224 * reaches 0, a new ime target will get computed.
4225 */
4226 void continueUpdateImeTarget() {
4227 if (mDeferUpdateImeTargetCount == 0) {
4228 return;
4229 }
4230
4231 mDeferUpdateImeTargetCount--;
4232 if (mDeferUpdateImeTargetCount == 0) {
4233 computeImeTarget(true /* updateImeTarget */);
4234 }
4235 }
4236
4237 /**
4238 * @return Whether a new IME target should be computed.
4239 */
4240 private boolean canUpdateImeTarget() {
4241 return mDeferUpdateImeTargetCount == 0;
4242 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004243
4244 InputMonitor getInputMonitor() {
4245 return mInputMonitor;
4246 }
Craig Mautner59c00972012-07-30 12:10:24 -07004247}