blob: 4f31ca4ff29380c78991187a6db358d3ce9d0896 [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;
Louis Chang7501e332018-08-20 13:08:39 +080079import static com.android.server.wm.DisplayContentProto.SURFACE_SIZE;
Riddle Hsua4d6fa22018-08-11 00:50:39 +080080import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070084import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070096import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070097import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070098import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080099import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700100import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700101import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
102import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700103import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700104import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700105import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
106import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700107import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700108import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700109import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700110import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700111import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700112import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700113import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700114import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700115import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700116import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800117import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700118
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700119import android.annotation.CallSuper;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700120import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700121import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700122import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700123import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700124import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700125import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800126import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700127import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700128import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100129import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700130import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700131import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700132import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700133import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700134import android.os.RemoteException;
135import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100136import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800137import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700138import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700139import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700140import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700141import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100142import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700143import android.view.DisplayInfo;
Riddle Hsua4d6fa22018-08-11 00:50:39 +0800144import android.view.Gravity;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700145import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700146import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700147import android.view.Surface;
148import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100149import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700150import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700151
Bryce Lee48f4b572017-04-10 10:54:15 -0700152import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800153import com.android.internal.util.ToBooleanFunction;
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
Jorim Jaggif1292892018-09-10 11:58:13 +0200412 /** Caches the value whether told display manager that we have content. */
413 private boolean mLastHasContent;
414
lumark90120a82018-08-15 00:33:03 +0800415 /**
416 * The input method window for this display.
417 */
418 WindowState mInputMethodWindow;
419
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800420 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
421 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800422 final AppWindowToken atoken = w.mAppToken;
423 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200424 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800425 if (w.performShowLocked()) {
426 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
427 if (DEBUG_LAYOUT_REPEATS) {
428 mService.mWindowPlacerLocked.debugLayoutRepeats(
429 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
430 }
431 }
432 }
433 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800434 };
435
436 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
437 final WindowStateAnimator winAnimator = w.mWinAnimator;
438 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
439 return;
440 }
441
Jorim Jaggi8f520872018-08-14 17:00:20 +0200442 // If this window is animating, ensure the animation background is set.
443 final AnimationAdapter anim = w.mAppToken != null
444 ? w.mAppToken.getAnimation()
445 : w.getAnimation();
446 if (anim != null) {
447 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800448 if (color != 0) {
449 final TaskStack stack = w.getStack();
450 if (stack != null) {
451 stack.setAnimationBackground(winAnimator, color);
452 }
453 }
454 }
455 };
456
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800457 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
458 final int lostFocusUid = mTmpWindow.mOwnerUid;
459 final Handler handler = mService.mH;
460 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
461 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
462 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
463 w.mAttrs.hideTimeoutMilliseconds);
464 }
465 }
466 };
467
468 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
469 final AppWindowToken focusedApp = mService.mFocusedApp;
470 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
471 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
472
473 if (!w.canReceiveKeys()) {
474 return false;
475 }
476
477 final AppWindowToken wtoken = w.mAppToken;
478
479 // If this window's application has been removed, just skip it.
480 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
481 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
482 + (wtoken.removed ? "removed" : "sendingToBottom"));
483 return false;
484 }
485
486 if (focusedApp == null) {
487 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
488 + " using new focus @ " + w);
489 mTmpWindow = w;
490 return true;
491 }
492
493 if (!focusedApp.windowsAreFocusable()) {
494 // Current focused app windows aren't focusable...
495 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
496 + " focusable using new focus @ " + w);
497 mTmpWindow = w;
498 return true;
499 }
500
501 // Descend through all of the app tokens and find the first that either matches
502 // win.mAppToken (return win) or mFocusedApp (return null).
503 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
504 if (focusedApp.compareTo(wtoken) > 0) {
505 // App stack below focused app stack. No focus for you!!!
506 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
507 "findFocusedWindow: Reached focused app=" + focusedApp);
508 mTmpWindow = null;
509 return true;
510 }
511 }
512
513 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
514 mTmpWindow = w;
515 return true;
516 };
517
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800518 private final Consumer<WindowState> mPerformLayout = w -> {
519 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
520 // wasting time and funky changes while a window is animating away.
521 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
522 || w.isGoneForLayoutLw();
523
524 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
525 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
526 + " mLayoutAttached=" + w.mLayoutAttached
527 + " screen changed=" + w.isConfigChanged());
528 final AppWindowToken atoken = w.mAppToken;
529 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200530 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800531 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
532 + " parentHidden=" + w.isParentWindowHidden());
533 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200534 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800535 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
536 + " parentHidden=" + w.isParentWindowHidden());
537 }
538
539 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
540 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
541 // since that means "perform layout as normal, just don't display").
542 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
543 || ((w.isConfigChanged() || w.setReportResizeHints())
544 && !w.isGoneForLayoutLw() &&
545 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
546 (w.mHasSurface && w.mAppToken != null &&
547 w.mAppToken.layoutConfigChanges)))) {
548 if (!w.mLayoutAttached) {
549 if (mTmpInitial) {
550 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700551 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800552 }
553 if (w.mAttrs.type == TYPE_DREAM) {
554 // Don't layout windows behind a dream, so that if it does stuff like hide
555 // the status bar we won't get a bad transition when it goes away.
556 mTmpWindow = w;
557 }
558 w.mLayoutNeeded = false;
559 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200560 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000561 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100562 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800563
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200564 // If this is the first layout, we need to initialize the last inset values as
565 // otherwise we'd immediately cause an unnecessary resize.
566 if (firstLayout) {
567 w.updateLastInsetValues();
568 }
569
Adrian Roos23df3a32018-03-15 15:41:13 +0100570 if (w.mAppToken != null) {
571 w.mAppToken.layoutLetterbox(w);
572 }
573
chaviw492139a2018-07-16 16:07:35 -0700574 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700575 + " mContainingFrame=" + w.getContainingFrame()
576 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800577 }
578 }
579 };
580
581 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
582 if (w.mLayoutAttached) {
583 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
584 + " mViewVisibility=" + w.mViewVisibility
585 + " mRelayoutCalled=" + w.mRelayoutCalled);
586 // If this view is GONE, then skip it -- keep the current frame, and let the caller
587 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
588 // windows, since that means "perform layout as normal, just don't display").
589 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
590 return;
591 }
592 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
593 || w.mLayoutNeeded) {
594 if (mTmpInitial) {
595 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
chaviw1454b392018-08-06 09:54:04 -0700596 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800597 }
598 w.mLayoutNeeded = false;
599 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000600 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100601 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700602 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700603 + " mContainingFrame=" + w.getContainingFrame()
604 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800605 }
606 } else if (w.mAttrs.type == TYPE_DREAM) {
607 // Don't layout windows behind a dream, so that if it does stuff like hide the
608 // status bar we won't get a bad transition when it goes away.
609 mTmpWindow = mTmpWindow2;
610 }
611 };
612
613 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
614 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
615 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
616 return w.canBeImeTarget();
617 };
618
619 private final Consumer<WindowState> mApplyPostLayoutPolicy =
620 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
621 mService.mInputMethodTarget);
622
623 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
624 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
625 final boolean obscuredChanged = w.mObscured !=
626 mTmpApplySurfaceChangesTransactionState.obscured;
627 final RootWindowContainer root = mService.mRoot;
628 // Only used if default window
629 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
630
631 // Update effect.
632 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
633 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
634 final boolean isDisplayed = w.isDisplayedLw();
635
636 if (isDisplayed && w.isObscuringDisplay()) {
637 // This window completely covers everything behind it, so we want to leave all
638 // of them as undimmed (for performance reasons).
639 root.mObscuringWindow = w;
640 mTmpApplySurfaceChangesTransactionState.obscured = true;
641 }
642
643 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
644 root.handleNotObscuredLocked(w,
645 mTmpApplySurfaceChangesTransactionState.obscured,
646 mTmpApplySurfaceChangesTransactionState.syswin);
647
648 if (w.mHasSurface && isDisplayed) {
649 final int type = w.mAttrs.type;
650 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
651 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
652 mTmpApplySurfaceChangesTransactionState.syswin = true;
653 }
654 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
655 && w.mAttrs.preferredRefreshRate != 0) {
656 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
657 = w.mAttrs.preferredRefreshRate;
658 }
659 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
660 && w.mAttrs.preferredDisplayModeId != 0) {
661 mTmpApplySurfaceChangesTransactionState.preferredModeId
662 = w.mAttrs.preferredDisplayModeId;
663 }
664 }
665 }
666
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800667 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
668 && mWallpaperController.isWallpaperTarget(w)) {
669 // This is the wallpaper target and its obscured state changed... make sure the
670 // current wallpaper's visibility has been updated accordingly.
671 mWallpaperController.updateWallpaperVisibility();
672 }
673
chaviw161ea3e2018-01-31 12:01:12 -0800674 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800675
676 final WindowStateAnimator winAnimator = w.mWinAnimator;
677
678 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
chaviw1454b392018-08-06 09:54:04 -0700679 w.resetContentChanged();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800680
681 // Moved from updateWindowsAndWallpaperLocked().
682 if (w.mHasSurface) {
683 // Take care of the window being ready to display.
684 final boolean committed = winAnimator.commitFinishDrawingLocked();
685 if (isDefaultDisplay && committed) {
686 if (w.mAttrs.type == TYPE_DREAM) {
687 // HACK: When a dream is shown, it may at that point hide the lock screen.
688 // So we need to redo the layout to let the phone window manager make this
689 // happen.
690 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
691 if (DEBUG_LAYOUT_REPEATS) {
692 surfacePlacer.debugLayoutRepeats(
693 "dream and commitFinishDrawingLocked true",
694 pendingLayoutChanges);
695 }
696 }
697 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
698 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
699 "First draw done in potential wallpaper target " + w);
700 root.mWallpaperMayChange = true;
701 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
702 if (DEBUG_LAYOUT_REPEATS) {
703 surfacePlacer.debugLayoutRepeats(
704 "wallpaper and commitFinishDrawingLocked true",
705 pendingLayoutChanges);
706 }
707 }
708 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800709 }
710
711 final AppWindowToken atoken = w.mAppToken;
712 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100713 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800714 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
715 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
716 mTmpUpdateAllDrawn.add(atoken);
717 }
718 }
719
720 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
721 && w.isDisplayedLw()) {
722 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
723 }
724
725 w.updateResizingWindowIfNeeded();
726 };
727
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800728 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800729 * Create new {@link DisplayContent} instance, add itself to the root window container and
730 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700731 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800732 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700733 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
734 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700735 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700736 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800737 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100738 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800739 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800740 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
741 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
742 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
743 + " new=" + display);
744 }
745
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700746 mDisplay = display;
747 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700748 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700749 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700750 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700751 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100752 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
753 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700754 initializeDisplayBaseInfo();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800755 mDisplayPolicy = new DisplayPolicy(service);
756 mDisplayRotation = new DisplayRotation(service, this);
757 if (isDefaultDisplay) {
758 // The policy may be invoked right after here, so it requires the necessary default
759 // fields of this display content.
760 mService.mPolicy.setDefaultDisplay(this);
761 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800762 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700763 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700764
Robert Carr74a66a22018-02-23 12:17:51 -0800765 // We use this as our arbitrary surface size for buffer-less parents
766 // that don't impose cropping on their children. It may need to be larger
767 // than the display size because fullscreen windows can be shifted offscreen
768 // due to surfaceInsets. 2 times the largest display dimension feels like an
769 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
770 // layers the ability to match their parent sizes and be able to skip
771 // such arbitrary size settings.
772 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700773
774 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
775 .setSize(mSurfaceSize, mSurfaceSize)
776 .setOpaque(true);
777 mWindowingLayer = b.setName("Display Root").build();
778 mOverlayLayer = b.setName("Display Overlays").build();
779
Robert Carrf59b8dd2017-10-02 18:58:36 -0700780 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700781 .setLayerStack(mWindowingLayer, mDisplayId)
782 .show(mWindowingLayer)
783 .setLayer(mOverlayLayer, 1)
784 .setLayerStack(mOverlayLayer, mDisplayId)
785 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700786 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700787
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700788 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700789 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700790 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700791 super.addChild(mAboveAppWindowsContainers, null);
792 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800793
794 // Add itself as a child to the root container.
795 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700796
797 // TODO(b/62541591): evaluate whether this is the best spot to declare the
798 // {@link DisplayContent} ready for use.
799 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800800
Arthur Hung39134b22018-08-14 11:58:28 +0800801 mInputMonitor = new InputMonitor(service, mDisplayId);
Bryce Leed1871262017-06-12 14:12:29 -0700802 }
803
804 boolean isReady() {
805 // The display is ready when the system and the individual display are both ready.
806 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700807 }
808
809 int getDisplayId() {
810 return mDisplayId;
811 }
812
Wale Ogunwale02319a62016-09-26 15:21:22 -0700813 WindowToken getWindowToken(IBinder binder) {
814 return mTokenMap.get(binder);
815 }
816
817 AppWindowToken getAppWindowToken(IBinder binder) {
818 final WindowToken token = getWindowToken(binder);
819 if (token == null) {
820 return null;
821 }
822 return token.asAppWindowToken();
823 }
824
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700825 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700826 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
827 if (dc != null) {
828 // We currently don't support adding a window token to the display if the display
829 // already has the binder mapped to another token. If there is a use case for supporting
830 // this moving forward we will either need to merge the WindowTokens some how or have
831 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700832 throw new IllegalArgumentException("Can't map token=" + token + " to display="
833 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700834 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700835 if (binder == null) {
836 throw new IllegalArgumentException("Can't map token=" + token + " to display="
837 + getName() + " binder is null");
838 }
839 if (token == null) {
840 throw new IllegalArgumentException("Can't map null token to display="
841 + getName() + " binder=" + binder);
842 }
843
Wale Ogunwale02319a62016-09-26 15:21:22 -0700844 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700845
846 if (token.asAppWindowToken() == null) {
847 // Add non-app token to container hierarchy on the display. App tokens are added through
848 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700849 switch (token.windowType) {
850 case TYPE_WALLPAPER:
851 mBelowAppWindowsContainers.addChild(token);
852 break;
853 case TYPE_INPUT_METHOD:
854 case TYPE_INPUT_METHOD_DIALOG:
855 mImeWindowsContainers.addChild(token);
856 break;
857 default:
858 mAboveAppWindowsContainers.addChild(token);
859 break;
860 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700861 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700862 }
863
864 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700865 final WindowToken token = mTokenMap.remove(binder);
866 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800867 token.setExiting();
868 }
869 return token;
870 }
871
872 /** Changes the display the input window token is housed on to this one. */
873 void reParentWindowToken(WindowToken token) {
874 final DisplayContent prevDc = token.getDisplayContent();
875 if (prevDc == this) {
876 return;
877 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800878 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
879 && token.asAppWindowToken() == null) {
880 // Removed the token from the map, but made sure it's not an app token before removing
881 // from parent.
882 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700883 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800884
885 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700886 }
887
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700888 void removeAppToken(IBinder binder) {
889 final WindowToken token = removeWindowToken(binder);
890 if (token == null) {
891 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
892 return;
893 }
894
895 final AppWindowToken appToken = token.asAppWindowToken();
896
897 if (appToken == null) {
898 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
899 return;
900 }
901
902 appToken.onRemovedFromDisplay();
903 }
904
Riddle Hsuad256a12018-07-18 16:11:30 +0800905 @Override
Riddle Hsu86cb7de2018-08-13 23:29:58 +0800906 DisplayWindowController getController() {
907 return (DisplayWindowController) super.getController();
908 }
909
910 @Override
Riddle Hsuad256a12018-07-18 16:11:30 +0800911 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700912 return mDisplay;
913 }
914
Craig Mautner59c00972012-07-30 12:10:24 -0700915 DisplayInfo getDisplayInfo() {
916 return mDisplayInfo;
917 }
918
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700919 DisplayMetrics getDisplayMetrics() {
920 return mDisplayMetrics;
921 }
922
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800923 DisplayPolicy getDisplayPolicy() {
924 return mDisplayPolicy;
925 }
926
Riddle Hsuad256a12018-07-18 16:11:30 +0800927 @Override
928 public DisplayRotation getDisplayRotation() {
929 return mDisplayRotation;
930 }
931
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800932 @VisibleForTesting
933 void setDisplayRotation(DisplayRotation displayRotation) {
934 mDisplayRotation = displayRotation;
935 }
936
Andrii Kulian8ee72852017-03-10 10:36:45 -0800937 int getRotation() {
938 return mRotation;
939 }
940
Andrii Kulianef5ce1c2018-03-20 19:27:24 -0700941 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -0800942 void setRotation(int newRotation) {
943 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +0800944 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -0800945 }
946
947 int getLastOrientation() {
948 return mLastOrientation;
949 }
950
951 void setLastOrientation(int orientation) {
952 mLastOrientation = orientation;
953 }
954
955 boolean getAltOrientation() {
956 return mAltOrientation;
957 }
958
959 void setAltOrientation(boolean altOrientation) {
960 mAltOrientation = altOrientation;
961 }
962
963 int getLastWindowForcedOrientation() {
964 return mLastWindowForcedOrientation;
965 }
966
Andrii Kulian06d07d62017-03-14 11:11:47 -0700967 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +0800968 * Temporarily pauses rotation changes until resumed.
969 *
970 * This can be used to prevent rotation changes from occurring while the user is
971 * performing certain operations, such as drag and drop.
972 *
973 * This call nests and must be matched by an equal number of calls to
974 * {@link #resumeRotationLocked}.
975 */
976 void pauseRotationLocked() {
977 mDeferredRotationPauseCount++;
978 }
979
980 /**
981 * Resumes normal rotation changes after being paused.
982 */
983 void resumeRotationLocked() {
984 if (mDeferredRotationPauseCount <= 0) {
985 return;
986 }
987
988 mDeferredRotationPauseCount--;
989 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800990 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +0800991 }
992 }
993
994 /**
Riddle Hsuad256a12018-07-18 16:11:30 +0800995 * If this is true we have updated our desired orientation, but not yet changed the real
996 * orientation our applied our screen rotation animation. For example, because a previous
997 * screen rotation was in progress.
998 *
999 * @return {@code true} if the there is an ongoing rotation change.
1000 */
1001 boolean rotationNeedsUpdate() {
1002 final int lastOrientation = getLastOrientation();
1003 final int oldRotation = getRotation();
1004 final boolean oldAltOrientation = getAltOrientation();
1005
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001006 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001007 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1008 lastOrientation, rotation);
1009 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1010 return false;
1011 }
1012 return true;
1013 }
1014
1015 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001016 * Update rotation of the display and send configuration if the rotation is changed.
1017 *
1018 * @return {@code true} if the rotation has been changed and the new config is sent.
1019 */
1020 boolean updateRotationAndSendNewConfigIfNeeded() {
1021 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1022 if (changed) {
1023 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
1024 }
1025 return changed;
1026 }
1027
1028 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001029 * Update rotation of the display.
1030 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001031 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1032 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001033 */
Robert Carrae606b42018-02-15 15:36:23 -08001034 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001035 return updateRotationUnchecked(false /* forceUpdate */);
1036 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001037
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001038 /**
1039 * Update rotation of the display with an option to force the update.
1040 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1041 * orientation because we're waiting for some rotation to finish or display
1042 * to unfreeze, which results in configuration of the previously visible
1043 * activity being applied to a newly visible one. Forcing the rotation
1044 * update allows to workaround this issue.
1045 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1046 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
1047 */
1048 boolean updateRotationUnchecked(boolean forceUpdate) {
1049 ScreenRotationAnimation screenRotationAnimation;
1050 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001051 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001052 // Rotation updates have been paused temporarily. Defer the update until
1053 // updates have been resumed.
1054 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1055 return false;
1056 }
1057
1058 screenRotationAnimation =
1059 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
1060 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1061 // Rotation updates cannot be performed while the previous rotation change
1062 // animation is still in progress. Skip this update. We will try updating
1063 // again after the animation is finished and the display is unfrozen.
1064 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1065 return false;
1066 }
1067 if (mService.mDisplayFrozen) {
1068 // Even if the screen rotation animation has finished (e.g. isAnimating
1069 // returns false), there is still some time where we haven't yet unfrozen
1070 // the display. We also need to abort rotation here.
1071 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1072 "Deferring rotation, still finishing previous rotation");
1073 return false;
1074 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001075 }
1076
1077 if (!mService.mDisplayEnabled) {
1078 // No point choosing a rotation if the display is not enabled.
1079 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1080 return false;
1081 }
1082
1083 final int oldRotation = mRotation;
1084 final int lastOrientation = mLastOrientation;
1085 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001086 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001087 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1088 + mDisplayId + " based on lastOrientation=" + lastOrientation
1089 + " and oldRotation=" + oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001090 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(mDisplayRotation,
1091 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001092
Robert Carr0e007272017-10-02 13:00:55 -07001093 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001094 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001095 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001096 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1097 // to complete (that is, waiting for windows to redraw). It's tempting to check
1098 // w.mSeamlessRotationCount but that could be incorrect in the case of
1099 // window-removal.
1100 return false;
1101 }
Robert Carr0e007272017-10-02 13:00:55 -07001102
1103 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001104 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001105 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001106 mayRotateSeamlessly = false;
1107 }
1108 for (int i = 0; i < mService.mSessions.size(); i++) {
1109 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1110 mayRotateSeamlessly = false;
1111 break;
1112 }
1113 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001114 }
Robert Carr0e007272017-10-02 13:00:55 -07001115 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001116
1117 // TODO: Implement forced rotation changes.
1118 // Set mAltOrientation to indicate that the application is receiving
1119 // an orientation that has different metrics than it expected.
1120 // eg. Portrait instead of Landscape.
1121
Riddle Hsuad256a12018-07-18 16:11:30 +08001122 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001123 lastOrientation, rotation);
1124
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001125 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1126 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001127 + ", got rotation " + rotation + " which has "
1128 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1129
1130 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1131 // No change.
1132 return false;
1133 }
1134
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001135 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1136 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001137 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1138 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1139
1140 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1141 mService.mWaitingForConfig = true;
1142 }
1143
Riddle Hsuad256a12018-07-18 16:11:30 +08001144 setRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001145 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001146
1147 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
Riddle Hsu654a6f92018-07-13 22:59:36 +08001148 mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1149 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001150
1151 setLayoutNeeded();
1152 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001153 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001154
1155 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001156 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001157 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1158 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1159 mDisplayId);
1160 } else {
1161 // The screen rotation animation uses a screenshot to freeze the screen
1162 // while windows resize underneath.
1163 // When we are rotating seamlessly, we allow the elements to transition
1164 // to their rotated state independently and without a freeze required.
1165 screenRotationAnimation = null;
1166
Robert Carrefc75702018-02-16 11:46:16 -08001167 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001168 }
1169
1170 // We need to update our screen size information to match the new rotation. If the rotation
1171 // has actually changed then this method will return true and, according to the comment at
1172 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1173 // By updating the Display info here it will be available to
1174 // #computeScreenConfiguration() later.
1175 updateDisplayAndOrientation(getConfiguration().uiMode);
1176
Robert Carrae606b42018-02-15 15:36:23 -08001177 // NOTE: We disable the rotation in the emulator because
1178 // it doesn't support hardware OpenGL emulation yet.
1179 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1180 && screenRotationAnimation.hasScreenshot()) {
1181 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1182 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1183 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1184 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001185 }
1186 }
1187
Vishnu Nair83537a72018-07-19 21:27:48 -07001188 forAllWindows(w -> {
Vishnu Nairddd80742018-08-21 14:12:46 -07001189 w.seamlesslyRotateIfAllowed(getPendingTransaction(), oldRotation, rotation,
1190 rotateSeamlessly);
Vishnu Nair83537a72018-07-19 21:27:48 -07001191 }, true /* traverseTopToBottom */);
1192
Robert Carrae606b42018-02-15 15:36:23 -08001193 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1194 scheduleAnimation();
1195
Andrii Kulian06d07d62017-03-14 11:11:47 -07001196 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001197 if (w.mHasSurface && !rotateSeamlessly) {
1198 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001199 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001200 mService.mRoot.mOrientationChangeComplete = false;
1201 w.mLastFreezeDuration = 0;
1202 }
1203 w.mReportOrientationChanged = true;
1204 }, true /* traverseTopToBottom */);
1205
1206 if (rotateSeamlessly) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001207 mService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1208 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001209 }
1210
1211 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1212 final WindowManagerService.RotationWatcher rotationWatcher
1213 = mService.mRotationWatchers.get(i);
1214 if (rotationWatcher.mDisplayId == mDisplayId) {
1215 try {
1216 rotationWatcher.mWatcher.onRotationChanged(rotation);
1217 } catch (RemoteException e) {
1218 // Ignore
1219 }
1220 }
1221 }
1222
1223 // TODO (multi-display): Magnification is supported only for the default display.
1224 // Announce rotation only if we will not animate as we already have the
1225 // windows in final state. Otherwise, we make this call at the rotation end.
1226 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1227 && isDefaultDisplay) {
1228 mService.mAccessibilityController.onRotationChangedLocked(this);
1229 }
1230
1231 return true;
1232 }
1233
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001234 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001235 final int width = mBaseDisplayWidth;
1236 final int height = mBaseDisplayHeight;
1237 final int shortSize;
1238 final int longSize;
1239 if (width > height) {
1240 shortSize = height;
1241 longSize = width;
1242 } else {
1243 shortSize = width;
1244 longSize = height;
1245 }
1246
1247 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1248 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1249
1250 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1251 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001252
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001253 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1254 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001255 }
1256
Andrii Kulian06d07d62017-03-14 11:11:47 -07001257 /**
1258 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1259 * changed.
1260 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1261 */
1262 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1263 // Use the effective "visual" dimensions based on current rotation
1264 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1265 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1266 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1267 int dw = realdw;
1268 int dh = realdh;
1269
1270 if (mAltOrientation) {
1271 if (realdw > realdh) {
1272 // Turn landscape into portrait.
1273 int maxw = (int)(realdh/1.3f);
1274 if (maxw < realdw) {
1275 dw = maxw;
1276 }
1277 } else {
1278 // Turn portrait into landscape.
1279 int maxh = (int)(realdw/1.3f);
1280 if (maxh < realdh) {
1281 dh = maxh;
1282 }
1283 }
1284 }
1285
1286 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001287 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1288 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1289
Andrii Kulian06d07d62017-03-14 11:11:47 -07001290 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001291 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001292 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001293 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001294 mDisplayInfo.rotation = mRotation;
1295 mDisplayInfo.logicalWidth = dw;
1296 mDisplayInfo.logicalHeight = dh;
1297 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1298 mDisplayInfo.appWidth = appWidth;
1299 mDisplayInfo.appHeight = appHeight;
1300 if (isDefaultDisplay) {
1301 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1302 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1303 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001304 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001305 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1306 if (mDisplayScalingDisabled) {
1307 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1308 } else {
1309 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1310 }
1311
Andrii Kulianf0379de2018-03-14 16:24:07 -07001312 // We usually set the override info in DisplayManager so that we get consistent display
1313 // metrics values when displays are changing and don't send out new values until WM is aware
1314 // of them. However, we don't do this for displays that serve as containers for ActivityView
1315 // because we don't want letter-/pillar-boxing during resize.
1316 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1317 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001318 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001319 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001320
1321 mBaseDisplayRect.set(0, 0, dw, dh);
1322
1323 if (isDefaultDisplay) {
1324 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1325 mCompatDisplayMetrics);
1326 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001327
1328 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001329 return mDisplayInfo;
1330 }
1331
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001332 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001333 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1334 }
1335
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001336 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001337 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001338 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001339 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001340 }
Adrian Roos11c25582018-02-19 18:06:36 +01001341 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001342 return WmDisplayCutout.computeSafeInsets(
1343 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001344 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001345 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Jorim Jaggi60640512018-06-29 01:14:31 +02001346 final List<Rect> bounds = WmDisplayCutout.computeSafeInsets(
1347 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
1348 .getDisplayCutout().getBoundingRects();
Adrian Roos11c25582018-02-19 18:06:36 +01001349 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1350 mTmpMatrix);
Jorim Jaggi60640512018-06-29 01:14:31 +02001351 final Region region = Region.obtain();
1352 for (int i = 0; i < bounds.size(); i++) {
1353 final Rect rect = bounds.get(i);
1354 final RectF rectF = new RectF(bounds.get(i));
1355 mTmpMatrix.mapRect(rectF);
1356 rectF.round(rect);
1357 region.op(rect, Op.UNION);
1358 }
1359
1360 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(region),
Adrian Roos24264212018-02-19 16:26:15 +01001361 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1362 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001363 }
1364
Andrii Kulian06d07d62017-03-14 11:11:47 -07001365 /**
1366 * Compute display configuration based on display properties and policy settings.
1367 * Do not call if mDisplayReady == false.
1368 */
1369 void computeScreenConfiguration(Configuration config) {
1370 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1371
1372 final int dw = displayInfo.logicalWidth;
1373 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001374 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001375 config.windowConfiguration.setWindowingMode(getWindowingMode());
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001376
Adrian Roos11c25582018-02-19 18:06:36 +01001377 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001378 config.screenWidthDp =
1379 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001380 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001381 config.screenHeightDp =
1382 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001383 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001384
Adrian Roos11c25582018-02-19 18:06:36 +01001385 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1386 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001387 final int leftInset = mTmpRect.left;
1388 final int topInset = mTmpRect.top;
1389 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001390 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1391 leftInset + displayInfo.appWidth /* right */,
1392 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001393 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1394 || displayInfo.rotation == Surface.ROTATION_270);
1395
1396 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001397 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001398
1399 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1400 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1401 ? Configuration.SCREENLAYOUT_ROUND_YES
1402 : Configuration.SCREENLAYOUT_ROUND_NO);
1403
1404 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1405 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1406 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1407 dh, mDisplayId);
1408 config.densityDpi = displayInfo.logicalDensityDpi;
1409
1410 config.colorMode =
Chia-I Wuf739bad2018-05-09 12:36:57 -07001411 ((displayInfo.isHdr() && mService.hasHdrSupport())
Andrii Kulian06d07d62017-03-14 11:11:47 -07001412 ? Configuration.COLOR_MODE_HDR_YES
1413 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001414 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001415 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1416 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1417
1418 // Update the configuration based on available input devices, lid switch,
1419 // and platform configuration.
1420 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1421 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1422 config.navigation = Configuration.NAVIGATION_NONAV;
1423
1424 int keyboardPresence = 0;
1425 int navigationPresence = 0;
1426 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1427 final int len = devices != null ? devices.length : 0;
1428 for (int i = 0; i < len; i++) {
1429 InputDevice device = devices[i];
1430 if (!device.isVirtual()) {
1431 final int sources = device.getSources();
1432 final int presenceFlag = device.isExternal() ?
1433 WindowManagerPolicy.PRESENCE_EXTERNAL :
1434 WindowManagerPolicy.PRESENCE_INTERNAL;
1435
1436 // TODO(multi-display): Configure on per-display basis.
1437 if (mService.mIsTouchDevice) {
1438 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1439 InputDevice.SOURCE_TOUCHSCREEN) {
1440 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1441 }
1442 } else {
1443 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1444 }
1445
1446 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1447 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1448 navigationPresence |= presenceFlag;
1449 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1450 && config.navigation == Configuration.NAVIGATION_NONAV) {
1451 config.navigation = Configuration.NAVIGATION_DPAD;
1452 navigationPresence |= presenceFlag;
1453 }
1454
1455 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1456 config.keyboard = Configuration.KEYBOARD_QWERTY;
1457 keyboardPresence |= presenceFlag;
1458 }
1459 }
1460 }
1461
1462 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1463 config.navigation = Configuration.NAVIGATION_DPAD;
1464 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1465 }
1466
1467 // Determine whether a hard keyboard is available and enabled.
1468 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1469 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1470 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1471 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1472 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1473 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1474 }
1475
1476 // Let the policy update hidden states.
1477 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1478 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1479 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1480 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1481 }
1482
1483 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1484 int displayId) {
1485 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1486 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1487 final int unrotDw, unrotDh;
1488 if (rotated) {
1489 unrotDw = dh;
1490 unrotDh = dw;
1491 } else {
1492 unrotDw = dw;
1493 unrotDh = dh;
1494 }
1495 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1496 displayId);
1497 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1498 displayId);
1499 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1500 displayId);
1501 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1502 displayId);
1503 return sw;
1504 }
1505
1506 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1507 DisplayMetrics dm, int dw, int dh, int displayId) {
1508 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001509 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001510 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001511 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001512 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1513 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1514 if (curSize == 0 || size < curSize) {
1515 curSize = size;
1516 }
1517 return curSize;
1518 }
1519
1520 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1521 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1522
1523 // We need to determine the smallest width that will occur under normal
1524 // operation. To this, start with the base screen size and compute the
1525 // width under the different possible rotations. We need to un-rotate
1526 // the current screen dimensions before doing this.
1527 int unrotDw, unrotDh;
1528 if (rotated) {
1529 unrotDw = dh;
1530 unrotDh = dw;
1531 } else {
1532 unrotDw = dw;
1533 unrotDh = dh;
1534 }
1535 displayInfo.smallestNominalAppWidth = 1<<30;
1536 displayInfo.smallestNominalAppHeight = 1<<30;
1537 displayInfo.largestNominalAppWidth = 0;
1538 displayInfo.largestNominalAppHeight = 0;
1539 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1540 unrotDh);
1541 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1542 unrotDw);
1543 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1544 unrotDh);
1545 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1546 unrotDw);
1547 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1548 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1549 displayId);
1550 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1551 displayId);
1552 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1553 displayId);
1554 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1555 displayId);
1556 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1557 outConfig.screenLayout = sl;
1558 }
1559
1560 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1561 int uiMode, int displayId) {
1562 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001563 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1564 mDisplayInfo.displayCutout);
1565 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1566 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001567
1568 // Compute the screen layout size class for this rotation.
1569 int longSize = w;
1570 int shortSize = h;
1571 if (longSize < shortSize) {
1572 int tmp = longSize;
1573 longSize = shortSize;
1574 shortSize = tmp;
1575 }
1576 longSize = (int)(longSize/density);
1577 shortSize = (int)(shortSize/density);
1578 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1579 }
1580
1581 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1582 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001583 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1584 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001585 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001586 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001587 if (width < displayInfo.smallestNominalAppWidth) {
1588 displayInfo.smallestNominalAppWidth = width;
1589 }
1590 if (width > displayInfo.largestNominalAppWidth) {
1591 displayInfo.largestNominalAppWidth = width;
1592 }
1593 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001594 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001595 if (height < displayInfo.smallestNominalAppHeight) {
1596 displayInfo.smallestNominalAppHeight = height;
1597 }
1598 if (height > displayInfo.largestNominalAppHeight) {
1599 displayInfo.largestNominalAppHeight = height;
1600 }
1601 }
1602
Riddle Hsua4d6fa22018-08-11 00:50:39 +08001603 /**
1604 * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
1605 * theme attribute) on devices that feature a physical options menu key attempt to position
1606 * their menu panel window along the edge of the screen nearest the physical menu key.
1607 * This lowers the travel distance between invoking the menu panel and selecting
1608 * a menu option.
1609 *
1610 * This method helps control where that menu is placed. Its current implementation makes
1611 * assumptions about the menu key and its relationship to the screen based on whether
1612 * the device's natural orientation is portrait (width < height) or landscape.
1613 *
1614 * The menu key is assumed to be located along the bottom edge of natural-portrait
1615 * devices and along the right edge of natural-landscape devices. If these assumptions
1616 * do not hold for the target device, this method should be changed to reflect that.
1617 *
1618 * @return A {@link Gravity} value for placing the options menu window.
1619 */
1620 int getPreferredOptionsPanelGravity() {
1621 final int rotation = getRotation();
1622 if (mInitialDisplayWidth < mInitialDisplayHeight) {
1623 // On devices with a natural orientation of portrait.
1624 switch (rotation) {
1625 default:
1626 case Surface.ROTATION_0:
1627 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1628 case Surface.ROTATION_90:
1629 return Gravity.RIGHT | Gravity.BOTTOM;
1630 case Surface.ROTATION_180:
1631 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1632 case Surface.ROTATION_270:
1633 return Gravity.START | Gravity.BOTTOM;
1634 }
1635 }
1636
1637 // On devices with a natural orientation of landscape.
1638 switch (rotation) {
1639 default:
1640 case Surface.ROTATION_0:
1641 return Gravity.RIGHT | Gravity.BOTTOM;
1642 case Surface.ROTATION_90:
1643 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1644 case Surface.ROTATION_180:
1645 return Gravity.START | Gravity.BOTTOM;
1646 case Surface.ROTATION_270:
1647 return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
1648 }
1649 }
1650
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001651 DockedStackDividerController getDockedDividerController() {
1652 return mDividerControllerLocked;
1653 }
1654
Winson Chung655332c2016-10-31 13:14:28 -07001655 PinnedStackController getPinnedStackController() {
1656 return mPinnedStackControllerLocked;
1657 }
1658
Jeff Browna506a6e2013-06-04 00:02:38 -07001659 /**
1660 * Returns true if the specified UID has access to this display.
1661 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001662 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001663 return mDisplay.hasAccess(uid);
1664 }
1665
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001666 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001667 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001668 }
1669
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001670 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001671 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001672 }
1673
Wale Ogunwale61911492017-10-11 08:50:50 -07001674 /**
1675 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1676 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001677 TaskStack getSplitScreenPrimaryStack() {
1678 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001679 return (stack != null && stack.isVisible()) ? stack : null;
1680 }
1681
Robert Carr9785cf32018-04-25 15:06:07 -07001682 boolean hasSplitScreenPrimaryStack() {
1683 return getSplitScreenPrimaryStack() != null;
1684 }
1685
Wale Ogunwale61911492017-10-11 08:50:50 -07001686 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001687 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001688 * not visible.
1689 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001690 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1691 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001692 }
1693
1694 TaskStack getPinnedStack() {
1695 return mTaskStackContainers.getPinnedStack();
1696 }
1697
1698 private boolean hasPinnedStack() {
1699 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001700 }
1701
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001702 /**
1703 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1704 * Null is no compatible stack on the display.
1705 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001706 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001707 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1708 }
1709
1710 /**
1711 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1712 * activity type. Null is no compatible stack on the display.
1713 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001714 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001715 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001716 }
1717
Bryce Lee48f4b572017-04-10 10:54:15 -07001718 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001719 WindowList<TaskStack> getStacks() {
1720 return mTaskStackContainers.mChildren;
1721 }
1722
1723 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001724 TaskStack getTopStack() {
1725 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001726 }
1727
Winson Chunge2d72172018-01-25 17:46:20 +00001728 ArrayList<Task> getVisibleTasks() {
1729 return mTaskStackContainers.getVisibleTasks();
1730 }
1731
Wale Ogunwale61911492017-10-11 08:50:50 -07001732 void onStackWindowingModeChanged(TaskStack stack) {
1733 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001734 }
1735
Andrii Kulian441e4492016-09-29 15:25:00 -07001736 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001737 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001738 super.onConfigurationChanged(newParentConfig);
1739
Andrii Kulian3a507b52016-09-19 18:14:12 -07001740 // The display size information is heavily dependent on the resources in the current
1741 // configuration, so we need to reconfigure it every time the configuration changes.
1742 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1743 mService.reconfigureDisplayLocked(this);
1744
Bryce Leef3c6a472017-11-14 14:53:06 -08001745 final DockedStackDividerController dividerController = getDockedDividerController();
1746
1747 if (dividerController != null) {
1748 getDockedDividerController().onConfigurationChanged();
1749 }
1750
1751 final PinnedStackController pinnedStackController = getPinnedStackController();
1752
1753 if (pinnedStackController != null) {
1754 getPinnedStackController().onConfigurationChanged();
1755 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001756 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001757
Andrii Kulian441e4492016-09-29 15:25:00 -07001758 /**
1759 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1760 * bounds were updated.
1761 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001762 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001763 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1764 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001765 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001766 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001767 }
1768 }
Winson Chung32c566f2017-04-11 18:31:21 -07001769
1770 // If there was no pinned stack, we still need to notify the controller of the display info
1771 // update as a result of the config change. We do this here to consolidate the flow between
1772 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001773 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001774 mPinnedStackControllerLocked.onDisplayInfoChanged();
1775 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001776 }
1777
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001778 @Override
1779 boolean fillsParent() {
1780 return true;
1781 }
1782
1783 @Override
1784 boolean isVisible() {
1785 return true;
1786 }
1787
1788 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001789 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001790 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001791 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001792 }
1793
Robert Carr9785cf32018-04-25 15:06:07 -07001794 /**
1795 * In split-screen mode we process the IME containers above the docked divider
1796 * rather than directly above their target.
1797 */
1798 private boolean skipTraverseChild(WindowContainer child) {
1799 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null
1800 && !hasSplitScreenPrimaryStack()) {
1801 return true;
1802 }
1803 return false;
1804 }
1805
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001806 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001807 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1808 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1809 // target, or here in order if there isn't an IME target.
1810 if (traverseTopToBottom) {
1811 for (int i = mChildren.size() - 1; i >= 0; --i) {
1812 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001813 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001814 continue;
1815 }
Robert Carr9785cf32018-04-25 15:06:07 -07001816
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001817 if (child.forAllWindows(callback, traverseTopToBottom)) {
1818 return true;
1819 }
1820 }
1821 } else {
1822 final int count = mChildren.size();
1823 for (int i = 0; i < count; i++) {
1824 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001825 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001826 continue;
1827 }
Robert Carr9785cf32018-04-25 15:06:07 -07001828
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001829 if (child.forAllWindows(callback, traverseTopToBottom)) {
1830 return true;
1831 }
1832 }
1833 }
1834 return false;
1835 }
1836
1837 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1838 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1839 }
1840
Wale Ogunwale399c8692017-05-08 14:22:42 -07001841 @Override
1842 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001843 final WindowManagerPolicy policy = mService.mPolicy;
1844
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001845 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001846 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001847 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1848 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001849 // If the display is frozen, some activities may be in the middle of restarting, and
1850 // thus have removed their old window. If the window has the flag to hide the lock
1851 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1852 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001853 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001854 } else if (policy.isKeyguardLocked()) {
1855 // Use the last orientation the while the display is frozen with the keyguard
1856 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1857 // window. We don't want to check the show when locked window directly though as
1858 // things aren't stable while the display is frozen, for example the window could be
1859 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001860 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1861 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001862 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001863 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001864 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001865 final int orientation = mAboveAppWindowsContainers.getOrientation();
1866 if (orientation != SCREEN_ORIENTATION_UNSET) {
1867 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001868 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001869 }
1870
Wale Ogunwale399c8692017-05-08 14:22:42 -07001871 // Top system windows are not requesting an orientation. Start searching from apps.
1872 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001873 }
1874
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001875 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001876 // Check if display metrics changed and update base values if needed.
1877 updateBaseDisplayMetricsIfNeeded();
1878
Craig Mautner722285e2012-09-07 13:55:58 -07001879 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001880 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001881
Wale Ogunwale61911492017-10-11 08:50:50 -07001882 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1883 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001884 }
Craig Mautner722285e2012-09-07 13:55:58 -07001885 }
1886
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001887 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001888 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1889 if (displayManagerInternal != null) {
1890 // Bootstrap the default logical display from the display manager.
1891 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1892 if (newDisplayInfo != null) {
1893 mDisplayInfo.copyFrom(newDisplayInfo);
1894 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001895 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001896
Andrii Kuliancd097992017-03-23 18:31:59 -07001897 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1898 mDisplayInfo.logicalDensityDpi);
1899 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1900 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1901 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001902 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001903 }
1904
Andrii Kuliancd097992017-03-23 18:31:59 -07001905 /**
1906 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1907 * values.
1908 */
1909 private void updateBaseDisplayMetricsIfNeeded() {
1910 // Get real display metrics without overrides from WM.
1911 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1912 final int orientation = mDisplayInfo.rotation;
1913 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1914 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1915 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1916 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001917 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001918
1919 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1920 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001921 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1922 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001923
1924 if (displayMetricsChanged) {
1925 // Check if display size or density is forced.
1926 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1927 || mBaseDisplayHeight != mInitialDisplayHeight;
1928 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1929
1930 // If there is an override set for base values - use it, otherwise use new values.
1931 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1932 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1933 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1934
1935 // Real display metrics changed, so we should also update initial values.
1936 mInitialDisplayWidth = newWidth;
1937 mInitialDisplayHeight = newHeight;
1938 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001939 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001940 mService.reconfigureDisplayLocked(this);
1941 }
1942 }
1943
Bryce Lee27cec322017-03-21 09:41:37 -07001944 /** Sets the maximum width the screen resolution can be */
1945 void setMaxUiWidth(int width) {
1946 if (DEBUG_DISPLAY) {
1947 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1948 }
1949
1950 mMaxUiWidth = width;
1951
1952 // Update existing metrics.
1953 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1954 }
1955
1956 /** Update base (override) display metrics. */
1957 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1958 mBaseDisplayWidth = baseWidth;
1959 mBaseDisplayHeight = baseHeight;
1960 mBaseDisplayDensity = baseDensity;
1961
1962 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1963 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1964 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1965 mBaseDisplayWidth = mMaxUiWidth;
1966
1967 if (DEBUG_DISPLAY) {
1968 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1969 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1970 + " on display:" + getDisplayId());
1971 }
1972 }
1973
1974 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001975
1976 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001977 }
1978
Wale Ogunwaledb506192017-12-08 10:57:32 -08001979 void getStableRect(Rect out) {
1980 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001981 }
1982
Wale Ogunwale61911492017-10-11 08:50:50 -07001983 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001984 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1985 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001986
Wale Ogunwale61911492017-10-11 08:50:50 -07001987 final TaskStack stack = new TaskStack(mService, stackId, controller);
1988 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001989 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001990 }
1991
Andrii Kulian51c1b672017-04-07 18:39:32 -07001992 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001993 final DisplayContent prevDc = stack.getDisplayContent();
1994 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001995 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1996 + " which is not currently attached to any display");
1997 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001998 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001999 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
2000 + " to its current displayId=" + mDisplayId);
2001 }
2002
Wale Ogunwale61911492017-10-11 08:50:50 -07002003 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07002004 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08002005 }
2006
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002007 @Override
2008 protected void addChild(DisplayChildWindowContainer child,
2009 Comparator<DisplayChildWindowContainer> comparator) {
2010 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2011 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07002012
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002013 @Override
2014 protected void addChild(DisplayChildWindowContainer child, int index) {
2015 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
2016 }
2017
2018 @Override
2019 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002020 // Only allow removal of direct children from this display if the display is in the process
2021 // of been removed.
2022 if (mRemovingDisplay) {
2023 super.removeChild(child);
2024 return;
2025 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002026 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002027 }
2028
Andrii Kuliand2765632016-12-12 22:26:34 -08002029 @Override
2030 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
2031 // Children of the display are statically ordered, so the real intention here is to perform
2032 // the operation on the display and not the static direct children.
2033 getParent().positionChildAt(position, this, includingParents);
2034 }
2035
Riddle Hsu57831b52018-07-27 00:31:48 +08002036 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2037 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002038 layoutAndAssignWindowLayersIfNeeded();
2039 }
2040
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002041 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002042 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2043 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002044 final int taskId = stack.taskIdFromPoint(x, y);
2045 if (taskId != -1) {
2046 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002047 }
2048 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002049 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002050 }
2051
Chong Zhang8e89b312015-09-09 15:09:30 -07002052 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002053 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002054 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002055 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002056 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002057 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002058 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002059 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2060 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002061 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002062 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002063 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002064
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002065 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2066 if (mTmpTaskForResizePointSearchResult.searchDone) {
2067 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002068 }
2069 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002070 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002071 }
2072
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002073 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08002074 // The provided task is the task on this display with focus, so if WindowManagerService's
2075 // focused app is not on this display, focusedTask will be null.
2076 if (focusedTask == null) {
2077 mTouchExcludeRegion.setEmpty();
2078 } else {
2079 mTouchExcludeRegion.set(mBaseDisplayRect);
2080 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2081 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07002082 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2083 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002084 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2085 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002086 }
2087 // If we removed the focused task above, add it back and only leave its
2088 // outside touch area in the exclusion. TapDectector is not interested in
2089 // any touch inside the focused task itself.
2090 if (!mTmpRect2.isEmpty()) {
2091 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2092 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002093 }
lumark90120a82018-08-15 00:33:03 +08002094 if (mInputMethodWindow != null && mInputMethodWindow.isVisibleLw()) {
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002095 // If the input method is visible and the user is typing, we don't want these touch
2096 // events to be intercepted and used to change focus. This would likely cause a
2097 // disappearance of the input method.
lumark90120a82018-08-15 00:33:03 +08002098 mInputMethodWindow.getTouchableRegion(mTmpRegion);
2099 if (mInputMethodWindow.getDisplayId() == mDisplayId) {
Andrii Kulian7a31b772017-05-02 13:22:42 -07002100 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2101 } else {
2102 // IME is on a different display, so we need to update its tap detector.
lumark90120a82018-08-15 00:33:03 +08002103 setTouchExcludeRegion(null /* focusedTask */);
Andrii Kulian7a31b772017-05-02 13:22:42 -07002104 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002105 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002106 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002107 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002108 win.getTouchableRegion(mTmpRegion);
2109 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2110 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002111 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2112 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2113 win.amendTapExcludeRegion(mTouchExcludeRegion);
2114 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002115 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002116 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002117 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002118 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002119 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2120 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002121 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002122 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002123 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002124 }
2125
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002126 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002127 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002128 super.switchUser();
2129 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002130 }
2131
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002132 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002133 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2134 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002135 }
2136 }
2137
Wale Ogunwale10124582016-09-15 20:25:50 -07002138 @Override
2139 void removeIfPossible() {
2140 if (isAnimating()) {
2141 mDeferredRemoval = true;
2142 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002143 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002144 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002145 }
2146
Wale Ogunwale10124582016-09-15 20:25:50 -07002147 @Override
2148 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002149 mRemovingDisplay = true;
2150 try {
2151 super.removeImmediately();
2152 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07002153 if (mService.canDispatchPointerEvents()) {
2154 if (mTapDetector != null) {
2155 mService.unregisterPointerEventListener(mTapDetector);
2156 }
2157 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
2158 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
2159 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002160 }
Jorim Jaggia3844032018-01-03 15:54:43 +01002161 mService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002162 mWindowingLayer.release();
2163 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002164 } finally {
2165 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002166 }
Bryce Leef19cbe22018-02-02 15:09:21 -08002167
Arthur Hung39134b22018-08-14 11:58:28 +08002168 mInputMonitor.onRemoved();
Bryce Leef19cbe22018-02-02 15:09:21 -08002169 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08002170 }
2171
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002172 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002173 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002174 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002175 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2176
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002177 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002178 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002179 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002180 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002181 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002182 }
2183
Andrii Kulian0214ed92017-05-16 13:44:05 -07002184 /** @return 'true' if removal of this display content is deferred due to active animation. */
2185 boolean isRemovalDeferred() {
2186 return mDeferredRemoval;
2187 }
2188
Wale Ogunwale10124582016-09-15 20:25:50 -07002189 boolean animateForIme(float interpolatedValue, float animationTarget,
2190 float dividerAnimationTarget) {
2191 boolean updated = false;
2192
Wale Ogunwale61911492017-10-11 08:50:50 -07002193 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2194 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002195 if (stack == null || !stack.isAdjustedForIme()) {
2196 continue;
2197 }
2198
2199 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2200 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2201 updated = true;
2202 } else {
2203 mDividerControllerLocked.mLastAnimationProgress =
2204 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2205 mDividerControllerLocked.mLastDividerProgress =
2206 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2207 updated |= stack.updateAdjustForIme(
2208 mDividerControllerLocked.mLastAnimationProgress,
2209 mDividerControllerLocked.mLastDividerProgress,
2210 false /* force */);
2211 }
2212 if (interpolatedValue >= 1f) {
2213 stack.endImeAdjustAnimation();
2214 }
2215 }
2216
2217 return updated;
2218 }
2219
2220 boolean clearImeAdjustAnimation() {
2221 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002222 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2223 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002224 if (stack != null && stack.isAdjustedForIme()) {
2225 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2226 changed = true;
2227 }
2228 }
2229 return changed;
2230 }
2231
2232 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002233 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2234 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002235 if (stack.isVisible() && stack.isAdjustedForIme()) {
2236 stack.beginImeAdjustAnimation();
2237 }
2238 }
2239 }
2240
2241 void adjustForImeIfNeeded() {
lumark90120a82018-08-15 00:33:03 +08002242 final WindowState imeWin = mInputMethodWindow;
Wale Ogunwale10124582016-09-15 20:25:50 -07002243 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2244 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002245 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002246 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2247 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2248 imeTargetStack.getDockSide() : DOCKED_INVALID;
2249 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2250 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2251 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002252 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002253 final boolean imeHeightChanged = imeVisible &&
2254 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2255
2256 // The divider could be adjusted for IME position, or be thinner than usual,
2257 // or both. There are three possible cases:
2258 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2259 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2260 // - If IME is not visible, divider is not moved and is normal width.
2261
2262 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002263 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2264 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002265 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002266 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2267 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002268 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2269 } else {
2270 stack.resetAdjustedForIme(false);
2271 }
2272 }
2273 mDividerControllerLocked.setAdjustedForIme(
2274 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2275 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002276 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2277 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002278 stack.resetAdjustedForIme(!dockVisible);
2279 }
2280 mDividerControllerLocked.setAdjustedForIme(
2281 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2282 }
Winson Chung655332c2016-10-31 13:14:28 -07002283 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002284 }
2285
2286 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002287 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2288 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002289 stack.prepareFreezingTaskBounds();
2290 }
2291 }
2292
Wale Ogunwale94744212015-09-21 19:01:47 -07002293 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002294 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002295
2296 // Compute a transform matrix to undo the coordinate space transformation,
2297 // and present the window at the same physical position it previously occupied.
2298 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2299 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2300
2301 mTmpRectF.set(bounds);
2302 mTmpMatrix.mapRect(mTmpRectF);
2303 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002304 }
2305
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002306 static int deltaRotation(int oldRotation, int newRotation) {
2307 int delta = newRotation - oldRotation;
2308 if (delta < 0) delta += 4;
2309 return delta;
2310 }
2311
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002312 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002313 Matrix outMatrix) {
2314 // For rotations without Z-ordering we don't need the target rectangle's position.
2315 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2316 displayHeight, outMatrix);
2317 }
2318
2319 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2320 float displayWidth, float displayHeight, Matrix outMatrix) {
2321 switch (rotation) {
2322 case ROTATION_0:
2323 outMatrix.reset();
2324 break;
2325 case ROTATION_270:
2326 outMatrix.setRotate(270, 0, 0);
2327 outMatrix.postTranslate(0, displayHeight);
2328 outMatrix.postTranslate(rectTop, 0);
2329 break;
2330 case ROTATION_180:
2331 outMatrix.reset();
2332 break;
2333 case ROTATION_90:
2334 outMatrix.setRotate(90, 0, 0);
2335 outMatrix.postTranslate(displayWidth, 0);
2336 outMatrix.postTranslate(-rectTop, rectLeft);
2337 break;
2338 }
2339 }
2340
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002341 @CallSuper
2342 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002343 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002344 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002345 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002346 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002347 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2348 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002349 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002350 }
2351 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2352 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002353 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2354 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002355 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002356 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002357 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2358 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002359 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002360 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002361 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2362 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002363 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002364 }
2365 proto.write(DPI, mBaseDisplayDensity);
2366 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002367 proto.write(ROTATION, mRotation);
2368 final ScreenRotationAnimation screenRotationAnimation =
2369 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2370 if (screenRotationAnimation != null) {
2371 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2372 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002373 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Louis Chang7501e332018-08-20 13:08:39 +08002374 proto.write(SURFACE_SIZE, mSurfaceSize);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002375 proto.end(token);
2376 }
2377
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002378 @Override
2379 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2380 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002381 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2382 final String subPrefix = " " + prefix;
2383 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2384 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2385 pw.print("dpi");
2386 if (mInitialDisplayWidth != mBaseDisplayWidth
2387 || mInitialDisplayHeight != mBaseDisplayHeight
2388 || mInitialDisplayDensity != mBaseDisplayDensity) {
2389 pw.print(" base=");
2390 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2391 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2392 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002393 if (mDisplayScalingDisabled) {
2394 pw.println(" noscale");
2395 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002396 pw.print(" cur=");
2397 pw.print(mDisplayInfo.logicalWidth);
2398 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2399 pw.print(" app=");
2400 pw.print(mDisplayInfo.appWidth);
2401 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2402 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2403 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2404 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2405 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002406 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002407 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002408 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002409
Craig Mautnerdc548482014-02-05 13:35:24 -08002410 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002411 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002412 pw.print(prefix);
2413 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002414
2415 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002416 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002417 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2418 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002419 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002420 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002421
Craig Mautnerdc548482014-02-05 13:35:24 -08002422 pw.println();
2423 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002424 pw.println();
2425 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002426 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002427 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002428 pw.print(" Exiting #"); pw.print(i);
2429 pw.print(' '); pw.print(token);
2430 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002431 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002432 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002433 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002434
Jorim Jaggi31f71702016-05-04 16:43:04 -07002435 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002436
2437 // Dump stack references
2438 final TaskStack homeStack = getHomeStack();
2439 if (homeStack != null) {
2440 pw.println(prefix + "homeStack=" + homeStack.getName());
2441 }
2442 final TaskStack pinnedStack = getPinnedStack();
2443 if (pinnedStack != null) {
2444 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2445 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002446 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002447 if (splitScreenPrimaryStack != null) {
2448 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2449 }
2450
2451 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002452 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002453 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002454 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002455
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002456 pw.println();
2457 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002458 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002459 mDisplayPolicy.dump(prefix, pw);
2460 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002461 mDisplayRotation.dump(prefix, pw);
2462 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002463 mInputMonitor.dump(pw, " ");
Craig Mautner59c00972012-07-30 12:10:24 -07002464 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002465
2466 @Override
2467 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002468 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002469 }
2470
2471 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002472 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002473 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002474
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002475 /** Returns true if the stack in the windowing mode is visible. */
2476 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002477 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002478 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002479 }
2480
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002481 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002482 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002483 final int x = (int) xf;
2484 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002485 final WindowState touchedWin = getWindow(w -> {
2486 final int flags = w.mAttrs.flags;
2487 if (!w.isVisibleLw()) {
2488 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002489 }
2490 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002491 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002492 }
2493
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002494 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002495 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002496 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002497 }
2498
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002499 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002500
2501 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002502 return mTmpRegion.contains(x, y) || touchFlags == 0;
2503 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002504
2505 return touchedWin;
2506 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002507
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002508 boolean canAddToastWindowForUid(int uid) {
2509 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002510 // Also if the app is focused adding more than one toast at
2511 // a time for better backwards compatibility.
2512 final WindowState focusedWindowForUid = getWindow(w ->
2513 w.mOwnerUid == uid && w.isFocused());
2514 if (focusedWindowForUid != null) {
2515 return true;
2516 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002517 final WindowState win = getWindow(w ->
2518 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2519 && !w.mWindowRemovalAllowed);
2520 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002521 }
2522
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002523 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002524 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2525 return;
2526 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002527
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002528 // Used to communicate the old focus to the callback method.
2529 mTmpWindow = oldFocus;
2530
2531 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002532 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002533
2534 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002535 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002536
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002537 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002538
2539 if (mTmpWindow == null) {
2540 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2541 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002542 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002543 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002544 }
2545
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002546 /** Updates the layer assignment of windows on this display. */
2547 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002548 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002549 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002550 if (setLayoutNeeded) {
2551 setLayoutNeeded();
2552 }
Robert Carrb1579c82017-09-05 14:54:47 -07002553
Robert Carrf59b8dd2017-10-02 18:58:36 -07002554 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002555 // the application of this transaction until the animation pass triggers
2556 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2557 // the hiding and showing of surfaces.
2558 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002559 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002560 }
2561
Wale Ogunwale1666e312016-12-16 11:27:18 -08002562 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2563 // moving containers or resizing them. Need to investigate the best way to have it automatically
2564 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002565 void layoutAndAssignWindowLayersIfNeeded() {
2566 mService.mWindowsChanged = true;
2567 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002568
2569 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2570 false /*updateInputWindows*/)) {
2571 assignWindowLayers(false /* setLayoutNeeded */);
2572 }
2573
Arthur Hung95b38a92018-07-20 18:56:12 +08002574 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002575 mService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08002576 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002577 }
2578
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002579 /** Returns true if a leaked surface was destroyed */
2580 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002581 // Used to indicate that a surface was leaked.
2582 mTmpWindow = null;
2583 forAllWindows(w -> {
2584 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002585 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002586 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002587 }
2588 if (!mService.mSessions.contains(wsa.mSession)) {
2589 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002590 + w + " surface=" + wsa.mSurfaceController
2591 + " token=" + w.mToken
2592 + " pid=" + w.mSession.mPid
2593 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002594 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002595 mService.mForceRemoves.add(w);
2596 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002597 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002598 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002599 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002600 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002601 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002602 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002603 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002604 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002605 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002606
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002607 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002608 }
2609
2610 /**
lumark90120a82018-08-15 00:33:03 +08002611 * Set input method window for the display.
2612 * @param win Set when window added or Null when destroyed.
2613 */
2614 void setInputMethodWindowLocked(WindowState win) {
2615 mInputMethodWindow = win;
2616 computeImeTarget(true /* updateImeTarget */);
2617 }
2618
2619 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002620 * Determine and return the window that should be the IME target.
2621 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2622 * @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 +00002623 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002624 WindowState computeImeTarget(boolean updateImeTarget) {
lumark90120a82018-08-15 00:33:03 +08002625 if (mInputMethodWindow == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002626 // There isn't an IME so there shouldn't be a target...That was easy!
2627 if (updateImeTarget) {
2628 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2629 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002630 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002631 }
2632 return null;
2633 }
2634
Chavi Weingarten3a748552018-05-14 17:32:42 +00002635 final WindowState curTarget = mService.mInputMethodTarget;
2636 if (!canUpdateImeTarget()) {
2637 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
2638 return curTarget;
2639 }
2640
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002641 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2642 // same display. Or even when the current IME/target are not on the same screen as the next
2643 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002644 mUpdateImeTarget = updateImeTarget;
2645 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002646
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002647
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002648 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2649 // to be on top of it, but it is not -really- where input will go. So look down below
2650 // for a real window to target...
2651 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2652 final AppWindowToken token = target.mAppToken;
2653 if (token != null) {
2654 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2655 if (betterTarget != null) {
2656 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002657 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002658 }
2659 }
2660
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002661 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2662 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002663
chaviw1c13ad32018-06-12 16:44:23 -07002664 // Now, a special case -- if the last target's window is in the process of exiting, but
2665 // not removed, and the new target is home, keep on the last target to avoid flicker.
2666 // Home is a special case since its above other stacks in the ordering list, but layed
2667 // out below the others.
2668 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
2669 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07002670 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00002671 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002672 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002673 }
2674
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002675 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2676 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002677
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002678 if (target == null) {
2679 if (updateImeTarget) {
2680 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2681 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2682 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002683 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002684 }
2685
2686 return null;
2687 }
2688
2689 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002690 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2691 if (token != null) {
2692
2693 // Now some fun for dealing with window animations that modify the Z order. We need
2694 // to look at all windows below the current target that are in this app, finding the
2695 // highest visible one in layering.
2696 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002697 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002698 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002699 }
2700
2701 if (highestTarget != null) {
2702 final AppTransition appTransition = mService.mAppTransition;
2703 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
Jorim Jaggi35d328a2018-08-14 17:00:20 +02002704 + " animating=" + highestTarget.isAnimating());
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002705
2706 if (appTransition.isTransitionSet()) {
2707 // If we are currently setting up for an animation, hold everything until we
2708 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002709 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002710 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002711 }
2712 }
2713 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002714
2715 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2716 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002717 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002718 }
2719
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002720 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002721 }
2722
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002723 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002724 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002725 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002726 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002727 }
2728
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002729 mService.mInputMethodTarget = target;
2730 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002731 assignWindowLayers(false /* setLayoutNeeded */);
2732 }
2733
2734 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2735 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2736 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2737 }
2738
2739 // Used to indicate we have reached the first window in the range we are interested in.
2740 mTmpWindow = null;
2741
2742 // TODO: Figure-out a more efficient way to do this.
2743 final WindowState candidate = getWindow(w -> {
2744 if (w == top) {
2745 // Reached the first window in the range we are interested in.
2746 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002747 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002748 if (mTmpWindow == null) {
2749 return false;
2750 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002751
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002752 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2753 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002754 }
2755 // If we reached the bottom of the range of windows we are considering,
2756 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002757 if (w == bottom) {
2758 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002759 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002760 return false;
2761 });
2762
2763 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002764 }
2765
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002766 void setLayoutNeeded() {
2767 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2768 mLayoutNeeded = true;
2769 }
2770
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002771 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002772 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2773 mLayoutNeeded = false;
2774 }
2775
2776 boolean isLayoutNeeded() {
2777 return mLayoutNeeded;
2778 }
2779
Wale Ogunwale02319a62016-09-26 15:21:22 -07002780 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2781 if (mTokenMap.isEmpty()) {
2782 return;
2783 }
2784 pw.println(" Display #" + mDisplayId);
2785 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2786 while (it.hasNext()) {
2787 final WindowToken token = it.next();
2788 pw.print(" ");
2789 pw.print(token);
2790 if (dumpAll) {
2791 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002792 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002793 } else {
2794 pw.println();
2795 }
2796 }
2797 }
2798
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002799 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002800 final int[] index = new int[1];
2801 forAllWindows(w -> {
2802 final WindowStateAnimator wAnim = w.mWinAnimator;
2803 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2804 index[0] = index[0] + 1;
2805 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002806 }
2807
Jorim Jaggife762342016-10-13 14:33:27 +02002808 /**
2809 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2810 */
2811 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2812 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002813 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002814 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2815 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002816 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002817 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002818 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002819 }
2820
Wale Ogunwale494009b82016-10-21 09:01:38 -07002821 boolean checkWaitingForWindows() {
2822
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002823 mHaveBootMsg = false;
2824 mHaveApp = false;
2825 mHaveWallpaper = false;
2826 mHaveKeyguard = true;
2827
2828 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002829 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2830 return true;
2831 }
2832 if (w.isDrawnLw()) {
2833 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002834 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002835 } else if (w.mAttrs.type == TYPE_APPLICATION
2836 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002837 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002838 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002839 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002840 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002841 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002842 }
2843 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002844 return false;
2845 });
2846
2847 if (visibleWindow != null) {
2848 // We have a visible window.
2849 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002850 }
2851
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002852 // if the wallpaper service is disabled on the device, we're never going to have
2853 // wallpaper, don't bother waiting for it
2854 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2855 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09002856 && mService.mContext.getResources().getBoolean(
2857 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002858 && !mService.mOnlyCore;
2859
Wale Ogunwale494009b82016-10-21 09:01:38 -07002860 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2861 "******** booted=" + mService.mSystemBooted
2862 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002863 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2864 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2865 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002866
2867 // If we are turning on the screen to show the boot message, don't do it until the boot
2868 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002869 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002870 return true;
2871 }
2872
2873 // If we are turning on the screen after the boot is completed normally, don't do so until
2874 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002875 if (mService.mSystemBooted
2876 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002877 return true;
2878 }
2879
2880 return false;
2881 }
2882
Jorim Jaggi8f520872018-08-14 17:00:20 +02002883 void updateWindowsForAnimator() {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002884 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002885 }
2886
Jorim Jaggi8f520872018-08-14 17:00:20 +02002887 /**
2888 * Updates the {@link TaskStack#setAnimationBackground} for all windows.
2889 */
2890 void updateBackgroundForAnimator() {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002891 resetAnimationBackgroundAnimator();
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002892 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002893 }
2894
Yohei Yukawa41f89c32018-09-19 14:30:04 -07002895 boolean isInputMethodClientFocus(int uid, int pid) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002896 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002897 if (imFocus == null) {
2898 return false;
2899 }
2900
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002901 if (DEBUG_INPUT_METHOD) {
2902 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2903 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2904 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002905 }
2906
Wale Ogunwale494009b82016-10-21 09:01:38 -07002907 if (DEBUG_INPUT_METHOD) {
Yohei Yukawa41f89c32018-09-19 14:30:04 -07002908 Slog.i(TAG_WM, "IM target uid/pid: " + imFocus.mSession.mUid
2909 + "/" + imFocus.mSession.mPid);
2910 Slog.i(TAG_WM, "Requesting client uid/pid: " + uid + "/" + pid);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002911 }
2912
Yohei Yukawa41f89c32018-09-19 14:30:04 -07002913 return imFocus.mSession.mUid == uid && imFocus.mSession.mPid == pid;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002914 }
2915
2916 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002917 final WindowState win = getWindow(
2918 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2919 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002920 }
2921
2922 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002923 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002924 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002925 final int curValue = w.mSystemUiVisibility;
2926 final int diff = (curValue ^ visibility) & globalDiff;
2927 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002928 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002929 w.mSeq++;
2930 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002931 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002932 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2933 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002934 visibility, newValue, diff);
2935 }
2936 } catch (RemoteException e) {
2937 // so sorry
2938 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002939 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002940 }
2941
2942 void onWindowFreezeTimeout() {
2943 Slog.w(TAG_WM, "Window freeze timeout expired.");
2944 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002945
2946 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002947 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002948 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002949 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002950 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002951 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2952 - mService.mDisplayFreezeTime);
2953 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002954 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002955 mService.mWindowPlacerLocked.performSurfacePlacement();
2956 }
2957
2958 void waitForAllWindowsDrawn() {
2959 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002960 forAllWindows(w -> {
2961 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2962 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2963 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002964 // Force add to mResizingWindows.
chaviw9c81e632018-07-31 11:17:52 -07002965 w.resetLastContentInsets();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002966 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002967 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002968 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002969 }
2970
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002971 // TODO: Super crazy long method that should be broken down...
2972 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2973
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002974 final int dw = mDisplayInfo.logicalWidth;
2975 final int dh = mDisplayInfo.logicalHeight;
2976 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2977
2978 mTmpUpdateAllDrawn.clear();
2979
2980 int repeats = 0;
2981 do {
2982 repeats++;
2983 if (repeats > 6) {
2984 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2985 clearLayoutNeeded();
2986 break;
2987 }
2988
2989 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2990 pendingLayoutChanges);
2991
Andrii Kulian839def92016-11-02 10:58:58 -07002992 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2993 // the wallpaper window jumping across displays.
2994 // Remove check for default display when there will be support for multiple wallpaper
2995 // targets (on different displays).
2996 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002997 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002998 }
2999
Riddle Hsu654a6f92018-07-13 22:59:36 +08003000 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003001 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08003002 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003003 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07003004 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003005 }
3006 }
3007
3008 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3009 setLayoutNeeded();
3010 }
3011
3012 // FIRST LOOP: Perform a layout, if needed.
3013 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3014 performLayout(repeats == 1, false /* updateInputWindows */);
3015 } else {
3016 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3017 }
3018
3019 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3020 pendingLayoutChanges = 0;
3021
3022 if (isDefaultDisplay) {
3023 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003024 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003025 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
3026 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3027 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
3028 }
3029 } while (pendingLayoutChanges != 0);
3030
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003031 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003032
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003033 mTmpRecoveringMemory = recoveringMemory;
3034 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003035 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003036
Jorim Jaggif1292892018-09-10 11:58:13 +02003037 mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003038 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Jorim Jaggif1292892018-09-10 11:58:13 +02003039 mLastHasContent,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003040 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3041 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003042 true /* inTraversal, must call performTraversalInTrans... below */);
3043
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003044 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3045 if (wallpaperVisible != mLastWallpaperVisible) {
3046 mLastWallpaperVisible = wallpaperVisible;
3047 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
3048 }
3049
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003050 while (!mTmpUpdateAllDrawn.isEmpty()) {
3051 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3052 // See if any windows have been drawn, so they (and others associated with them)
3053 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003054 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003055 }
3056
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003057 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003058 }
3059
Bryce Leef3c6a472017-11-14 14:53:06 -08003060 private void updateBounds() {
3061 calculateBounds(mTmpBounds);
3062 setBounds(mTmpBounds);
3063 }
3064
3065 // Determines the current display bounds based on the current state
3066 private void calculateBounds(Rect out) {
3067 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
3068 final int orientation = mDisplayInfo.rotation;
3069 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
3070 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3071 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
3072 int width = mDisplayInfo.logicalWidth;
3073 int left = (physWidth - width) / 2;
3074 int height = mDisplayInfo.logicalHeight;
3075 int top = (physHeight - height) / 2;
3076 out.set(left, top, left + width, top + height);
3077 }
3078
3079 @Override
3080 public void getBounds(Rect out) {
3081 calculateBounds(out);
3082 }
3083
3084 private void getBounds(Rect out, int orientation) {
3085 getBounds(out);
3086
3087 // Rotate the Rect if needed.
3088 final int currentRotation = mDisplayInfo.rotation;
3089 final int rotationDelta = deltaRotation(currentRotation, orientation);
3090 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3091 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3092 mTmpRectF.set(out);
3093 mTmpMatrix.mapRect(mTmpRectF);
3094 mTmpRectF.round(out);
3095 }
3096 }
3097
Louis Chang7501e332018-08-20 13:08:39 +08003098 int getSurfaceSize() {
3099 return mSurfaceSize;
3100 }
3101
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003102 void performLayout(boolean initial, boolean updateInputWindows) {
3103 if (!isLayoutNeeded()) {
3104 return;
3105 }
3106 clearLayoutNeeded();
3107
3108 final int dw = mDisplayInfo.logicalWidth;
3109 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003110 if (DEBUG_LAYOUT) {
3111 Slog.v(TAG, "-------------------------------------");
3112 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3113 }
3114
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003115 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3116 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003117 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3118 // display info above...
3119 mDisplayFrames.mRotation = mRotation;
3120 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003121 if (isDefaultDisplay) {
3122 // Not needed on non-default displays.
3123 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
3124 mService.mScreenRect.set(0, 0, dw, dh);
3125 }
3126
Adrian Roos5251b1d2018-03-23 18:57:43 +01003127 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003128 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003129 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003130
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003131 // Used to indicate that we have processed the dream window and all additional windows are
3132 // behind it.
3133 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003134 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003135
3136 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003137 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003138
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003139 // Used to indicate that we have processed the dream window and all additional attached
3140 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003141 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003142 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003143
3144 // Now perform layout of attached windows, which usually depend on the position of the
3145 // window they are attached to. XXX does not deal with windows that are attached to windows
3146 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003147 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003148
3149 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003150 mInputMonitor.layoutInputConsumers(dw, dh);
3151 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003152 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003153 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003154 }
3155
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003156 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
3157 }
3158
3159 /**
3160 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3161 * In portrait mode, it grabs the full screenshot.
3162 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003163 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003164 */
chaviw0315a1a2018-03-05 15:28:35 -08003165 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
3166 if (!mService.mPolicy.isScreenOn()) {
3167 if (DEBUG_SCREENSHOT) {
3168 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003169 }
chaviw0315a1a2018-03-05 15:28:35 -08003170 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003171 }
chaviwfbe47df2017-11-10 16:14:49 -08003172
chaviw0315a1a2018-03-05 15:28:35 -08003173 int dw = mDisplayInfo.logicalWidth;
3174 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003175
chaviw0315a1a2018-03-05 15:28:35 -08003176 if (dw <= 0 || dh <= 0) {
3177 return null;
3178 }
chaviwfbe47df2017-11-10 16:14:49 -08003179
chaviw0315a1a2018-03-05 15:28:35 -08003180 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003181
chaviw0315a1a2018-03-05 15:28:35 -08003182 // The screenshot API does not apply the current screen rotation.
3183 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003184
chaviw0315a1a2018-03-05 15:28:35 -08003185 if (rot == ROTATION_90 || rot == ROTATION_270) {
3186 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3187 }
chaviwfbe47df2017-11-10 16:14:49 -08003188
chaviw0315a1a2018-03-05 15:28:35 -08003189 // SurfaceFlinger is not aware of orientation, so convert our logical
3190 // crop to SurfaceFlinger's portrait orientation.
3191 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3192
3193 final ScreenRotationAnimation screenRotationAnimation =
3194 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3195 final boolean inRotation = screenRotationAnimation != null &&
3196 screenRotationAnimation.isAnimating();
3197 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3198
3199 // TODO(b/68392460): We should screenshot Task controls directly
3200 // but it's difficult at the moment as the Task doesn't have the
3201 // correct size set.
chaviw08520a02018-09-10 16:44:56 -07003202 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, inRotation, rot);
chaviw0315a1a2018-03-05 15:28:35 -08003203 if (bitmap == null) {
3204 Slog.w(TAG_WM, "Failed to take screenshot");
3205 return null;
3206 }
3207
3208 // Create a copy of the screenshot that is immutable and backed in ashmem.
3209 // This greatly reduces the overhead of passing the bitmap between processes.
3210 final Bitmap ret = bitmap.createAshmemBitmap(config);
3211 bitmap.recycle();
3212 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003213 }
3214
3215 // TODO: Can this use createRotationMatrix()?
3216 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3217 if (rot == Surface.ROTATION_90) {
3218 final int tmp = crop.top;
3219 crop.top = dw - crop.right;
3220 crop.right = crop.bottom;
3221 crop.bottom = dw - crop.left;
3222 crop.left = tmp;
3223 } else if (rot == Surface.ROTATION_180) {
3224 int tmp = crop.top;
3225 crop.top = dh - crop.bottom;
3226 crop.bottom = dh - tmp;
3227 tmp = crop.right;
3228 crop.right = dw - crop.left;
3229 crop.left = dw - tmp;
3230 } else if (rot == Surface.ROTATION_270) {
3231 final int tmp = crop.top;
3232 crop.top = crop.left;
3233 crop.left = dh - crop.bottom;
3234 crop.bottom = crop.right;
3235 crop.right = dh - tmp;
3236 }
3237 }
3238
3239 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003240 // Used to indicate the layout is needed.
3241 mTmpWindow = null;
3242
3243 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003244 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003245 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003246 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003247 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003248 w.setDisplayLayoutNeeded();
3249 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003250 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003251
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003252 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003253 mService.mWindowPlacerLocked.performSurfacePlacement();
3254 }
3255 }
3256
Wale Ogunwale1666e312016-12-16 11:27:18 -08003257 void setExitingTokensHasVisible(boolean hasVisible) {
3258 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3259 mExitingTokens.get(i).hasVisible = hasVisible;
3260 }
3261
3262 // Initialize state of exiting applications.
3263 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3264 }
3265
3266 void removeExistingTokensIfPossible() {
3267 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3268 final WindowToken token = mExitingTokens.get(i);
3269 if (!token.hasVisible) {
3270 mExitingTokens.remove(i);
3271 }
3272 }
3273
3274 // Time to remove any exiting applications?
3275 mTaskStackContainers.removeExistingAppTokensIfPossible();
3276 }
3277
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003278 @Override
3279 void onDescendantOverrideConfigurationChanged() {
3280 setLayoutNeeded();
3281 mService.requestTraversal();
3282 }
3283
David Stevens9440dc82017-03-16 19:00:20 -07003284 boolean okToDisplay() {
3285 if (mDisplayId == DEFAULT_DISPLAY) {
3286 return !mService.mDisplayFrozen
3287 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3288 }
3289 return mDisplayInfo.state == Display.STATE_ON;
3290 }
3291
3292 boolean okToAnimate() {
3293 return okToDisplay() &&
3294 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3295 }
3296
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003297 static final class TaskForResizePointSearchResult {
3298 boolean searchDone;
3299 Task taskForResize;
3300
3301 void reset() {
3302 searchDone = false;
3303 taskForResize = null;
3304 }
3305 }
Robert Carr3b716242016-08-16 16:02:21 -07003306
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003307 private static final class ApplySurfaceChangesTransactionState {
3308 boolean displayHasContent;
3309 boolean obscured;
3310 boolean syswin;
3311 boolean focusDisplayed;
3312 float preferredRefreshRate;
3313 int preferredModeId;
3314
3315 void reset() {
3316 displayHasContent = false;
3317 obscured = false;
3318 syswin = false;
3319 focusDisplayed = false;
3320 preferredRefreshRate = 0;
3321 preferredModeId = 0;
3322 }
3323 }
3324
3325 private static final class ScreenshotApplicationState {
3326 WindowState appWin;
3327 int maxLayer;
3328 int minLayer;
3329 boolean screenshotReady;
3330
3331 void reset(boolean screenshotReady) {
3332 appWin = null;
3333 maxLayer = 0;
3334 minLayer = 0;
3335 this.screenshotReady = screenshotReady;
3336 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3337 }
3338 }
3339
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003340 /**
3341 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3342 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3343 * homogeneous children type which is currently required by sub-classes of
3344 * {@link WindowContainer} class.
3345 */
3346 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3347
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003348 DisplayChildWindowContainer(WindowManagerService service) {
3349 super(service);
3350 }
3351
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003352 @Override
3353 boolean fillsParent() {
3354 return true;
3355 }
3356
3357 @Override
3358 boolean isVisible() {
3359 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003360 }
3361 }
3362
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003363 /**
3364 * Window container class that contains all containers on this display relating to Apps.
3365 * I.e Activities.
3366 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003367 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003368 /**
3369 * A control placed at the appropriate level for transitions to occur.
3370 */
chaviw23ee71c2017-12-18 11:29:41 -08003371 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003372 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003373 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003374
Robert Carrf7a7ca82017-12-06 13:17:07 -08003375 /**
3376 * Given that the split-screen divider does not have an AppWindowToken, it
3377 * will have to live inside of a "NonAppWindowContainer", in particular
3378 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3379 * it will need to be interleaved with some of our children, appearing on top of
3380 * both docked stacks but underneath any assistant stacks.
3381 *
3382 * To solve this problem we have this anchor control, which will always exist so
3383 * we can always assign it the correct value in our {@link #assignChildLayers}.
3384 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3385 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3386 * events between the two containers.
3387 */
3388 SurfaceControl mSplitScreenDividerAnchor = null;
3389
Wale Ogunwale61911492017-10-11 08:50:50 -07003390 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3391 // through the list to find them.
3392 private TaskStack mHomeStack = null;
3393 private TaskStack mPinnedStack = null;
3394 private TaskStack mSplitScreenPrimaryStack = null;
3395
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003396 TaskStackContainers(WindowManagerService service) {
3397 super(service);
3398 }
3399
Wale Ogunwale61911492017-10-11 08:50:50 -07003400 /**
3401 * Returns the topmost stack on the display that is compatible with the input windowing mode
3402 * and activity type. Null is no compatible stack on the display.
3403 */
3404 TaskStack getStack(int windowingMode, int activityType) {
3405 if (activityType == ACTIVITY_TYPE_HOME) {
3406 return mHomeStack;
3407 }
3408 if (windowingMode == WINDOWING_MODE_PINNED) {
3409 return mPinnedStack;
3410 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3411 return mSplitScreenPrimaryStack;
3412 }
3413 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3414 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003415 if (activityType == ACTIVITY_TYPE_UNDEFINED
3416 && windowingMode == stack.getWindowingMode()) {
3417 // Passing in undefined type means we want to match the topmost stack with the
3418 // windowing mode.
3419 return stack;
3420 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003421 if (stack.isCompatible(windowingMode, activityType)) {
3422 return stack;
3423 }
3424 }
3425 return null;
3426 }
3427
3428 @VisibleForTesting
3429 TaskStack getTopStack() {
3430 return mTaskStackContainers.getChildCount() > 0
3431 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3432 }
3433
3434 TaskStack getHomeStack() {
3435 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3436 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3437 }
3438 return mHomeStack;
3439 }
3440
3441 TaskStack getPinnedStack() {
3442 return mPinnedStack;
3443 }
3444
Matthew Ng64e77cf2017-10-31 14:01:31 -07003445 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003446 return mSplitScreenPrimaryStack;
3447 }
3448
Winson Chunge2d72172018-01-25 17:46:20 +00003449 ArrayList<Task> getVisibleTasks() {
3450 final ArrayList<Task> visibleTasks = new ArrayList<>();
3451 forAllTasks(task -> {
3452 if (task.isVisible()) {
3453 visibleTasks.add(task);
3454 }
3455 });
3456 return visibleTasks;
3457 }
3458
Andrii Kulian839def92016-11-02 10:58:58 -07003459 /**
3460 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003461 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003462 */
3463 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003464 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003465 addChild(stack, onTop);
3466 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003467 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003468
Wale Ogunwale61911492017-10-11 08:50:50 -07003469 void onStackWindowingModeChanged(TaskStack stack) {
3470 removeStackReferenceIfNeeded(stack);
3471 addStackReferenceIfNeeded(stack);
3472 if (stack == mPinnedStack && getTopStack() != stack) {
3473 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3474 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3475 }
3476 }
3477
3478 private void addStackReferenceIfNeeded(TaskStack stack) {
3479 if (stack.isActivityTypeHome()) {
3480 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003481 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003482 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003483
Wale Ogunwale61911492017-10-11 08:50:50 -07003484 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003485 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003486 }
3487 final int windowingMode = stack.getWindowingMode();
3488 if (windowingMode == WINDOWING_MODE_PINNED) {
3489 if (mPinnedStack != null) {
3490 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3491 + mPinnedStack + " already exist on display=" + this
3492 + " stack=" + stack);
3493 }
3494 mPinnedStack = stack;
3495 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3496 if (mSplitScreenPrimaryStack != null) {
3497 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3498 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3499 + " already exist on display=" + this + " stack=" + stack);
3500 }
3501 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003502 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003503 }
3504 }
3505
3506 private void removeStackReferenceIfNeeded(TaskStack stack) {
3507 if (stack == mHomeStack) {
3508 mHomeStack = null;
3509 } else if (stack == mPinnedStack) {
3510 mPinnedStack = null;
3511 } else if (stack == mSplitScreenPrimaryStack) {
3512 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003513 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3514 mService.setDockedStackCreateStateLocked(
3515 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3516 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003517 }
Andrii Kulian839def92016-11-02 10:58:58 -07003518 }
3519
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003520 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003521 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3522 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003523 addChild(stack, addIndex);
3524 setLayoutNeeded();
3525 }
3526
Wale Ogunwale61911492017-10-11 08:50:50 -07003527 @Override
3528 protected void removeChild(TaskStack stack) {
3529 super.removeChild(stack);
3530 removeStackReferenceIfNeeded(stack);
3531 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003532
3533 @Override
3534 boolean isOnTop() {
3535 // Considered always on top
3536 return true;
3537 }
3538
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003539 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003540 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003541 if (child.getWindowConfiguration().isAlwaysOnTop()
3542 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003543 // This stack is always-on-top, override the default behavior.
3544 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3545
3546 // Moving to its current position, as we must call super but we don't want to
3547 // perform any meaningful action.
3548 final int currentPosition = mChildren.indexOf(child);
3549 super.positionChildAt(currentPosition, child, false /* includingParents */);
3550 return;
3551 }
3552
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003553 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3554 super.positionChildAt(targetPosition, child, includingParents);
3555
Riddle Hsu2f6e1742018-08-23 22:44:36 +08003556 if (includingParents) {
3557 // We still want to move the display of this stack container to top because even the
3558 // target position is adjusted to non-top, the intention of the condition is to have
3559 // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front
3560 // in a non-top display which is using picture-in-picture mode).
3561 final int topChildPosition = getChildCount() - 1;
3562 if (targetPosition < topChildPosition && position >= topChildPosition) {
3563 getParent().positionChildAt(POSITION_TOP, this /* child */,
3564 true /* includingParents */);
3565 }
3566 }
3567
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003568 setLayoutNeeded();
3569 }
3570
3571 /**
3572 * When stack is added or repositioned, find a proper position for it.
3573 * This will make sure that pinned stack always stays on top.
3574 * @param requestedPosition Position requested by caller.
3575 * @param stack Stack to be added or positioned.
3576 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3577 * @return The proper position for the stack.
3578 */
3579 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003580 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09003581 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09003582 }
3583
Kazuki Takisef85197b2018-06-18 18:18:36 +09003584 final int topChildPosition = mChildren.size() - 1;
3585 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
3586 for (int i = topChildPosition; i >= 0; --i) {
3587 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
3588 belowAlwaysOnTopPosition = i;
3589 break;
3590 }
3591 }
3592
3593 // The max possible position we can insert the stack at.
3594 int maxPosition = POSITION_TOP;
3595 // The min possible position we can insert the stack at.
3596 int minPosition = POSITION_BOTTOM;
3597
3598 if (stack.isAlwaysOnTop()) {
3599 if (hasPinnedStack()) {
3600 // Always-on-top stacks go below the pinned stack.
3601 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
3602 }
3603 // Always-on-top stacks need to be above all other stacks.
3604 minPosition = belowAlwaysOnTopPosition !=
3605 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
3606 } else {
3607 // Other stacks need to be below the always-on-top stacks.
3608 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08003609 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09003610 }
3611
3612 int targetPosition = requestedPosition;
3613 targetPosition = Math.min(targetPosition, maxPosition);
3614 targetPosition = Math.max(targetPosition, minPosition);
3615
3616 int prevPosition = getStacks().indexOf(stack);
3617 // The positions we calculated above (maxPosition, minPosition) do not take into
3618 // consideration the following edge cases.
3619 // 1) We need to adjust the position depending on the value "adding".
3620 // 2) When we are moving a stack to another position, we also need to adjust the
3621 // position depending on whether the stack is moving to a higher or lower position.
3622 if ((targetPosition != requestedPosition) &&
3623 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003624 targetPosition++;
3625 }
3626
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003627 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003628 }
3629
3630 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003631 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3632 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003633 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003634 if (super.forAllWindows(callback, traverseTopToBottom)) {
3635 return true;
3636 }
3637 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3638 return true;
3639 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003640 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003641 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3642 return true;
3643 }
3644 if (super.forAllWindows(callback, traverseTopToBottom)) {
3645 return true;
3646 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003647 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003648 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003649 }
3650
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003651 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003652 boolean traverseTopToBottom) {
3653 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3654 // app tokens.
3655 // TODO: Investigate if we need to continue to do this or if we can just process them
3656 // in-order.
3657 if (traverseTopToBottom) {
3658 for (int i = mChildren.size() - 1; i >= 0; --i) {
3659 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3660 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003661 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3662 traverseTopToBottom)) {
3663 return true;
3664 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003665 }
3666 }
3667 } else {
3668 final int count = mChildren.size();
3669 for (int i = 0; i < count; ++i) {
3670 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3671 final int appTokensCount = appTokens.size();
3672 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003673 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3674 traverseTopToBottom)) {
3675 return true;
3676 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003677 }
3678 }
3679 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003680 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003681 }
3682
Wale Ogunwale1666e312016-12-16 11:27:18 -08003683 void setExitingTokensHasVisible(boolean hasVisible) {
3684 for (int i = mChildren.size() - 1; i >= 0; --i) {
3685 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3686 for (int j = appTokens.size() - 1; j >= 0; --j) {
3687 appTokens.get(j).hasVisible = hasVisible;
3688 }
3689 }
3690 }
3691
3692 void removeExistingAppTokensIfPossible() {
3693 for (int i = mChildren.size() - 1; i >= 0; --i) {
3694 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3695 for (int j = appTokens.size() - 1; j >= 0; --j) {
3696 final AppWindowToken token = appTokens.get(j);
3697 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3698 && (!token.mIsExiting || token.isEmpty())) {
3699 // Make sure there is no animation running on this token, so any windows
3700 // associated with it will be removed as soon as their animations are
3701 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003702 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003703 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3704 "performLayout: App token exiting now removed" + token);
3705 token.removeIfPossible();
3706 }
3707 }
3708 }
3709 }
3710
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003711 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003712 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003713 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3714 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003715 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07003716 // docked or freeform stack is visible...except for the home stack if the docked
3717 // stack is minimized and it actually set something and the bounds is different from
3718 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003719 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003720 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003721 && !(mDividerControllerLocked.isHomeStackResizable()
3722 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003723 final int orientation = mHomeStack.getOrientation();
3724 if (orientation != SCREEN_ORIENTATION_UNSET) {
3725 return orientation;
3726 }
3727 }
3728 return SCREEN_ORIENTATION_UNSPECIFIED;
3729 }
3730
3731 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003732 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3733 PackageManager.FEATURE_AUTOMOTIVE);
3734 if (isCar) {
3735 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3736 // allow anything but the default orientation.
3737 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003738 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
3739 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07003740 return SCREEN_ORIENTATION_UNSPECIFIED;
3741 }
3742
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003743 if (orientation != SCREEN_ORIENTATION_UNSET
3744 && orientation != SCREEN_ORIENTATION_BEHIND) {
3745 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003746 "App is requesting an orientation, return " + orientation
3747 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003748 return orientation;
3749 }
3750
3751 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003752 "No app is requesting an orientation, return " + mLastOrientation
3753 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003754 // The next app has not been requested to be visible, so we keep the current orientation
3755 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003756 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003757 }
Robert Carrb1579c82017-09-05 14:54:47 -07003758
3759 @Override
3760 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003761 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003762
Robert Carr2f8aa392018-01-31 14:46:51 -08003763 for (int i = 0; i < mChildren.size(); i++) {
3764 final TaskStack s = mChildren.get(i);
3765 s.assignChildLayers(t);
3766 }
3767 }
3768
3769 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02003770
Robert Carrf7a7ca82017-12-06 13:17:07 -08003771 final int HOME_STACK_STATE = 0;
3772 final int NORMAL_STACK_STATE = 1;
3773 final int ALWAYS_ON_TOP_STATE = 2;
3774
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003775 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003776 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02003777 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02003778 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003779
Robert Carrf7a7ca82017-12-06 13:17:07 -08003780 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3781 for (int i = 0; i < mChildren.size(); i++) {
3782 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003783 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3784 continue;
3785 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3786 || s.isAlwaysOnTop())) {
3787 continue;
3788 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3789 continue;
3790 }
3791 s.assignLayer(t, layer++);
3792 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3793 t.setLayer(mSplitScreenDividerAnchor, layer++);
3794 }
Winson Chungd41f71d2018-03-16 15:26:07 -07003795 if ((s.isTaskAnimating() || s.isAppAnimating())
3796 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003797 // Ensure the animation layer ends up above the
3798 // highest animating stack and no higher.
3799 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003800 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003801 if (state != ALWAYS_ON_TOP_STATE) {
3802 layerForBoostedAnimationLayer = layer++;
3803 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08003804 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003805 if (state == HOME_STACK_STATE) {
3806 layerForHomeAnimationLayer = layer++;
3807 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003808 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003809 if (mAppAnimationLayer != null) {
3810 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003811 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003812 if (mBoostedAppAnimationLayer != null) {
3813 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
3814 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003815 if (mHomeAppAnimationLayer != null) {
3816 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
3817 }
Robert Carrb1579c82017-09-05 14:54:47 -07003818 }
3819
3820 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02003821 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
3822 switch (animationLayer) {
3823 case ANIMATION_LAYER_BOOSTED:
3824 return mBoostedAppAnimationLayer;
3825 case ANIMATION_LAYER_HOME:
3826 return mHomeAppAnimationLayer;
3827 case ANIMATION_LAYER_STANDARD:
3828 default:
3829 return mAppAnimationLayer;
3830 }
chaviw23ee71c2017-12-18 11:29:41 -08003831 }
3832
Robert Carrf7a7ca82017-12-06 13:17:07 -08003833 SurfaceControl getSplitScreenDividerAnchor() {
3834 return mSplitScreenDividerAnchor;
3835 }
3836
chaviw23ee71c2017-12-18 11:29:41 -08003837 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003838 void onParentSet() {
3839 super.onParentSet();
3840 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003841 mAppAnimationLayer = makeChildSurface(null)
3842 .setName("animationLayer")
3843 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02003844 mBoostedAppAnimationLayer = makeChildSurface(null)
3845 .setName("boostedAnimationLayer")
3846 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02003847 mHomeAppAnimationLayer = makeChildSurface(null)
3848 .setName("homeAnimationLayer")
3849 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003850 mSplitScreenDividerAnchor = makeChildSurface(null)
3851 .setName("splitScreenDividerAnchor")
3852 .build();
3853 getPendingTransaction()
3854 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02003855 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02003856 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08003857 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003858 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003859 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003860 mAppAnimationLayer.destroy();
3861 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003862 mBoostedAppAnimationLayer.destroy();
3863 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003864 mHomeAppAnimationLayer.destroy();
3865 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003866 mSplitScreenDividerAnchor.destroy();
3867 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003868 }
3869 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003870 }
3871
Robert Carree4d4b92017-11-22 12:21:46 -08003872 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003873 AboveAppWindowContainers(String name, WindowManagerService service) {
3874 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003875 }
3876
Robert Carrb9506032018-02-13 13:54:00 -08003877 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07003878 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
3879 final SurfaceControl.Builder builder = super.makeChildSurface(child);
3880 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
3881 // To draw above the ColorFade layer during the screen off transition, the
3882 // rounded corner overlays need to be at the root of the surface hierarchy.
3883 // TODO: move the ColorLayer into the display overlay layer such that this is not
3884 // necessary anymore.
3885 builder.setParent(null);
3886 }
3887 return builder;
3888 }
3889
3890 @Override
Robert Carrb9506032018-02-13 13:54:00 -08003891 void assignChildLayers(SurfaceControl.Transaction t) {
3892 assignChildLayers(t, null /* imeContainer */);
3893 }
3894
Robert Carree4d4b92017-11-22 12:21:46 -08003895 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3896 boolean needAssignIme = imeContainer != null
3897 && imeContainer.getSurfaceControl() != null;
3898 for (int j = 0; j < mChildren.size(); ++j) {
3899 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003900
3901 // See {@link mSplitScreenDividerAnchor}
3902 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3903 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3904 continue;
3905 }
Vishnu Nair83537a72018-07-19 21:27:48 -07003906 if (wt.mRoundedCornerOverlay) {
3907 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
3908 continue;
3909 }
Robert Carree4d4b92017-11-22 12:21:46 -08003910 wt.assignLayer(t, j);
3911 wt.assignChildLayers(t);
3912
3913 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3914 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003915
3916 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3917 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003918 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003919 needAssignIme = false;
3920 }
3921 }
3922 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003923 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003924 }
3925 }
3926 }
3927
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003928 /**
3929 * Window container class that contains all containers on this display that are not related to
3930 * Apps. E.g. status bar.
3931 */
Robert Carree4d4b92017-11-22 12:21:46 -08003932 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003933 /**
3934 * Compares two child window tokens returns -1 if the first is lesser than the second in
3935 * terms of z-order and 1 otherwise.
3936 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003937 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003938 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003939 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3940 token1.mOwnerCanManageAppTokens)
3941 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3942 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003943
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003944 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3945 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3946 return false;
3947 }
3948 final int req = w.mAttrs.screenOrientation;
3949 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3950 || req == SCREEN_ORIENTATION_UNSET) {
3951 return false;
3952 }
3953 return true;
3954 };
3955
Wale Ogunwale3a931692016-11-02 16:49:48 -07003956 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003957 private final Dimmer mDimmer = new Dimmer(this);
3958 private final Rect mTmpDimBoundsRect = new Rect();
3959
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003960 NonAppWindowContainers(String name, WindowManagerService service) {
3961 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003962 mName = name;
3963 }
3964
3965 void addChild(WindowToken token) {
3966 addChild(token, mWindowComparator);
3967 }
3968
3969 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003970 int getOrientation() {
3971 final WindowManagerPolicy policy = mService.mPolicy;
3972 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003973 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003974
3975 if (win != null) {
3976 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003977 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003978 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003979 if (mService.mKeyguardGoingAway) {
3980 // Keyguard can't affect the orientation if it is going away...
3981 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3982 return SCREEN_ORIENTATION_UNSET;
3983 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003984 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003985 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
3986 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003987 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003988 }
3989
Andrii Kulian8ee72852017-03-10 10:36:45 -08003990 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003991
Jorim Jaggi1c530592018-04-06 15:11:47 +02003992 // Only allow force setting the orientation when all unknown visibilities have been
3993 // resolved, as otherwise we just may be starting another occluding activity.
3994 final boolean isUnoccluding =
3995 mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
3996 && mService.mUnknownAppVisibilityController.allResolved();
3997 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003998 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003999 }
4000
4001 return SCREEN_ORIENTATION_UNSET;
4002 }
4003
4004 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07004005 String getName() {
4006 return mName;
4007 }
chaviwf29223e2018-01-31 13:23:51 -08004008
4009 @Override
4010 Dimmer getDimmer() {
4011 return mDimmer;
4012 }
4013
4014 @Override
4015 void prepareSurfaces() {
4016 mDimmer.resetDimStates();
4017 super.prepareSurfaces();
4018 getBounds(mTmpDimBoundsRect);
4019
4020 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4021 scheduleAnimation();
4022 }
4023 }
Robert Carr3b716242016-08-16 16:02:21 -07004024 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004025
Robert Carr9034d962018-01-04 18:27:42 -08004026 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4027 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4028 super(name, service);
4029 }
4030
4031 @Override
4032 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4033 }
4034 };
4035
Robert Carrb1579c82017-09-05 14:54:47 -07004036 SurfaceControl.Builder makeSurface(SurfaceSession s) {
4037 return mService.makeSurfaceBuilder(s)
4038 .setParent(mWindowingLayer);
4039 }
4040
4041 @Override
4042 SurfaceSession getSession() {
4043 return mSession;
4044 }
4045
4046 @Override
4047 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004048 SurfaceSession s = child != null ? child.getSession() : getSession();
4049 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07004050 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004051
4052 if (child == null) {
4053 return b;
4054 }
4055
Robert Carree4d4b92017-11-22 12:21:46 -08004056 return b.setName(child.getName())
4057 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004058 }
4059
4060 /**
4061 * The makeSurface variants are for use by the window-container
4062 * hierarchy. makeOverlay here is a function for various non windowing
4063 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4064 * and other potpourii.
4065 */
4066 SurfaceControl.Builder makeOverlay() {
4067 return mService.makeSurfaceBuilder(mSession)
4068 .setParent(mOverlayLayer);
4069 }
4070
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004071 /**
4072 * Reparents the given surface to mOverlayLayer.
4073 */
4074 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4075 transaction.reparent(surface, mOverlayLayer.getHandle());
4076 }
4077
Robert Carrb1579c82017-09-05 14:54:47 -07004078 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004079 if (spec.scale != 1.0) {
4080 mMagnificationSpec = spec;
4081 } else {
4082 mMagnificationSpec = null;
4083 }
4084
Robert Carrf59b8dd2017-10-02 18:58:36 -07004085 applyMagnificationSpec(getPendingTransaction(), spec);
4086 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004087 }
4088
Robert Carr24be9ab2018-04-30 17:54:53 -07004089 void reapplyMagnificationSpec() {
4090 if (mMagnificationSpec != null) {
4091 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4092 }
4093 }
4094
Robert Carrb1579c82017-09-05 14:54:47 -07004095 @Override
4096 void onParentSet() {
4097 // Since we are the top of the SurfaceControl hierarchy here
4098 // we create the root surfaces explicitly rather than chaining
4099 // up as the default implementation in onParentSet does. So we
4100 // explicitly do NOT call super here.
4101 }
4102
4103 @Override
4104 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004105
4106 // These are layers as children of "mWindowingLayer"
4107 mBelowAppWindowsContainers.assignLayer(t, 0);
4108 mTaskStackContainers.assignLayer(t, 1);
4109 mAboveAppWindowsContainers.assignLayer(t, 2);
4110
4111 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004112 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004113
Robert Carree4d4b92017-11-22 12:21:46 -08004114 // In the case where we have an IME target that is not in split-screen
4115 // mode IME assignment is easy. We just need the IME to go directly above
4116 // the target. This way children of the target will naturally go above the IME
4117 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004118 //
Robert Carree4d4b92017-11-22 12:21:46 -08004119 // In the case of split-screen windowing mode, we need to elevate the IME above the
4120 // docked divider while keeping the app itself below the docked divider, so instead
4121 // we use relative layering of the IME targets child windows, and place the
4122 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004123 //
Robert Carr234b6332018-03-20 13:38:16 -07004124 // In the case the IME target is animating, the animation Z order may be different
4125 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4126 // IME target. In this case we just layer the IME over all transitions by placing it in the
4127 // above applications layer.
4128 //
Robert Carree4d4b92017-11-22 12:21:46 -08004129 // In the case where we have no IME target we assign it where it's base layer would
4130 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004131 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4132 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004133 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004134 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004135 // TODO: We need to use an extra level on the app surface to ensure
4136 // this is always above SurfaceView but always below attached window.
4137 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004138 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004139 }
4140
4141 // Above we have assigned layers to our children, now we ask them to assign
4142 // layers to their children.
4143 mBelowAppWindowsContainers.assignChildLayers(t);
4144 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004145 mAboveAppWindowsContainers.assignChildLayers(t,
4146 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004147 mImeWindowsContainers.assignChildLayers(t);
4148 }
4149
4150 /**
4151 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4152 * that the IME target is one of the docked applications. We'd like the docked divider to be
4153 * above both of the applications, and we'd like the IME to be above the docked divider.
4154 * However we need child windows of the applications to be above the IME (Text drag handles).
4155 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4156 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
4157 * with {@link #WindowState#assignLayer}
4158 */
4159 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004160 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004161 }
4162
4163 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004164 void prepareSurfaces() {
4165 final ScreenRotationAnimation screenRotationAnimation =
4166 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
4167 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4168 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4169 mPendingTransaction.setMatrix(mWindowingLayer,
4170 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4171 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4172 mPendingTransaction.setPosition(mWindowingLayer,
4173 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4174 mPendingTransaction.setAlpha(mWindowingLayer,
4175 screenRotationAnimation.getEnterTransformation().getAlpha());
4176 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004177
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004178 super.prepareSurfaces();
4179 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004180
Jorim Jaggibe418292018-03-26 16:14:12 +02004181 void assignStackOrdering() {
4182 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004183 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004184
4185 /**
4186 * Increment the deferral count to determine whether to update the IME target.
4187 */
4188 void deferUpdateImeTarget() {
4189 mDeferUpdateImeTargetCount++;
4190 }
4191
4192 /**
4193 * Decrement the deferral count to determine whether to update the IME target. If the count
4194 * reaches 0, a new ime target will get computed.
4195 */
4196 void continueUpdateImeTarget() {
4197 if (mDeferUpdateImeTargetCount == 0) {
4198 return;
4199 }
4200
4201 mDeferUpdateImeTargetCount--;
4202 if (mDeferUpdateImeTargetCount == 0) {
4203 computeImeTarget(true /* updateImeTarget */);
4204 }
4205 }
4206
4207 /**
4208 * @return Whether a new IME target should be computed.
4209 */
4210 private boolean canUpdateImeTarget() {
4211 return mDeferUpdateImeTargetCount == 0;
4212 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004213
4214 InputMonitor getInputMonitor() {
4215 return mInputMonitor;
4216 }
Jorim Jaggif1292892018-09-10 11:58:13 +02004217
4218 /**
4219 * @return Cached value whether we told display manager that we have content.
4220 */
4221 boolean getLastHasContent() {
4222 return mLastHasContent;
4223 }
Craig Mautner59c00972012-07-30 12:10:24 -07004224}