blob: ab38f650bc8826fb88bfc54c46da2218d5302584 [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;
Louis Chang7d0037c2018-08-13 12:42:06 +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;
Louis Chang7d0037c2018-08-13 12:42:06 +080067import static com.android.server.wm.DisplayContentProto.ABOVE_APP_WINDOWS;
68import static com.android.server.wm.DisplayContentProto.BELOW_APP_WINDOWS;
69import static com.android.server.wm.DisplayContentProto.DISPLAY_FRAMES;
70import static com.android.server.wm.DisplayContentProto.DISPLAY_INFO;
71import static com.android.server.wm.DisplayContentProto.DOCKED_STACK_DIVIDER_CONTROLLER;
72import static com.android.server.wm.DisplayContentProto.DPI;
73import static com.android.server.wm.DisplayContentProto.ID;
74import static com.android.server.wm.DisplayContentProto.IME_WINDOWS;
75import static com.android.server.wm.DisplayContentProto.PINNED_STACK_CONTROLLER;
76import static com.android.server.wm.DisplayContentProto.ROTATION;
77import static com.android.server.wm.DisplayContentProto.SCREEN_ROTATION_ANIMATION;
78import static com.android.server.wm.DisplayContentProto.STACKS;
79import static com.android.server.wm.DisplayContentProto.WINDOW_CONTAINER;
Wale Ogunwale1666e312016-12-16 11:27:18 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070085import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070095import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070096import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070097import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080098import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070099import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700100import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
101import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700102import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700103import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700104import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
105import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700106import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700107import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700108import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700109import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700110import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700111import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700112import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700113import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700114import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700115import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Louis Chang7d0037c2018-08-13 12:42:06 +0800116import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700117
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700118import android.annotation.CallSuper;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700119import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700120import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700121import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700122import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700123import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700124import android.graphics.Matrix;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800125import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700126import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700127import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100128import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700129import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700130import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700131import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700132import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700133import android.os.RemoteException;
134import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100135import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800136import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700137import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700138import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700139import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700140import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100141import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700142import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700143import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700144import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700145import android.view.Surface;
146import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100147import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700148import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700149
Bryce Lee48f4b572017-04-10 10:54:15 -0700150import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800151import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700152import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100153import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100154import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100155import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700156
157import java.io.PrintWriter;
158import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700159import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700160import java.util.HashMap;
161import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700162import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700163import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100164import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800165import java.util.function.Consumer;
166import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700167
Craig Mautner59c00972012-07-30 12:10:24 -0700168/**
169 * Utility class for keeping track of the WindowStates and other pertinent contents of a
170 * particular Display.
171 *
172 * IMPORTANT: No method from this class should ever be used without holding
173 * WindowManagerService.mWindowMap.
174 */
Riddle Hsuad256a12018-07-18 16:11:30 +0800175class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer>
176 implements WindowManagerPolicy.DisplayContentInfo {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700177 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700178
179 /** Unique identifier of this stack. */
180 private final int mDisplayId;
181
Wale Ogunwale3a931692016-11-02 16:49:48 -0700182 /** The containers below are the only child containers the display can have. */
183 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100184 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700185 // Contains all non-app window containers that should be displayed above the app containers
186 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800187 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100188 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700189 // Contains all non-app window containers that should be displayed below the app containers
190 // (e.g. Wallpaper).
191 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100192 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700193 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
194 // 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 -0800195 // window containers together and move them in-sync if/when needed. We use a subclass of
196 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
197 private final NonMagnifiableWindowContainers mImeWindowsContainers =
198 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700199
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000200 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800201 private WindowState mTmpWindow2;
202 private WindowAnimator mTmpWindowAnimator;
203 private boolean mTmpRecoveringMemory;
204 private boolean mUpdateImeTarget;
205 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700206 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700207
Wale Ogunwale02319a62016-09-26 15:21:22 -0700208 // Mapping from a token IBinder to a WindowToken object on this display.
209 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
210
Andrii Kuliancd097992017-03-23 18:31:59 -0700211 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700212 int mInitialDisplayWidth = 0;
213 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700214 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700215
Adrian Roos1cf585052018-01-03 18:43:27 +0100216 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100217 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100218 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100219
Andrii Kuliancd097992017-03-23 18:31:59 -0700220 /**
221 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
222 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
223 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
224 */
Craig Mautner59c00972012-07-30 12:10:24 -0700225 int mBaseDisplayWidth = 0;
226 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700227 /**
228 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
229 * but can be set from Settings or via shell command "adb shell wm density".
230 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
231 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700232 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700233 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700234 private final DisplayInfo mDisplayInfo = new DisplayInfo();
235 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700236 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800237 private final DisplayPolicy mDisplayPolicy;
238 private DisplayRotation mDisplayRotation;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000239 DisplayFrames mDisplayFrames;
240
Andrii Kulian06d07d62017-03-14 11:11:47 -0700241 /**
242 * For default display it contains real metrics, empty for others.
243 * @see WindowManagerService#createWatermarkInTransaction()
244 */
245 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
246 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
247 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700248
Andrii Kulian06d07d62017-03-14 11:11:47 -0700249 /**
250 * Compat metrics computed based on {@link #mDisplayMetrics}.
251 * @see #updateDisplayAndOrientation(int)
252 */
253 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
254
255 /** The desired scaling factor for compatible apps. */
256 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700257
Andrii Kulian8ee72852017-03-10 10:36:45 -0800258 /**
259 * Current rotation of the display.
260 * Constants as per {@link android.view.Surface.Rotation}.
261 *
Robert Carrae606b42018-02-15 15:36:23 -0800262 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800263 */
264 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700265
Andrii Kulian8ee72852017-03-10 10:36:45 -0800266 /**
267 * Last applied orientation of the display.
268 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
269 *
270 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
271 */
272 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700273
Andrii Kulian8ee72852017-03-10 10:36:45 -0800274 /**
275 * Flag indicating that the application is receiving an orientation that has different metrics
276 * than it expected. E.g. Portrait instead of Landscape.
277 *
Robert Carrae606b42018-02-15 15:36:23 -0800278 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800279 */
280 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700281
Andrii Kulian8ee72852017-03-10 10:36:45 -0800282 /**
283 * Orientation forced by some window. If there is no visible window that specifies orientation
284 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
285 *
286 * @see NonAppWindowContainers#getOrientation()
287 */
288 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700289
Andrii Kulian8ee72852017-03-10 10:36:45 -0800290 /**
291 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
292 * occluded.
293 *
294 * @see NonAppWindowContainers#getOrientation()
295 */
296 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
297
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700298 /**
299 * Keep track of wallpaper visibility to notify changes.
300 */
301 private boolean mLastWallpaperVisible = false;
302
Andrii Kulian06d07d62017-03-14 11:11:47 -0700303 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700304
Craig Mautner39834192012-09-02 07:47:24 -0700305 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700306 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700307 int pendingLayoutChanges;
Riddle Hsu654a6f92018-07-13 22:59:36 +0800308 int mDeferredRotationPauseCount;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800309
Andrii Kulian839def92016-11-02 10:58:58 -0700310 // TODO(multi-display): remove some of the usages.
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800311 @VisibleForTesting
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800312 boolean isDefaultDisplay;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800313
Andrii Kulianf0379de2018-03-14 16:24:07 -0700314 /**
315 * Flag indicating whether WindowManager should override info for this display in
316 * DisplayManager.
317 */
318 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700319
Craig Mautnerdc548482014-02-05 13:35:24 -0800320 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700321 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800322
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700323 /** Detect user tapping outside of current focused task bounds .*/
324 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700325
Craig Mautner6601b7b2013-04-29 10:29:11 -0700326 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700327 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700328
Craig Mautner6601b7b2013-04-29 10:29:11 -0700329 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800330 private final Rect mTmpRect = new Rect();
331 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700332 private final RectF mTmpRectF = new RectF();
333 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800334 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700335
Bryce Leef3c6a472017-11-14 14:53:06 -0800336 /** Used for handing back size of display */
337 private final Rect mTmpBounds = new Rect();
338
Craig Mautner95da1082014-02-24 17:54:35 -0800339 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700340 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800341
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700342 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700343 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700344
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800345 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800346 /** A collection of windows that provide tap exclude regions inside of them. */
347 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800348
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000349 private boolean mHaveBootMsg = false;
350 private boolean mHaveApp = false;
351 private boolean mHaveWallpaper = false;
352 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700353
354 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
355
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700356 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
357 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000358 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
359 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700360
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700361 // True if this display is in the process of being removed. Used to determine if the removal of
362 // the display's direct children should be allowed.
363 private boolean mRemovingDisplay = false;
364
Bryce Leed1871262017-06-12 14:12:29 -0700365 // {@code false} if this display is in the processing of being created.
366 private boolean mDisplayReady = false;
367
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800368 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700369
Robert Carrb1579c82017-09-05 14:54:47 -0700370 private final SurfaceSession mSession = new SurfaceSession();
371
372 /**
373 * We organize all top-level Surfaces in to the following layers.
374 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800375 * and omitted from Screen-Magnification, for example the strict mode flash or
376 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700377 * {@link #mWindowingLayer} contains everything else.
378 */
379 private SurfaceControl mOverlayLayer;
380
381 /**
382 * See {@link #mOverlayLayer}
383 */
384 private SurfaceControl mWindowingLayer;
385
386 /**
387 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
388 * <p>
389 * For these surfaces currently we use a surface based on the larger of width or height so we
390 * don't have to resize when rotating the display.
391 */
392 private int mSurfaceSize;
393
Adrian Roos5251b1d2018-03-23 18:57:43 +0100394 /**
395 * Sequence number for the current layout pass.
396 */
397 int mLayoutSeq = 0;
398
Chavi Weingarten3a748552018-05-14 17:32:42 +0000399 /**
400 * Specifies the count to determine whether to defer updating the IME target until ready.
401 */
402 private int mDeferUpdateImeTargetCount;
403
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100404 /** Temporary float array to retrieve 3x3 matrix values. */
405 private final float[] mTmpFloats = new float[9];
406
Robert Carr24be9ab2018-04-30 17:54:53 -0700407 private MagnificationSpec mMagnificationSpec;
408
Arthur Hung95b38a92018-07-20 18:56:12 +0800409 private InputMonitor mInputMonitor;
410
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800411 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
412 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800413 final AppWindowToken atoken = w.mAppToken;
414 if (winAnimator.mDrawState == READY_TO_SHOW) {
Jorim Jaggiaf0d6d22018-06-08 15:25:35 +0200415 if (atoken == null || atoken.canShowWindows()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800416 if (w.performShowLocked()) {
417 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
418 if (DEBUG_LAYOUT_REPEATS) {
419 mService.mWindowPlacerLocked.debugLayoutRepeats(
420 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
421 }
422 }
423 }
424 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800425 };
426
427 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
428 final WindowStateAnimator winAnimator = w.mWinAnimator;
429 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
430 return;
431 }
432
433 final int flags = w.mAttrs.flags;
434
435 // If this window is animating, make a note that we have an animating window and take
436 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100437 if (winAnimator.isAnimationSet()) {
438 final AnimationAdapter anim = w.getAnimation();
439 if (anim != null) {
440 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800441 mTmpWindow = w;
442 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100443 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800444 if (color != 0) {
445 final TaskStack stack = w.getStack();
446 if (stack != null) {
447 stack.setAnimationBackground(winAnimator, color);
448 }
449 }
450 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800451 }
452
453 // If this window's app token is running a detached wallpaper animation, make a note so
454 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200455 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
456 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
457 if (animation != null) {
458 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800459 mTmpWindow = w;
460 }
461
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200462 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800463 if (color != 0) {
464 final TaskStack stack = w.getStack();
465 if (stack != null) {
466 stack.setAnimationBackground(winAnimator, color);
467 }
468 }
469 }
470 };
471
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800472 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
473 final int lostFocusUid = mTmpWindow.mOwnerUid;
474 final Handler handler = mService.mH;
475 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
476 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
477 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
478 w.mAttrs.hideTimeoutMilliseconds);
479 }
480 }
481 };
482
483 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
484 final AppWindowToken focusedApp = mService.mFocusedApp;
485 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
486 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
487
488 if (!w.canReceiveKeys()) {
489 return false;
490 }
491
492 final AppWindowToken wtoken = w.mAppToken;
493
494 // If this window's application has been removed, just skip it.
495 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
496 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
497 + (wtoken.removed ? "removed" : "sendingToBottom"));
498 return false;
499 }
500
501 if (focusedApp == null) {
502 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
503 + " using new focus @ " + w);
504 mTmpWindow = w;
505 return true;
506 }
507
508 if (!focusedApp.windowsAreFocusable()) {
509 // Current focused app windows aren't focusable...
510 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
511 + " focusable using new focus @ " + w);
512 mTmpWindow = w;
513 return true;
514 }
515
516 // Descend through all of the app tokens and find the first that either matches
517 // win.mAppToken (return win) or mFocusedApp (return null).
518 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
519 if (focusedApp.compareTo(wtoken) > 0) {
520 // App stack below focused app stack. No focus for you!!!
521 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
522 "findFocusedWindow: Reached focused app=" + focusedApp);
523 mTmpWindow = null;
524 return true;
525 }
526 }
527
528 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
529 mTmpWindow = w;
530 return true;
531 };
532
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800533 private final Consumer<WindowState> mPerformLayout = w -> {
534 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
535 // wasting time and funky changes while a window is animating away.
536 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
537 || w.isGoneForLayoutLw();
538
539 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
540 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
541 + " mLayoutAttached=" + w.mLayoutAttached
542 + " screen changed=" + w.isConfigChanged());
543 final AppWindowToken atoken = w.mAppToken;
544 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200545 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800546 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
547 + " parentHidden=" + w.isParentWindowHidden());
548 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200549 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800550 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
551 + " parentHidden=" + w.isParentWindowHidden());
552 }
553
554 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
555 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
556 // since that means "perform layout as normal, just don't display").
557 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
558 || ((w.isConfigChanged() || w.setReportResizeHints())
559 && !w.isGoneForLayoutLw() &&
560 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
561 (w.mHasSurface && w.mAppToken != null &&
562 w.mAppToken.layoutConfigChanges)))) {
563 if (!w.mLayoutAttached) {
564 if (mTmpInitial) {
565 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
566 w.mContentChanged = false;
567 }
568 if (w.mAttrs.type == TYPE_DREAM) {
569 // Don't layout windows behind a dream, so that if it does stuff like hide
570 // the status bar we won't get a bad transition when it goes away.
571 mTmpWindow = w;
572 }
573 w.mLayoutNeeded = false;
574 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200575 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000576 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100577 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800578
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200579 // If this is the first layout, we need to initialize the last inset values as
580 // otherwise we'd immediately cause an unnecessary resize.
581 if (firstLayout) {
582 w.updateLastInsetValues();
583 }
584
Adrian Roos23df3a32018-03-15 15:41:13 +0100585 if (w.mAppToken != null) {
586 w.mAppToken.layoutLetterbox(w);
587 }
588
chaviw492139a2018-07-16 16:07:35 -0700589 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700590 + " mContainingFrame=" + w.getContainingFrame()
591 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800592 }
593 }
594 };
595
596 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
597 if (w.mLayoutAttached) {
598 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
599 + " mViewVisibility=" + w.mViewVisibility
600 + " mRelayoutCalled=" + w.mRelayoutCalled);
601 // If this view is GONE, then skip it -- keep the current frame, and let the caller
602 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
603 // windows, since that means "perform layout as normal, just don't display").
604 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
605 return;
606 }
607 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
608 || w.mLayoutNeeded) {
609 if (mTmpInitial) {
610 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
611 w.mContentChanged = false;
612 }
613 w.mLayoutNeeded = false;
614 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000615 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100616 w.mLayoutSeq = mLayoutSeq;
chaviw492139a2018-07-16 16:07:35 -0700617 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.getFrameLw()
chaviw553b0212018-07-12 13:37:01 -0700618 + " mContainingFrame=" + w.getContainingFrame()
619 + " mDisplayFrame=" + w.getDisplayFrameLw());
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800620 }
621 } else if (w.mAttrs.type == TYPE_DREAM) {
622 // Don't layout windows behind a dream, so that if it does stuff like hide the
623 // status bar we won't get a bad transition when it goes away.
624 mTmpWindow = mTmpWindow2;
625 }
626 };
627
628 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
629 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
630 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
631 return w.canBeImeTarget();
632 };
633
634 private final Consumer<WindowState> mApplyPostLayoutPolicy =
635 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
636 mService.mInputMethodTarget);
637
638 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
639 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
640 final boolean obscuredChanged = w.mObscured !=
641 mTmpApplySurfaceChangesTransactionState.obscured;
642 final RootWindowContainer root = mService.mRoot;
643 // Only used if default window
644 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
645
646 // Update effect.
647 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
648 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
649 final boolean isDisplayed = w.isDisplayedLw();
650
651 if (isDisplayed && w.isObscuringDisplay()) {
652 // This window completely covers everything behind it, so we want to leave all
653 // of them as undimmed (for performance reasons).
654 root.mObscuringWindow = w;
655 mTmpApplySurfaceChangesTransactionState.obscured = true;
656 }
657
658 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
659 root.handleNotObscuredLocked(w,
660 mTmpApplySurfaceChangesTransactionState.obscured,
661 mTmpApplySurfaceChangesTransactionState.syswin);
662
663 if (w.mHasSurface && isDisplayed) {
664 final int type = w.mAttrs.type;
665 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
666 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
667 mTmpApplySurfaceChangesTransactionState.syswin = true;
668 }
669 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
670 && w.mAttrs.preferredRefreshRate != 0) {
671 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
672 = w.mAttrs.preferredRefreshRate;
673 }
674 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
675 && w.mAttrs.preferredDisplayModeId != 0) {
676 mTmpApplySurfaceChangesTransactionState.preferredModeId
677 = w.mAttrs.preferredDisplayModeId;
678 }
679 }
680 }
681
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800682 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
683 && mWallpaperController.isWallpaperTarget(w)) {
684 // This is the wallpaper target and its obscured state changed... make sure the
685 // current wallpaper's visibility has been updated accordingly.
686 mWallpaperController.updateWallpaperVisibility();
687 }
688
chaviw161ea3e2018-01-31 12:01:12 -0800689 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800690
691 final WindowStateAnimator winAnimator = w.mWinAnimator;
692
693 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
694 w.mContentChanged = false;
695
696 // Moved from updateWindowsAndWallpaperLocked().
697 if (w.mHasSurface) {
698 // Take care of the window being ready to display.
699 final boolean committed = winAnimator.commitFinishDrawingLocked();
700 if (isDefaultDisplay && committed) {
701 if (w.mAttrs.type == TYPE_DREAM) {
702 // HACK: When a dream is shown, it may at that point hide the lock screen.
703 // So we need to redo the layout to let the phone window manager make this
704 // happen.
705 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
706 if (DEBUG_LAYOUT_REPEATS) {
707 surfacePlacer.debugLayoutRepeats(
708 "dream and commitFinishDrawingLocked true",
709 pendingLayoutChanges);
710 }
711 }
712 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
713 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
714 "First draw done in potential wallpaper target " + w);
715 root.mWallpaperMayChange = true;
716 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
717 if (DEBUG_LAYOUT_REPEATS) {
718 surfacePlacer.debugLayoutRepeats(
719 "wallpaper and commitFinishDrawingLocked true",
720 pendingLayoutChanges);
721 }
722 }
723 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800724 }
725
726 final AppWindowToken atoken = w.mAppToken;
727 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100728 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800729 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
730 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
731 mTmpUpdateAllDrawn.add(atoken);
732 }
733 }
734
735 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
736 && w.isDisplayedLw()) {
737 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
738 }
739
740 w.updateResizingWindowIfNeeded();
741 };
742
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800743 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800744 * Create new {@link DisplayContent} instance, add itself to the root window container and
745 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700746 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800747 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700748 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
749 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700750 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700751 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800752 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100753 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800754 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800755 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
756 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
757 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
758 + " new=" + display);
759 }
760
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700761 mDisplay = display;
762 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700763 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700764 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700765 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700766 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100767 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
768 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700769 initializeDisplayBaseInfo();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800770 mDisplayPolicy = new DisplayPolicy(service);
771 mDisplayRotation = new DisplayRotation(service, this);
772 if (isDefaultDisplay) {
773 // The policy may be invoked right after here, so it requires the necessary default
774 // fields of this display content.
775 mService.mPolicy.setDefaultDisplay(this);
776 }
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800777 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700778 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700779
Robert Carr74a66a22018-02-23 12:17:51 -0800780 // We use this as our arbitrary surface size for buffer-less parents
781 // that don't impose cropping on their children. It may need to be larger
782 // than the display size because fullscreen windows can be shifted offscreen
783 // due to surfaceInsets. 2 times the largest display dimension feels like an
784 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
785 // layers the ability to match their parent sizes and be able to skip
786 // such arbitrary size settings.
787 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700788
789 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
790 .setSize(mSurfaceSize, mSurfaceSize)
791 .setOpaque(true);
792 mWindowingLayer = b.setName("Display Root").build();
793 mOverlayLayer = b.setName("Display Overlays").build();
794
Robert Carrf59b8dd2017-10-02 18:58:36 -0700795 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700796 .setLayerStack(mWindowingLayer, mDisplayId)
797 .show(mWindowingLayer)
798 .setLayer(mOverlayLayer, 1)
799 .setLayerStack(mOverlayLayer, mDisplayId)
800 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700801 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700802
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700803 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700804 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700805 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700806 super.addChild(mAboveAppWindowsContainers, null);
807 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800808
809 // Add itself as a child to the root container.
810 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700811
812 // TODO(b/62541591): evaluate whether this is the best spot to declare the
813 // {@link DisplayContent} ready for use.
814 mDisplayReady = true;
Arthur Hung95b38a92018-07-20 18:56:12 +0800815
Siarhei Vishniakou96283082018-08-13 18:55:55 +0000816 // TODO(b/112081256): Use independent InputMonitor.
817 mInputMonitor = isDefaultDisplay ? new InputMonitor(service, mDisplayId)
818 : mService.getDefaultDisplayContentLocked().mInputMonitor;
Bryce Leed1871262017-06-12 14:12:29 -0700819 }
820
821 boolean isReady() {
822 // The display is ready when the system and the individual display are both ready.
823 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700824 }
825
826 int getDisplayId() {
827 return mDisplayId;
828 }
829
Wale Ogunwale02319a62016-09-26 15:21:22 -0700830 WindowToken getWindowToken(IBinder binder) {
831 return mTokenMap.get(binder);
832 }
833
834 AppWindowToken getAppWindowToken(IBinder binder) {
835 final WindowToken token = getWindowToken(binder);
836 if (token == null) {
837 return null;
838 }
839 return token.asAppWindowToken();
840 }
841
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700842 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700843 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
844 if (dc != null) {
845 // We currently don't support adding a window token to the display if the display
846 // already has the binder mapped to another token. If there is a use case for supporting
847 // this moving forward we will either need to merge the WindowTokens some how or have
848 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700849 throw new IllegalArgumentException("Can't map token=" + token + " to display="
850 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700851 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700852 if (binder == null) {
853 throw new IllegalArgumentException("Can't map token=" + token + " to display="
854 + getName() + " binder is null");
855 }
856 if (token == null) {
857 throw new IllegalArgumentException("Can't map null token to display="
858 + getName() + " binder=" + binder);
859 }
860
Wale Ogunwale02319a62016-09-26 15:21:22 -0700861 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700862
863 if (token.asAppWindowToken() == null) {
864 // Add non-app token to container hierarchy on the display. App tokens are added through
865 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700866 switch (token.windowType) {
867 case TYPE_WALLPAPER:
868 mBelowAppWindowsContainers.addChild(token);
869 break;
870 case TYPE_INPUT_METHOD:
871 case TYPE_INPUT_METHOD_DIALOG:
872 mImeWindowsContainers.addChild(token);
873 break;
874 default:
875 mAboveAppWindowsContainers.addChild(token);
876 break;
877 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700878 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700879 }
880
881 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700882 final WindowToken token = mTokenMap.remove(binder);
883 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800884 token.setExiting();
885 }
886 return token;
887 }
888
889 /** Changes the display the input window token is housed on to this one. */
890 void reParentWindowToken(WindowToken token) {
891 final DisplayContent prevDc = token.getDisplayContent();
892 if (prevDc == this) {
893 return;
894 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800895 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
896 && token.asAppWindowToken() == null) {
897 // Removed the token from the map, but made sure it's not an app token before removing
898 // from parent.
899 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700900 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800901
902 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700903 }
904
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700905 void removeAppToken(IBinder binder) {
906 final WindowToken token = removeWindowToken(binder);
907 if (token == null) {
908 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
909 return;
910 }
911
912 final AppWindowToken appToken = token.asAppWindowToken();
913
914 if (appToken == null) {
915 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
916 return;
917 }
918
919 appToken.onRemovedFromDisplay();
920 }
921
Riddle Hsuad256a12018-07-18 16:11:30 +0800922 @Override
923 public Display getDisplay() {
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700924 return mDisplay;
925 }
926
Craig Mautner59c00972012-07-30 12:10:24 -0700927 DisplayInfo getDisplayInfo() {
928 return mDisplayInfo;
929 }
930
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700931 DisplayMetrics getDisplayMetrics() {
932 return mDisplayMetrics;
933 }
934
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800935 DisplayPolicy getDisplayPolicy() {
936 return mDisplayPolicy;
937 }
938
Riddle Hsuad256a12018-07-18 16:11:30 +0800939 @Override
940 public DisplayRotation getDisplayRotation() {
941 return mDisplayRotation;
942 }
943
Riddle Hsu5ce4bb32018-07-18 16:11:30 +0800944 @VisibleForTesting
945 void setDisplayRotation(DisplayRotation displayRotation) {
946 mDisplayRotation = displayRotation;
947 }
948
Andrii Kulian8ee72852017-03-10 10:36:45 -0800949 int getRotation() {
950 return mRotation;
951 }
952
Andrii Kulianef5ce1c2018-03-20 19:27:24 -0700953 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -0800954 void setRotation(int newRotation) {
955 mRotation = newRotation;
Riddle Hsuad256a12018-07-18 16:11:30 +0800956 mDisplayRotation.setRotation(newRotation);
Andrii Kulian8ee72852017-03-10 10:36:45 -0800957 }
958
959 int getLastOrientation() {
960 return mLastOrientation;
961 }
962
963 void setLastOrientation(int orientation) {
964 mLastOrientation = orientation;
965 }
966
967 boolean getAltOrientation() {
968 return mAltOrientation;
969 }
970
971 void setAltOrientation(boolean altOrientation) {
972 mAltOrientation = altOrientation;
973 }
974
975 int getLastWindowForcedOrientation() {
976 return mLastWindowForcedOrientation;
977 }
978
Andrii Kulian06d07d62017-03-14 11:11:47 -0700979 /**
Riddle Hsu654a6f92018-07-13 22:59:36 +0800980 * Temporarily pauses rotation changes until resumed.
981 *
982 * This can be used to prevent rotation changes from occurring while the user is
983 * performing certain operations, such as drag and drop.
984 *
985 * This call nests and must be matched by an equal number of calls to
986 * {@link #resumeRotationLocked}.
987 */
988 void pauseRotationLocked() {
989 mDeferredRotationPauseCount++;
990 }
991
992 /**
993 * Resumes normal rotation changes after being paused.
994 */
995 void resumeRotationLocked() {
996 if (mDeferredRotationPauseCount <= 0) {
997 return;
998 }
999
1000 mDeferredRotationPauseCount--;
1001 if (mDeferredRotationPauseCount == 0) {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001002 updateRotationAndSendNewConfigIfNeeded();
Riddle Hsu654a6f92018-07-13 22:59:36 +08001003 }
1004 }
1005
1006 /**
Riddle Hsuad256a12018-07-18 16:11:30 +08001007 * If this is true we have updated our desired orientation, but not yet changed the real
1008 * orientation our applied our screen rotation animation. For example, because a previous
1009 * screen rotation was in progress.
1010 *
1011 * @return {@code true} if the there is an ongoing rotation change.
1012 */
1013 boolean rotationNeedsUpdate() {
1014 final int lastOrientation = getLastOrientation();
1015 final int oldRotation = getRotation();
1016 final boolean oldAltOrientation = getAltOrientation();
1017
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001018 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001019 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
1020 lastOrientation, rotation);
1021 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1022 return false;
1023 }
1024 return true;
1025 }
1026
1027 /**
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001028 * Update rotation of the display and send configuration if the rotation is changed.
1029 *
1030 * @return {@code true} if the rotation has been changed and the new config is sent.
1031 */
1032 boolean updateRotationAndSendNewConfigIfNeeded() {
1033 final boolean changed = updateRotationUnchecked(false /* forceUpdate */);
1034 if (changed) {
1035 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
1036 }
1037 return changed;
1038 }
1039
1040 /**
Andrii Kulian06d07d62017-03-14 11:11:47 -07001041 * Update rotation of the display.
1042 *
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001043 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1044 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
Andrii Kulian06d07d62017-03-14 11:11:47 -07001045 */
Robert Carrae606b42018-02-15 15:36:23 -08001046 boolean updateRotationUnchecked() {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001047 return updateRotationUnchecked(false /* forceUpdate */);
1048 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001049
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001050 /**
1051 * Update rotation of the display with an option to force the update.
1052 * @param forceUpdate Force the rotation update. Sometimes in WM we might skip updating
1053 * orientation because we're waiting for some rotation to finish or display
1054 * to unfreeze, which results in configuration of the previously visible
1055 * activity being applied to a newly visible one. Forcing the rotation
1056 * update allows to workaround this issue.
1057 * @return {@code true} if the rotation has been changed. In this case YOU MUST CALL
1058 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
1059 */
1060 boolean updateRotationUnchecked(boolean forceUpdate) {
1061 ScreenRotationAnimation screenRotationAnimation;
1062 if (!forceUpdate) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001063 if (mDeferredRotationPauseCount > 0) {
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001064 // Rotation updates have been paused temporarily. Defer the update until
1065 // updates have been resumed.
1066 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
1067 return false;
1068 }
1069
1070 screenRotationAnimation =
1071 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
1072 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
1073 // Rotation updates cannot be performed while the previous rotation change
1074 // animation is still in progress. Skip this update. We will try updating
1075 // again after the animation is finished and the display is unfrozen.
1076 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
1077 return false;
1078 }
1079 if (mService.mDisplayFrozen) {
1080 // Even if the screen rotation animation has finished (e.g. isAnimating
1081 // returns false), there is still some time where we haven't yet unfrozen
1082 // the display. We also need to abort rotation here.
1083 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
1084 "Deferring rotation, still finishing previous rotation");
1085 return false;
1086 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001087 }
1088
1089 if (!mService.mDisplayEnabled) {
1090 // No point choosing a rotation if the display is not enabled.
1091 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
1092 return false;
1093 }
1094
1095 final int oldRotation = mRotation;
1096 final int lastOrientation = mLastOrientation;
1097 final boolean oldAltOrientation = mAltOrientation;
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001098 final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001099 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
1100 + mDisplayId + " based on lastOrientation=" + lastOrientation
1101 + " and oldRotation=" + oldRotation);
Riddle Hsuad256a12018-07-18 16:11:30 +08001102 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(mDisplayRotation,
1103 oldRotation, rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001104
Robert Carr0e007272017-10-02 13:00:55 -07001105 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001106 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
Andrii Kulian6cdcfe42018-05-23 17:59:43 -07001107 if (seamlessRotated != null && !forceUpdate) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001108 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
1109 // to complete (that is, waiting for windows to redraw). It's tempting to check
1110 // w.mSeamlessRotationCount but that could be incorrect in the case of
1111 // window-removal.
1112 return false;
1113 }
Robert Carr0e007272017-10-02 13:00:55 -07001114
1115 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001116 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001117 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001118 mayRotateSeamlessly = false;
1119 }
1120 for (int i = 0; i < mService.mSessions.size(); i++) {
1121 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1122 mayRotateSeamlessly = false;
1123 break;
1124 }
1125 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001126 }
Robert Carr0e007272017-10-02 13:00:55 -07001127 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001128
1129 // TODO: Implement forced rotation changes.
1130 // Set mAltOrientation to indicate that the application is receiving
1131 // an orientation that has different metrics than it expected.
1132 // eg. Portrait instead of Landscape.
1133
Riddle Hsuad256a12018-07-18 16:11:30 +08001134 final boolean altOrientation = !mDisplayRotation.rotationHasCompatibleMetrics(
Andrii Kulian06d07d62017-03-14 11:11:47 -07001135 lastOrientation, rotation);
1136
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001137 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1138 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001139 + ", got rotation " + rotation + " which has "
1140 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1141
1142 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1143 // No change.
1144 return false;
1145 }
1146
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001147 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1148 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001149 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1150 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1151
1152 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1153 mService.mWaitingForConfig = true;
1154 }
1155
Riddle Hsuad256a12018-07-18 16:11:30 +08001156 setRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001157 mAltOrientation = altOrientation;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001158
1159 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
Riddle Hsu654a6f92018-07-13 22:59:36 +08001160 mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1161 this, WINDOW_FREEZE_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001162
1163 setLayoutNeeded();
1164 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001165 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001166
1167 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001168 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001169 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1170 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1171 mDisplayId);
1172 } else {
1173 // The screen rotation animation uses a screenshot to freeze the screen
1174 // while windows resize underneath.
1175 // When we are rotating seamlessly, we allow the elements to transition
1176 // to their rotated state independently and without a freeze required.
1177 screenRotationAnimation = null;
1178
Robert Carrefc75702018-02-16 11:46:16 -08001179 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001180 }
1181
1182 // We need to update our screen size information to match the new rotation. If the rotation
1183 // has actually changed then this method will return true and, according to the comment at
1184 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1185 // By updating the Display info here it will be available to
1186 // #computeScreenConfiguration() later.
1187 updateDisplayAndOrientation(getConfiguration().uiMode);
1188
Robert Carrae606b42018-02-15 15:36:23 -08001189 // NOTE: We disable the rotation in the emulator because
1190 // it doesn't support hardware OpenGL emulation yet.
1191 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1192 && screenRotationAnimation.hasScreenshot()) {
1193 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1194 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1195 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1196 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001197 }
1198 }
1199
Vishnu Nair83537a72018-07-19 21:27:48 -07001200 forAllWindows(w -> {
1201 w.forceSeamlesslyRotateIfAllowed(oldRotation, rotation);
1202 }, true /* traverseTopToBottom */);
1203
1204 // TODO(b/111504081): Consolidate seamless rotation logic.
Robert Carrae606b42018-02-15 15:36:23 -08001205 if (rotateSeamlessly) {
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001206 seamlesslyRotate(getPendingTransaction(), oldRotation, rotation);
Robert Carrae606b42018-02-15 15:36:23 -08001207 }
1208
1209 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1210 scheduleAnimation();
1211
Andrii Kulian06d07d62017-03-14 11:11:47 -07001212 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001213 if (w.mHasSurface && !rotateSeamlessly) {
1214 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001215 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001216 mService.mRoot.mOrientationChangeComplete = false;
1217 w.mLastFreezeDuration = 0;
1218 }
1219 w.mReportOrientationChanged = true;
1220 }, true /* traverseTopToBottom */);
1221
1222 if (rotateSeamlessly) {
Riddle Hsu654a6f92018-07-13 22:59:36 +08001223 mService.mH.sendNewMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1224 this, SEAMLESS_ROTATION_TIMEOUT_DURATION);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001225 }
1226
1227 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1228 final WindowManagerService.RotationWatcher rotationWatcher
1229 = mService.mRotationWatchers.get(i);
1230 if (rotationWatcher.mDisplayId == mDisplayId) {
1231 try {
1232 rotationWatcher.mWatcher.onRotationChanged(rotation);
1233 } catch (RemoteException e) {
1234 // Ignore
1235 }
1236 }
1237 }
1238
1239 // TODO (multi-display): Magnification is supported only for the default display.
1240 // Announce rotation only if we will not animate as we already have the
1241 // windows in final state. Otherwise, we make this call at the rotation end.
1242 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1243 && isDefaultDisplay) {
1244 mService.mAccessibilityController.onRotationChangedLocked(this);
1245 }
1246
1247 return true;
1248 }
1249
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001250 void configureDisplayPolicy() {
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08001251 final int width = mBaseDisplayWidth;
1252 final int height = mBaseDisplayHeight;
1253 final int shortSize;
1254 final int longSize;
1255 if (width > height) {
1256 shortSize = height;
1257 longSize = width;
1258 } else {
1259 shortSize = width;
1260 longSize = height;
1261 }
1262
1263 final int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1264 final int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / mBaseDisplayDensity;
1265
1266 mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
1267 mDisplayPolicy.configure(width, height, shortSizeDp);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001268
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001269 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1270 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001271 }
1272
Andrii Kulian06d07d62017-03-14 11:11:47 -07001273 /**
1274 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1275 * changed.
1276 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1277 */
1278 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1279 // Use the effective "visual" dimensions based on current rotation
1280 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1281 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1282 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1283 int dw = realdw;
1284 int dh = realdh;
1285
1286 if (mAltOrientation) {
1287 if (realdw > realdh) {
1288 // Turn landscape into portrait.
1289 int maxw = (int)(realdh/1.3f);
1290 if (maxw < realdw) {
1291 dw = maxw;
1292 }
1293 } else {
1294 // Turn portrait into landscape.
1295 int maxh = (int)(realdw/1.3f);
1296 if (maxh < realdh) {
1297 dh = maxh;
1298 }
1299 }
1300 }
1301
1302 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001303 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1304 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1305
Andrii Kulian06d07d62017-03-14 11:11:47 -07001306 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001307 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001308 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001309 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001310 mDisplayInfo.rotation = mRotation;
1311 mDisplayInfo.logicalWidth = dw;
1312 mDisplayInfo.logicalHeight = dh;
1313 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1314 mDisplayInfo.appWidth = appWidth;
1315 mDisplayInfo.appHeight = appHeight;
1316 if (isDefaultDisplay) {
1317 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1318 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1319 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001320 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001321 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1322 if (mDisplayScalingDisabled) {
1323 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1324 } else {
1325 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1326 }
1327
Andrii Kulianf0379de2018-03-14 16:24:07 -07001328 // We usually set the override info in DisplayManager so that we get consistent display
1329 // metrics values when displays are changing and don't send out new values until WM is aware
1330 // of them. However, we don't do this for displays that serve as containers for ActivityView
1331 // because we don't want letter-/pillar-boxing during resize.
1332 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1333 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001334 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001335 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001336
1337 mBaseDisplayRect.set(0, 0, dw, dh);
1338
1339 if (isDefaultDisplay) {
1340 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1341 mCompatDisplayMetrics);
1342 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001343
1344 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001345 return mDisplayInfo;
1346 }
1347
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001348 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001349 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1350 }
1351
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001352 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001353 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001354 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001355 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001356 }
Adrian Roos11c25582018-02-19 18:06:36 +01001357 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001358 return WmDisplayCutout.computeSafeInsets(
1359 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001360 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001361 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Jorim Jaggi60640512018-06-29 01:14:31 +02001362 final List<Rect> bounds = WmDisplayCutout.computeSafeInsets(
1363 cutout, mInitialDisplayWidth, mInitialDisplayHeight)
1364 .getDisplayCutout().getBoundingRects();
Adrian Roos11c25582018-02-19 18:06:36 +01001365 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1366 mTmpMatrix);
Jorim Jaggi60640512018-06-29 01:14:31 +02001367 final Region region = Region.obtain();
1368 for (int i = 0; i < bounds.size(); i++) {
1369 final Rect rect = bounds.get(i);
1370 final RectF rectF = new RectF(bounds.get(i));
1371 mTmpMatrix.mapRect(rectF);
1372 rectF.round(rect);
1373 region.op(rect, Op.UNION);
1374 }
1375
1376 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(region),
Adrian Roos24264212018-02-19 16:26:15 +01001377 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1378 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001379 }
1380
Andrii Kulian06d07d62017-03-14 11:11:47 -07001381 /**
1382 * Compute display configuration based on display properties and policy settings.
1383 * Do not call if mDisplayReady == false.
1384 */
1385 void computeScreenConfiguration(Configuration config) {
1386 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1387
1388 final int dw = displayInfo.logicalWidth;
1389 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001390 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
Garfield Tane0846042018-07-26 13:42:04 -07001391 config.windowConfiguration.setWindowingMode(getWindowingMode());
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001392
Adrian Roos11c25582018-02-19 18:06:36 +01001393 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001394 config.screenWidthDp =
1395 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001396 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001397 config.screenHeightDp =
1398 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001399 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001400
Adrian Roos11c25582018-02-19 18:06:36 +01001401 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1402 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001403 final int leftInset = mTmpRect.left;
1404 final int topInset = mTmpRect.top;
1405 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001406 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1407 leftInset + displayInfo.appWidth /* right */,
1408 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001409 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1410 || displayInfo.rotation == Surface.ROTATION_270);
1411
1412 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001413 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001414
1415 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1416 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1417 ? Configuration.SCREENLAYOUT_ROUND_YES
1418 : Configuration.SCREENLAYOUT_ROUND_NO);
1419
1420 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1421 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1422 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1423 dh, mDisplayId);
1424 config.densityDpi = displayInfo.logicalDensityDpi;
1425
1426 config.colorMode =
1427 (displayInfo.isHdr()
1428 ? Configuration.COLOR_MODE_HDR_YES
1429 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001430 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001431 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1432 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1433
1434 // Update the configuration based on available input devices, lid switch,
1435 // and platform configuration.
1436 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1437 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1438 config.navigation = Configuration.NAVIGATION_NONAV;
1439
1440 int keyboardPresence = 0;
1441 int navigationPresence = 0;
1442 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1443 final int len = devices != null ? devices.length : 0;
1444 for (int i = 0; i < len; i++) {
1445 InputDevice device = devices[i];
1446 if (!device.isVirtual()) {
1447 final int sources = device.getSources();
1448 final int presenceFlag = device.isExternal() ?
1449 WindowManagerPolicy.PRESENCE_EXTERNAL :
1450 WindowManagerPolicy.PRESENCE_INTERNAL;
1451
1452 // TODO(multi-display): Configure on per-display basis.
1453 if (mService.mIsTouchDevice) {
1454 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1455 InputDevice.SOURCE_TOUCHSCREEN) {
1456 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1457 }
1458 } else {
1459 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1460 }
1461
1462 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1463 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1464 navigationPresence |= presenceFlag;
1465 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1466 && config.navigation == Configuration.NAVIGATION_NONAV) {
1467 config.navigation = Configuration.NAVIGATION_DPAD;
1468 navigationPresence |= presenceFlag;
1469 }
1470
1471 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1472 config.keyboard = Configuration.KEYBOARD_QWERTY;
1473 keyboardPresence |= presenceFlag;
1474 }
1475 }
1476 }
1477
1478 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1479 config.navigation = Configuration.NAVIGATION_DPAD;
1480 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1481 }
1482
1483 // Determine whether a hard keyboard is available and enabled.
1484 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1485 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1486 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1487 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1488 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1489 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1490 }
1491
1492 // Let the policy update hidden states.
1493 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1494 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1495 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1496 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1497 }
1498
1499 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1500 int displayId) {
1501 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1502 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1503 final int unrotDw, unrotDh;
1504 if (rotated) {
1505 unrotDw = dh;
1506 unrotDh = dw;
1507 } else {
1508 unrotDw = dw;
1509 unrotDh = dh;
1510 }
1511 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1512 displayId);
1513 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1514 displayId);
1515 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1516 displayId);
1517 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1518 displayId);
1519 return sw;
1520 }
1521
1522 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1523 DisplayMetrics dm, int dw, int dh, int displayId) {
1524 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001525 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001526 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001527 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001528 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1529 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1530 if (curSize == 0 || size < curSize) {
1531 curSize = size;
1532 }
1533 return curSize;
1534 }
1535
1536 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1537 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1538
1539 // We need to determine the smallest width that will occur under normal
1540 // operation. To this, start with the base screen size and compute the
1541 // width under the different possible rotations. We need to un-rotate
1542 // the current screen dimensions before doing this.
1543 int unrotDw, unrotDh;
1544 if (rotated) {
1545 unrotDw = dh;
1546 unrotDh = dw;
1547 } else {
1548 unrotDw = dw;
1549 unrotDh = dh;
1550 }
1551 displayInfo.smallestNominalAppWidth = 1<<30;
1552 displayInfo.smallestNominalAppHeight = 1<<30;
1553 displayInfo.largestNominalAppWidth = 0;
1554 displayInfo.largestNominalAppHeight = 0;
1555 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1556 unrotDh);
1557 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1558 unrotDw);
1559 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1560 unrotDh);
1561 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1562 unrotDw);
1563 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1564 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1565 displayId);
1566 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1567 displayId);
1568 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1569 displayId);
1570 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1571 displayId);
1572 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1573 outConfig.screenLayout = sl;
1574 }
1575
1576 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1577 int uiMode, int displayId) {
1578 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001579 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1580 mDisplayInfo.displayCutout);
1581 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1582 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001583
1584 // Compute the screen layout size class for this rotation.
1585 int longSize = w;
1586 int shortSize = h;
1587 if (longSize < shortSize) {
1588 int tmp = longSize;
1589 longSize = shortSize;
1590 shortSize = tmp;
1591 }
1592 longSize = (int)(longSize/density);
1593 shortSize = (int)(shortSize/density);
1594 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1595 }
1596
1597 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1598 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001599 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1600 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001601 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001602 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001603 if (width < displayInfo.smallestNominalAppWidth) {
1604 displayInfo.smallestNominalAppWidth = width;
1605 }
1606 if (width > displayInfo.largestNominalAppWidth) {
1607 displayInfo.largestNominalAppWidth = width;
1608 }
1609 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001610 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001611 if (height < displayInfo.smallestNominalAppHeight) {
1612 displayInfo.smallestNominalAppHeight = height;
1613 }
1614 if (height > displayInfo.largestNominalAppHeight) {
1615 displayInfo.largestNominalAppHeight = height;
1616 }
1617 }
1618
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001619 DockedStackDividerController getDockedDividerController() {
1620 return mDividerControllerLocked;
1621 }
1622
Winson Chung655332c2016-10-31 13:14:28 -07001623 PinnedStackController getPinnedStackController() {
1624 return mPinnedStackControllerLocked;
1625 }
1626
Jeff Browna506a6e2013-06-04 00:02:38 -07001627 /**
1628 * Returns true if the specified UID has access to this display.
1629 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001630 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001631 return mDisplay.hasAccess(uid);
1632 }
1633
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001634 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001635 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001636 }
1637
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001638 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001639 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001640 }
1641
Wale Ogunwale61911492017-10-11 08:50:50 -07001642 /**
1643 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1644 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001645 TaskStack getSplitScreenPrimaryStack() {
1646 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001647 return (stack != null && stack.isVisible()) ? stack : null;
1648 }
1649
Robert Carr9785cf32018-04-25 15:06:07 -07001650 boolean hasSplitScreenPrimaryStack() {
1651 return getSplitScreenPrimaryStack() != null;
1652 }
1653
Wale Ogunwale61911492017-10-11 08:50:50 -07001654 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001655 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001656 * not visible.
1657 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001658 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1659 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001660 }
1661
1662 TaskStack getPinnedStack() {
1663 return mTaskStackContainers.getPinnedStack();
1664 }
1665
1666 private boolean hasPinnedStack() {
1667 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001668 }
1669
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001670 /**
1671 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1672 * Null is no compatible stack on the display.
1673 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001674 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001675 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1676 }
1677
1678 /**
1679 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1680 * activity type. Null is no compatible stack on the display.
1681 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001682 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001683 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001684 }
1685
Bryce Lee48f4b572017-04-10 10:54:15 -07001686 @VisibleForTesting
Kazuki Takise148d00a2018-05-31 15:32:19 +09001687 WindowList<TaskStack> getStacks() {
1688 return mTaskStackContainers.mChildren;
1689 }
1690
1691 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001692 TaskStack getTopStack() {
1693 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001694 }
1695
Winson Chunge2d72172018-01-25 17:46:20 +00001696 ArrayList<Task> getVisibleTasks() {
1697 return mTaskStackContainers.getVisibleTasks();
1698 }
1699
Wale Ogunwale61911492017-10-11 08:50:50 -07001700 void onStackWindowingModeChanged(TaskStack stack) {
1701 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001702 }
1703
Andrii Kulian441e4492016-09-29 15:25:00 -07001704 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001705 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001706 super.onConfigurationChanged(newParentConfig);
1707
Andrii Kulian3a507b52016-09-19 18:14:12 -07001708 // The display size information is heavily dependent on the resources in the current
1709 // configuration, so we need to reconfigure it every time the configuration changes.
1710 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1711 mService.reconfigureDisplayLocked(this);
1712
Bryce Leef3c6a472017-11-14 14:53:06 -08001713 final DockedStackDividerController dividerController = getDockedDividerController();
1714
1715 if (dividerController != null) {
1716 getDockedDividerController().onConfigurationChanged();
1717 }
1718
1719 final PinnedStackController pinnedStackController = getPinnedStackController();
1720
1721 if (pinnedStackController != null) {
1722 getPinnedStackController().onConfigurationChanged();
1723 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001724 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001725
Andrii Kulian441e4492016-09-29 15:25:00 -07001726 /**
1727 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1728 * bounds were updated.
1729 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001730 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001731 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1732 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001733 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001734 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001735 }
1736 }
Winson Chung32c566f2017-04-11 18:31:21 -07001737
1738 // If there was no pinned stack, we still need to notify the controller of the display info
1739 // update as a result of the config change. We do this here to consolidate the flow between
1740 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001741 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001742 mPinnedStackControllerLocked.onDisplayInfoChanged();
1743 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001744 }
1745
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001746 @Override
1747 boolean fillsParent() {
1748 return true;
1749 }
1750
1751 @Override
1752 boolean isVisible() {
1753 return true;
1754 }
1755
1756 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001757 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001758 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001759 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001760 }
1761
Robert Carr9785cf32018-04-25 15:06:07 -07001762 /**
1763 * In split-screen mode we process the IME containers above the docked divider
1764 * rather than directly above their target.
1765 */
1766 private boolean skipTraverseChild(WindowContainer child) {
1767 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null
1768 && !hasSplitScreenPrimaryStack()) {
1769 return true;
1770 }
1771 return false;
1772 }
1773
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001774 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001775 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1776 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1777 // target, or here in order if there isn't an IME target.
1778 if (traverseTopToBottom) {
1779 for (int i = mChildren.size() - 1; i >= 0; --i) {
1780 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001781 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001782 continue;
1783 }
Robert Carr9785cf32018-04-25 15:06:07 -07001784
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001785 if (child.forAllWindows(callback, traverseTopToBottom)) {
1786 return true;
1787 }
1788 }
1789 } else {
1790 final int count = mChildren.size();
1791 for (int i = 0; i < count; i++) {
1792 final DisplayChildWindowContainer child = mChildren.get(i);
Robert Carr9785cf32018-04-25 15:06:07 -07001793 if (skipTraverseChild(child)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001794 continue;
1795 }
Robert Carr9785cf32018-04-25 15:06:07 -07001796
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001797 if (child.forAllWindows(callback, traverseTopToBottom)) {
1798 return true;
1799 }
1800 }
1801 }
1802 return false;
1803 }
1804
1805 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1806 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1807 }
1808
Wale Ogunwale399c8692017-05-08 14:22:42 -07001809 @Override
1810 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001811 final WindowManagerPolicy policy = mService.mPolicy;
1812
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001813 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001814 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001815 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1816 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001817 // If the display is frozen, some activities may be in the middle of restarting, and
1818 // thus have removed their old window. If the window has the flag to hide the lock
1819 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1820 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001821 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001822 } else if (policy.isKeyguardLocked()) {
1823 // Use the last orientation the while the display is frozen with the keyguard
1824 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1825 // window. We don't want to check the show when locked window directly though as
1826 // things aren't stable while the display is frozen, for example the window could be
1827 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001828 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1829 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001830 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001831 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001832 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001833 final int orientation = mAboveAppWindowsContainers.getOrientation();
1834 if (orientation != SCREEN_ORIENTATION_UNSET) {
1835 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001836 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001837 }
1838
Wale Ogunwale399c8692017-05-08 14:22:42 -07001839 // Top system windows are not requesting an orientation. Start searching from apps.
1840 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001841 }
1842
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001843 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001844 // Check if display metrics changed and update base values if needed.
1845 updateBaseDisplayMetricsIfNeeded();
1846
Craig Mautner722285e2012-09-07 13:55:58 -07001847 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001848 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001849
Wale Ogunwale61911492017-10-11 08:50:50 -07001850 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1851 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001852 }
Craig Mautner722285e2012-09-07 13:55:58 -07001853 }
1854
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001855 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001856 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1857 if (displayManagerInternal != null) {
1858 // Bootstrap the default logical display from the display manager.
1859 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1860 if (newDisplayInfo != null) {
1861 mDisplayInfo.copyFrom(newDisplayInfo);
1862 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001863 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001864
Andrii Kuliancd097992017-03-23 18:31:59 -07001865 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1866 mDisplayInfo.logicalDensityDpi);
1867 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1868 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1869 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001870 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001871 }
1872
Andrii Kuliancd097992017-03-23 18:31:59 -07001873 /**
1874 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1875 * values.
1876 */
1877 private void updateBaseDisplayMetricsIfNeeded() {
1878 // Get real display metrics without overrides from WM.
1879 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1880 final int orientation = mDisplayInfo.rotation;
1881 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1882 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1883 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1884 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001885 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001886
1887 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1888 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001889 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1890 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001891
1892 if (displayMetricsChanged) {
1893 // Check if display size or density is forced.
1894 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1895 || mBaseDisplayHeight != mInitialDisplayHeight;
1896 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1897
1898 // If there is an override set for base values - use it, otherwise use new values.
1899 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1900 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1901 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1902
1903 // Real display metrics changed, so we should also update initial values.
1904 mInitialDisplayWidth = newWidth;
1905 mInitialDisplayHeight = newHeight;
1906 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001907 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001908 mService.reconfigureDisplayLocked(this);
1909 }
1910 }
1911
Bryce Lee27cec322017-03-21 09:41:37 -07001912 /** Sets the maximum width the screen resolution can be */
1913 void setMaxUiWidth(int width) {
1914 if (DEBUG_DISPLAY) {
1915 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1916 }
1917
1918 mMaxUiWidth = width;
1919
1920 // Update existing metrics.
1921 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1922 }
1923
1924 /** Update base (override) display metrics. */
1925 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1926 mBaseDisplayWidth = baseWidth;
1927 mBaseDisplayHeight = baseHeight;
1928 mBaseDisplayDensity = baseDensity;
1929
1930 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1931 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1932 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1933 mBaseDisplayWidth = mMaxUiWidth;
1934
1935 if (DEBUG_DISPLAY) {
1936 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1937 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1938 + " on display:" + getDisplayId());
1939 }
1940 }
1941
1942 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001943
1944 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001945 }
1946
Wale Ogunwaledb506192017-12-08 10:57:32 -08001947 void getStableRect(Rect out) {
1948 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001949 }
1950
Wale Ogunwale61911492017-10-11 08:50:50 -07001951 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001952 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1953 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001954
Wale Ogunwale61911492017-10-11 08:50:50 -07001955 final TaskStack stack = new TaskStack(mService, stackId, controller);
1956 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001957 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001958 }
1959
Andrii Kulian51c1b672017-04-07 18:39:32 -07001960 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001961 final DisplayContent prevDc = stack.getDisplayContent();
1962 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001963 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1964 + " which is not currently attached to any display");
1965 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001966 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001967 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1968 + " to its current displayId=" + mDisplayId);
1969 }
1970
Wale Ogunwale61911492017-10-11 08:50:50 -07001971 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001972 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001973 }
1974
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001975 @Override
1976 protected void addChild(DisplayChildWindowContainer child,
1977 Comparator<DisplayChildWindowContainer> comparator) {
1978 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1979 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001980
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001981 @Override
1982 protected void addChild(DisplayChildWindowContainer child, int index) {
1983 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1984 }
1985
1986 @Override
1987 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001988 // Only allow removal of direct children from this display if the display is in the process
1989 // of been removed.
1990 if (mRemovingDisplay) {
1991 super.removeChild(child);
1992 return;
1993 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001994 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001995 }
1996
Andrii Kuliand2765632016-12-12 22:26:34 -08001997 @Override
1998 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1999 // Children of the display are statically ordered, so the real intention here is to perform
2000 // the operation on the display and not the static direct children.
2001 getParent().positionChildAt(position, this, includingParents);
2002 }
2003
Riddle Hsu57831b52018-07-27 00:31:48 +08002004 void positionStackAt(int position, TaskStack child, boolean includingParents) {
2005 mTaskStackContainers.positionChildAt(position, child, includingParents);
Winson Chung59a47ded2018-01-25 17:46:06 +00002006 layoutAndAssignWindowLayersIfNeeded();
2007 }
2008
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002009 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002010 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2011 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002012 final int taskId = stack.taskIdFromPoint(x, y);
2013 if (taskId != -1) {
2014 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07002015 }
2016 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08002017 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07002018 }
2019
Chong Zhang8e89b312015-09-09 15:09:30 -07002020 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08002021 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07002022 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07002023 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07002024 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002025 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002026 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07002027 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2028 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002029 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002030 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002031 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002032
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002033 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
2034 if (mTmpTaskForResizePointSearchResult.searchDone) {
2035 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07002036 }
2037 }
Chong Zhang9184ec62015-09-24 12:32:21 -07002038 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07002039 }
2040
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002041 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08002042 // The provided task is the task on this display with focus, so if WindowManagerService's
2043 // focused app is not on this display, focusedTask will be null.
2044 if (focusedTask == null) {
2045 mTouchExcludeRegion.setEmpty();
2046 } else {
2047 mTouchExcludeRegion.set(mBaseDisplayRect);
2048 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
2049 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07002050 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2051 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002052 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
2053 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08002054 }
2055 // If we removed the focused task above, add it back and only leave its
2056 // outside touch area in the exclusion. TapDectector is not interested in
2057 // any touch inside the focused task itself.
2058 if (!mTmpRect2.isEmpty()) {
2059 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
2060 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08002061 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002062 final WindowState inputMethod = mService.mInputMethodWindow;
2063 if (inputMethod != null && inputMethod.isVisibleLw()) {
2064 // If the input method is visible and the user is typing, we don't want these touch
2065 // events to be intercepted and used to change focus. This would likely cause a
2066 // disappearance of the input method.
2067 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07002068 if (inputMethod.getDisplayId() == mDisplayId) {
2069 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2070 } else {
2071 // IME is on a different display, so we need to update its tap detector.
2072 // TODO(multidisplay): Remove when IME will always appear on same display.
2073 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
2074 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08002075 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002076 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002077 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08002078 win.getTouchableRegion(mTmpRegion);
2079 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
2080 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08002081 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
2082 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
2083 win.amendTapExcludeRegion(mTouchExcludeRegion);
2084 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08002085 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07002086 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002087 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07002088 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01002089 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
2090 }
Craig Mautner1bef3892015-02-17 15:09:47 -08002091 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07002092 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08002093 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07002094 }
2095
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002096 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002097 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002098 super.switchUser();
2099 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07002100 }
2101
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07002102 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002103 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2104 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07002105 }
2106 }
2107
Wale Ogunwale10124582016-09-15 20:25:50 -07002108 @Override
2109 void removeIfPossible() {
2110 if (isAnimating()) {
2111 mDeferredRemoval = true;
2112 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07002113 }
Wale Ogunwale10124582016-09-15 20:25:50 -07002114 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07002115 }
2116
Wale Ogunwale10124582016-09-15 20:25:50 -07002117 @Override
2118 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002119 mRemovingDisplay = true;
2120 try {
2121 super.removeImmediately();
2122 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07002123 if (mService.canDispatchPointerEvents()) {
2124 if (mTapDetector != null) {
2125 mService.unregisterPointerEventListener(mTapDetector);
2126 }
2127 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
2128 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
2129 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002130 }
Jorim Jaggia3844032018-01-03 15:54:43 +01002131 mService.mAnimator.removeDisplayLocked(mDisplayId);
Louis Chang207f9112018-07-30 08:58:54 +08002132 mWindowingLayer.release();
2133 mOverlayLayer.release();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07002134 } finally {
2135 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08002136 }
Bryce Leef19cbe22018-02-02 15:09:21 -08002137
2138 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08002139 }
2140
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002141 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07002142 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002143 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07002144 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
2145
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002146 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002147 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002148 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08002149 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07002150 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08002151 }
2152
Andrii Kulian0214ed92017-05-16 13:44:05 -07002153 /** @return 'true' if removal of this display content is deferred due to active animation. */
2154 boolean isRemovalDeferred() {
2155 return mDeferredRemoval;
2156 }
2157
Wale Ogunwale10124582016-09-15 20:25:50 -07002158 boolean animateForIme(float interpolatedValue, float animationTarget,
2159 float dividerAnimationTarget) {
2160 boolean updated = false;
2161
Wale Ogunwale61911492017-10-11 08:50:50 -07002162 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2163 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002164 if (stack == null || !stack.isAdjustedForIme()) {
2165 continue;
2166 }
2167
2168 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2169 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2170 updated = true;
2171 } else {
2172 mDividerControllerLocked.mLastAnimationProgress =
2173 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2174 mDividerControllerLocked.mLastDividerProgress =
2175 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2176 updated |= stack.updateAdjustForIme(
2177 mDividerControllerLocked.mLastAnimationProgress,
2178 mDividerControllerLocked.mLastDividerProgress,
2179 false /* force */);
2180 }
2181 if (interpolatedValue >= 1f) {
2182 stack.endImeAdjustAnimation();
2183 }
2184 }
2185
2186 return updated;
2187 }
2188
2189 boolean clearImeAdjustAnimation() {
2190 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002191 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2192 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002193 if (stack != null && stack.isAdjustedForIme()) {
2194 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2195 changed = true;
2196 }
2197 }
2198 return changed;
2199 }
2200
2201 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002202 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2203 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002204 if (stack.isVisible() && stack.isAdjustedForIme()) {
2205 stack.beginImeAdjustAnimation();
2206 }
2207 }
2208 }
2209
2210 void adjustForImeIfNeeded() {
2211 final WindowState imeWin = mService.mInputMethodWindow;
2212 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2213 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002214 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002215 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2216 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2217 imeTargetStack.getDockSide() : DOCKED_INVALID;
2218 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2219 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2220 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002221 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002222 final boolean imeHeightChanged = imeVisible &&
2223 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2224
2225 // The divider could be adjusted for IME position, or be thinner than usual,
2226 // or both. There are three possible cases:
2227 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2228 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2229 // - If IME is not visible, divider is not moved and is normal width.
2230
2231 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002232 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2233 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002234 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002235 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2236 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002237 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2238 } else {
2239 stack.resetAdjustedForIme(false);
2240 }
2241 }
2242 mDividerControllerLocked.setAdjustedForIme(
2243 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2244 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002245 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2246 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002247 stack.resetAdjustedForIme(!dockVisible);
2248 }
2249 mDividerControllerLocked.setAdjustedForIme(
2250 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2251 }
Winson Chung655332c2016-10-31 13:14:28 -07002252 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002253 }
2254
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002255 /**
2256 * If a window that has an animation specifying a colored background and the current wallpaper
2257 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2258 * suddenly disappear.
2259 */
2260 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002261 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2262 w -> w.mIsWallpaper && w.isVisibleNow());
2263
2264 if (visibleWallpaper != null) {
2265 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002266 }
2267 return winAnimator.mAnimLayer;
2268 }
2269
Wale Ogunwale10124582016-09-15 20:25:50 -07002270 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002271 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2272 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002273 stack.prepareFreezingTaskBounds();
2274 }
2275 }
2276
Wale Ogunwale94744212015-09-21 19:01:47 -07002277 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002278 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002279
2280 // Compute a transform matrix to undo the coordinate space transformation,
2281 // and present the window at the same physical position it previously occupied.
2282 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2283 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2284
2285 mTmpRectF.set(bounds);
2286 mTmpMatrix.mapRect(mTmpRectF);
2287 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002288 }
2289
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002290 static int deltaRotation(int oldRotation, int newRotation) {
2291 int delta = newRotation - oldRotation;
2292 if (delta < 0) delta += 4;
2293 return delta;
2294 }
2295
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002296 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002297 Matrix outMatrix) {
2298 // For rotations without Z-ordering we don't need the target rectangle's position.
2299 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2300 displayHeight, outMatrix);
2301 }
2302
2303 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2304 float displayWidth, float displayHeight, Matrix outMatrix) {
2305 switch (rotation) {
2306 case ROTATION_0:
2307 outMatrix.reset();
2308 break;
2309 case ROTATION_270:
2310 outMatrix.setRotate(270, 0, 0);
2311 outMatrix.postTranslate(0, displayHeight);
2312 outMatrix.postTranslate(rectTop, 0);
2313 break;
2314 case ROTATION_180:
2315 outMatrix.reset();
2316 break;
2317 case ROTATION_90:
2318 outMatrix.setRotate(90, 0, 0);
2319 outMatrix.postTranslate(displayWidth, 0);
2320 outMatrix.postTranslate(-rectTop, rectLeft);
2321 break;
2322 }
2323 }
2324
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002325 @CallSuper
2326 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002327 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002328 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002329 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002330 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002331 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2332 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002333 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002334 }
2335 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2336 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002337 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2338 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002339 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002340 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002341 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2342 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002343 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002344 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002345 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2346 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002347 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002348 }
2349 proto.write(DPI, mBaseDisplayDensity);
2350 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002351 proto.write(ROTATION, mRotation);
2352 final ScreenRotationAnimation screenRotationAnimation =
2353 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2354 if (screenRotationAnimation != null) {
2355 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2356 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002357 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002358 proto.end(token);
2359 }
2360
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002361 @Override
2362 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2363 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002364 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2365 final String subPrefix = " " + prefix;
2366 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2367 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2368 pw.print("dpi");
2369 if (mInitialDisplayWidth != mBaseDisplayWidth
2370 || mInitialDisplayHeight != mBaseDisplayHeight
2371 || mInitialDisplayDensity != mBaseDisplayDensity) {
2372 pw.print(" base=");
2373 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2374 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2375 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002376 if (mDisplayScalingDisabled) {
2377 pw.println(" noscale");
2378 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002379 pw.print(" cur=");
2380 pw.print(mDisplayInfo.logicalWidth);
2381 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2382 pw.print(" app=");
2383 pw.print(mDisplayInfo.appWidth);
2384 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2385 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2386 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2387 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2388 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002389 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002390 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002391 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002392
Craig Mautnerdc548482014-02-05 13:35:24 -08002393 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002394 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
Riddle Hsu654a6f92018-07-13 22:59:36 +08002395 pw.print(prefix);
2396 pw.print("mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
Adrian Roos5251b1d2018-03-23 18:57:43 +01002397
2398 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002399 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002400 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2401 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002402 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002403 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002404
Craig Mautnerdc548482014-02-05 13:35:24 -08002405 pw.println();
2406 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002407 pw.println();
2408 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002409 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002410 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002411 pw.print(" Exiting #"); pw.print(i);
2412 pw.print(' '); pw.print(token);
2413 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002414 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002415 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002416 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002417
Jorim Jaggi31f71702016-05-04 16:43:04 -07002418 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002419
2420 // Dump stack references
2421 final TaskStack homeStack = getHomeStack();
2422 if (homeStack != null) {
2423 pw.println(prefix + "homeStack=" + homeStack.getName());
2424 }
2425 final TaskStack pinnedStack = getPinnedStack();
2426 if (pinnedStack != null) {
2427 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2428 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002429 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002430 if (splitScreenPrimaryStack != null) {
2431 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2432 }
2433
2434 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002435 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002436 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002437 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002438
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002439 pw.println();
2440 mDisplayFrames.dump(prefix, pw);
Arthur Hung95b38a92018-07-20 18:56:12 +08002441 pw.println();
Riddle Hsu5ce4bb32018-07-18 16:11:30 +08002442 mDisplayPolicy.dump(prefix, pw);
2443 pw.println();
Riddle Hsuad256a12018-07-18 16:11:30 +08002444 mDisplayRotation.dump(prefix, pw);
2445 pw.println();
Arthur Hung95b38a92018-07-20 18:56:12 +08002446 mInputMonitor.dump(pw, " ");
Craig Mautner59c00972012-07-30 12:10:24 -07002447 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002448
2449 @Override
2450 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002451 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002452 }
2453
2454 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002455 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002456 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002457
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002458 /** Returns true if the stack in the windowing mode is visible. */
2459 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002460 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002461 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002462 }
2463
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002464 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002465 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002466 final int x = (int) xf;
2467 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002468 final WindowState touchedWin = getWindow(w -> {
2469 final int flags = w.mAttrs.flags;
2470 if (!w.isVisibleLw()) {
2471 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002472 }
2473 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002474 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002475 }
2476
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002477 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002478 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002479 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002480 }
2481
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002482 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002483
2484 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002485 return mTmpRegion.contains(x, y) || touchFlags == 0;
2486 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002487
2488 return touchedWin;
2489 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002490
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002491 boolean canAddToastWindowForUid(int uid) {
2492 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002493 // Also if the app is focused adding more than one toast at
2494 // a time for better backwards compatibility.
2495 final WindowState focusedWindowForUid = getWindow(w ->
2496 w.mOwnerUid == uid && w.isFocused());
2497 if (focusedWindowForUid != null) {
2498 return true;
2499 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002500 final WindowState win = getWindow(w ->
2501 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2502 && !w.mWindowRemovalAllowed);
2503 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002504 }
2505
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002506 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002507 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2508 return;
2509 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002510
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002511 // Used to communicate the old focus to the callback method.
2512 mTmpWindow = oldFocus;
2513
2514 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002515 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002516
2517 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002518 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002519
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002520 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002521
2522 if (mTmpWindow == null) {
2523 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2524 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002525 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002526 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002527 }
2528
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002529 /** Updates the layer assignment of windows on this display. */
2530 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002531 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002532 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002533 if (setLayoutNeeded) {
2534 setLayoutNeeded();
2535 }
Robert Carrb1579c82017-09-05 14:54:47 -07002536
Robert Carrf59b8dd2017-10-02 18:58:36 -07002537 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002538 // the application of this transaction until the animation pass triggers
2539 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2540 // the hiding and showing of surfaces.
2541 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002542 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002543 }
2544
Wale Ogunwale1666e312016-12-16 11:27:18 -08002545 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2546 // moving containers or resizing them. Need to investigate the best way to have it automatically
2547 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002548 void layoutAndAssignWindowLayersIfNeeded() {
2549 mService.mWindowsChanged = true;
2550 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002551
2552 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2553 false /*updateInputWindows*/)) {
2554 assignWindowLayers(false /* setLayoutNeeded */);
2555 }
2556
Arthur Hung95b38a92018-07-20 18:56:12 +08002557 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002558 mService.mWindowPlacerLocked.performSurfacePlacement();
Arthur Hung95b38a92018-07-20 18:56:12 +08002559 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002560 }
2561
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002562 /** Returns true if a leaked surface was destroyed */
2563 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002564 // Used to indicate that a surface was leaked.
2565 mTmpWindow = null;
2566 forAllWindows(w -> {
2567 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002568 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002569 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002570 }
2571 if (!mService.mSessions.contains(wsa.mSession)) {
2572 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002573 + w + " surface=" + wsa.mSurfaceController
2574 + " token=" + w.mToken
2575 + " pid=" + w.mSession.mPid
2576 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002577 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002578 mService.mForceRemoves.add(w);
2579 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002580 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002581 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002582 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002583 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002584 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002585 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002586 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002587 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002588 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002589
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002590 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002591 }
2592
2593 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002594 * Determine and return the window that should be the IME target.
2595 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2596 * @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 +00002597 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002598 WindowState computeImeTarget(boolean updateImeTarget) {
2599 if (mService.mInputMethodWindow == null) {
2600 // There isn't an IME so there shouldn't be a target...That was easy!
2601 if (updateImeTarget) {
2602 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2603 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002604 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002605 }
2606 return null;
2607 }
2608
Chavi Weingarten3a748552018-05-14 17:32:42 +00002609 final WindowState curTarget = mService.mInputMethodTarget;
2610 if (!canUpdateImeTarget()) {
2611 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Defer updating IME target");
2612 return curTarget;
2613 }
2614
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002615 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2616 // same display. Or even when the current IME/target are not on the same screen as the next
2617 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002618 mUpdateImeTarget = updateImeTarget;
2619 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002620
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002621
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002622 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2623 // to be on top of it, but it is not -really- where input will go. So look down below
2624 // for a real window to target...
2625 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2626 final AppWindowToken token = target.mAppToken;
2627 if (token != null) {
2628 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2629 if (betterTarget != null) {
2630 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002631 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002632 }
2633 }
2634
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002635 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2636 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002637
chaviw1c13ad32018-06-12 16:44:23 -07002638 // Now, a special case -- if the last target's window is in the process of exiting, but
2639 // not removed, and the new target is home, keep on the last target to avoid flicker.
2640 // Home is a special case since its above other stacks in the ordering list, but layed
2641 // out below the others.
2642 if (curTarget != null && !curTarget.mRemoved && curTarget.isDisplayedLw()
2643 && curTarget.isClosing() && (target == null || target.isActivityTypeHome())) {
chaviw4ad54912018-05-30 11:05:44 -07002644 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "New target is home while current target is "
Chavi Weingarten3a748552018-05-14 17:32:42 +00002645 + "closing, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002646 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002647 }
2648
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002649 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2650 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002651
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002652 if (target == null) {
2653 if (updateImeTarget) {
2654 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2655 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2656 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002657 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002658 }
2659
2660 return null;
2661 }
2662
2663 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002664 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2665 if (token != null) {
2666
2667 // Now some fun for dealing with window animations that modify the Z order. We need
2668 // to look at all windows below the current target that are in this app, finding the
2669 // highest visible one in layering.
2670 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002671 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002672 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002673 }
2674
2675 if (highestTarget != null) {
2676 final AppTransition appTransition = mService.mAppTransition;
2677 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2678 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2679 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002680 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002681
2682 if (appTransition.isTransitionSet()) {
2683 // If we are currently setting up for an animation, hold everything until we
2684 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002685 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002686 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002687 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002688 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002689 // If the window we are currently targeting is involved with an animation,
2690 // and it is on top of the next target we will be over, then hold off on
2691 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002692 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002693 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002694 }
2695 }
2696 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002697
2698 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2699 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002700 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002701 }
2702
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002703 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002704 }
2705
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002706 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002707 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002708 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002709 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002710 }
2711
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002712 mService.mInputMethodTarget = target;
2713 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002714 assignWindowLayers(false /* setLayoutNeeded */);
2715 }
2716
2717 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2718 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2719 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2720 }
2721
2722 // Used to indicate we have reached the first window in the range we are interested in.
2723 mTmpWindow = null;
2724
2725 // TODO: Figure-out a more efficient way to do this.
2726 final WindowState candidate = getWindow(w -> {
2727 if (w == top) {
2728 // Reached the first window in the range we are interested in.
2729 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002730 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002731 if (mTmpWindow == null) {
2732 return false;
2733 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002734
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002735 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2736 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002737 }
2738 // If we reached the bottom of the range of windows we are considering,
2739 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002740 if (w == bottom) {
2741 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002742 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002743 return false;
2744 });
2745
2746 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002747 }
2748
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002749 void setLayoutNeeded() {
2750 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2751 mLayoutNeeded = true;
2752 }
2753
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002754 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002755 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2756 mLayoutNeeded = false;
2757 }
2758
2759 boolean isLayoutNeeded() {
2760 return mLayoutNeeded;
2761 }
2762
Wale Ogunwale02319a62016-09-26 15:21:22 -07002763 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2764 if (mTokenMap.isEmpty()) {
2765 return;
2766 }
2767 pw.println(" Display #" + mDisplayId);
2768 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2769 while (it.hasNext()) {
2770 final WindowToken token = it.next();
2771 pw.print(" ");
2772 pw.print(token);
2773 if (dumpAll) {
2774 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002775 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002776 } else {
2777 pw.println();
2778 }
2779 }
2780 }
2781
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002782 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002783 final int[] index = new int[1];
2784 forAllWindows(w -> {
2785 final WindowStateAnimator wAnim = w.mWinAnimator;
2786 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2787 index[0] = index[0] + 1;
2788 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002789 }
2790
Jorim Jaggife762342016-10-13 14:33:27 +02002791 /**
2792 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2793 */
2794 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2795 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002796 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002797 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2798 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002799 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002800 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002801 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002802 }
2803
Wale Ogunwale494009b82016-10-21 09:01:38 -07002804 boolean checkWaitingForWindows() {
2805
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002806 mHaveBootMsg = false;
2807 mHaveApp = false;
2808 mHaveWallpaper = false;
2809 mHaveKeyguard = true;
2810
2811 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002812 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2813 return true;
2814 }
2815 if (w.isDrawnLw()) {
2816 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002817 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002818 } else if (w.mAttrs.type == TYPE_APPLICATION
2819 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002820 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002821 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002822 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002823 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002824 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002825 }
2826 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002827 return false;
2828 });
2829
2830 if (visibleWindow != null) {
2831 // We have a visible window.
2832 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002833 }
2834
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002835 // if the wallpaper service is disabled on the device, we're never going to have
2836 // wallpaper, don't bother waiting for it
2837 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2838 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09002839 && mService.mContext.getResources().getBoolean(
2840 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002841 && !mService.mOnlyCore;
2842
Wale Ogunwale494009b82016-10-21 09:01:38 -07002843 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2844 "******** booted=" + mService.mSystemBooted
2845 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002846 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2847 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2848 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002849
2850 // If we are turning on the screen to show the boot message, don't do it until the boot
2851 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002852 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002853 return true;
2854 }
2855
2856 // If we are turning on the screen after the boot is completed normally, don't do so until
2857 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002858 if (mService.mSystemBooted
2859 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002860 return true;
2861 }
2862
2863 return false;
2864 }
2865
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002866 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002867 mTmpWindowAnimator = animator;
2868 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002869 }
2870
2871 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002872 resetAnimationBackgroundAnimator();
2873
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002874 // Used to indicate a detached wallpaper.
2875 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002876 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002877
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002878 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002879
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002880 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002881 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002882 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2883 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002884 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2885 }
2886 }
2887
Wale Ogunwale494009b82016-10-21 09:01:38 -07002888 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002889 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002890 if (imFocus == null) {
2891 return false;
2892 }
2893
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002894 if (DEBUG_INPUT_METHOD) {
2895 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2896 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2897 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002898 }
2899
Wale Ogunwale494009b82016-10-21 09:01:38 -07002900 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2901
2902 if (DEBUG_INPUT_METHOD) {
2903 Slog.i(TAG_WM, "IM target client: " + imeClient);
2904 if (imeClient != null) {
2905 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2906 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2907 }
2908 }
2909
2910 return imeClient != null && imeClient.asBinder() == client.asBinder();
2911 }
2912
2913 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002914 final WindowState win = getWindow(
2915 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2916 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002917 }
2918
2919 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002920 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002921 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002922 final int curValue = w.mSystemUiVisibility;
2923 final int diff = (curValue ^ visibility) & globalDiff;
2924 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002925 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002926 w.mSeq++;
2927 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002928 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002929 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2930 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002931 visibility, newValue, diff);
2932 }
2933 } catch (RemoteException e) {
2934 // so sorry
2935 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002936 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002937 }
2938
2939 void onWindowFreezeTimeout() {
2940 Slog.w(TAG_WM, "Window freeze timeout expired.");
2941 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002942
2943 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002944 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002945 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002946 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002947 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002948 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2949 - mService.mDisplayFreezeTime);
2950 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002951 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002952 mService.mWindowPlacerLocked.performSurfacePlacement();
2953 }
2954
2955 void waitForAllWindowsDrawn() {
2956 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002957 forAllWindows(w -> {
2958 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2959 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2960 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002961 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002962 w.mLastContentInsets.set(-1, -1, -1, -1);
2963 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002964 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002965 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002966 }
2967
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002968 // TODO: Super crazy long method that should be broken down...
2969 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2970
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002971 final int dw = mDisplayInfo.logicalWidth;
2972 final int dh = mDisplayInfo.logicalHeight;
2973 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2974
2975 mTmpUpdateAllDrawn.clear();
2976
2977 int repeats = 0;
2978 do {
2979 repeats++;
2980 if (repeats > 6) {
2981 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2982 clearLayoutNeeded();
2983 break;
2984 }
2985
2986 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2987 pendingLayoutChanges);
2988
Andrii Kulian839def92016-11-02 10:58:58 -07002989 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2990 // the wallpaper window jumping across displays.
2991 // Remove check for default display when there will be support for multiple wallpaper
2992 // targets (on different displays).
2993 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002994 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002995 }
2996
Riddle Hsu654a6f92018-07-13 22:59:36 +08002997 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002998 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08002999 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003000 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07003001 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003002 }
3003 }
3004
3005 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
3006 setLayoutNeeded();
3007 }
3008
3009 // FIRST LOOP: Perform a layout, if needed.
3010 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
3011 performLayout(repeats == 1, false /* updateInputWindows */);
3012 } else {
3013 Slog.w(TAG, "Layout repeat skipped after too many iterations");
3014 }
3015
3016 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
3017 pendingLayoutChanges = 0;
3018
3019 if (isDefaultDisplay) {
3020 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003021 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003022 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
3023 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
3024 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
3025 }
3026 } while (pendingLayoutChanges != 0);
3027
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003028 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003029
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003030 mTmpRecoveringMemory = recoveringMemory;
3031 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01003032 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003033
3034 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003035 mTmpApplySurfaceChangesTransactionState.displayHasContent,
3036 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
3037 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003038 true /* inTraversal, must call performTraversalInTrans... below */);
3039
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07003040 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
3041 if (wallpaperVisible != mLastWallpaperVisible) {
3042 mLastWallpaperVisible = wallpaperVisible;
3043 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
3044 }
3045
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003046 while (!mTmpUpdateAllDrawn.isEmpty()) {
3047 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
3048 // See if any windows have been drawn, so they (and others associated with them)
3049 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07003050 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003051 }
3052
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003053 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003054 }
3055
Bryce Leef3c6a472017-11-14 14:53:06 -08003056 private void updateBounds() {
3057 calculateBounds(mTmpBounds);
3058 setBounds(mTmpBounds);
3059 }
3060
3061 // Determines the current display bounds based on the current state
3062 private void calculateBounds(Rect out) {
3063 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
3064 final int orientation = mDisplayInfo.rotation;
3065 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
3066 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
3067 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
3068 int width = mDisplayInfo.logicalWidth;
3069 int left = (physWidth - width) / 2;
3070 int height = mDisplayInfo.logicalHeight;
3071 int top = (physHeight - height) / 2;
3072 out.set(left, top, left + width, top + height);
3073 }
3074
3075 @Override
3076 public void getBounds(Rect out) {
3077 calculateBounds(out);
3078 }
3079
3080 private void getBounds(Rect out, int orientation) {
3081 getBounds(out);
3082
3083 // Rotate the Rect if needed.
3084 final int currentRotation = mDisplayInfo.rotation;
3085 final int rotationDelta = deltaRotation(currentRotation, orientation);
3086 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
3087 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
3088 mTmpRectF.set(out);
3089 mTmpMatrix.mapRect(mTmpRectF);
3090 mTmpRectF.round(out);
3091 }
3092 }
3093
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003094 void performLayout(boolean initial, boolean updateInputWindows) {
3095 if (!isLayoutNeeded()) {
3096 return;
3097 }
3098 clearLayoutNeeded();
3099
3100 final int dw = mDisplayInfo.logicalWidth;
3101 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003102 if (DEBUG_LAYOUT) {
3103 Slog.v(TAG, "-------------------------------------");
3104 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
3105 }
3106
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003107 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
3108 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00003109 // TODO: Not sure if we really need to set the rotation here since we are updating from the
3110 // display info above...
3111 mDisplayFrames.mRotation = mRotation;
3112 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003113 if (isDefaultDisplay) {
3114 // Not needed on non-default displays.
3115 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
3116 mService.mScreenRect.set(0, 0, dw, dh);
3117 }
3118
Adrian Roos5251b1d2018-03-23 18:57:43 +01003119 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003120 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01003121 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003122
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003123 // Used to indicate that we have processed the dream window and all additional windows are
3124 // behind it.
3125 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003126 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003127
3128 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003129 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
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 attached
3132 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003133 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003134 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003135
3136 // Now perform layout of attached windows, which usually depend on the position of the
3137 // window they are attached to. XXX does not deal with windows that are attached to windows
3138 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003139 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003140
3141 // Window frames may have changed. Tell the input dispatcher about it.
Arthur Hung95b38a92018-07-20 18:56:12 +08003142 mInputMonitor.layoutInputConsumers(dw, dh);
3143 mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003144 if (updateInputWindows) {
Arthur Hung95b38a92018-07-20 18:56:12 +08003145 mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003146 }
3147
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003148 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
3149 }
3150
3151 /**
3152 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
3153 * In portrait mode, it grabs the full screenshot.
3154 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003155 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003156 */
chaviw0315a1a2018-03-05 15:28:35 -08003157 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
3158 if (!mService.mPolicy.isScreenOn()) {
3159 if (DEBUG_SCREENSHOT) {
3160 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003161 }
chaviw0315a1a2018-03-05 15:28:35 -08003162 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003163 }
chaviwfbe47df2017-11-10 16:14:49 -08003164
chaviw0315a1a2018-03-05 15:28:35 -08003165 int dw = mDisplayInfo.logicalWidth;
3166 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08003167
chaviw0315a1a2018-03-05 15:28:35 -08003168 if (dw <= 0 || dh <= 0) {
3169 return null;
3170 }
chaviwfbe47df2017-11-10 16:14:49 -08003171
chaviw0315a1a2018-03-05 15:28:35 -08003172 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003173
chaviw0315a1a2018-03-05 15:28:35 -08003174 // The screenshot API does not apply the current screen rotation.
3175 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003176
chaviw0315a1a2018-03-05 15:28:35 -08003177 if (rot == ROTATION_90 || rot == ROTATION_270) {
3178 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3179 }
chaviwfbe47df2017-11-10 16:14:49 -08003180
chaviw0315a1a2018-03-05 15:28:35 -08003181 // SurfaceFlinger is not aware of orientation, so convert our logical
3182 // crop to SurfaceFlinger's portrait orientation.
3183 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3184
3185 final ScreenRotationAnimation screenRotationAnimation =
3186 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3187 final boolean inRotation = screenRotationAnimation != null &&
3188 screenRotationAnimation.isAnimating();
3189 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3190
3191 // TODO(b/68392460): We should screenshot Task controls directly
3192 // but it's difficult at the moment as the Task doesn't have the
3193 // correct size set.
3194 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3195 if (bitmap == null) {
3196 Slog.w(TAG_WM, "Failed to take screenshot");
3197 return null;
3198 }
3199
3200 // Create a copy of the screenshot that is immutable and backed in ashmem.
3201 // This greatly reduces the overhead of passing the bitmap between processes.
3202 final Bitmap ret = bitmap.createAshmemBitmap(config);
3203 bitmap.recycle();
3204 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003205 }
3206
3207 // TODO: Can this use createRotationMatrix()?
3208 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3209 if (rot == Surface.ROTATION_90) {
3210 final int tmp = crop.top;
3211 crop.top = dw - crop.right;
3212 crop.right = crop.bottom;
3213 crop.bottom = dw - crop.left;
3214 crop.left = tmp;
3215 } else if (rot == Surface.ROTATION_180) {
3216 int tmp = crop.top;
3217 crop.top = dh - crop.bottom;
3218 crop.bottom = dh - tmp;
3219 tmp = crop.right;
3220 crop.right = dw - crop.left;
3221 crop.left = dw - tmp;
3222 } else if (rot == Surface.ROTATION_270) {
3223 final int tmp = crop.top;
3224 crop.top = crop.left;
3225 crop.left = dh - crop.bottom;
3226 crop.bottom = crop.right;
3227 crop.right = dh - tmp;
3228 }
3229 }
3230
3231 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003232 // Used to indicate the layout is needed.
3233 mTmpWindow = null;
3234
3235 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003236 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003237 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003238 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003239 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003240 w.setDisplayLayoutNeeded();
3241 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003242 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003243
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003244 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003245 mService.mWindowPlacerLocked.performSurfacePlacement();
3246 }
3247 }
3248
Wale Ogunwale1666e312016-12-16 11:27:18 -08003249 void setExitingTokensHasVisible(boolean hasVisible) {
3250 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3251 mExitingTokens.get(i).hasVisible = hasVisible;
3252 }
3253
3254 // Initialize state of exiting applications.
3255 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3256 }
3257
3258 void removeExistingTokensIfPossible() {
3259 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3260 final WindowToken token = mExitingTokens.get(i);
3261 if (!token.hasVisible) {
3262 mExitingTokens.remove(i);
3263 }
3264 }
3265
3266 // Time to remove any exiting applications?
3267 mTaskStackContainers.removeExistingAppTokensIfPossible();
3268 }
3269
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003270 @Override
3271 void onDescendantOverrideConfigurationChanged() {
3272 setLayoutNeeded();
3273 mService.requestTraversal();
3274 }
3275
David Stevens9440dc82017-03-16 19:00:20 -07003276 boolean okToDisplay() {
3277 if (mDisplayId == DEFAULT_DISPLAY) {
3278 return !mService.mDisplayFrozen
3279 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3280 }
3281 return mDisplayInfo.state == Display.STATE_ON;
3282 }
3283
3284 boolean okToAnimate() {
3285 return okToDisplay() &&
3286 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3287 }
3288
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003289 static final class TaskForResizePointSearchResult {
3290 boolean searchDone;
3291 Task taskForResize;
3292
3293 void reset() {
3294 searchDone = false;
3295 taskForResize = null;
3296 }
3297 }
Robert Carr3b716242016-08-16 16:02:21 -07003298
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003299 private static final class ApplySurfaceChangesTransactionState {
3300 boolean displayHasContent;
3301 boolean obscured;
3302 boolean syswin;
3303 boolean focusDisplayed;
3304 float preferredRefreshRate;
3305 int preferredModeId;
3306
3307 void reset() {
3308 displayHasContent = false;
3309 obscured = false;
3310 syswin = false;
3311 focusDisplayed = false;
3312 preferredRefreshRate = 0;
3313 preferredModeId = 0;
3314 }
3315 }
3316
3317 private static final class ScreenshotApplicationState {
3318 WindowState appWin;
3319 int maxLayer;
3320 int minLayer;
3321 boolean screenshotReady;
3322
3323 void reset(boolean screenshotReady) {
3324 appWin = null;
3325 maxLayer = 0;
3326 minLayer = 0;
3327 this.screenshotReady = screenshotReady;
3328 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3329 }
3330 }
3331
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003332 /**
3333 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3334 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3335 * homogeneous children type which is currently required by sub-classes of
3336 * {@link WindowContainer} class.
3337 */
3338 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3339
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003340 DisplayChildWindowContainer(WindowManagerService service) {
3341 super(service);
3342 }
3343
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003344 @Override
3345 boolean fillsParent() {
3346 return true;
3347 }
3348
3349 @Override
3350 boolean isVisible() {
3351 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003352 }
3353 }
3354
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003355 /**
3356 * Window container class that contains all containers on this display relating to Apps.
3357 * I.e Activities.
3358 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003359 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003360 /**
3361 * A control placed at the appropriate level for transitions to occur.
3362 */
chaviw23ee71c2017-12-18 11:29:41 -08003363 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003364 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003365 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003366
Robert Carrf7a7ca82017-12-06 13:17:07 -08003367 /**
3368 * Given that the split-screen divider does not have an AppWindowToken, it
3369 * will have to live inside of a "NonAppWindowContainer", in particular
3370 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3371 * it will need to be interleaved with some of our children, appearing on top of
3372 * both docked stacks but underneath any assistant stacks.
3373 *
3374 * To solve this problem we have this anchor control, which will always exist so
3375 * we can always assign it the correct value in our {@link #assignChildLayers}.
3376 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3377 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3378 * events between the two containers.
3379 */
3380 SurfaceControl mSplitScreenDividerAnchor = null;
3381
Wale Ogunwale61911492017-10-11 08:50:50 -07003382 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3383 // through the list to find them.
3384 private TaskStack mHomeStack = null;
3385 private TaskStack mPinnedStack = null;
3386 private TaskStack mSplitScreenPrimaryStack = null;
3387
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003388 TaskStackContainers(WindowManagerService service) {
3389 super(service);
3390 }
3391
Wale Ogunwale61911492017-10-11 08:50:50 -07003392 /**
3393 * Returns the topmost stack on the display that is compatible with the input windowing mode
3394 * and activity type. Null is no compatible stack on the display.
3395 */
3396 TaskStack getStack(int windowingMode, int activityType) {
3397 if (activityType == ACTIVITY_TYPE_HOME) {
3398 return mHomeStack;
3399 }
3400 if (windowingMode == WINDOWING_MODE_PINNED) {
3401 return mPinnedStack;
3402 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3403 return mSplitScreenPrimaryStack;
3404 }
3405 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3406 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003407 if (activityType == ACTIVITY_TYPE_UNDEFINED
3408 && windowingMode == stack.getWindowingMode()) {
3409 // Passing in undefined type means we want to match the topmost stack with the
3410 // windowing mode.
3411 return stack;
3412 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003413 if (stack.isCompatible(windowingMode, activityType)) {
3414 return stack;
3415 }
3416 }
3417 return null;
3418 }
3419
3420 @VisibleForTesting
3421 TaskStack getTopStack() {
3422 return mTaskStackContainers.getChildCount() > 0
3423 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3424 }
3425
3426 TaskStack getHomeStack() {
3427 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3428 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3429 }
3430 return mHomeStack;
3431 }
3432
3433 TaskStack getPinnedStack() {
3434 return mPinnedStack;
3435 }
3436
Matthew Ng64e77cf2017-10-31 14:01:31 -07003437 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003438 return mSplitScreenPrimaryStack;
3439 }
3440
Winson Chunge2d72172018-01-25 17:46:20 +00003441 ArrayList<Task> getVisibleTasks() {
3442 final ArrayList<Task> visibleTasks = new ArrayList<>();
3443 forAllTasks(task -> {
3444 if (task.isVisible()) {
3445 visibleTasks.add(task);
3446 }
3447 });
3448 return visibleTasks;
3449 }
3450
Andrii Kulian839def92016-11-02 10:58:58 -07003451 /**
3452 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003453 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003454 */
3455 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003456 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003457 addChild(stack, onTop);
3458 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003459 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003460
Wale Ogunwale61911492017-10-11 08:50:50 -07003461 void onStackWindowingModeChanged(TaskStack stack) {
3462 removeStackReferenceIfNeeded(stack);
3463 addStackReferenceIfNeeded(stack);
3464 if (stack == mPinnedStack && getTopStack() != stack) {
3465 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3466 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3467 }
3468 }
3469
3470 private void addStackReferenceIfNeeded(TaskStack stack) {
3471 if (stack.isActivityTypeHome()) {
3472 if (mHomeStack != null) {
Louis Chang7d0037c2018-08-13 12:42:06 +08003473 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
Wale Ogunwale61911492017-10-11 08:50:50 -07003474 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
Louis Chang7d0037c2018-08-13 12:42:06 +08003475
Wale Ogunwale61911492017-10-11 08:50:50 -07003476 }
Louis Chang7d0037c2018-08-13 12:42:06 +08003477 mHomeStack = stack;
Wale Ogunwale61911492017-10-11 08:50:50 -07003478 }
3479 final int windowingMode = stack.getWindowingMode();
3480 if (windowingMode == WINDOWING_MODE_PINNED) {
3481 if (mPinnedStack != null) {
3482 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3483 + mPinnedStack + " already exist on display=" + this
3484 + " stack=" + stack);
3485 }
3486 mPinnedStack = stack;
3487 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3488 if (mSplitScreenPrimaryStack != null) {
3489 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3490 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3491 + " already exist on display=" + this + " stack=" + stack);
3492 }
3493 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003494 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003495 }
3496 }
3497
3498 private void removeStackReferenceIfNeeded(TaskStack stack) {
3499 if (stack == mHomeStack) {
3500 mHomeStack = null;
3501 } else if (stack == mPinnedStack) {
3502 mPinnedStack = null;
3503 } else if (stack == mSplitScreenPrimaryStack) {
3504 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003505 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3506 mService.setDockedStackCreateStateLocked(
3507 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3508 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003509 }
Andrii Kulian839def92016-11-02 10:58:58 -07003510 }
3511
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003512 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003513 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3514 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003515 addChild(stack, addIndex);
3516 setLayoutNeeded();
3517 }
3518
Wale Ogunwale61911492017-10-11 08:50:50 -07003519 @Override
3520 protected void removeChild(TaskStack stack) {
3521 super.removeChild(stack);
3522 removeStackReferenceIfNeeded(stack);
3523 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003524
3525 @Override
3526 boolean isOnTop() {
3527 // Considered always on top
3528 return true;
3529 }
3530
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003531 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003532 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003533 if (child.getWindowConfiguration().isAlwaysOnTop()
3534 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003535 // This stack is always-on-top, override the default behavior.
3536 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3537
3538 // Moving to its current position, as we must call super but we don't want to
3539 // perform any meaningful action.
3540 final int currentPosition = mChildren.indexOf(child);
3541 super.positionChildAt(currentPosition, child, false /* includingParents */);
3542 return;
3543 }
3544
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003545 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3546 super.positionChildAt(targetPosition, child, includingParents);
3547
3548 setLayoutNeeded();
3549 }
3550
3551 /**
3552 * When stack is added or repositioned, find a proper position for it.
3553 * This will make sure that pinned stack always stays on top.
3554 * @param requestedPosition Position requested by caller.
3555 * @param stack Stack to be added or positioned.
3556 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3557 * @return The proper position for the stack.
3558 */
3559 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003560 if (stack.inPinnedWindowingMode()) {
Kazuki Takisef85197b2018-06-18 18:18:36 +09003561 return POSITION_TOP;
Kazuki Takise148d00a2018-05-31 15:32:19 +09003562 }
3563
Kazuki Takisef85197b2018-06-18 18:18:36 +09003564 final int topChildPosition = mChildren.size() - 1;
3565 int belowAlwaysOnTopPosition = POSITION_BOTTOM;
3566 for (int i = topChildPosition; i >= 0; --i) {
3567 if (getStacks().get(i) != stack && !getStacks().get(i).isAlwaysOnTop()) {
3568 belowAlwaysOnTopPosition = i;
3569 break;
3570 }
3571 }
3572
3573 // The max possible position we can insert the stack at.
3574 int maxPosition = POSITION_TOP;
3575 // The min possible position we can insert the stack at.
3576 int minPosition = POSITION_BOTTOM;
3577
3578 if (stack.isAlwaysOnTop()) {
3579 if (hasPinnedStack()) {
3580 // Always-on-top stacks go below the pinned stack.
3581 maxPosition = getStacks().indexOf(mPinnedStack) - 1;
3582 }
3583 // Always-on-top stacks need to be above all other stacks.
3584 minPosition = belowAlwaysOnTopPosition !=
3585 POSITION_BOTTOM ? belowAlwaysOnTopPosition : topChildPosition;
3586 } else {
3587 // Other stacks need to be below the always-on-top stacks.
3588 maxPosition = belowAlwaysOnTopPosition !=
Arthur Hung928d8dc2018-07-18 15:38:05 +08003589 POSITION_BOTTOM ? belowAlwaysOnTopPosition : 0;
Kazuki Takisef85197b2018-06-18 18:18:36 +09003590 }
3591
3592 int targetPosition = requestedPosition;
3593 targetPosition = Math.min(targetPosition, maxPosition);
3594 targetPosition = Math.max(targetPosition, minPosition);
3595
3596 int prevPosition = getStacks().indexOf(stack);
3597 // The positions we calculated above (maxPosition, minPosition) do not take into
3598 // consideration the following edge cases.
3599 // 1) We need to adjust the position depending on the value "adding".
3600 // 2) When we are moving a stack to another position, we also need to adjust the
3601 // position depending on whether the stack is moving to a higher or lower position.
3602 if ((targetPosition != requestedPosition) &&
3603 (adding || targetPosition < prevPosition)) {
Kazuki Takise148d00a2018-05-31 15:32:19 +09003604 targetPosition++;
3605 }
3606
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003607 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003608 }
3609
3610 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003611 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3612 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003613 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003614 if (super.forAllWindows(callback, traverseTopToBottom)) {
3615 return true;
3616 }
3617 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3618 return true;
3619 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003620 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003621 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3622 return true;
3623 }
3624 if (super.forAllWindows(callback, traverseTopToBottom)) {
3625 return true;
3626 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003627 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003628 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003629 }
3630
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003631 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003632 boolean traverseTopToBottom) {
3633 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3634 // app tokens.
3635 // TODO: Investigate if we need to continue to do this or if we can just process them
3636 // in-order.
3637 if (traverseTopToBottom) {
3638 for (int i = mChildren.size() - 1; i >= 0; --i) {
3639 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3640 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003641 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3642 traverseTopToBottom)) {
3643 return true;
3644 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003645 }
3646 }
3647 } else {
3648 final int count = mChildren.size();
3649 for (int i = 0; i < count; ++i) {
3650 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3651 final int appTokensCount = appTokens.size();
3652 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003653 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3654 traverseTopToBottom)) {
3655 return true;
3656 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003657 }
3658 }
3659 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003660 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003661 }
3662
Wale Ogunwale1666e312016-12-16 11:27:18 -08003663 void setExitingTokensHasVisible(boolean hasVisible) {
3664 for (int i = mChildren.size() - 1; i >= 0; --i) {
3665 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3666 for (int j = appTokens.size() - 1; j >= 0; --j) {
3667 appTokens.get(j).hasVisible = hasVisible;
3668 }
3669 }
3670 }
3671
3672 void removeExistingAppTokensIfPossible() {
3673 for (int i = mChildren.size() - 1; i >= 0; --i) {
3674 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3675 for (int j = appTokens.size() - 1; j >= 0; --j) {
3676 final AppWindowToken token = appTokens.get(j);
3677 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3678 && (!token.mIsExiting || token.isEmpty())) {
3679 // Make sure there is no animation running on this token, so any windows
3680 // associated with it will be removed as soon as their animations are
3681 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003682 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003683 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3684 "performLayout: App token exiting now removed" + token);
3685 token.removeIfPossible();
3686 }
3687 }
3688 }
3689 }
3690
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003691 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003692 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003693 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3694 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003695 // Apps and their containers are not allowed to specify an orientation while the
Wale Ogunwaled0c225c2018-06-15 14:47:46 -07003696 // docked or freeform stack is visible...except for the home stack if the docked
3697 // stack is minimized and it actually set something and the bounds is different from
3698 // the display.
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003699 if (mHomeStack != null && mHomeStack.isVisible()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003700 && mDividerControllerLocked.isMinimizedDock()
Wale Ogunwalecf2d6472018-06-14 08:55:42 -07003701 && !(mDividerControllerLocked.isHomeStackResizable()
3702 && mHomeStack.matchParentBounds())) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003703 final int orientation = mHomeStack.getOrientation();
3704 if (orientation != SCREEN_ORIENTATION_UNSET) {
3705 return orientation;
3706 }
3707 }
3708 return SCREEN_ORIENTATION_UNSPECIFIED;
3709 }
3710
3711 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003712 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3713 PackageManager.FEATURE_AUTOMOTIVE);
3714 if (isCar) {
3715 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3716 // allow anything but the default orientation.
3717 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003718 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
3719 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07003720 return SCREEN_ORIENTATION_UNSPECIFIED;
3721 }
3722
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003723 if (orientation != SCREEN_ORIENTATION_UNSET
3724 && orientation != SCREEN_ORIENTATION_BEHIND) {
3725 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003726 "App is requesting an orientation, return " + orientation
3727 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003728 return orientation;
3729 }
3730
3731 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003732 "No app is requesting an orientation, return " + mLastOrientation
3733 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003734 // The next app has not been requested to be visible, so we keep the current orientation
3735 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003736 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003737 }
Robert Carrb1579c82017-09-05 14:54:47 -07003738
3739 @Override
3740 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003741 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003742
Robert Carr2f8aa392018-01-31 14:46:51 -08003743 for (int i = 0; i < mChildren.size(); i++) {
3744 final TaskStack s = mChildren.get(i);
3745 s.assignChildLayers(t);
3746 }
3747 }
3748
3749 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02003750
Robert Carrf7a7ca82017-12-06 13:17:07 -08003751 final int HOME_STACK_STATE = 0;
3752 final int NORMAL_STACK_STATE = 1;
3753 final int ALWAYS_ON_TOP_STATE = 2;
3754
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003755 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003756 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02003757 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02003758 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003759
Robert Carrf7a7ca82017-12-06 13:17:07 -08003760 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3761 for (int i = 0; i < mChildren.size(); i++) {
3762 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003763 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3764 continue;
3765 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3766 || s.isAlwaysOnTop())) {
3767 continue;
3768 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3769 continue;
3770 }
3771 s.assignLayer(t, layer++);
3772 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3773 t.setLayer(mSplitScreenDividerAnchor, layer++);
3774 }
Winson Chungd41f71d2018-03-16 15:26:07 -07003775 if ((s.isTaskAnimating() || s.isAppAnimating())
3776 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003777 // Ensure the animation layer ends up above the
3778 // highest animating stack and no higher.
3779 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003780 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003781 if (state != ALWAYS_ON_TOP_STATE) {
3782 layerForBoostedAnimationLayer = layer++;
3783 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08003784 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003785 if (state == HOME_STACK_STATE) {
3786 layerForHomeAnimationLayer = layer++;
3787 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003788 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003789 if (mAppAnimationLayer != null) {
3790 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003791 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003792 if (mBoostedAppAnimationLayer != null) {
3793 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
3794 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003795 if (mHomeAppAnimationLayer != null) {
3796 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
3797 }
Robert Carrb1579c82017-09-05 14:54:47 -07003798 }
3799
3800 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02003801 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
3802 switch (animationLayer) {
3803 case ANIMATION_LAYER_BOOSTED:
3804 return mBoostedAppAnimationLayer;
3805 case ANIMATION_LAYER_HOME:
3806 return mHomeAppAnimationLayer;
3807 case ANIMATION_LAYER_STANDARD:
3808 default:
3809 return mAppAnimationLayer;
3810 }
chaviw23ee71c2017-12-18 11:29:41 -08003811 }
3812
Robert Carrf7a7ca82017-12-06 13:17:07 -08003813 SurfaceControl getSplitScreenDividerAnchor() {
3814 return mSplitScreenDividerAnchor;
3815 }
3816
chaviw23ee71c2017-12-18 11:29:41 -08003817 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003818 void onParentSet() {
3819 super.onParentSet();
3820 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003821 mAppAnimationLayer = makeChildSurface(null)
3822 .setName("animationLayer")
3823 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02003824 mBoostedAppAnimationLayer = makeChildSurface(null)
3825 .setName("boostedAnimationLayer")
3826 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02003827 mHomeAppAnimationLayer = makeChildSurface(null)
3828 .setName("homeAnimationLayer")
3829 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003830 mSplitScreenDividerAnchor = makeChildSurface(null)
3831 .setName("splitScreenDividerAnchor")
3832 .build();
3833 getPendingTransaction()
3834 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02003835 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02003836 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08003837 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003838 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003839 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003840 mAppAnimationLayer.destroy();
3841 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003842 mBoostedAppAnimationLayer.destroy();
3843 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003844 mHomeAppAnimationLayer.destroy();
3845 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003846 mSplitScreenDividerAnchor.destroy();
3847 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003848 }
3849 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003850 }
3851
Robert Carree4d4b92017-11-22 12:21:46 -08003852 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003853 AboveAppWindowContainers(String name, WindowManagerService service) {
3854 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003855 }
3856
Robert Carrb9506032018-02-13 13:54:00 -08003857 @Override
Vishnu Nair83537a72018-07-19 21:27:48 -07003858 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
3859 final SurfaceControl.Builder builder = super.makeChildSurface(child);
3860 if (child instanceof WindowToken && ((WindowToken) child).mRoundedCornerOverlay) {
3861 // To draw above the ColorFade layer during the screen off transition, the
3862 // rounded corner overlays need to be at the root of the surface hierarchy.
3863 // TODO: move the ColorLayer into the display overlay layer such that this is not
3864 // necessary anymore.
3865 builder.setParent(null);
3866 }
3867 return builder;
3868 }
3869
3870 @Override
Robert Carrb9506032018-02-13 13:54:00 -08003871 void assignChildLayers(SurfaceControl.Transaction t) {
3872 assignChildLayers(t, null /* imeContainer */);
3873 }
3874
Robert Carree4d4b92017-11-22 12:21:46 -08003875 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3876 boolean needAssignIme = imeContainer != null
3877 && imeContainer.getSurfaceControl() != null;
3878 for (int j = 0; j < mChildren.size(); ++j) {
3879 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003880
3881 // See {@link mSplitScreenDividerAnchor}
3882 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3883 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3884 continue;
3885 }
Vishnu Nair83537a72018-07-19 21:27:48 -07003886 if (wt.mRoundedCornerOverlay) {
3887 wt.assignLayer(t, WindowManagerPolicy.COLOR_FADE_LAYER + 1);
3888 continue;
3889 }
Robert Carree4d4b92017-11-22 12:21:46 -08003890 wt.assignLayer(t, j);
3891 wt.assignChildLayers(t);
3892
3893 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3894 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003895
3896 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3897 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003898 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003899 needAssignIme = false;
3900 }
3901 }
3902 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003903 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003904 }
3905 }
3906 }
3907
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003908 /**
3909 * Window container class that contains all containers on this display that are not related to
3910 * Apps. E.g. status bar.
3911 */
Robert Carree4d4b92017-11-22 12:21:46 -08003912 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003913 /**
3914 * Compares two child window tokens returns -1 if the first is lesser than the second in
3915 * terms of z-order and 1 otherwise.
3916 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003917 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003918 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003919 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3920 token1.mOwnerCanManageAppTokens)
3921 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3922 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003923
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003924 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3925 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3926 return false;
3927 }
3928 final int req = w.mAttrs.screenOrientation;
3929 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3930 || req == SCREEN_ORIENTATION_UNSET) {
3931 return false;
3932 }
3933 return true;
3934 };
3935
Wale Ogunwale3a931692016-11-02 16:49:48 -07003936 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003937 private final Dimmer mDimmer = new Dimmer(this);
3938 private final Rect mTmpDimBoundsRect = new Rect();
3939
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003940 NonAppWindowContainers(String name, WindowManagerService service) {
3941 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003942 mName = name;
3943 }
3944
3945 void addChild(WindowToken token) {
3946 addChild(token, mWindowComparator);
3947 }
3948
3949 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003950 int getOrientation() {
3951 final WindowManagerPolicy policy = mService.mPolicy;
3952 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003953 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003954
3955 if (win != null) {
3956 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003957 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003958 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003959 if (mService.mKeyguardGoingAway) {
3960 // Keyguard can't affect the orientation if it is going away...
3961 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3962 return SCREEN_ORIENTATION_UNSET;
3963 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003964 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003965 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
3966 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003967 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003968 }
3969
Andrii Kulian8ee72852017-03-10 10:36:45 -08003970 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003971
Jorim Jaggi1c530592018-04-06 15:11:47 +02003972 // Only allow force setting the orientation when all unknown visibilities have been
3973 // resolved, as otherwise we just may be starting another occluding activity.
3974 final boolean isUnoccluding =
3975 mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
3976 && mService.mUnknownAppVisibilityController.allResolved();
3977 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003978 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003979 }
3980
3981 return SCREEN_ORIENTATION_UNSET;
3982 }
3983
3984 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003985 String getName() {
3986 return mName;
3987 }
chaviwf29223e2018-01-31 13:23:51 -08003988
3989 @Override
3990 Dimmer getDimmer() {
3991 return mDimmer;
3992 }
3993
3994 @Override
3995 void prepareSurfaces() {
3996 mDimmer.resetDimStates();
3997 super.prepareSurfaces();
3998 getBounds(mTmpDimBoundsRect);
3999
4000 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
4001 scheduleAnimation();
4002 }
4003 }
Robert Carr3b716242016-08-16 16:02:21 -07004004 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01004005
Robert Carr9034d962018-01-04 18:27:42 -08004006 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
4007 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
4008 super(name, service);
4009 }
4010
4011 @Override
4012 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
4013 }
4014 };
4015
Robert Carrb1579c82017-09-05 14:54:47 -07004016 SurfaceControl.Builder makeSurface(SurfaceSession s) {
4017 return mService.makeSurfaceBuilder(s)
4018 .setParent(mWindowingLayer);
4019 }
4020
4021 @Override
4022 SurfaceSession getSession() {
4023 return mSession;
4024 }
4025
4026 @Override
4027 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004028 SurfaceSession s = child != null ? child.getSession() : getSession();
4029 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07004030 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004031
4032 if (child == null) {
4033 return b;
4034 }
4035
Robert Carree4d4b92017-11-22 12:21:46 -08004036 return b.setName(child.getName())
4037 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07004038 }
4039
4040 /**
4041 * The makeSurface variants are for use by the window-container
4042 * hierarchy. makeOverlay here is a function for various non windowing
4043 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
4044 * and other potpourii.
4045 */
4046 SurfaceControl.Builder makeOverlay() {
4047 return mService.makeSurfaceBuilder(mSession)
4048 .setParent(mOverlayLayer);
4049 }
4050
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09004051 /**
4052 * Reparents the given surface to mOverlayLayer.
4053 */
4054 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
4055 transaction.reparent(surface, mOverlayLayer.getHandle());
4056 }
4057
Robert Carrb1579c82017-09-05 14:54:47 -07004058 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07004059 if (spec.scale != 1.0) {
4060 mMagnificationSpec = spec;
4061 } else {
4062 mMagnificationSpec = null;
4063 }
4064
Robert Carrf59b8dd2017-10-02 18:58:36 -07004065 applyMagnificationSpec(getPendingTransaction(), spec);
4066 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07004067 }
4068
Robert Carr24be9ab2018-04-30 17:54:53 -07004069 void reapplyMagnificationSpec() {
4070 if (mMagnificationSpec != null) {
4071 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
4072 }
4073 }
4074
Robert Carrb1579c82017-09-05 14:54:47 -07004075 @Override
4076 void onParentSet() {
4077 // Since we are the top of the SurfaceControl hierarchy here
4078 // we create the root surfaces explicitly rather than chaining
4079 // up as the default implementation in onParentSet does. So we
4080 // explicitly do NOT call super here.
4081 }
4082
4083 @Override
4084 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07004085
4086 // These are layers as children of "mWindowingLayer"
4087 mBelowAppWindowsContainers.assignLayer(t, 0);
4088 mTaskStackContainers.assignLayer(t, 1);
4089 mAboveAppWindowsContainers.assignLayer(t, 2);
4090
4091 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08004092 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08004093
Robert Carree4d4b92017-11-22 12:21:46 -08004094 // In the case where we have an IME target that is not in split-screen
4095 // mode IME assignment is easy. We just need the IME to go directly above
4096 // the target. This way children of the target will naturally go above the IME
4097 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08004098 //
Robert Carree4d4b92017-11-22 12:21:46 -08004099 // In the case of split-screen windowing mode, we need to elevate the IME above the
4100 // docked divider while keeping the app itself below the docked divider, so instead
4101 // we use relative layering of the IME targets child windows, and place the
4102 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08004103 //
Robert Carr234b6332018-03-20 13:38:16 -07004104 // In the case the IME target is animating, the animation Z order may be different
4105 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
4106 // IME target. In this case we just layer the IME over all transitions by placing it in the
4107 // above applications layer.
4108 //
Robert Carree4d4b92017-11-22 12:21:46 -08004109 // In the case where we have no IME target we assign it where it's base layer would
4110 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07004111 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
4112 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08004113 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01004114 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07004115 // TODO: We need to use an extra level on the app surface to ensure
4116 // this is always above SurfaceView but always below attached window.
4117 1);
Robert Carree4d4b92017-11-22 12:21:46 -08004118 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07004119 }
4120
4121 // Above we have assigned layers to our children, now we ask them to assign
4122 // layers to their children.
4123 mBelowAppWindowsContainers.assignChildLayers(t);
4124 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08004125 mAboveAppWindowsContainers.assignChildLayers(t,
4126 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07004127 mImeWindowsContainers.assignChildLayers(t);
4128 }
4129
4130 /**
4131 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
4132 * that the IME target is one of the docked applications. We'd like the docked divider to be
4133 * above both of the applications, and we'd like the IME to be above the docked divider.
4134 * However we need child windows of the applications to be above the IME (Text drag handles).
4135 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
4136 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
4137 * with {@link #WindowState#assignLayer}
4138 */
4139 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07004140 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07004141 }
4142
4143 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004144 void prepareSurfaces() {
4145 final ScreenRotationAnimation screenRotationAnimation =
4146 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
4147 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
4148 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
4149 mPendingTransaction.setMatrix(mWindowingLayer,
4150 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
4151 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
4152 mPendingTransaction.setPosition(mWindowingLayer,
4153 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
4154 mPendingTransaction.setAlpha(mWindowingLayer,
4155 screenRotationAnimation.getEnterTransformation().getAlpha());
4156 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00004157
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004158 super.prepareSurfaces();
4159 }
Robert Carr2f8aa392018-01-31 14:46:51 -08004160
Jorim Jaggibe418292018-03-26 16:14:12 +02004161 void assignStackOrdering() {
4162 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08004163 }
Chavi Weingarten3a748552018-05-14 17:32:42 +00004164
4165 /**
4166 * Increment the deferral count to determine whether to update the IME target.
4167 */
4168 void deferUpdateImeTarget() {
4169 mDeferUpdateImeTargetCount++;
4170 }
4171
4172 /**
4173 * Decrement the deferral count to determine whether to update the IME target. If the count
4174 * reaches 0, a new ime target will get computed.
4175 */
4176 void continueUpdateImeTarget() {
4177 if (mDeferUpdateImeTargetCount == 0) {
4178 return;
4179 }
4180
4181 mDeferUpdateImeTargetCount--;
4182 if (mDeferUpdateImeTargetCount == 0) {
4183 computeImeTarget(true /* updateImeTarget */);
4184 }
4185 }
4186
4187 /**
4188 * @return Whether a new IME target should be computed.
4189 */
4190 private boolean canUpdateImeTarget() {
4191 return mDeferUpdateImeTargetCount == 0;
4192 }
Arthur Hung95b38a92018-07-20 18:56:12 +08004193
4194 InputMonitor getInputMonitor() {
4195 return mInputMonitor;
4196 }
Craig Mautner59c00972012-07-30 12:10:24 -07004197}