blob: 9621eddc348a8889fdb0bac89c476e6ce7307c62 [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 Ogunwale30e441d2017-11-09 08:28:45 -080019import static android.app.ActivityManager.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 Ogunwale687b4272017-07-27 02:56:23 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070024import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
25import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070027import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
28import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070029import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
30import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070031import static android.view.Display.DEFAULT_DISPLAY;
32import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070033import static android.view.Surface.ROTATION_0;
34import static android.view.Surface.ROTATION_180;
35import static android.view.Surface.ROTATION_270;
36import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070037import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070038import static android.view.WindowManager.DOCKED_BOTTOM;
39import static android.view.WindowManager.DOCKED_INVALID;
40import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080041import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
43import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070044import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070045import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070046import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
47import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070051import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080052import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070053import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070054import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070055import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070057import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070058import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
59import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070060import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070061import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Adrian Roose99bc052017-11-20 17:55:31 +010062import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
63import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
64import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Adrian Roos1cf585052018-01-03 18:43:27 +010066import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010067import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
Wale Ogunwale1666e312016-12-16 11:27:18 -080068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020076import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070077import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070078import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070079import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070083import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070084import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070085import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080086import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070087import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070088import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
89import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070090import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070091import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -070092import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
93import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070094import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -070095import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070096import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070097import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070098import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070099import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700100import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700101import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700102import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700103import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700104import static com.android.server.wm.DisplayProto.ABOVE_APP_WINDOWS;
105import static com.android.server.wm.DisplayProto.BELOW_APP_WINDOWS;
106import static com.android.server.wm.DisplayProto.DISPLAY_FRAMES;
107import static com.android.server.wm.DisplayProto.DISPLAY_INFO;
108import static com.android.server.wm.DisplayProto.DOCKED_STACK_DIVIDER_CONTROLLER;
109import static com.android.server.wm.DisplayProto.DPI;
110import static com.android.server.wm.DisplayProto.ID;
111import static com.android.server.wm.DisplayProto.IME_WINDOWS;
112import static com.android.server.wm.DisplayProto.PINNED_STACK_CONTROLLER;
113import static com.android.server.wm.DisplayProto.ROTATION;
114import static com.android.server.wm.DisplayProto.SCREEN_ROTATION_ANIMATION;
115import static com.android.server.wm.DisplayProto.STACKS;
116import static com.android.server.wm.DisplayProto.WINDOW_CONTAINER;
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;
Adrian Roos1cf585052018-01-03 18:43:27 +0100125import android.graphics.Path;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800126import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700127import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700128import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100129import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700130import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700131import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700132import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700133import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700134import android.os.RemoteException;
135import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100136import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800137import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700138import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700139import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700140import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700141import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100142import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700143import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700144import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700145import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700146import android.view.Surface;
147import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100148import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700149import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700150
Bryce Lee48f4b572017-04-10 10:54:15 -0700151import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800152import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700153import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100154import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100155import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100156import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700157
158import java.io.PrintWriter;
159import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700160import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700161import java.util.HashMap;
162import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700163import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700164import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100165import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800166import java.util.function.Consumer;
167import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700168
Craig Mautner59c00972012-07-30 12:10:24 -0700169/**
170 * Utility class for keeping track of the WindowStates and other pertinent contents of a
171 * particular Display.
172 *
173 * IMPORTANT: No method from this class should ever be used without holding
174 * WindowManagerService.mWindowMap.
175 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700176class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
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();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000237 DisplayFrames mDisplayFrames;
238
Andrii Kulian06d07d62017-03-14 11:11:47 -0700239 /**
240 * For default display it contains real metrics, empty for others.
241 * @see WindowManagerService#createWatermarkInTransaction()
242 */
243 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
244 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
245 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700246
Andrii Kulian06d07d62017-03-14 11:11:47 -0700247 /**
248 * Compat metrics computed based on {@link #mDisplayMetrics}.
249 * @see #updateDisplayAndOrientation(int)
250 */
251 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
252
253 /** The desired scaling factor for compatible apps. */
254 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700255
Andrii Kulian8ee72852017-03-10 10:36:45 -0800256 /**
257 * Current rotation of the display.
258 * Constants as per {@link android.view.Surface.Rotation}.
259 *
Robert Carrae606b42018-02-15 15:36:23 -0800260 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800261 */
262 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700263
Andrii Kulian8ee72852017-03-10 10:36:45 -0800264 /**
265 * Last applied orientation of the display.
266 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
267 *
268 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
269 */
270 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700271
Andrii Kulian8ee72852017-03-10 10:36:45 -0800272 /**
273 * Flag indicating that the application is receiving an orientation that has different metrics
274 * than it expected. E.g. Portrait instead of Landscape.
275 *
Robert Carrae606b42018-02-15 15:36:23 -0800276 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800277 */
278 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700279
Andrii Kulian8ee72852017-03-10 10:36:45 -0800280 /**
281 * Orientation forced by some window. If there is no visible window that specifies orientation
282 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
283 *
284 * @see NonAppWindowContainers#getOrientation()
285 */
286 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700287
Andrii Kulian8ee72852017-03-10 10:36:45 -0800288 /**
289 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
290 * occluded.
291 *
292 * @see NonAppWindowContainers#getOrientation()
293 */
294 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
295
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700296 /**
297 * Keep track of wallpaper visibility to notify changes.
298 */
299 private boolean mLastWallpaperVisible = false;
300
Andrii Kulian06d07d62017-03-14 11:11:47 -0700301 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700302
Craig Mautner39834192012-09-02 07:47:24 -0700303 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700304 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700305 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700306 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800307 boolean isDefaultDisplay;
Andrii Kulianf0379de2018-03-14 16:24:07 -0700308 /**
309 * Flag indicating whether WindowManager should override info for this display in
310 * DisplayManager.
311 */
312 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700313
Craig Mautnerdc548482014-02-05 13:35:24 -0800314 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700315 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800316
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700317 /** Detect user tapping outside of current focused task bounds .*/
318 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700319
Craig Mautner6601b7b2013-04-29 10:29:11 -0700320 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700321 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700322
Craig Mautner6601b7b2013-04-29 10:29:11 -0700323 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800324 private final Rect mTmpRect = new Rect();
325 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700326 private final RectF mTmpRectF = new RectF();
327 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800328 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700329
Bryce Leef3c6a472017-11-14 14:53:06 -0800330 /** Used for handing back size of display */
331 private final Rect mTmpBounds = new Rect();
332
Craig Mautner95da1082014-02-24 17:54:35 -0800333 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700334 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800335
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700336 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700337 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700338
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800339 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800340 /** A collection of windows that provide tap exclude regions inside of them. */
341 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800342
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000343 private boolean mHaveBootMsg = false;
344 private boolean mHaveApp = false;
345 private boolean mHaveWallpaper = false;
346 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700347
348 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
349
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700350 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
351 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000352 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
353 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700354
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700355 // True if this display is in the process of being removed. Used to determine if the removal of
356 // the display's direct children should be allowed.
357 private boolean mRemovingDisplay = false;
358
Bryce Leed1871262017-06-12 14:12:29 -0700359 // {@code false} if this display is in the processing of being created.
360 private boolean mDisplayReady = false;
361
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800362 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700363
Robert Carrb1579c82017-09-05 14:54:47 -0700364 private final SurfaceSession mSession = new SurfaceSession();
365
366 /**
367 * We organize all top-level Surfaces in to the following layers.
368 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800369 * and omitted from Screen-Magnification, for example the strict mode flash or
370 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700371 * {@link #mWindowingLayer} contains everything else.
372 */
373 private SurfaceControl mOverlayLayer;
374
375 /**
376 * See {@link #mOverlayLayer}
377 */
378 private SurfaceControl mWindowingLayer;
379
380 /**
381 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
382 * <p>
383 * For these surfaces currently we use a surface based on the larger of width or height so we
384 * don't have to resize when rotating the display.
385 */
386 private int mSurfaceSize;
387
Adrian Roos5251b1d2018-03-23 18:57:43 +0100388 /**
389 * Sequence number for the current layout pass.
390 */
391 int mLayoutSeq = 0;
392
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100393 /** Temporary float array to retrieve 3x3 matrix values. */
394 private final float[] mTmpFloats = new float[9];
395
Robert Carr24be9ab2018-04-30 17:54:53 -0700396 private MagnificationSpec mMagnificationSpec;
397
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800398 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
399 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800400 final AppWindowToken atoken = w.mAppToken;
401 if (winAnimator.mDrawState == READY_TO_SHOW) {
402 if (atoken == null || atoken.allDrawn) {
403 if (w.performShowLocked()) {
404 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
405 if (DEBUG_LAYOUT_REPEATS) {
406 mService.mWindowPlacerLocked.debugLayoutRepeats(
407 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
408 }
409 }
410 }
411 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800412 };
413
414 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
415 final WindowStateAnimator winAnimator = w.mWinAnimator;
416 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
417 return;
418 }
419
420 final int flags = w.mAttrs.flags;
421
422 // If this window is animating, make a note that we have an animating window and take
423 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100424 if (winAnimator.isAnimationSet()) {
425 final AnimationAdapter anim = w.getAnimation();
426 if (anim != null) {
427 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800428 mTmpWindow = w;
429 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100430 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800431 if (color != 0) {
432 final TaskStack stack = w.getStack();
433 if (stack != null) {
434 stack.setAnimationBackground(winAnimator, color);
435 }
436 }
437 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800438 }
439
440 // If this window's app token is running a detached wallpaper animation, make a note so
441 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200442 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
443 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
444 if (animation != null) {
445 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800446 mTmpWindow = w;
447 }
448
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200449 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800450 if (color != 0) {
451 final TaskStack stack = w.getStack();
452 if (stack != null) {
453 stack.setAnimationBackground(winAnimator, color);
454 }
455 }
456 }
457 };
458
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800459 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
460 final int lostFocusUid = mTmpWindow.mOwnerUid;
461 final Handler handler = mService.mH;
462 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
463 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
464 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
465 w.mAttrs.hideTimeoutMilliseconds);
466 }
467 }
468 };
469
470 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
471 final AppWindowToken focusedApp = mService.mFocusedApp;
472 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
473 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
474
475 if (!w.canReceiveKeys()) {
476 return false;
477 }
478
479 final AppWindowToken wtoken = w.mAppToken;
480
481 // If this window's application has been removed, just skip it.
482 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
483 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
484 + (wtoken.removed ? "removed" : "sendingToBottom"));
485 return false;
486 }
487
488 if (focusedApp == null) {
489 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
490 + " using new focus @ " + w);
491 mTmpWindow = w;
492 return true;
493 }
494
495 if (!focusedApp.windowsAreFocusable()) {
496 // Current focused app windows aren't focusable...
497 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
498 + " focusable using new focus @ " + w);
499 mTmpWindow = w;
500 return true;
501 }
502
503 // Descend through all of the app tokens and find the first that either matches
504 // win.mAppToken (return win) or mFocusedApp (return null).
505 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
506 if (focusedApp.compareTo(wtoken) > 0) {
507 // App stack below focused app stack. No focus for you!!!
508 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
509 "findFocusedWindow: Reached focused app=" + focusedApp);
510 mTmpWindow = null;
511 return true;
512 }
513 }
514
515 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
516 mTmpWindow = w;
517 return true;
518 };
519
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800520 private final Consumer<WindowState> mPerformLayout = w -> {
521 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
522 // wasting time and funky changes while a window is animating away.
523 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
524 || w.isGoneForLayoutLw();
525
526 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
527 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
528 + " mLayoutAttached=" + w.mLayoutAttached
529 + " screen changed=" + w.isConfigChanged());
530 final AppWindowToken atoken = w.mAppToken;
531 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200532 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800533 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
534 + " parentHidden=" + w.isParentWindowHidden());
535 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200536 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800537 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
538 + " parentHidden=" + w.isParentWindowHidden());
539 }
540
541 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
542 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
543 // since that means "perform layout as normal, just don't display").
544 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
545 || ((w.isConfigChanged() || w.setReportResizeHints())
546 && !w.isGoneForLayoutLw() &&
547 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
548 (w.mHasSurface && w.mAppToken != null &&
549 w.mAppToken.layoutConfigChanges)))) {
550 if (!w.mLayoutAttached) {
551 if (mTmpInitial) {
552 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
553 w.mContentChanged = false;
554 }
555 if (w.mAttrs.type == TYPE_DREAM) {
556 // Don't layout windows behind a dream, so that if it does stuff like hide
557 // the status bar we won't get a bad transition when it goes away.
558 mTmpWindow = w;
559 }
560 w.mLayoutNeeded = false;
561 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200562 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000563 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100564 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800565
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200566 // If this is the first layout, we need to initialize the last inset values as
567 // otherwise we'd immediately cause an unnecessary resize.
568 if (firstLayout) {
569 w.updateLastInsetValues();
570 }
571
Adrian Roos23df3a32018-03-15 15:41:13 +0100572 if (w.mAppToken != null) {
573 w.mAppToken.layoutLetterbox(w);
574 }
575
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800576 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
577 + " mContainingFrame=" + w.mContainingFrame
578 + " mDisplayFrame=" + w.mDisplayFrame);
579 }
580 }
581 };
582
583 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
584 if (w.mLayoutAttached) {
585 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
586 + " mViewVisibility=" + w.mViewVisibility
587 + " mRelayoutCalled=" + w.mRelayoutCalled);
588 // If this view is GONE, then skip it -- keep the current frame, and let the caller
589 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
590 // windows, since that means "perform layout as normal, just don't display").
591 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
592 return;
593 }
594 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
595 || w.mLayoutNeeded) {
596 if (mTmpInitial) {
597 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
598 w.mContentChanged = false;
599 }
600 w.mLayoutNeeded = false;
601 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000602 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Adrian Roos5251b1d2018-03-23 18:57:43 +0100603 w.mLayoutSeq = mLayoutSeq;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800604 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
605 + " mContainingFrame=" + w.mContainingFrame
606 + " mDisplayFrame=" + w.mDisplayFrame);
607 }
608 } else if (w.mAttrs.type == TYPE_DREAM) {
609 // Don't layout windows behind a dream, so that if it does stuff like hide the
610 // status bar we won't get a bad transition when it goes away.
611 mTmpWindow = mTmpWindow2;
612 }
613 };
614
615 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
616 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
617 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
618 return w.canBeImeTarget();
619 };
620
621 private final Consumer<WindowState> mApplyPostLayoutPolicy =
622 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
623 mService.mInputMethodTarget);
624
625 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
626 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
627 final boolean obscuredChanged = w.mObscured !=
628 mTmpApplySurfaceChangesTransactionState.obscured;
629 final RootWindowContainer root = mService.mRoot;
630 // Only used if default window
631 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
632
633 // Update effect.
634 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
635 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
636 final boolean isDisplayed = w.isDisplayedLw();
637
638 if (isDisplayed && w.isObscuringDisplay()) {
639 // This window completely covers everything behind it, so we want to leave all
640 // of them as undimmed (for performance reasons).
641 root.mObscuringWindow = w;
642 mTmpApplySurfaceChangesTransactionState.obscured = true;
643 }
644
645 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
646 root.handleNotObscuredLocked(w,
647 mTmpApplySurfaceChangesTransactionState.obscured,
648 mTmpApplySurfaceChangesTransactionState.syswin);
649
650 if (w.mHasSurface && isDisplayed) {
651 final int type = w.mAttrs.type;
652 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
653 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
654 mTmpApplySurfaceChangesTransactionState.syswin = true;
655 }
656 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
657 && w.mAttrs.preferredRefreshRate != 0) {
658 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
659 = w.mAttrs.preferredRefreshRate;
660 }
661 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
662 && w.mAttrs.preferredDisplayModeId != 0) {
663 mTmpApplySurfaceChangesTransactionState.preferredModeId
664 = w.mAttrs.preferredDisplayModeId;
665 }
666 }
667 }
668
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800669 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
670 && mWallpaperController.isWallpaperTarget(w)) {
671 // This is the wallpaper target and its obscured state changed... make sure the
672 // current wallpaper's visibility has been updated accordingly.
673 mWallpaperController.updateWallpaperVisibility();
674 }
675
chaviw161ea3e2018-01-31 12:01:12 -0800676 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800677
678 final WindowStateAnimator winAnimator = w.mWinAnimator;
679
680 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
681 w.mContentChanged = false;
682
683 // Moved from updateWindowsAndWallpaperLocked().
684 if (w.mHasSurface) {
685 // Take care of the window being ready to display.
686 final boolean committed = winAnimator.commitFinishDrawingLocked();
687 if (isDefaultDisplay && committed) {
688 if (w.mAttrs.type == TYPE_DREAM) {
689 // HACK: When a dream is shown, it may at that point hide the lock screen.
690 // So we need to redo the layout to let the phone window manager make this
691 // happen.
692 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
693 if (DEBUG_LAYOUT_REPEATS) {
694 surfacePlacer.debugLayoutRepeats(
695 "dream and commitFinishDrawingLocked true",
696 pendingLayoutChanges);
697 }
698 }
699 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
700 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
701 "First draw done in potential wallpaper target " + w);
702 root.mWallpaperMayChange = true;
703 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
704 if (DEBUG_LAYOUT_REPEATS) {
705 surfacePlacer.debugLayoutRepeats(
706 "wallpaper and commitFinishDrawingLocked true",
707 pendingLayoutChanges);
708 }
709 }
710 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800711 }
712
713 final AppWindowToken atoken = w.mAppToken;
714 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100715 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800716 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
717 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
718 mTmpUpdateAllDrawn.add(atoken);
719 }
720 }
721
722 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
723 && w.isDisplayedLw()) {
724 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
725 }
726
727 w.updateResizingWindowIfNeeded();
728 };
729
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800730 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800731 * Create new {@link DisplayContent} instance, add itself to the root window container and
732 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700733 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800734 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700735 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
736 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700737 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700738 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800739 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100740 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800741 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800742 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
743 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
744 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
745 + " new=" + display);
746 }
747
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700748 mDisplay = display;
749 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700750 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700751 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700752 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700753 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100754 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
755 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700756 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800757 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700758 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700759
Robert Carr74a66a22018-02-23 12:17:51 -0800760 // We use this as our arbitrary surface size for buffer-less parents
761 // that don't impose cropping on their children. It may need to be larger
762 // than the display size because fullscreen windows can be shifted offscreen
763 // due to surfaceInsets. 2 times the largest display dimension feels like an
764 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
765 // layers the ability to match their parent sizes and be able to skip
766 // such arbitrary size settings.
767 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700768
769 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
770 .setSize(mSurfaceSize, mSurfaceSize)
771 .setOpaque(true);
772 mWindowingLayer = b.setName("Display Root").build();
773 mOverlayLayer = b.setName("Display Overlays").build();
774
Robert Carrf59b8dd2017-10-02 18:58:36 -0700775 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700776 .setLayerStack(mWindowingLayer, mDisplayId)
777 .show(mWindowingLayer)
778 .setLayer(mOverlayLayer, 1)
779 .setLayerStack(mOverlayLayer, mDisplayId)
780 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700781 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700782
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700783 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700784 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700785 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700786 super.addChild(mAboveAppWindowsContainers, null);
787 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800788
789 // Add itself as a child to the root container.
790 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700791
792 // TODO(b/62541591): evaluate whether this is the best spot to declare the
793 // {@link DisplayContent} ready for use.
794 mDisplayReady = true;
795 }
796
797 boolean isReady() {
798 // The display is ready when the system and the individual display are both ready.
799 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700800 }
801
802 int getDisplayId() {
803 return mDisplayId;
804 }
805
Wale Ogunwale02319a62016-09-26 15:21:22 -0700806 WindowToken getWindowToken(IBinder binder) {
807 return mTokenMap.get(binder);
808 }
809
810 AppWindowToken getAppWindowToken(IBinder binder) {
811 final WindowToken token = getWindowToken(binder);
812 if (token == null) {
813 return null;
814 }
815 return token.asAppWindowToken();
816 }
817
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700818 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700819 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
820 if (dc != null) {
821 // We currently don't support adding a window token to the display if the display
822 // already has the binder mapped to another token. If there is a use case for supporting
823 // this moving forward we will either need to merge the WindowTokens some how or have
824 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700825 throw new IllegalArgumentException("Can't map token=" + token + " to display="
826 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700827 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700828 if (binder == null) {
829 throw new IllegalArgumentException("Can't map token=" + token + " to display="
830 + getName() + " binder is null");
831 }
832 if (token == null) {
833 throw new IllegalArgumentException("Can't map null token to display="
834 + getName() + " binder=" + binder);
835 }
836
Wale Ogunwale02319a62016-09-26 15:21:22 -0700837 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700838
839 if (token.asAppWindowToken() == null) {
840 // Add non-app token to container hierarchy on the display. App tokens are added through
841 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700842 switch (token.windowType) {
843 case TYPE_WALLPAPER:
844 mBelowAppWindowsContainers.addChild(token);
845 break;
846 case TYPE_INPUT_METHOD:
847 case TYPE_INPUT_METHOD_DIALOG:
848 mImeWindowsContainers.addChild(token);
849 break;
850 default:
851 mAboveAppWindowsContainers.addChild(token);
852 break;
853 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700854 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700855 }
856
857 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700858 final WindowToken token = mTokenMap.remove(binder);
859 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800860 token.setExiting();
861 }
862 return token;
863 }
864
865 /** Changes the display the input window token is housed on to this one. */
866 void reParentWindowToken(WindowToken token) {
867 final DisplayContent prevDc = token.getDisplayContent();
868 if (prevDc == this) {
869 return;
870 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800871 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
872 && token.asAppWindowToken() == null) {
873 // Removed the token from the map, but made sure it's not an app token before removing
874 // from parent.
875 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700876 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800877
878 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700879 }
880
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700881 void removeAppToken(IBinder binder) {
882 final WindowToken token = removeWindowToken(binder);
883 if (token == null) {
884 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
885 return;
886 }
887
888 final AppWindowToken appToken = token.asAppWindowToken();
889
890 if (appToken == null) {
891 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
892 return;
893 }
894
895 appToken.onRemovedFromDisplay();
896 }
897
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700898 Display getDisplay() {
899 return mDisplay;
900 }
901
Craig Mautner59c00972012-07-30 12:10:24 -0700902 DisplayInfo getDisplayInfo() {
903 return mDisplayInfo;
904 }
905
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700906 DisplayMetrics getDisplayMetrics() {
907 return mDisplayMetrics;
908 }
909
Andrii Kulian8ee72852017-03-10 10:36:45 -0800910 int getRotation() {
911 return mRotation;
912 }
913
Andrii Kulianef5ce1c2018-03-20 19:27:24 -0700914 @VisibleForTesting
Andrii Kulian8ee72852017-03-10 10:36:45 -0800915 void setRotation(int newRotation) {
916 mRotation = newRotation;
917 }
918
919 int getLastOrientation() {
920 return mLastOrientation;
921 }
922
923 void setLastOrientation(int orientation) {
924 mLastOrientation = orientation;
925 }
926
927 boolean getAltOrientation() {
928 return mAltOrientation;
929 }
930
931 void setAltOrientation(boolean altOrientation) {
932 mAltOrientation = altOrientation;
933 }
934
935 int getLastWindowForcedOrientation() {
936 return mLastWindowForcedOrientation;
937 }
938
Andrii Kulian06d07d62017-03-14 11:11:47 -0700939 /**
940 * Update rotation of the display.
941 *
942 * Returns true if the rotation has been changed. In this case YOU MUST CALL
943 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
944 */
Robert Carrae606b42018-02-15 15:36:23 -0800945 boolean updateRotationUnchecked() {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700946 if (mService.mDeferredRotationPauseCount > 0) {
947 // Rotation updates have been paused temporarily. Defer the update until
948 // updates have been resumed.
949 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
950 return false;
951 }
952
953 ScreenRotationAnimation screenRotationAnimation =
954 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
955 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
956 // Rotation updates cannot be performed while the previous rotation change
957 // animation is still in progress. Skip this update. We will try updating
958 // again after the animation is finished and the display is unfrozen.
959 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
960 return false;
961 }
962 if (mService.mDisplayFrozen) {
963 // Even if the screen rotation animation has finished (e.g. isAnimating
964 // returns false), there is still some time where we haven't yet unfrozen
965 // the display. We also need to abort rotation here.
966 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
967 "Deferring rotation, still finishing previous rotation");
968 return false;
969 }
970
971 if (!mService.mDisplayEnabled) {
972 // No point choosing a rotation if the display is not enabled.
973 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
974 return false;
975 }
976
977 final int oldRotation = mRotation;
978 final int lastOrientation = mLastOrientation;
979 final boolean oldAltOrientation = mAltOrientation;
Andrii Kulianef5ce1c2018-03-20 19:27:24 -0700980 final int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation,
981 isDefaultDisplay);
982 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
983 + mDisplayId + " based on lastOrientation=" + lastOrientation
984 + " and oldRotation=" + oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700985 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700986 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700987
Robert Carr0e007272017-10-02 13:00:55 -0700988 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700989 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
990 if (seamlessRotated != null) {
991 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
992 // to complete (that is, waiting for windows to redraw). It's tempting to check
993 // w.mSeamlessRotationCount but that could be incorrect in the case of
994 // window-removal.
995 return false;
996 }
Robert Carr0e007272017-10-02 13:00:55 -0700997
998 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700999 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -07001000 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -07001001 mayRotateSeamlessly = false;
1002 }
1003 for (int i = 0; i < mService.mSessions.size(); i++) {
1004 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
1005 mayRotateSeamlessly = false;
1006 break;
1007 }
1008 }
Andrii Kulian06d07d62017-03-14 11:11:47 -07001009 }
Robert Carr0e007272017-10-02 13:00:55 -07001010 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001011
1012 // TODO: Implement forced rotation changes.
1013 // Set mAltOrientation to indicate that the application is receiving
1014 // an orientation that has different metrics than it expected.
1015 // eg. Portrait instead of Landscape.
1016
1017 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
1018 lastOrientation, rotation);
1019
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001020 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1021 + " selected orientation " + lastOrientation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001022 + ", got rotation " + rotation + " which has "
1023 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1024
1025 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1026 // No change.
1027 return false;
1028 }
1029
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001030 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1031 + " rotation changed to " + rotation
Andrii Kulian06d07d62017-03-14 11:11:47 -07001032 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1033 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1034
1035 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1036 mService.mWaitingForConfig = true;
1037 }
1038
1039 mRotation = rotation;
1040 mAltOrientation = altOrientation;
1041 if (isDefaultDisplay) {
1042 mService.mPolicy.setRotationLw(rotation);
1043 }
1044
1045 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1046 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1047 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1048 WINDOW_FREEZE_TIMEOUT_DURATION);
1049
1050 setLayoutNeeded();
1051 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001052 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001053
1054 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001055 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001056 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1057 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1058 mDisplayId);
1059 } else {
1060 // The screen rotation animation uses a screenshot to freeze the screen
1061 // while windows resize underneath.
1062 // When we are rotating seamlessly, we allow the elements to transition
1063 // to their rotated state independently and without a freeze required.
1064 screenRotationAnimation = null;
1065
Robert Carrefc75702018-02-16 11:46:16 -08001066 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001067 }
1068
1069 // We need to update our screen size information to match the new rotation. If the rotation
1070 // has actually changed then this method will return true and, according to the comment at
1071 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1072 // By updating the Display info here it will be available to
1073 // #computeScreenConfiguration() later.
1074 updateDisplayAndOrientation(getConfiguration().uiMode);
1075
Robert Carrae606b42018-02-15 15:36:23 -08001076 // NOTE: We disable the rotation in the emulator because
1077 // it doesn't support hardware OpenGL emulation yet.
1078 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1079 && screenRotationAnimation.hasScreenshot()) {
1080 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1081 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1082 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1083 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001084 }
1085 }
1086
Robert Carrae606b42018-02-15 15:36:23 -08001087 if (rotateSeamlessly) {
1088 forAllWindows(w -> {
1089 w.mWinAnimator.seamlesslyRotateWindow(getPendingTransaction(),
1090 oldRotation, rotation);
1091 }, true /* traverseTopToBottom */);
1092 }
1093
1094 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1095 scheduleAnimation();
1096
Andrii Kulian06d07d62017-03-14 11:11:47 -07001097 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001098 if (w.mHasSurface && !rotateSeamlessly) {
1099 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001100 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001101 mService.mRoot.mOrientationChangeComplete = false;
1102 w.mLastFreezeDuration = 0;
1103 }
1104 w.mReportOrientationChanged = true;
1105 }, true /* traverseTopToBottom */);
1106
1107 if (rotateSeamlessly) {
1108 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1109 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1110 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1111 }
1112
1113 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1114 final WindowManagerService.RotationWatcher rotationWatcher
1115 = mService.mRotationWatchers.get(i);
1116 if (rotationWatcher.mDisplayId == mDisplayId) {
1117 try {
1118 rotationWatcher.mWatcher.onRotationChanged(rotation);
1119 } catch (RemoteException e) {
1120 // Ignore
1121 }
1122 }
1123 }
1124
1125 // TODO (multi-display): Magnification is supported only for the default display.
1126 // Announce rotation only if we will not animate as we already have the
1127 // windows in final state. Otherwise, we make this call at the rotation end.
1128 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1129 && isDefaultDisplay) {
1130 mService.mAccessibilityController.onRotationChangedLocked(this);
1131 }
1132
1133 return true;
1134 }
1135
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001136 void configureDisplayPolicy() {
1137 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1138 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1139
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001140 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1141 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001142 }
1143
Andrii Kulian06d07d62017-03-14 11:11:47 -07001144 /**
1145 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1146 * changed.
1147 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1148 */
1149 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1150 // Use the effective "visual" dimensions based on current rotation
1151 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1152 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1153 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1154 int dw = realdw;
1155 int dh = realdh;
1156
1157 if (mAltOrientation) {
1158 if (realdw > realdh) {
1159 // Turn landscape into portrait.
1160 int maxw = (int)(realdh/1.3f);
1161 if (maxw < realdw) {
1162 dw = maxw;
1163 }
1164 } else {
1165 // Turn portrait into landscape.
1166 int maxh = (int)(realdw/1.3f);
1167 if (maxh < realdh) {
1168 dh = maxh;
1169 }
1170 }
1171 }
1172
1173 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001174 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1175 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1176
Andrii Kulian06d07d62017-03-14 11:11:47 -07001177 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001178 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001179 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001180 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001181 mDisplayInfo.rotation = mRotation;
1182 mDisplayInfo.logicalWidth = dw;
1183 mDisplayInfo.logicalHeight = dh;
1184 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1185 mDisplayInfo.appWidth = appWidth;
1186 mDisplayInfo.appHeight = appHeight;
1187 if (isDefaultDisplay) {
1188 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1189 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1190 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001191 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001192 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1193 if (mDisplayScalingDisabled) {
1194 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1195 } else {
1196 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1197 }
1198
Andrii Kulianf0379de2018-03-14 16:24:07 -07001199 // We usually set the override info in DisplayManager so that we get consistent display
1200 // metrics values when displays are changing and don't send out new values until WM is aware
1201 // of them. However, we don't do this for displays that serve as containers for ActivityView
1202 // because we don't want letter-/pillar-boxing during resize.
1203 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1204 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001205 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001206 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001207
1208 mBaseDisplayRect.set(0, 0, dw, dh);
1209
1210 if (isDefaultDisplay) {
1211 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1212 mCompatDisplayMetrics);
1213 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001214
1215 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001216 return mDisplayInfo;
1217 }
1218
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001219 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001220 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1221 }
1222
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001223 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001224 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001225 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001226 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001227 }
Adrian Roos11c25582018-02-19 18:06:36 +01001228 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001229 return WmDisplayCutout.computeSafeInsets(
1230 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001231 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001232 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001233 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001234 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1235 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001236 bounds.transform(mTmpMatrix);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001237 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(bounds),
Adrian Roos24264212018-02-19 16:26:15 +01001238 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1239 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001240 }
1241
Andrii Kulian06d07d62017-03-14 11:11:47 -07001242 /**
1243 * Compute display configuration based on display properties and policy settings.
1244 * Do not call if mDisplayReady == false.
1245 */
1246 void computeScreenConfiguration(Configuration config) {
1247 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1248
1249 final int dw = displayInfo.logicalWidth;
1250 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001251 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1252 // TODO: Probably best to set this based on some setting in the display content object,
1253 // so the display can be configured for things like fullscreen.
1254 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001255
Adrian Roos11c25582018-02-19 18:06:36 +01001256 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001257 config.screenWidthDp =
1258 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001259 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001260 config.screenHeightDp =
1261 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001262 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001263
Adrian Roos11c25582018-02-19 18:06:36 +01001264 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1265 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001266 final int leftInset = mTmpRect.left;
1267 final int topInset = mTmpRect.top;
1268 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001269 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1270 leftInset + displayInfo.appWidth /* right */,
1271 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001272 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1273 || displayInfo.rotation == Surface.ROTATION_270);
1274
1275 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001276 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001277
1278 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1279 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1280 ? Configuration.SCREENLAYOUT_ROUND_YES
1281 : Configuration.SCREENLAYOUT_ROUND_NO);
1282
1283 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1284 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1285 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1286 dh, mDisplayId);
1287 config.densityDpi = displayInfo.logicalDensityDpi;
1288
1289 config.colorMode =
1290 (displayInfo.isHdr()
1291 ? Configuration.COLOR_MODE_HDR_YES
1292 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001293 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001294 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1295 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1296
1297 // Update the configuration based on available input devices, lid switch,
1298 // and platform configuration.
1299 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1300 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1301 config.navigation = Configuration.NAVIGATION_NONAV;
1302
1303 int keyboardPresence = 0;
1304 int navigationPresence = 0;
1305 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1306 final int len = devices != null ? devices.length : 0;
1307 for (int i = 0; i < len; i++) {
1308 InputDevice device = devices[i];
1309 if (!device.isVirtual()) {
1310 final int sources = device.getSources();
1311 final int presenceFlag = device.isExternal() ?
1312 WindowManagerPolicy.PRESENCE_EXTERNAL :
1313 WindowManagerPolicy.PRESENCE_INTERNAL;
1314
1315 // TODO(multi-display): Configure on per-display basis.
1316 if (mService.mIsTouchDevice) {
1317 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1318 InputDevice.SOURCE_TOUCHSCREEN) {
1319 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1320 }
1321 } else {
1322 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1323 }
1324
1325 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1326 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1327 navigationPresence |= presenceFlag;
1328 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1329 && config.navigation == Configuration.NAVIGATION_NONAV) {
1330 config.navigation = Configuration.NAVIGATION_DPAD;
1331 navigationPresence |= presenceFlag;
1332 }
1333
1334 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1335 config.keyboard = Configuration.KEYBOARD_QWERTY;
1336 keyboardPresence |= presenceFlag;
1337 }
1338 }
1339 }
1340
1341 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1342 config.navigation = Configuration.NAVIGATION_DPAD;
1343 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1344 }
1345
1346 // Determine whether a hard keyboard is available and enabled.
1347 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1348 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1349 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1350 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1351 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1352 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1353 }
1354
1355 // Let the policy update hidden states.
1356 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1357 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1358 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1359 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1360 }
1361
1362 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1363 int displayId) {
1364 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1365 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1366 final int unrotDw, unrotDh;
1367 if (rotated) {
1368 unrotDw = dh;
1369 unrotDh = dw;
1370 } else {
1371 unrotDw = dw;
1372 unrotDh = dh;
1373 }
1374 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1375 displayId);
1376 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1377 displayId);
1378 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1379 displayId);
1380 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1381 displayId);
1382 return sw;
1383 }
1384
1385 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1386 DisplayMetrics dm, int dw, int dh, int displayId) {
1387 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001388 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001389 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001390 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001391 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1392 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1393 if (curSize == 0 || size < curSize) {
1394 curSize = size;
1395 }
1396 return curSize;
1397 }
1398
1399 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1400 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1401
1402 // We need to determine the smallest width that will occur under normal
1403 // operation. To this, start with the base screen size and compute the
1404 // width under the different possible rotations. We need to un-rotate
1405 // the current screen dimensions before doing this.
1406 int unrotDw, unrotDh;
1407 if (rotated) {
1408 unrotDw = dh;
1409 unrotDh = dw;
1410 } else {
1411 unrotDw = dw;
1412 unrotDh = dh;
1413 }
1414 displayInfo.smallestNominalAppWidth = 1<<30;
1415 displayInfo.smallestNominalAppHeight = 1<<30;
1416 displayInfo.largestNominalAppWidth = 0;
1417 displayInfo.largestNominalAppHeight = 0;
1418 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1419 unrotDh);
1420 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1421 unrotDw);
1422 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1423 unrotDh);
1424 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1425 unrotDw);
1426 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1427 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1428 displayId);
1429 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1430 displayId);
1431 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1432 displayId);
1433 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1434 displayId);
1435 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1436 outConfig.screenLayout = sl;
1437 }
1438
1439 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1440 int uiMode, int displayId) {
1441 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001442 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1443 mDisplayInfo.displayCutout);
1444 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1445 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001446
1447 // Compute the screen layout size class for this rotation.
1448 int longSize = w;
1449 int shortSize = h;
1450 if (longSize < shortSize) {
1451 int tmp = longSize;
1452 longSize = shortSize;
1453 shortSize = tmp;
1454 }
1455 longSize = (int)(longSize/density);
1456 shortSize = (int)(shortSize/density);
1457 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1458 }
1459
1460 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1461 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001462 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1463 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001464 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001465 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001466 if (width < displayInfo.smallestNominalAppWidth) {
1467 displayInfo.smallestNominalAppWidth = width;
1468 }
1469 if (width > displayInfo.largestNominalAppWidth) {
1470 displayInfo.largestNominalAppWidth = width;
1471 }
1472 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001473 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001474 if (height < displayInfo.smallestNominalAppHeight) {
1475 displayInfo.smallestNominalAppHeight = height;
1476 }
1477 if (height > displayInfo.largestNominalAppHeight) {
1478 displayInfo.largestNominalAppHeight = height;
1479 }
1480 }
1481
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001482 DockedStackDividerController getDockedDividerController() {
1483 return mDividerControllerLocked;
1484 }
1485
Winson Chung655332c2016-10-31 13:14:28 -07001486 PinnedStackController getPinnedStackController() {
1487 return mPinnedStackControllerLocked;
1488 }
1489
Jeff Browna506a6e2013-06-04 00:02:38 -07001490 /**
1491 * Returns true if the specified UID has access to this display.
1492 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001493 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001494 return mDisplay.hasAccess(uid);
1495 }
1496
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001497 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001498 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001499 }
1500
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001501 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001502 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001503 }
1504
Wale Ogunwale61911492017-10-11 08:50:50 -07001505 /**
1506 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1507 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001508 TaskStack getSplitScreenPrimaryStack() {
1509 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001510 return (stack != null && stack.isVisible()) ? stack : null;
1511 }
1512
1513 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001514 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001515 * not visible.
1516 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001517 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1518 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001519 }
1520
1521 TaskStack getPinnedStack() {
1522 return mTaskStackContainers.getPinnedStack();
1523 }
1524
1525 private boolean hasPinnedStack() {
1526 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001527 }
1528
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001529 /**
1530 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1531 * Null is no compatible stack on the display.
1532 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001533 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001534 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1535 }
1536
1537 /**
1538 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1539 * activity type. Null is no compatible stack on the display.
1540 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001541 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001542 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001543 }
1544
Bryce Lee48f4b572017-04-10 10:54:15 -07001545 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001546 TaskStack getTopStack() {
1547 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001548 }
1549
Winson Chunge2d72172018-01-25 17:46:20 +00001550 ArrayList<Task> getVisibleTasks() {
1551 return mTaskStackContainers.getVisibleTasks();
1552 }
1553
Wale Ogunwale61911492017-10-11 08:50:50 -07001554 void onStackWindowingModeChanged(TaskStack stack) {
1555 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001556 }
1557
Andrii Kulian441e4492016-09-29 15:25:00 -07001558 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001559 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001560 super.onConfigurationChanged(newParentConfig);
1561
Andrii Kulian3a507b52016-09-19 18:14:12 -07001562 // The display size information is heavily dependent on the resources in the current
1563 // configuration, so we need to reconfigure it every time the configuration changes.
1564 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1565 mService.reconfigureDisplayLocked(this);
1566
Bryce Leef3c6a472017-11-14 14:53:06 -08001567 final DockedStackDividerController dividerController = getDockedDividerController();
1568
1569 if (dividerController != null) {
1570 getDockedDividerController().onConfigurationChanged();
1571 }
1572
1573 final PinnedStackController pinnedStackController = getPinnedStackController();
1574
1575 if (pinnedStackController != null) {
1576 getPinnedStackController().onConfigurationChanged();
1577 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001578 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001579
Andrii Kulian441e4492016-09-29 15:25:00 -07001580 /**
1581 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1582 * bounds were updated.
1583 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001584 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001585 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1586 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001587 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001588 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001589 }
1590 }
Winson Chung32c566f2017-04-11 18:31:21 -07001591
1592 // If there was no pinned stack, we still need to notify the controller of the display info
1593 // update as a result of the config change. We do this here to consolidate the flow between
1594 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001595 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001596 mPinnedStackControllerLocked.onDisplayInfoChanged();
1597 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001598 }
1599
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001600 @Override
1601 boolean fillsParent() {
1602 return true;
1603 }
1604
1605 @Override
1606 boolean isVisible() {
1607 return true;
1608 }
1609
1610 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001611 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001612 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001613 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001614 }
1615
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001616 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001617 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1618 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1619 // target, or here in order if there isn't an IME target.
1620 if (traverseTopToBottom) {
1621 for (int i = mChildren.size() - 1; i >= 0; --i) {
1622 final DisplayChildWindowContainer child = mChildren.get(i);
1623 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1624 // In this case the Ime windows will be processed above their target so we skip
1625 // here.
1626 continue;
1627 }
1628 if (child.forAllWindows(callback, traverseTopToBottom)) {
1629 return true;
1630 }
1631 }
1632 } else {
1633 final int count = mChildren.size();
1634 for (int i = 0; i < count; i++) {
1635 final DisplayChildWindowContainer child = mChildren.get(i);
1636 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1637 // In this case the Ime windows will be processed above their target so we skip
1638 // here.
1639 continue;
1640 }
1641 if (child.forAllWindows(callback, traverseTopToBottom)) {
1642 return true;
1643 }
1644 }
1645 }
1646 return false;
1647 }
1648
1649 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1650 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1651 }
1652
Wale Ogunwale399c8692017-05-08 14:22:42 -07001653 @Override
1654 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001655 final WindowManagerPolicy policy = mService.mPolicy;
1656
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001657 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001658 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001659 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1660 + " is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001661 // If the display is frozen, some activities may be in the middle of restarting, and
1662 // thus have removed their old window. If the window has the flag to hide the lock
1663 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1664 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001665 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001666 } else if (policy.isKeyguardLocked()) {
1667 // Use the last orientation the while the display is frozen with the keyguard
1668 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1669 // window. We don't want to check the show when locked window directly though as
1670 // things aren't stable while the display is frozen, for example the window could be
1671 // momentarily unavailable due to activity relaunch.
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07001672 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
1673 + " is frozen while keyguard locked, return " + mLastOrientation);
Andrii Kulian8ee72852017-03-10 10:36:45 -08001674 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001675 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001676 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001677 final int orientation = mAboveAppWindowsContainers.getOrientation();
1678 if (orientation != SCREEN_ORIENTATION_UNSET) {
1679 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001680 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001681 }
1682
Wale Ogunwale399c8692017-05-08 14:22:42 -07001683 // Top system windows are not requesting an orientation. Start searching from apps.
1684 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001685 }
1686
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001687 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001688 // Check if display metrics changed and update base values if needed.
1689 updateBaseDisplayMetricsIfNeeded();
1690
Craig Mautner722285e2012-09-07 13:55:58 -07001691 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001692 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001693
Wale Ogunwale61911492017-10-11 08:50:50 -07001694 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1695 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001696 }
Craig Mautner722285e2012-09-07 13:55:58 -07001697 }
1698
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001699 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001700 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1701 if (displayManagerInternal != null) {
1702 // Bootstrap the default logical display from the display manager.
1703 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1704 if (newDisplayInfo != null) {
1705 mDisplayInfo.copyFrom(newDisplayInfo);
1706 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001707 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001708
Andrii Kuliancd097992017-03-23 18:31:59 -07001709 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1710 mDisplayInfo.logicalDensityDpi);
1711 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1712 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1713 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001714 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001715 }
1716
Andrii Kuliancd097992017-03-23 18:31:59 -07001717 /**
1718 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1719 * values.
1720 */
1721 private void updateBaseDisplayMetricsIfNeeded() {
1722 // Get real display metrics without overrides from WM.
1723 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1724 final int orientation = mDisplayInfo.rotation;
1725 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1726 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1727 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1728 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001729 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001730
1731 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1732 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001733 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1734 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001735
1736 if (displayMetricsChanged) {
1737 // Check if display size or density is forced.
1738 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1739 || mBaseDisplayHeight != mInitialDisplayHeight;
1740 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1741
1742 // If there is an override set for base values - use it, otherwise use new values.
1743 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1744 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1745 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1746
1747 // Real display metrics changed, so we should also update initial values.
1748 mInitialDisplayWidth = newWidth;
1749 mInitialDisplayHeight = newHeight;
1750 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001751 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001752 mService.reconfigureDisplayLocked(this);
1753 }
1754 }
1755
Bryce Lee27cec322017-03-21 09:41:37 -07001756 /** Sets the maximum width the screen resolution can be */
1757 void setMaxUiWidth(int width) {
1758 if (DEBUG_DISPLAY) {
1759 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1760 }
1761
1762 mMaxUiWidth = width;
1763
1764 // Update existing metrics.
1765 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1766 }
1767
1768 /** Update base (override) display metrics. */
1769 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1770 mBaseDisplayWidth = baseWidth;
1771 mBaseDisplayHeight = baseHeight;
1772 mBaseDisplayDensity = baseDensity;
1773
1774 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1775 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1776 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1777 mBaseDisplayWidth = mMaxUiWidth;
1778
1779 if (DEBUG_DISPLAY) {
1780 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1781 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1782 + " on display:" + getDisplayId());
1783 }
1784 }
1785
1786 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001787
1788 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001789 }
1790
Wale Ogunwaledb506192017-12-08 10:57:32 -08001791 void getStableRect(Rect out) {
1792 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001793 }
1794
Wale Ogunwale61911492017-10-11 08:50:50 -07001795 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001796 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1797 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001798
Wale Ogunwale61911492017-10-11 08:50:50 -07001799 final TaskStack stack = new TaskStack(mService, stackId, controller);
1800 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001801 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001802 }
1803
Andrii Kulian51c1b672017-04-07 18:39:32 -07001804 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001805 final DisplayContent prevDc = stack.getDisplayContent();
1806 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001807 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1808 + " which is not currently attached to any display");
1809 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001810 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001811 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1812 + " to its current displayId=" + mDisplayId);
1813 }
1814
Wale Ogunwale61911492017-10-11 08:50:50 -07001815 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001816 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001817 }
1818
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001819 @Override
1820 protected void addChild(DisplayChildWindowContainer child,
1821 Comparator<DisplayChildWindowContainer> comparator) {
1822 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1823 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001824
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001825 @Override
1826 protected void addChild(DisplayChildWindowContainer child, int index) {
1827 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1828 }
1829
1830 @Override
1831 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001832 // Only allow removal of direct children from this display if the display is in the process
1833 // of been removed.
1834 if (mRemovingDisplay) {
1835 super.removeChild(child);
1836 return;
1837 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001838 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001839 }
1840
Andrii Kuliand2765632016-12-12 22:26:34 -08001841 @Override
1842 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1843 // Children of the display are statically ordered, so the real intention here is to perform
1844 // the operation on the display and not the static direct children.
1845 getParent().positionChildAt(position, this, includingParents);
1846 }
1847
Winson Chung59a47ded2018-01-25 17:46:06 +00001848 void positionStackAt(int position, TaskStack child) {
1849 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1850 layoutAndAssignWindowLayersIfNeeded();
1851 }
1852
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001853 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001854 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1855 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001856 final int taskId = stack.taskIdFromPoint(x, y);
1857 if (taskId != -1) {
1858 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001859 }
1860 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001861 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001862 }
1863
Chong Zhang8e89b312015-09-09 15:09:30 -07001864 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001865 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001866 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001867 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001868 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001869 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001870 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001871 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1872 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001873 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001874 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001875 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001876
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001877 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1878 if (mTmpTaskForResizePointSearchResult.searchDone) {
1879 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001880 }
1881 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001882 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001883 }
1884
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001885 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001886 // The provided task is the task on this display with focus, so if WindowManagerService's
1887 // focused app is not on this display, focusedTask will be null.
1888 if (focusedTask == null) {
1889 mTouchExcludeRegion.setEmpty();
1890 } else {
1891 mTouchExcludeRegion.set(mBaseDisplayRect);
1892 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1893 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001894 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1895 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001896 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1897 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001898 }
1899 // If we removed the focused task above, add it back and only leave its
1900 // outside touch area in the exclusion. TapDectector is not interested in
1901 // any touch inside the focused task itself.
1902 if (!mTmpRect2.isEmpty()) {
1903 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1904 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001905 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001906 final WindowState inputMethod = mService.mInputMethodWindow;
1907 if (inputMethod != null && inputMethod.isVisibleLw()) {
1908 // If the input method is visible and the user is typing, we don't want these touch
1909 // events to be intercepted and used to change focus. This would likely cause a
1910 // disappearance of the input method.
1911 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001912 if (inputMethod.getDisplayId() == mDisplayId) {
1913 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1914 } else {
1915 // IME is on a different display, so we need to update its tap detector.
1916 // TODO(multidisplay): Remove when IME will always appear on same display.
1917 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1918 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001919 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001920 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001921 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001922 win.getTouchableRegion(mTmpRegion);
1923 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1924 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001925 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1926 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1927 win.amendTapExcludeRegion(mTouchExcludeRegion);
1928 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001929 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001930 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001931 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001932 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001933 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1934 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001935 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001936 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001937 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001938 }
1939
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001940 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001941 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001942 super.switchUser();
1943 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001944 }
1945
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001946 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001947 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1948 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001949 }
1950 }
1951
Wale Ogunwale10124582016-09-15 20:25:50 -07001952 @Override
1953 void removeIfPossible() {
1954 if (isAnimating()) {
1955 mDeferredRemoval = true;
1956 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001957 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001958 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001959 }
1960
Wale Ogunwale10124582016-09-15 20:25:50 -07001961 @Override
1962 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001963 mRemovingDisplay = true;
1964 try {
1965 super.removeImmediately();
1966 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001967 if (mService.canDispatchPointerEvents()) {
1968 if (mTapDetector != null) {
1969 mService.unregisterPointerEventListener(mTapDetector);
1970 }
1971 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1972 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1973 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001974 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001975 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001976 } finally {
1977 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001978 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001979
1980 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001981 }
1982
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001983 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001984 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001985 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001986 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1987
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001988 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001989 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001990 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001991 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001992 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001993 }
1994
Andrii Kulian0214ed92017-05-16 13:44:05 -07001995 /** @return 'true' if removal of this display content is deferred due to active animation. */
1996 boolean isRemovalDeferred() {
1997 return mDeferredRemoval;
1998 }
1999
Wale Ogunwale10124582016-09-15 20:25:50 -07002000 boolean animateForIme(float interpolatedValue, float animationTarget,
2001 float dividerAnimationTarget) {
2002 boolean updated = false;
2003
Wale Ogunwale61911492017-10-11 08:50:50 -07002004 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2005 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002006 if (stack == null || !stack.isAdjustedForIme()) {
2007 continue;
2008 }
2009
2010 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2011 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2012 updated = true;
2013 } else {
2014 mDividerControllerLocked.mLastAnimationProgress =
2015 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2016 mDividerControllerLocked.mLastDividerProgress =
2017 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2018 updated |= stack.updateAdjustForIme(
2019 mDividerControllerLocked.mLastAnimationProgress,
2020 mDividerControllerLocked.mLastDividerProgress,
2021 false /* force */);
2022 }
2023 if (interpolatedValue >= 1f) {
2024 stack.endImeAdjustAnimation();
2025 }
2026 }
2027
2028 return updated;
2029 }
2030
2031 boolean clearImeAdjustAnimation() {
2032 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002033 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2034 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002035 if (stack != null && stack.isAdjustedForIme()) {
2036 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2037 changed = true;
2038 }
2039 }
2040 return changed;
2041 }
2042
2043 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002044 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2045 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002046 if (stack.isVisible() && stack.isAdjustedForIme()) {
2047 stack.beginImeAdjustAnimation();
2048 }
2049 }
2050 }
2051
2052 void adjustForImeIfNeeded() {
2053 final WindowState imeWin = mService.mInputMethodWindow;
2054 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2055 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002056 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002057 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2058 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2059 imeTargetStack.getDockSide() : DOCKED_INVALID;
2060 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2061 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2062 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002063 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002064 final boolean imeHeightChanged = imeVisible &&
2065 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2066
2067 // The divider could be adjusted for IME position, or be thinner than usual,
2068 // or both. There are three possible cases:
2069 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2070 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2071 // - If IME is not visible, divider is not moved and is normal width.
2072
2073 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002074 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2075 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002076 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002077 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2078 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002079 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2080 } else {
2081 stack.resetAdjustedForIme(false);
2082 }
2083 }
2084 mDividerControllerLocked.setAdjustedForIme(
2085 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2086 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002087 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2088 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002089 stack.resetAdjustedForIme(!dockVisible);
2090 }
2091 mDividerControllerLocked.setAdjustedForIme(
2092 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2093 }
Winson Chung655332c2016-10-31 13:14:28 -07002094 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002095 }
2096
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002097 /**
2098 * If a window that has an animation specifying a colored background and the current wallpaper
2099 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2100 * suddenly disappear.
2101 */
2102 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002103 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2104 w -> w.mIsWallpaper && w.isVisibleNow());
2105
2106 if (visibleWallpaper != null) {
2107 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002108 }
2109 return winAnimator.mAnimLayer;
2110 }
2111
Wale Ogunwale10124582016-09-15 20:25:50 -07002112 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002113 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2114 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002115 stack.prepareFreezingTaskBounds();
2116 }
2117 }
2118
Wale Ogunwale94744212015-09-21 19:01:47 -07002119 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002120 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002121
2122 // Compute a transform matrix to undo the coordinate space transformation,
2123 // and present the window at the same physical position it previously occupied.
2124 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2125 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2126
2127 mTmpRectF.set(bounds);
2128 mTmpMatrix.mapRect(mTmpRectF);
2129 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002130 }
2131
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002132 static int deltaRotation(int oldRotation, int newRotation) {
2133 int delta = newRotation - oldRotation;
2134 if (delta < 0) delta += 4;
2135 return delta;
2136 }
2137
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002138 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002139 Matrix outMatrix) {
2140 // For rotations without Z-ordering we don't need the target rectangle's position.
2141 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2142 displayHeight, outMatrix);
2143 }
2144
2145 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2146 float displayWidth, float displayHeight, Matrix outMatrix) {
2147 switch (rotation) {
2148 case ROTATION_0:
2149 outMatrix.reset();
2150 break;
2151 case ROTATION_270:
2152 outMatrix.setRotate(270, 0, 0);
2153 outMatrix.postTranslate(0, displayHeight);
2154 outMatrix.postTranslate(rectTop, 0);
2155 break;
2156 case ROTATION_180:
2157 outMatrix.reset();
2158 break;
2159 case ROTATION_90:
2160 outMatrix.setRotate(90, 0, 0);
2161 outMatrix.postTranslate(displayWidth, 0);
2162 outMatrix.postTranslate(-rectTop, rectLeft);
2163 break;
2164 }
2165 }
2166
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002167 @CallSuper
2168 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002169 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002170 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002171 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002172 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002173 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2174 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002175 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002176 }
2177 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2178 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002179 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2180 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002181 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002182 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002183 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2184 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002185 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002186 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002187 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2188 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002189 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002190 }
2191 proto.write(DPI, mBaseDisplayDensity);
2192 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002193 proto.write(ROTATION, mRotation);
2194 final ScreenRotationAnimation screenRotationAnimation =
2195 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2196 if (screenRotationAnimation != null) {
2197 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2198 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002199 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002200 proto.end(token);
2201 }
2202
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002203 @Override
2204 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2205 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002206 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2207 final String subPrefix = " " + prefix;
2208 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2209 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2210 pw.print("dpi");
2211 if (mInitialDisplayWidth != mBaseDisplayWidth
2212 || mInitialDisplayHeight != mBaseDisplayHeight
2213 || mInitialDisplayDensity != mBaseDisplayDensity) {
2214 pw.print(" base=");
2215 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2216 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2217 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002218 if (mDisplayScalingDisabled) {
2219 pw.println(" noscale");
2220 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002221 pw.print(" cur=");
2222 pw.print(mDisplayInfo.logicalWidth);
2223 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2224 pw.print(" app=");
2225 pw.print(mDisplayInfo.appWidth);
2226 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2227 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2228 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2229 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2230 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002231 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002232 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002233 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002234
Craig Mautnerdc548482014-02-05 13:35:24 -08002235 pw.println();
Adrian Roos5251b1d2018-03-23 18:57:43 +01002236 pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);
2237
2238 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002239 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002240 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2241 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002242 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002243 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002244
Craig Mautnerdc548482014-02-05 13:35:24 -08002245 pw.println();
2246 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002247 pw.println();
2248 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002249 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002250 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002251 pw.print(" Exiting #"); pw.print(i);
2252 pw.print(' '); pw.print(token);
2253 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002254 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002255 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002256 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002257
Jorim Jaggi31f71702016-05-04 16:43:04 -07002258 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002259
2260 // Dump stack references
2261 final TaskStack homeStack = getHomeStack();
2262 if (homeStack != null) {
2263 pw.println(prefix + "homeStack=" + homeStack.getName());
2264 }
2265 final TaskStack pinnedStack = getPinnedStack();
2266 if (pinnedStack != null) {
2267 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2268 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002269 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002270 if (splitScreenPrimaryStack != null) {
2271 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2272 }
2273
2274 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002275 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002276 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002277 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002278
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002279 pw.println();
2280 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002281 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002282
2283 @Override
2284 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002285 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002286 }
2287
2288 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002289 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002290 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002291
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002292 /** Returns true if the stack in the windowing mode is visible. */
2293 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002294 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002295 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002296 }
2297
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002298 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002299 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002300 final int x = (int) xf;
2301 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002302 final WindowState touchedWin = getWindow(w -> {
2303 final int flags = w.mAttrs.flags;
2304 if (!w.isVisibleLw()) {
2305 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002306 }
2307 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002308 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002309 }
2310
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002311 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002312 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002313 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002314 }
2315
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002316 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002317
2318 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002319 return mTmpRegion.contains(x, y) || touchFlags == 0;
2320 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002321
2322 return touchedWin;
2323 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002324
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002325 boolean canAddToastWindowForUid(int uid) {
2326 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002327 // Also if the app is focused adding more than one toast at
2328 // a time for better backwards compatibility.
2329 final WindowState focusedWindowForUid = getWindow(w ->
2330 w.mOwnerUid == uid && w.isFocused());
2331 if (focusedWindowForUid != null) {
2332 return true;
2333 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002334 final WindowState win = getWindow(w ->
2335 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2336 && !w.mWindowRemovalAllowed);
2337 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002338 }
2339
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002340 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002341 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2342 return;
2343 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002344
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002345 // Used to communicate the old focus to the callback method.
2346 mTmpWindow = oldFocus;
2347
2348 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002349 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002350
2351 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002352 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002353
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002354 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002355
2356 if (mTmpWindow == null) {
2357 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2358 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002359 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002360 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002361 }
2362
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002363 /** Updates the layer assignment of windows on this display. */
2364 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002365 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002366 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002367 if (setLayoutNeeded) {
2368 setLayoutNeeded();
2369 }
Robert Carrb1579c82017-09-05 14:54:47 -07002370
Robert Carrf59b8dd2017-10-02 18:58:36 -07002371 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002372 // the application of this transaction until the animation pass triggers
2373 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2374 // the hiding and showing of surfaces.
2375 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002376 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002377 }
2378
Wale Ogunwale1666e312016-12-16 11:27:18 -08002379 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2380 // moving containers or resizing them. Need to investigate the best way to have it automatically
2381 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002382 void layoutAndAssignWindowLayersIfNeeded() {
2383 mService.mWindowsChanged = true;
2384 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002385
2386 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2387 false /*updateInputWindows*/)) {
2388 assignWindowLayers(false /* setLayoutNeeded */);
2389 }
2390
2391 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2392 mService.mWindowPlacerLocked.performSurfacePlacement();
2393 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2394 }
2395
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002396 /** Returns true if a leaked surface was destroyed */
2397 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002398 // Used to indicate that a surface was leaked.
2399 mTmpWindow = null;
2400 forAllWindows(w -> {
2401 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002402 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002403 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002404 }
2405 if (!mService.mSessions.contains(wsa.mSession)) {
2406 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002407 + w + " surface=" + wsa.mSurfaceController
2408 + " token=" + w.mToken
2409 + " pid=" + w.mSession.mPid
2410 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002411 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002412 mService.mForceRemoves.add(w);
2413 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002414 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002415 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002416 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002417 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002418 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002419 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002420 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002421 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002422 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002423
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002424 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002425 }
2426
2427 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002428 * Determine and return the window that should be the IME target.
2429 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2430 * @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 +00002431 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002432 WindowState computeImeTarget(boolean updateImeTarget) {
2433 if (mService.mInputMethodWindow == null) {
2434 // There isn't an IME so there shouldn't be a target...That was easy!
2435 if (updateImeTarget) {
2436 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2437 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002438 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002439 }
2440 return null;
2441 }
2442
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002443 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2444 // same display. Or even when the current IME/target are not on the same screen as the next
2445 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002446 mUpdateImeTarget = updateImeTarget;
2447 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002448
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002449
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002450 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2451 // to be on top of it, but it is not -really- where input will go. So look down below
2452 // for a real window to target...
2453 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2454 final AppWindowToken token = target.mAppToken;
2455 if (token != null) {
2456 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2457 if (betterTarget != null) {
2458 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002459 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002460 }
2461 }
2462
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002463 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2464 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002465
2466 // Now, a special case -- if the last target's window is in the process of exiting, and is
2467 // above the new target, keep on the last target to avoid flicker. Consider for example a
2468 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2469 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2470 // scrim.
2471 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002472 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2473 && (target == null
2474 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002475 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002476 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002477 }
2478
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002479 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2480 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002481
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002482 if (target == null) {
2483 if (updateImeTarget) {
2484 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2485 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2486 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002487 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002488 }
2489
2490 return null;
2491 }
2492
2493 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002494 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2495 if (token != null) {
2496
2497 // Now some fun for dealing with window animations that modify the Z order. We need
2498 // to look at all windows below the current target that are in this app, finding the
2499 // highest visible one in layering.
2500 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002501 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002502 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002503 }
2504
2505 if (highestTarget != null) {
2506 final AppTransition appTransition = mService.mAppTransition;
2507 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2508 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2509 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002510 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002511
2512 if (appTransition.isTransitionSet()) {
2513 // If we are currently setting up for an animation, hold everything until we
2514 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002515 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002516 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002517 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002518 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002519 // If the window we are currently targeting is involved with an animation,
2520 // and it is on top of the next target we will be over, then hold off on
2521 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002522 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002523 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002524 }
2525 }
2526 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002527
2528 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2529 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002530 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002531 }
2532
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002533 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002534 }
2535
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002536 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002537 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002538 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002539 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002540 }
2541
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002542 mService.mInputMethodTarget = target;
2543 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002544 assignWindowLayers(false /* setLayoutNeeded */);
2545 }
2546
2547 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2548 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2549 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2550 }
2551
2552 // Used to indicate we have reached the first window in the range we are interested in.
2553 mTmpWindow = null;
2554
2555 // TODO: Figure-out a more efficient way to do this.
2556 final WindowState candidate = getWindow(w -> {
2557 if (w == top) {
2558 // Reached the first window in the range we are interested in.
2559 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002560 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002561 if (mTmpWindow == null) {
2562 return false;
2563 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002564
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002565 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2566 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002567 }
2568 // If we reached the bottom of the range of windows we are considering,
2569 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002570 if (w == bottom) {
2571 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002572 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002573 return false;
2574 });
2575
2576 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002577 }
2578
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002579 void setLayoutNeeded() {
2580 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2581 mLayoutNeeded = true;
2582 }
2583
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002584 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002585 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2586 mLayoutNeeded = false;
2587 }
2588
2589 boolean isLayoutNeeded() {
2590 return mLayoutNeeded;
2591 }
2592
Wale Ogunwale02319a62016-09-26 15:21:22 -07002593 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2594 if (mTokenMap.isEmpty()) {
2595 return;
2596 }
2597 pw.println(" Display #" + mDisplayId);
2598 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2599 while (it.hasNext()) {
2600 final WindowToken token = it.next();
2601 pw.print(" ");
2602 pw.print(token);
2603 if (dumpAll) {
2604 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002605 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002606 } else {
2607 pw.println();
2608 }
2609 }
2610 }
2611
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002612 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002613 final int[] index = new int[1];
2614 forAllWindows(w -> {
2615 final WindowStateAnimator wAnim = w.mWinAnimator;
2616 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2617 index[0] = index[0] + 1;
2618 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002619 }
2620
Jorim Jaggife762342016-10-13 14:33:27 +02002621 /**
2622 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2623 */
2624 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2625 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002626 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002627 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2628 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002629 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002630 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002631 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002632 }
2633
Wale Ogunwale494009b82016-10-21 09:01:38 -07002634 boolean checkWaitingForWindows() {
2635
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002636 mHaveBootMsg = false;
2637 mHaveApp = false;
2638 mHaveWallpaper = false;
2639 mHaveKeyguard = true;
2640
2641 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002642 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2643 return true;
2644 }
2645 if (w.isDrawnLw()) {
2646 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002647 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002648 } else if (w.mAttrs.type == TYPE_APPLICATION
2649 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002650 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002651 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002652 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002653 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002654 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002655 }
2656 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002657 return false;
2658 });
2659
2660 if (visibleWindow != null) {
2661 // We have a visible window.
2662 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002663 }
2664
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002665 // if the wallpaper service is disabled on the device, we're never going to have
2666 // wallpaper, don't bother waiting for it
2667 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2668 com.android.internal.R.bool.config_enableWallpaperService)
Daichi Hironoc1432222018-03-29 13:06:07 +09002669 && mService.mContext.getResources().getBoolean(
2670 com.android.internal.R.bool.config_checkWallpaperAtBoot)
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002671 && !mService.mOnlyCore;
2672
Wale Ogunwale494009b82016-10-21 09:01:38 -07002673 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2674 "******** booted=" + mService.mSystemBooted
2675 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002676 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2677 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2678 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002679
2680 // If we are turning on the screen to show the boot message, don't do it until the boot
2681 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002682 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002683 return true;
2684 }
2685
2686 // If we are turning on the screen after the boot is completed normally, don't do so until
2687 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002688 if (mService.mSystemBooted
2689 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002690 return true;
2691 }
2692
2693 return false;
2694 }
2695
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002696 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002697 mTmpWindowAnimator = animator;
2698 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002699 }
2700
2701 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002702 resetAnimationBackgroundAnimator();
2703
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002704 // Used to indicate a detached wallpaper.
2705 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002706 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002707
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002708 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002709
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002710 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002711 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002712 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2713 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002714 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2715 }
2716 }
2717
Wale Ogunwale494009b82016-10-21 09:01:38 -07002718 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002719 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002720 if (imFocus == null) {
2721 return false;
2722 }
2723
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002724 if (DEBUG_INPUT_METHOD) {
2725 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2726 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2727 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002728 }
2729
Wale Ogunwale494009b82016-10-21 09:01:38 -07002730 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2731
2732 if (DEBUG_INPUT_METHOD) {
2733 Slog.i(TAG_WM, "IM target client: " + imeClient);
2734 if (imeClient != null) {
2735 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2736 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2737 }
2738 }
2739
2740 return imeClient != null && imeClient.asBinder() == client.asBinder();
2741 }
2742
2743 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002744 final WindowState win = getWindow(
2745 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2746 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002747 }
2748
2749 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002750 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002751 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002752 final int curValue = w.mSystemUiVisibility;
2753 final int diff = (curValue ^ visibility) & globalDiff;
2754 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002755 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002756 w.mSeq++;
2757 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002758 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002759 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2760 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002761 visibility, newValue, diff);
2762 }
2763 } catch (RemoteException e) {
2764 // so sorry
2765 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002766 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002767 }
2768
2769 void onWindowFreezeTimeout() {
2770 Slog.w(TAG_WM, "Window freeze timeout expired.");
2771 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002772
2773 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002774 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002775 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002776 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002777 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002778 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2779 - mService.mDisplayFreezeTime);
2780 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002781 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002782 mService.mWindowPlacerLocked.performSurfacePlacement();
2783 }
2784
2785 void waitForAllWindowsDrawn() {
2786 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002787 forAllWindows(w -> {
2788 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2789 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2790 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002791 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002792 w.mLastContentInsets.set(-1, -1, -1, -1);
2793 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002794 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002795 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002796 }
2797
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002798 // TODO: Super crazy long method that should be broken down...
2799 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2800
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002801 final int dw = mDisplayInfo.logicalWidth;
2802 final int dh = mDisplayInfo.logicalHeight;
2803 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2804
2805 mTmpUpdateAllDrawn.clear();
2806
2807 int repeats = 0;
2808 do {
2809 repeats++;
2810 if (repeats > 6) {
2811 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2812 clearLayoutNeeded();
2813 break;
2814 }
2815
2816 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2817 pendingLayoutChanges);
2818
Andrii Kulian839def92016-11-02 10:58:58 -07002819 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2820 // the wallpaper window jumping across displays.
2821 // Remove check for default display when there will be support for multiple wallpaper
2822 // targets (on different displays).
2823 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002824 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002825 }
2826
2827 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2828 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08002829 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002830 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002831 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002832 }
2833 }
2834
2835 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2836 setLayoutNeeded();
2837 }
2838
2839 // FIRST LOOP: Perform a layout, if needed.
2840 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2841 performLayout(repeats == 1, false /* updateInputWindows */);
2842 } else {
2843 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2844 }
2845
2846 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2847 pendingLayoutChanges = 0;
2848
2849 if (isDefaultDisplay) {
2850 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002851 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002852 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2853 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2854 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2855 }
2856 } while (pendingLayoutChanges != 0);
2857
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002858 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002859
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002860 mTmpRecoveringMemory = recoveringMemory;
2861 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002862 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002863
2864 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002865 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2866 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2867 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002868 true /* inTraversal, must call performTraversalInTrans... below */);
2869
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002870 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2871 if (wallpaperVisible != mLastWallpaperVisible) {
2872 mLastWallpaperVisible = wallpaperVisible;
2873 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2874 }
2875
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002876 while (!mTmpUpdateAllDrawn.isEmpty()) {
2877 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2878 // See if any windows have been drawn, so they (and others associated with them)
2879 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002880 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002881 }
2882
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002883 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002884 }
2885
Bryce Leef3c6a472017-11-14 14:53:06 -08002886 private void updateBounds() {
2887 calculateBounds(mTmpBounds);
2888 setBounds(mTmpBounds);
2889 }
2890
2891 // Determines the current display bounds based on the current state
2892 private void calculateBounds(Rect out) {
2893 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2894 final int orientation = mDisplayInfo.rotation;
2895 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2896 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2897 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2898 int width = mDisplayInfo.logicalWidth;
2899 int left = (physWidth - width) / 2;
2900 int height = mDisplayInfo.logicalHeight;
2901 int top = (physHeight - height) / 2;
2902 out.set(left, top, left + width, top + height);
2903 }
2904
2905 @Override
2906 public void getBounds(Rect out) {
2907 calculateBounds(out);
2908 }
2909
2910 private void getBounds(Rect out, int orientation) {
2911 getBounds(out);
2912
2913 // Rotate the Rect if needed.
2914 final int currentRotation = mDisplayInfo.rotation;
2915 final int rotationDelta = deltaRotation(currentRotation, orientation);
2916 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2917 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2918 mTmpRectF.set(out);
2919 mTmpMatrix.mapRect(mTmpRectF);
2920 mTmpRectF.round(out);
2921 }
2922 }
2923
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002924 void performLayout(boolean initial, boolean updateInputWindows) {
2925 if (!isLayoutNeeded()) {
2926 return;
2927 }
2928 clearLayoutNeeded();
2929
2930 final int dw = mDisplayInfo.logicalWidth;
2931 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002932 if (DEBUG_LAYOUT) {
2933 Slog.v(TAG, "-------------------------------------");
2934 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2935 }
2936
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01002937 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
2938 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002939 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2940 // display info above...
2941 mDisplayFrames.mRotation = mRotation;
2942 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002943 if (isDefaultDisplay) {
2944 // Not needed on non-default displays.
2945 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2946 mService.mScreenRect.set(0, 0, dw, dh);
2947 }
2948
Adrian Roos5251b1d2018-03-23 18:57:43 +01002949 int seq = mLayoutSeq + 1;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002950 if (seq < 0) seq = 0;
Adrian Roos5251b1d2018-03-23 18:57:43 +01002951 mLayoutSeq = seq;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002952
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002953 // Used to indicate that we have processed the dream window and all additional windows are
2954 // behind it.
2955 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002956 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002957
2958 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002959 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002960
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002961 // Used to indicate that we have processed the dream window and all additional attached
2962 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002963 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002964 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002965
2966 // Now perform layout of attached windows, which usually depend on the position of the
2967 // window they are attached to. XXX does not deal with windows that are attached to windows
2968 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002969 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002970
2971 // Window frames may have changed. Tell the input dispatcher about it.
2972 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2973 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2974 if (updateInputWindows) {
2975 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2976 }
2977
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002978 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2979 }
2980
2981 /**
2982 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2983 * In portrait mode, it grabs the full screenshot.
2984 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002985 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002986 */
chaviw0315a1a2018-03-05 15:28:35 -08002987 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
2988 if (!mService.mPolicy.isScreenOn()) {
2989 if (DEBUG_SCREENSHOT) {
2990 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002991 }
chaviw0315a1a2018-03-05 15:28:35 -08002992 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002993 }
chaviwfbe47df2017-11-10 16:14:49 -08002994
chaviw0315a1a2018-03-05 15:28:35 -08002995 int dw = mDisplayInfo.logicalWidth;
2996 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08002997
chaviw0315a1a2018-03-05 15:28:35 -08002998 if (dw <= 0 || dh <= 0) {
2999 return null;
3000 }
chaviwfbe47df2017-11-10 16:14:49 -08003001
chaviw0315a1a2018-03-05 15:28:35 -08003002 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08003003
chaviw0315a1a2018-03-05 15:28:35 -08003004 // The screenshot API does not apply the current screen rotation.
3005 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08003006
chaviw0315a1a2018-03-05 15:28:35 -08003007 if (rot == ROTATION_90 || rot == ROTATION_270) {
3008 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3009 }
chaviwfbe47df2017-11-10 16:14:49 -08003010
chaviw0315a1a2018-03-05 15:28:35 -08003011 // SurfaceFlinger is not aware of orientation, so convert our logical
3012 // crop to SurfaceFlinger's portrait orientation.
3013 convertCropForSurfaceFlinger(frame, rot, dw, dh);
3014
3015 final ScreenRotationAnimation screenRotationAnimation =
3016 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3017 final boolean inRotation = screenRotationAnimation != null &&
3018 screenRotationAnimation.isAnimating();
3019 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3020
3021 // TODO(b/68392460): We should screenshot Task controls directly
3022 // but it's difficult at the moment as the Task doesn't have the
3023 // correct size set.
3024 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3025 if (bitmap == null) {
3026 Slog.w(TAG_WM, "Failed to take screenshot");
3027 return null;
3028 }
3029
3030 // Create a copy of the screenshot that is immutable and backed in ashmem.
3031 // This greatly reduces the overhead of passing the bitmap between processes.
3032 final Bitmap ret = bitmap.createAshmemBitmap(config);
3033 bitmap.recycle();
3034 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003035 }
3036
3037 // TODO: Can this use createRotationMatrix()?
3038 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3039 if (rot == Surface.ROTATION_90) {
3040 final int tmp = crop.top;
3041 crop.top = dw - crop.right;
3042 crop.right = crop.bottom;
3043 crop.bottom = dw - crop.left;
3044 crop.left = tmp;
3045 } else if (rot == Surface.ROTATION_180) {
3046 int tmp = crop.top;
3047 crop.top = dh - crop.bottom;
3048 crop.bottom = dh - tmp;
3049 tmp = crop.right;
3050 crop.right = dw - crop.left;
3051 crop.left = dw - tmp;
3052 } else if (rot == Surface.ROTATION_270) {
3053 final int tmp = crop.top;
3054 crop.top = crop.left;
3055 crop.left = dh - crop.bottom;
3056 crop.bottom = crop.right;
3057 crop.right = dh - tmp;
3058 }
3059 }
3060
3061 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003062 // Used to indicate the layout is needed.
3063 mTmpWindow = null;
3064
3065 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003066 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003067 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003068 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003069 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003070 w.setDisplayLayoutNeeded();
3071 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003072 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003073
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003074 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003075 mService.mWindowPlacerLocked.performSurfacePlacement();
3076 }
3077 }
3078
Wale Ogunwale1666e312016-12-16 11:27:18 -08003079 void setExitingTokensHasVisible(boolean hasVisible) {
3080 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3081 mExitingTokens.get(i).hasVisible = hasVisible;
3082 }
3083
3084 // Initialize state of exiting applications.
3085 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3086 }
3087
3088 void removeExistingTokensIfPossible() {
3089 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3090 final WindowToken token = mExitingTokens.get(i);
3091 if (!token.hasVisible) {
3092 mExitingTokens.remove(i);
3093 }
3094 }
3095
3096 // Time to remove any exiting applications?
3097 mTaskStackContainers.removeExistingAppTokensIfPossible();
3098 }
3099
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003100 @Override
3101 void onDescendantOverrideConfigurationChanged() {
3102 setLayoutNeeded();
3103 mService.requestTraversal();
3104 }
3105
David Stevens9440dc82017-03-16 19:00:20 -07003106 boolean okToDisplay() {
3107 if (mDisplayId == DEFAULT_DISPLAY) {
3108 return !mService.mDisplayFrozen
3109 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3110 }
3111 return mDisplayInfo.state == Display.STATE_ON;
3112 }
3113
3114 boolean okToAnimate() {
3115 return okToDisplay() &&
3116 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3117 }
3118
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003119 static final class TaskForResizePointSearchResult {
3120 boolean searchDone;
3121 Task taskForResize;
3122
3123 void reset() {
3124 searchDone = false;
3125 taskForResize = null;
3126 }
3127 }
Robert Carr3b716242016-08-16 16:02:21 -07003128
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003129 private static final class ApplySurfaceChangesTransactionState {
3130 boolean displayHasContent;
3131 boolean obscured;
3132 boolean syswin;
3133 boolean focusDisplayed;
3134 float preferredRefreshRate;
3135 int preferredModeId;
3136
3137 void reset() {
3138 displayHasContent = false;
3139 obscured = false;
3140 syswin = false;
3141 focusDisplayed = false;
3142 preferredRefreshRate = 0;
3143 preferredModeId = 0;
3144 }
3145 }
3146
3147 private static final class ScreenshotApplicationState {
3148 WindowState appWin;
3149 int maxLayer;
3150 int minLayer;
3151 boolean screenshotReady;
3152
3153 void reset(boolean screenshotReady) {
3154 appWin = null;
3155 maxLayer = 0;
3156 minLayer = 0;
3157 this.screenshotReady = screenshotReady;
3158 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3159 }
3160 }
3161
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003162 /**
3163 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3164 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3165 * homogeneous children type which is currently required by sub-classes of
3166 * {@link WindowContainer} class.
3167 */
3168 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3169
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003170 DisplayChildWindowContainer(WindowManagerService service) {
3171 super(service);
3172 }
3173
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003174 @Override
3175 boolean fillsParent() {
3176 return true;
3177 }
3178
3179 @Override
3180 boolean isVisible() {
3181 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003182 }
3183 }
3184
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003185 /**
3186 * Window container class that contains all containers on this display relating to Apps.
3187 * I.e Activities.
3188 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003189 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003190 /**
3191 * A control placed at the appropriate level for transitions to occur.
3192 */
chaviw23ee71c2017-12-18 11:29:41 -08003193 SurfaceControl mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003194 SurfaceControl mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003195 SurfaceControl mHomeAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003196
Robert Carrf7a7ca82017-12-06 13:17:07 -08003197 /**
3198 * Given that the split-screen divider does not have an AppWindowToken, it
3199 * will have to live inside of a "NonAppWindowContainer", in particular
3200 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3201 * it will need to be interleaved with some of our children, appearing on top of
3202 * both docked stacks but underneath any assistant stacks.
3203 *
3204 * To solve this problem we have this anchor control, which will always exist so
3205 * we can always assign it the correct value in our {@link #assignChildLayers}.
3206 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3207 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3208 * events between the two containers.
3209 */
3210 SurfaceControl mSplitScreenDividerAnchor = null;
3211
Wale Ogunwale61911492017-10-11 08:50:50 -07003212 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3213 // through the list to find them.
3214 private TaskStack mHomeStack = null;
3215 private TaskStack mPinnedStack = null;
3216 private TaskStack mSplitScreenPrimaryStack = null;
3217
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003218 TaskStackContainers(WindowManagerService service) {
3219 super(service);
3220 }
3221
Wale Ogunwale61911492017-10-11 08:50:50 -07003222 /**
3223 * Returns the topmost stack on the display that is compatible with the input windowing mode
3224 * and activity type. Null is no compatible stack on the display.
3225 */
3226 TaskStack getStack(int windowingMode, int activityType) {
3227 if (activityType == ACTIVITY_TYPE_HOME) {
3228 return mHomeStack;
3229 }
3230 if (windowingMode == WINDOWING_MODE_PINNED) {
3231 return mPinnedStack;
3232 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3233 return mSplitScreenPrimaryStack;
3234 }
3235 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3236 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003237 if (activityType == ACTIVITY_TYPE_UNDEFINED
3238 && windowingMode == stack.getWindowingMode()) {
3239 // Passing in undefined type means we want to match the topmost stack with the
3240 // windowing mode.
3241 return stack;
3242 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003243 if (stack.isCompatible(windowingMode, activityType)) {
3244 return stack;
3245 }
3246 }
3247 return null;
3248 }
3249
3250 @VisibleForTesting
3251 TaskStack getTopStack() {
3252 return mTaskStackContainers.getChildCount() > 0
3253 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3254 }
3255
3256 TaskStack getHomeStack() {
3257 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3258 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3259 }
3260 return mHomeStack;
3261 }
3262
3263 TaskStack getPinnedStack() {
3264 return mPinnedStack;
3265 }
3266
Matthew Ng64e77cf2017-10-31 14:01:31 -07003267 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003268 return mSplitScreenPrimaryStack;
3269 }
3270
Winson Chunge2d72172018-01-25 17:46:20 +00003271 ArrayList<Task> getVisibleTasks() {
3272 final ArrayList<Task> visibleTasks = new ArrayList<>();
3273 forAllTasks(task -> {
3274 if (task.isVisible()) {
3275 visibleTasks.add(task);
3276 }
3277 });
3278 return visibleTasks;
3279 }
3280
Andrii Kulian839def92016-11-02 10:58:58 -07003281 /**
3282 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003283 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003284 */
3285 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003286 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003287 addChild(stack, onTop);
3288 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003289 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003290
Wale Ogunwale61911492017-10-11 08:50:50 -07003291 void onStackWindowingModeChanged(TaskStack stack) {
3292 removeStackReferenceIfNeeded(stack);
3293 addStackReferenceIfNeeded(stack);
3294 if (stack == mPinnedStack && getTopStack() != stack) {
3295 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3296 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3297 }
3298 }
3299
3300 private void addStackReferenceIfNeeded(TaskStack stack) {
3301 if (stack.isActivityTypeHome()) {
3302 if (mHomeStack != null) {
3303 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3304 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3305 }
3306 mHomeStack = stack;
3307 }
3308 final int windowingMode = stack.getWindowingMode();
3309 if (windowingMode == WINDOWING_MODE_PINNED) {
3310 if (mPinnedStack != null) {
3311 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3312 + mPinnedStack + " already exist on display=" + this
3313 + " stack=" + stack);
3314 }
3315 mPinnedStack = stack;
3316 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3317 if (mSplitScreenPrimaryStack != null) {
3318 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3319 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3320 + " already exist on display=" + this + " stack=" + stack);
3321 }
3322 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003323 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003324 }
3325 }
3326
3327 private void removeStackReferenceIfNeeded(TaskStack stack) {
3328 if (stack == mHomeStack) {
3329 mHomeStack = null;
3330 } else if (stack == mPinnedStack) {
3331 mPinnedStack = null;
3332 } else if (stack == mSplitScreenPrimaryStack) {
3333 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003334 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3335 mService.setDockedStackCreateStateLocked(
3336 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3337 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003338 }
Andrii Kulian839def92016-11-02 10:58:58 -07003339 }
3340
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003341 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003342 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3343 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003344 addChild(stack, addIndex);
3345 setLayoutNeeded();
3346 }
3347
Wale Ogunwale61911492017-10-11 08:50:50 -07003348 @Override
3349 protected void removeChild(TaskStack stack) {
3350 super.removeChild(stack);
3351 removeStackReferenceIfNeeded(stack);
3352 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003353
3354 @Override
3355 boolean isOnTop() {
3356 // Considered always on top
3357 return true;
3358 }
3359
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003360 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003361 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003362 if (child.getWindowConfiguration().isAlwaysOnTop()
3363 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003364 // This stack is always-on-top, override the default behavior.
3365 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3366
3367 // Moving to its current position, as we must call super but we don't want to
3368 // perform any meaningful action.
3369 final int currentPosition = mChildren.indexOf(child);
3370 super.positionChildAt(currentPosition, child, false /* includingParents */);
3371 return;
3372 }
3373
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003374 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3375 super.positionChildAt(targetPosition, child, includingParents);
3376
3377 setLayoutNeeded();
3378 }
3379
3380 /**
3381 * When stack is added or repositioned, find a proper position for it.
3382 * This will make sure that pinned stack always stays on top.
3383 * @param requestedPosition Position requested by caller.
3384 * @param stack Stack to be added or positioned.
3385 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3386 * @return The proper position for the stack.
3387 */
3388 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3389 final int topChildPosition = mChildren.size() - 1;
3390 boolean toTop = requestedPosition == POSITION_TOP;
3391 toTop |= adding ? requestedPosition >= topChildPosition + 1
3392 : requestedPosition >= topChildPosition;
3393 int targetPosition = requestedPosition;
3394
Wale Ogunwale61911492017-10-11 08:50:50 -07003395 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003396 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003397 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003398 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003399 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3400 }
3401
3402 // So, stack is moved just below the pinned stack.
3403 // When we're adding a new stack the target is the current pinned stack position.
3404 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003405 // stack, because WindowContainer#positionAt() first removes element and then adds
3406 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003407 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3408 }
3409
3410 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003411 }
3412
3413 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003414 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3415 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003416 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003417 if (super.forAllWindows(callback, traverseTopToBottom)) {
3418 return true;
3419 }
3420 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3421 return true;
3422 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003423 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003424 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3425 return true;
3426 }
3427 if (super.forAllWindows(callback, traverseTopToBottom)) {
3428 return true;
3429 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003430 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003431 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003432 }
3433
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003434 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003435 boolean traverseTopToBottom) {
3436 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3437 // app tokens.
3438 // TODO: Investigate if we need to continue to do this or if we can just process them
3439 // in-order.
3440 if (traverseTopToBottom) {
3441 for (int i = mChildren.size() - 1; i >= 0; --i) {
3442 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3443 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003444 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3445 traverseTopToBottom)) {
3446 return true;
3447 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003448 }
3449 }
3450 } else {
3451 final int count = mChildren.size();
3452 for (int i = 0; i < count; ++i) {
3453 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3454 final int appTokensCount = appTokens.size();
3455 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003456 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3457 traverseTopToBottom)) {
3458 return true;
3459 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003460 }
3461 }
3462 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003463 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003464 }
3465
Wale Ogunwale1666e312016-12-16 11:27:18 -08003466 void setExitingTokensHasVisible(boolean hasVisible) {
3467 for (int i = mChildren.size() - 1; i >= 0; --i) {
3468 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3469 for (int j = appTokens.size() - 1; j >= 0; --j) {
3470 appTokens.get(j).hasVisible = hasVisible;
3471 }
3472 }
3473 }
3474
3475 void removeExistingAppTokensIfPossible() {
3476 for (int i = mChildren.size() - 1; i >= 0; --i) {
3477 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3478 for (int j = appTokens.size() - 1; j >= 0; --j) {
3479 final AppWindowToken token = appTokens.get(j);
3480 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3481 && (!token.mIsExiting || token.isEmpty())) {
3482 // Make sure there is no animation running on this token, so any windows
3483 // associated with it will be removed as soon as their animations are
3484 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003485 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003486 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3487 "performLayout: App token exiting now removed" + token);
3488 token.removeIfPossible();
3489 }
3490 }
3491 }
3492 }
3493
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003494 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003495 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003496 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3497 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003498 // Apps and their containers are not allowed to specify an orientation while the
3499 // docked or freeform stack is visible...except for the home stack/task if the
3500 // docked stack is minimized and it actually set something.
3501 if (mHomeStack != null && mHomeStack.isVisible()
3502 && mDividerControllerLocked.isMinimizedDock()) {
3503 final int orientation = mHomeStack.getOrientation();
3504 if (orientation != SCREEN_ORIENTATION_UNSET) {
3505 return orientation;
3506 }
3507 }
3508 return SCREEN_ORIENTATION_UNSPECIFIED;
3509 }
3510
3511 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003512 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3513 PackageManager.FEATURE_AUTOMOTIVE);
3514 if (isCar) {
3515 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3516 // allow anything but the default orientation.
3517 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003518 "Forcing UNSPECIFIED orientation in car for display id=" + mDisplayId
3519 + ". Ignoring " + orientation);
Dean Harding3e5a1522017-10-06 09:19:01 -07003520 return SCREEN_ORIENTATION_UNSPECIFIED;
3521 }
3522
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003523 if (orientation != SCREEN_ORIENTATION_UNSET
3524 && orientation != SCREEN_ORIENTATION_BEHIND) {
3525 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003526 "App is requesting an orientation, return " + orientation
3527 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003528 return orientation;
3529 }
3530
3531 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003532 "No app is requesting an orientation, return " + mLastOrientation
3533 + " for display id=" + mDisplayId);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003534 // The next app has not been requested to be visible, so we keep the current orientation
3535 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003536 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003537 }
Robert Carrb1579c82017-09-05 14:54:47 -07003538
3539 @Override
3540 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003541 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003542
Robert Carr2f8aa392018-01-31 14:46:51 -08003543 for (int i = 0; i < mChildren.size(); i++) {
3544 final TaskStack s = mChildren.get(i);
3545 s.assignChildLayers(t);
3546 }
3547 }
3548
3549 void assignStackOrdering(SurfaceControl.Transaction t) {
Jorim Jaggibe418292018-03-26 16:14:12 +02003550
Robert Carrf7a7ca82017-12-06 13:17:07 -08003551 final int HOME_STACK_STATE = 0;
3552 final int NORMAL_STACK_STATE = 1;
3553 final int ALWAYS_ON_TOP_STATE = 2;
3554
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003555 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003556 int layerForAnimationLayer = 0;
Jorim Jaggibe418292018-03-26 16:14:12 +02003557 int layerForBoostedAnimationLayer = 0;
Jorim Jaggi391790622018-04-18 15:30:44 +02003558 int layerForHomeAnimationLayer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003559
Robert Carrf7a7ca82017-12-06 13:17:07 -08003560 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3561 for (int i = 0; i < mChildren.size(); i++) {
3562 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003563 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3564 continue;
3565 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3566 || s.isAlwaysOnTop())) {
3567 continue;
3568 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3569 continue;
3570 }
3571 s.assignLayer(t, layer++);
3572 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3573 t.setLayer(mSplitScreenDividerAnchor, layer++);
3574 }
Winson Chungd41f71d2018-03-16 15:26:07 -07003575 if ((s.isTaskAnimating() || s.isAppAnimating())
3576 && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003577 // Ensure the animation layer ends up above the
3578 // highest animating stack and no higher.
3579 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003580 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003581 if (state != ALWAYS_ON_TOP_STATE) {
3582 layerForBoostedAnimationLayer = layer++;
3583 }
Robert Carrf7a7ca82017-12-06 13:17:07 -08003584 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003585 if (state == HOME_STACK_STATE) {
3586 layerForHomeAnimationLayer = layer++;
3587 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003588 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003589 if (mAppAnimationLayer != null) {
3590 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003591 }
Jorim Jaggibe418292018-03-26 16:14:12 +02003592 if (mBoostedAppAnimationLayer != null) {
3593 t.setLayer(mBoostedAppAnimationLayer, layerForBoostedAnimationLayer);
3594 }
Jorim Jaggi391790622018-04-18 15:30:44 +02003595 if (mHomeAppAnimationLayer != null) {
3596 t.setLayer(mHomeAppAnimationLayer, layerForHomeAnimationLayer);
3597 }
Robert Carrb1579c82017-09-05 14:54:47 -07003598 }
3599
3600 @Override
Jorim Jaggi391790622018-04-18 15:30:44 +02003601 SurfaceControl getAppAnimationLayer(@AnimationLayer int animationLayer) {
3602 switch (animationLayer) {
3603 case ANIMATION_LAYER_BOOSTED:
3604 return mBoostedAppAnimationLayer;
3605 case ANIMATION_LAYER_HOME:
3606 return mHomeAppAnimationLayer;
3607 case ANIMATION_LAYER_STANDARD:
3608 default:
3609 return mAppAnimationLayer;
3610 }
chaviw23ee71c2017-12-18 11:29:41 -08003611 }
3612
Robert Carrf7a7ca82017-12-06 13:17:07 -08003613 SurfaceControl getSplitScreenDividerAnchor() {
3614 return mSplitScreenDividerAnchor;
3615 }
3616
chaviw23ee71c2017-12-18 11:29:41 -08003617 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003618 void onParentSet() {
3619 super.onParentSet();
3620 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003621 mAppAnimationLayer = makeChildSurface(null)
3622 .setName("animationLayer")
3623 .build();
Jorim Jaggibe418292018-03-26 16:14:12 +02003624 mBoostedAppAnimationLayer = makeChildSurface(null)
3625 .setName("boostedAnimationLayer")
3626 .build();
Jorim Jaggi391790622018-04-18 15:30:44 +02003627 mHomeAppAnimationLayer = makeChildSurface(null)
3628 .setName("homeAnimationLayer")
3629 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003630 mSplitScreenDividerAnchor = makeChildSurface(null)
3631 .setName("splitScreenDividerAnchor")
3632 .build();
3633 getPendingTransaction()
3634 .show(mAppAnimationLayer)
Jorim Jaggibe418292018-03-26 16:14:12 +02003635 .show(mBoostedAppAnimationLayer)
Jorim Jaggi391790622018-04-18 15:30:44 +02003636 .show(mHomeAppAnimationLayer)
Robert Carrf7a7ca82017-12-06 13:17:07 -08003637 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003638 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003639 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003640 mAppAnimationLayer.destroy();
3641 mAppAnimationLayer = null;
Jorim Jaggibe418292018-03-26 16:14:12 +02003642 mBoostedAppAnimationLayer.destroy();
3643 mBoostedAppAnimationLayer = null;
Jorim Jaggi391790622018-04-18 15:30:44 +02003644 mHomeAppAnimationLayer.destroy();
3645 mHomeAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003646 mSplitScreenDividerAnchor.destroy();
3647 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003648 }
3649 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003650 }
3651
Robert Carree4d4b92017-11-22 12:21:46 -08003652 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003653 AboveAppWindowContainers(String name, WindowManagerService service) {
3654 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003655 }
3656
Robert Carrb9506032018-02-13 13:54:00 -08003657 @Override
3658 void assignChildLayers(SurfaceControl.Transaction t) {
3659 assignChildLayers(t, null /* imeContainer */);
3660 }
3661
Robert Carree4d4b92017-11-22 12:21:46 -08003662 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3663 boolean needAssignIme = imeContainer != null
3664 && imeContainer.getSurfaceControl() != null;
3665 for (int j = 0; j < mChildren.size(); ++j) {
3666 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003667
3668 // See {@link mSplitScreenDividerAnchor}
3669 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3670 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3671 continue;
3672 }
Robert Carree4d4b92017-11-22 12:21:46 -08003673 wt.assignLayer(t, j);
3674 wt.assignChildLayers(t);
3675
3676 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3677 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003678
3679 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3680 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003681 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003682 needAssignIme = false;
3683 }
3684 }
3685 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003686 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003687 }
3688 }
3689 }
3690
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003691 /**
3692 * Window container class that contains all containers on this display that are not related to
3693 * Apps. E.g. status bar.
3694 */
Robert Carree4d4b92017-11-22 12:21:46 -08003695 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003696 /**
3697 * Compares two child window tokens returns -1 if the first is lesser than the second in
3698 * terms of z-order and 1 otherwise.
3699 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003700 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003701 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003702 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3703 token1.mOwnerCanManageAppTokens)
3704 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3705 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003706
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003707 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3708 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3709 return false;
3710 }
3711 final int req = w.mAttrs.screenOrientation;
3712 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3713 || req == SCREEN_ORIENTATION_UNSET) {
3714 return false;
3715 }
3716 return true;
3717 };
3718
Wale Ogunwale3a931692016-11-02 16:49:48 -07003719 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003720 private final Dimmer mDimmer = new Dimmer(this);
3721 private final Rect mTmpDimBoundsRect = new Rect();
3722
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003723 NonAppWindowContainers(String name, WindowManagerService service) {
3724 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003725 mName = name;
3726 }
3727
3728 void addChild(WindowToken token) {
3729 addChild(token, mWindowComparator);
3730 }
3731
3732 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003733 int getOrientation() {
3734 final WindowManagerPolicy policy = mService.mPolicy;
3735 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003736 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003737
3738 if (win != null) {
3739 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003740 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003741 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003742 if (mService.mKeyguardGoingAway) {
3743 // Keyguard can't affect the orientation if it is going away...
3744 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3745 return SCREEN_ORIENTATION_UNSET;
3746 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003747 }
Andrii Kulianef5ce1c2018-03-20 19:27:24 -07003748 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req
3749 + " for display id=" + mDisplayId);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003750 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003751 }
3752
Andrii Kulian8ee72852017-03-10 10:36:45 -08003753 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003754
Jorim Jaggi1c530592018-04-06 15:11:47 +02003755 // Only allow force setting the orientation when all unknown visibilities have been
3756 // resolved, as otherwise we just may be starting another occluding activity.
3757 final boolean isUnoccluding =
3758 mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
3759 && mService.mUnknownAppVisibilityController.allResolved();
3760 if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003761 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003762 }
3763
3764 return SCREEN_ORIENTATION_UNSET;
3765 }
3766
3767 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003768 String getName() {
3769 return mName;
3770 }
chaviwf29223e2018-01-31 13:23:51 -08003771
3772 @Override
3773 Dimmer getDimmer() {
3774 return mDimmer;
3775 }
3776
3777 @Override
3778 void prepareSurfaces() {
3779 mDimmer.resetDimStates();
3780 super.prepareSurfaces();
3781 getBounds(mTmpDimBoundsRect);
3782
3783 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3784 scheduleAnimation();
3785 }
3786 }
Robert Carr3b716242016-08-16 16:02:21 -07003787 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003788
Robert Carr9034d962018-01-04 18:27:42 -08003789 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3790 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3791 super(name, service);
3792 }
3793
3794 @Override
3795 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3796 }
3797 };
3798
Robert Carrb1579c82017-09-05 14:54:47 -07003799 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3800 return mService.makeSurfaceBuilder(s)
3801 .setParent(mWindowingLayer);
3802 }
3803
3804 @Override
3805 SurfaceSession getSession() {
3806 return mSession;
3807 }
3808
3809 @Override
3810 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003811 SurfaceSession s = child != null ? child.getSession() : getSession();
3812 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003813 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003814
3815 if (child == null) {
3816 return b;
3817 }
3818
Robert Carree4d4b92017-11-22 12:21:46 -08003819 return b.setName(child.getName())
3820 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003821 }
3822
3823 /**
3824 * The makeSurface variants are for use by the window-container
3825 * hierarchy. makeOverlay here is a function for various non windowing
3826 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3827 * and other potpourii.
3828 */
3829 SurfaceControl.Builder makeOverlay() {
3830 return mService.makeSurfaceBuilder(mSession)
3831 .setParent(mOverlayLayer);
3832 }
3833
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003834 /**
3835 * Reparents the given surface to mOverlayLayer.
3836 */
3837 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3838 transaction.reparent(surface, mOverlayLayer.getHandle());
3839 }
3840
Robert Carrb1579c82017-09-05 14:54:47 -07003841 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carr24be9ab2018-04-30 17:54:53 -07003842 if (spec.scale != 1.0) {
3843 mMagnificationSpec = spec;
3844 } else {
3845 mMagnificationSpec = null;
3846 }
3847
Robert Carrf59b8dd2017-10-02 18:58:36 -07003848 applyMagnificationSpec(getPendingTransaction(), spec);
3849 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003850 }
3851
Robert Carr24be9ab2018-04-30 17:54:53 -07003852 void reapplyMagnificationSpec() {
3853 if (mMagnificationSpec != null) {
3854 applyMagnificationSpec(getPendingTransaction(), mMagnificationSpec);
3855 }
3856 }
3857
Robert Carrb1579c82017-09-05 14:54:47 -07003858 @Override
3859 void onParentSet() {
3860 // Since we are the top of the SurfaceControl hierarchy here
3861 // we create the root surfaces explicitly rather than chaining
3862 // up as the default implementation in onParentSet does. So we
3863 // explicitly do NOT call super here.
3864 }
3865
3866 @Override
3867 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003868
3869 // These are layers as children of "mWindowingLayer"
3870 mBelowAppWindowsContainers.assignLayer(t, 0);
3871 mTaskStackContainers.assignLayer(t, 1);
3872 mAboveAppWindowsContainers.assignLayer(t, 2);
3873
3874 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003875 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003876
Robert Carree4d4b92017-11-22 12:21:46 -08003877 // In the case where we have an IME target that is not in split-screen
3878 // mode IME assignment is easy. We just need the IME to go directly above
3879 // the target. This way children of the target will naturally go above the IME
3880 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003881 //
Robert Carree4d4b92017-11-22 12:21:46 -08003882 // In the case of split-screen windowing mode, we need to elevate the IME above the
3883 // docked divider while keeping the app itself below the docked divider, so instead
3884 // we use relative layering of the IME targets child windows, and place the
3885 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003886 //
Robert Carr234b6332018-03-20 13:38:16 -07003887 // In the case the IME target is animating, the animation Z order may be different
3888 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
3889 // IME target. In this case we just layer the IME over all transitions by placing it in the
3890 // above applications layer.
3891 //
Robert Carree4d4b92017-11-22 12:21:46 -08003892 // In the case where we have no IME target we assign it where it's base layer would
3893 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07003894 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
3895 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08003896 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003897 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003898 // TODO: We need to use an extra level on the app surface to ensure
3899 // this is always above SurfaceView but always below attached window.
3900 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003901 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003902 }
3903
3904 // Above we have assigned layers to our children, now we ask them to assign
3905 // layers to their children.
3906 mBelowAppWindowsContainers.assignChildLayers(t);
3907 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003908 mAboveAppWindowsContainers.assignChildLayers(t,
3909 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003910 mImeWindowsContainers.assignChildLayers(t);
3911 }
3912
3913 /**
3914 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3915 * that the IME target is one of the docked applications. We'd like the docked divider to be
3916 * above both of the applications, and we'd like the IME to be above the docked divider.
3917 * However we need child windows of the applications to be above the IME (Text drag handles).
3918 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3919 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3920 * with {@link #WindowState#assignLayer}
3921 */
3922 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
Robert Carrbb5de662018-04-26 13:29:51 -07003923 child.assignRelativeLayer(t, mImeWindowsContainers.getSurfaceControl(), 1);
Robert Carrb1579c82017-09-05 14:54:47 -07003924 }
3925
3926 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003927 void prepareSurfaces() {
3928 final ScreenRotationAnimation screenRotationAnimation =
3929 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3930 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3931 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3932 mPendingTransaction.setMatrix(mWindowingLayer,
3933 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3934 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3935 mPendingTransaction.setPosition(mWindowingLayer,
3936 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3937 mPendingTransaction.setAlpha(mWindowingLayer,
3938 screenRotationAnimation.getEnterTransformation().getAlpha());
3939 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003940
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003941 super.prepareSurfaces();
3942 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003943
Jorim Jaggibe418292018-03-26 16:14:12 +02003944 void assignStackOrdering() {
3945 mTaskStackContainers.assignStackOrdering(getPendingTransaction());
Robert Carr2f8aa392018-01-31 14:46:51 -08003946 }
Craig Mautner59c00972012-07-30 12:10:24 -07003947}