blob: 841586ab9fb723e247b833bd6aa606d9ee98425a [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;
Andrii Kulian06d07d62017-03-14 11:11:47 -070083import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070084import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070085import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070086import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080087import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070088import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070089import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
90import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070091import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070092import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -070093import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
94import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070095import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -070096import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070097import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070098import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070099import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700100import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700101import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700102import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700103import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700104import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import static com.android.server.wm.proto.DisplayProto.ABOVE_APP_WINDOWS;
106import static com.android.server.wm.proto.DisplayProto.BELOW_APP_WINDOWS;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000107import static com.android.server.wm.proto.DisplayProto.DISPLAY_FRAMES;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700108import static com.android.server.wm.proto.DisplayProto.DISPLAY_INFO;
109import static com.android.server.wm.proto.DisplayProto.DOCKED_STACK_DIVIDER_CONTROLLER;
110import static com.android.server.wm.proto.DisplayProto.DPI;
111import static com.android.server.wm.proto.DisplayProto.ID;
112import static com.android.server.wm.proto.DisplayProto.IME_WINDOWS;
113import static com.android.server.wm.proto.DisplayProto.PINNED_STACK_CONTROLLER;
Steven Timotiusf2d68892017-08-28 17:00:01 -0700114import static com.android.server.wm.proto.DisplayProto.ROTATION;
115import static com.android.server.wm.proto.DisplayProto.SCREEN_ROTATION_ANIMATION;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700116import static com.android.server.wm.proto.DisplayProto.STACKS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700117import static com.android.server.wm.proto.DisplayProto.WINDOW_CONTAINER;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700118
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700119import android.annotation.CallSuper;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700120import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700121import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700122import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700123import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700124import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700125import android.graphics.Matrix;
Adrian Roos1cf585052018-01-03 18:43:27 +0100126import android.graphics.Path;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800127import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700128import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700129import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100130import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700131import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700132import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700133import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700134import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700135import android.os.RemoteException;
136import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100137import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800138import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700139import android.util.DisplayMetrics;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800140import android.util.MutableBoolean;
Adrian Roos24264212018-02-19 16:26:15 +0100141import android.util.Size;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700142import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700143import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700144import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100145import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700146import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700147import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700148import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700149import android.view.Surface;
150import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100151import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700152import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700153
Bryce Lee48f4b572017-04-10 10:54:15 -0700154import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800155import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700156import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100157import com.android.server.policy.WindowManagerPolicy;
Craig Mautner59c00972012-07-30 12:10:24 -0700158
Robert Carr3b716242016-08-16 16:02:21 -0700159import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700160import java.io.PrintWriter;
161import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700162import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700163import java.util.HashMap;
164import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700165import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700166import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100167import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800168import java.util.function.Consumer;
169import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700170
Craig Mautner59c00972012-07-30 12:10:24 -0700171/**
172 * Utility class for keeping track of the WindowStates and other pertinent contents of a
173 * particular Display.
174 *
175 * IMPORTANT: No method from this class should ever be used without holding
176 * WindowManagerService.mWindowMap.
177 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700178class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700179 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700180
181 /** Unique identifier of this stack. */
182 private final int mDisplayId;
183
Wale Ogunwale3a931692016-11-02 16:49:48 -0700184 /** The containers below are the only child containers the display can have. */
185 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100186 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700187 // Contains all non-app window containers that should be displayed above the app containers
188 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800189 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100190 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700191 // Contains all non-app window containers that should be displayed below the app containers
192 // (e.g. Wallpaper).
193 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100194 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700195 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
196 // 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 -0800197 // window containers together and move them in-sync if/when needed. We use a subclass of
198 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
199 private final NonMagnifiableWindowContainers mImeWindowsContainers =
200 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700201
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000202 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800203 private WindowState mTmpWindow2;
204 private WindowAnimator mTmpWindowAnimator;
205 private boolean mTmpRecoveringMemory;
206 private boolean mUpdateImeTarget;
207 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700208 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700209
Wale Ogunwale02319a62016-09-26 15:21:22 -0700210 // Mapping from a token IBinder to a WindowToken object on this display.
211 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
212
Andrii Kuliancd097992017-03-23 18:31:59 -0700213 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700214 int mInitialDisplayWidth = 0;
215 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700216 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700217
Adrian Roos1cf585052018-01-03 18:43:27 +0100218 DisplayCutout mInitialDisplayCutout;
219 DisplayCutout mDisplayCutoutOverride;
220
Andrii Kuliancd097992017-03-23 18:31:59 -0700221 /**
222 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
223 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
224 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
225 */
Craig Mautner59c00972012-07-30 12:10:24 -0700226 int mBaseDisplayWidth = 0;
227 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700228 /**
229 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
230 * but can be set from Settings or via shell command "adb shell wm density".
231 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
232 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700233 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700234 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700235 private final DisplayInfo mDisplayInfo = new DisplayInfo();
236 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700237 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000238 DisplayFrames mDisplayFrames;
239
Andrii Kulian06d07d62017-03-14 11:11:47 -0700240 /**
241 * For default display it contains real metrics, empty for others.
242 * @see WindowManagerService#createWatermarkInTransaction()
243 */
244 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
245 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
246 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700247
Andrii Kulian06d07d62017-03-14 11:11:47 -0700248 /**
249 * Compat metrics computed based on {@link #mDisplayMetrics}.
250 * @see #updateDisplayAndOrientation(int)
251 */
252 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
253
254 /** The desired scaling factor for compatible apps. */
255 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700256
Andrii Kulian8ee72852017-03-10 10:36:45 -0800257 /**
258 * Current rotation of the display.
259 * Constants as per {@link android.view.Surface.Rotation}.
260 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700261 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800262 */
263 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700264
Andrii Kulian8ee72852017-03-10 10:36:45 -0800265 /**
266 * Last applied orientation of the display.
267 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
268 *
269 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
270 */
271 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700272
Andrii Kulian8ee72852017-03-10 10:36:45 -0800273 /**
274 * Flag indicating that the application is receiving an orientation that has different metrics
275 * than it expected. E.g. Portrait instead of Landscape.
276 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700277 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800278 */
279 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700280
Andrii Kulian8ee72852017-03-10 10:36:45 -0800281 /**
282 * Orientation forced by some window. If there is no visible window that specifies orientation
283 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
284 *
285 * @see NonAppWindowContainers#getOrientation()
286 */
287 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700288
Andrii Kulian8ee72852017-03-10 10:36:45 -0800289 /**
290 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
291 * occluded.
292 *
293 * @see NonAppWindowContainers#getOrientation()
294 */
295 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
296
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700297 /**
298 * Keep track of wallpaper visibility to notify changes.
299 */
300 private boolean mLastWallpaperVisible = false;
301
Andrii Kulian06d07d62017-03-14 11:11:47 -0700302 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700303
Craig Mautner39834192012-09-02 07:47:24 -0700304 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700305 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700306 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700307 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800308 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700309
Craig Mautnerdc548482014-02-05 13:35:24 -0800310 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700311 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800312
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700313 /** Detect user tapping outside of current focused task bounds .*/
314 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700315
Craig Mautner6601b7b2013-04-29 10:29:11 -0700316 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700317 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700318
Craig Mautner6601b7b2013-04-29 10:29:11 -0700319 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800320 private final Rect mTmpRect = new Rect();
321 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700322 private final RectF mTmpRectF = new RectF();
323 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800324 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700325
Bryce Leef3c6a472017-11-14 14:53:06 -0800326 /** Used for handing back size of display */
327 private final Rect mTmpBounds = new Rect();
328
Craig Mautner95da1082014-02-24 17:54:35 -0800329 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700330 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800331
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700332 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700333 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700334
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800335 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800336 /** A collection of windows that provide tap exclude regions inside of them. */
337 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800338
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000339 private boolean mHaveBootMsg = false;
340 private boolean mHaveApp = false;
341 private boolean mHaveWallpaper = false;
342 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700343
344 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
345
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700346 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
347 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000348 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
349 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700350
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700351 // True if this display is in the process of being removed. Used to determine if the removal of
352 // the display's direct children should be allowed.
353 private boolean mRemovingDisplay = false;
354
Bryce Leed1871262017-06-12 14:12:29 -0700355 // {@code false} if this display is in the processing of being created.
356 private boolean mDisplayReady = false;
357
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800358 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700359
Robert Carrb1579c82017-09-05 14:54:47 -0700360 private final SurfaceSession mSession = new SurfaceSession();
361
362 /**
363 * We organize all top-level Surfaces in to the following layers.
364 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800365 * and omitted from Screen-Magnification, for example the strict mode flash or
366 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700367 * {@link #mWindowingLayer} contains everything else.
368 */
369 private SurfaceControl mOverlayLayer;
370
371 /**
372 * See {@link #mOverlayLayer}
373 */
374 private SurfaceControl mWindowingLayer;
375
376 /**
377 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
378 * <p>
379 * For these surfaces currently we use a surface based on the larger of width or height so we
380 * don't have to resize when rotating the display.
381 */
382 private int mSurfaceSize;
383
Chavi Weingarten38804382018-02-15 21:00:15 +0000384 /**
385 * A list of surfaces to be destroyed after {@link #mPendingTransaction} is applied.
386 */
387 private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>();
388
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100389 /** Temporary float array to retrieve 3x3 matrix values. */
390 private final float[] mTmpFloats = new float[9];
391
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800392 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
393 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800394 final AppWindowToken atoken = w.mAppToken;
395 if (winAnimator.mDrawState == READY_TO_SHOW) {
396 if (atoken == null || atoken.allDrawn) {
397 if (w.performShowLocked()) {
398 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
399 if (DEBUG_LAYOUT_REPEATS) {
400 mService.mWindowPlacerLocked.debugLayoutRepeats(
401 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
402 }
403 }
404 }
405 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800406 };
407
408 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
409 final WindowStateAnimator winAnimator = w.mWinAnimator;
410 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
411 return;
412 }
413
414 final int flags = w.mAttrs.flags;
415
416 // If this window is animating, make a note that we have an animating window and take
417 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100418 if (winAnimator.isAnimationSet()) {
419 final AnimationAdapter anim = w.getAnimation();
420 if (anim != null) {
421 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800422 mTmpWindow = w;
423 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100424 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800425 if (color != 0) {
426 final TaskStack stack = w.getStack();
427 if (stack != null) {
428 stack.setAnimationBackground(winAnimator, color);
429 }
430 }
431 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800432 }
433
434 // If this window's app token is running a detached wallpaper animation, make a note so
435 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200436 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
437 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
438 if (animation != null) {
439 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800440 mTmpWindow = w;
441 }
442
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200443 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800444 if (color != 0) {
445 final TaskStack stack = w.getStack();
446 if (stack != null) {
447 stack.setAnimationBackground(winAnimator, color);
448 }
449 }
450 }
451 };
452
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800453 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
454 final int lostFocusUid = mTmpWindow.mOwnerUid;
455 final Handler handler = mService.mH;
456 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
457 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
458 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
459 w.mAttrs.hideTimeoutMilliseconds);
460 }
461 }
462 };
463
464 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
465 final AppWindowToken focusedApp = mService.mFocusedApp;
466 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
467 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
468
469 if (!w.canReceiveKeys()) {
470 return false;
471 }
472
473 final AppWindowToken wtoken = w.mAppToken;
474
475 // If this window's application has been removed, just skip it.
476 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
477 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
478 + (wtoken.removed ? "removed" : "sendingToBottom"));
479 return false;
480 }
481
482 if (focusedApp == null) {
483 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
484 + " using new focus @ " + w);
485 mTmpWindow = w;
486 return true;
487 }
488
489 if (!focusedApp.windowsAreFocusable()) {
490 // Current focused app windows aren't focusable...
491 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
492 + " focusable using new focus @ " + w);
493 mTmpWindow = w;
494 return true;
495 }
496
497 // Descend through all of the app tokens and find the first that either matches
498 // win.mAppToken (return win) or mFocusedApp (return null).
499 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
500 if (focusedApp.compareTo(wtoken) > 0) {
501 // App stack below focused app stack. No focus for you!!!
502 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
503 "findFocusedWindow: Reached focused app=" + focusedApp);
504 mTmpWindow = null;
505 return true;
506 }
507 }
508
509 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
510 mTmpWindow = w;
511 return true;
512 };
513
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800514 private final Consumer<WindowState> mPerformLayout = w -> {
515 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
516 // wasting time and funky changes while a window is animating away.
517 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
518 || w.isGoneForLayoutLw();
519
520 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
521 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
522 + " mLayoutAttached=" + w.mLayoutAttached
523 + " screen changed=" + w.isConfigChanged());
524 final AppWindowToken atoken = w.mAppToken;
525 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200526 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800527 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
528 + " parentHidden=" + w.isParentWindowHidden());
529 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200530 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800531 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
532 + " parentHidden=" + w.isParentWindowHidden());
533 }
534
535 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
536 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
537 // since that means "perform layout as normal, just don't display").
538 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
539 || ((w.isConfigChanged() || w.setReportResizeHints())
540 && !w.isGoneForLayoutLw() &&
541 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
542 (w.mHasSurface && w.mAppToken != null &&
543 w.mAppToken.layoutConfigChanges)))) {
544 if (!w.mLayoutAttached) {
545 if (mTmpInitial) {
546 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
547 w.mContentChanged = false;
548 }
549 if (w.mAttrs.type == TYPE_DREAM) {
550 // Don't layout windows behind a dream, so that if it does stuff like hide
551 // the status bar we won't get a bad transition when it goes away.
552 mTmpWindow = w;
553 }
554 w.mLayoutNeeded = false;
555 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200556 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000557 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800558 w.mLayoutSeq = mService.mLayoutSeq;
559
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200560 // If this is the first layout, we need to initialize the last inset values as
561 // otherwise we'd immediately cause an unnecessary resize.
562 if (firstLayout) {
563 w.updateLastInsetValues();
564 }
565
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800566 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
567 + " mContainingFrame=" + w.mContainingFrame
568 + " mDisplayFrame=" + w.mDisplayFrame);
569 }
570 }
571 };
572
573 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
574 if (w.mLayoutAttached) {
575 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
576 + " mViewVisibility=" + w.mViewVisibility
577 + " mRelayoutCalled=" + w.mRelayoutCalled);
578 // If this view is GONE, then skip it -- keep the current frame, and let the caller
579 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
580 // windows, since that means "perform layout as normal, just don't display").
581 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
582 return;
583 }
584 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
585 || w.mLayoutNeeded) {
586 if (mTmpInitial) {
587 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
588 w.mContentChanged = false;
589 }
590 w.mLayoutNeeded = false;
591 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000592 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800593 w.mLayoutSeq = mService.mLayoutSeq;
594 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
595 + " mContainingFrame=" + w.mContainingFrame
596 + " mDisplayFrame=" + w.mDisplayFrame);
597 }
598 } else if (w.mAttrs.type == TYPE_DREAM) {
599 // Don't layout windows behind a dream, so that if it does stuff like hide the
600 // status bar we won't get a bad transition when it goes away.
601 mTmpWindow = mTmpWindow2;
602 }
603 };
604
605 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
606 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
607 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
608 return w.canBeImeTarget();
609 };
610
611 private final Consumer<WindowState> mApplyPostLayoutPolicy =
612 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
613 mService.mInputMethodTarget);
614
615 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
616 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
617 final boolean obscuredChanged = w.mObscured !=
618 mTmpApplySurfaceChangesTransactionState.obscured;
619 final RootWindowContainer root = mService.mRoot;
620 // Only used if default window
621 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
622
623 // Update effect.
624 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
625 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
626 final boolean isDisplayed = w.isDisplayedLw();
627
628 if (isDisplayed && w.isObscuringDisplay()) {
629 // This window completely covers everything behind it, so we want to leave all
630 // of them as undimmed (for performance reasons).
631 root.mObscuringWindow = w;
632 mTmpApplySurfaceChangesTransactionState.obscured = true;
633 }
634
635 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
636 root.handleNotObscuredLocked(w,
637 mTmpApplySurfaceChangesTransactionState.obscured,
638 mTmpApplySurfaceChangesTransactionState.syswin);
639
640 if (w.mHasSurface && isDisplayed) {
641 final int type = w.mAttrs.type;
642 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
643 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
644 mTmpApplySurfaceChangesTransactionState.syswin = true;
645 }
646 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
647 && w.mAttrs.preferredRefreshRate != 0) {
648 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
649 = w.mAttrs.preferredRefreshRate;
650 }
651 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
652 && w.mAttrs.preferredDisplayModeId != 0) {
653 mTmpApplySurfaceChangesTransactionState.preferredModeId
654 = w.mAttrs.preferredDisplayModeId;
655 }
656 }
657 }
658
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800659 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
660 && mWallpaperController.isWallpaperTarget(w)) {
661 // This is the wallpaper target and its obscured state changed... make sure the
662 // current wallpaper's visibility has been updated accordingly.
663 mWallpaperController.updateWallpaperVisibility();
664 }
665
chaviw161ea3e2018-01-31 12:01:12 -0800666 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800667
668 final WindowStateAnimator winAnimator = w.mWinAnimator;
669
670 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
671 w.mContentChanged = false;
672
673 // Moved from updateWindowsAndWallpaperLocked().
674 if (w.mHasSurface) {
675 // Take care of the window being ready to display.
676 final boolean committed = winAnimator.commitFinishDrawingLocked();
677 if (isDefaultDisplay && committed) {
678 if (w.mAttrs.type == TYPE_DREAM) {
679 // HACK: When a dream is shown, it may at that point hide the lock screen.
680 // So we need to redo the layout to let the phone window manager make this
681 // happen.
682 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
683 if (DEBUG_LAYOUT_REPEATS) {
684 surfacePlacer.debugLayoutRepeats(
685 "dream and commitFinishDrawingLocked true",
686 pendingLayoutChanges);
687 }
688 }
689 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
690 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
691 "First draw done in potential wallpaper target " + w);
692 root.mWallpaperMayChange = true;
693 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
694 if (DEBUG_LAYOUT_REPEATS) {
695 surfacePlacer.debugLayoutRepeats(
696 "wallpaper and commitFinishDrawingLocked true",
697 pendingLayoutChanges);
698 }
699 }
700 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800701 }
702
703 final AppWindowToken atoken = w.mAppToken;
704 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100705 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800706 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
707 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
708 mTmpUpdateAllDrawn.add(atoken);
709 }
710 }
711
712 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
713 && w.isDisplayedLw()) {
714 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
715 }
716
717 w.updateResizingWindowIfNeeded();
718 };
719
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800720 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800721 * Create new {@link DisplayContent} instance, add itself to the root window container and
722 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700723 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800724 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700725 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
726 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700727 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700728 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800729 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100730 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800731 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800732 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
733 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
734 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
735 + " new=" + display);
736 }
737
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700738 mDisplay = display;
739 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700740 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700741 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700742 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700743 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000744 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700745 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800746 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700747 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700748
Robert Carrb1579c82017-09-05 14:54:47 -0700749 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth);
750
751 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
752 .setSize(mSurfaceSize, mSurfaceSize)
753 .setOpaque(true);
754 mWindowingLayer = b.setName("Display Root").build();
755 mOverlayLayer = b.setName("Display Overlays").build();
756
Robert Carrf59b8dd2017-10-02 18:58:36 -0700757 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700758 .setLayerStack(mWindowingLayer, mDisplayId)
759 .show(mWindowingLayer)
760 .setLayer(mOverlayLayer, 1)
761 .setLayerStack(mOverlayLayer, mDisplayId)
762 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700763 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700764
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700765 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700766 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700767 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700768 super.addChild(mAboveAppWindowsContainers, null);
769 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800770
771 // Add itself as a child to the root container.
772 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700773
774 // TODO(b/62541591): evaluate whether this is the best spot to declare the
775 // {@link DisplayContent} ready for use.
776 mDisplayReady = true;
777 }
778
779 boolean isReady() {
780 // The display is ready when the system and the individual display are both ready.
781 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700782 }
783
784 int getDisplayId() {
785 return mDisplayId;
786 }
787
Wale Ogunwale02319a62016-09-26 15:21:22 -0700788 WindowToken getWindowToken(IBinder binder) {
789 return mTokenMap.get(binder);
790 }
791
792 AppWindowToken getAppWindowToken(IBinder binder) {
793 final WindowToken token = getWindowToken(binder);
794 if (token == null) {
795 return null;
796 }
797 return token.asAppWindowToken();
798 }
799
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700800 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700801 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
802 if (dc != null) {
803 // We currently don't support adding a window token to the display if the display
804 // already has the binder mapped to another token. If there is a use case for supporting
805 // this moving forward we will either need to merge the WindowTokens some how or have
806 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700807 throw new IllegalArgumentException("Can't map token=" + token + " to display="
808 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700809 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700810 if (binder == null) {
811 throw new IllegalArgumentException("Can't map token=" + token + " to display="
812 + getName() + " binder is null");
813 }
814 if (token == null) {
815 throw new IllegalArgumentException("Can't map null token to display="
816 + getName() + " binder=" + binder);
817 }
818
Wale Ogunwale02319a62016-09-26 15:21:22 -0700819 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700820
821 if (token.asAppWindowToken() == null) {
822 // Add non-app token to container hierarchy on the display. App tokens are added through
823 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700824 switch (token.windowType) {
825 case TYPE_WALLPAPER:
826 mBelowAppWindowsContainers.addChild(token);
827 break;
828 case TYPE_INPUT_METHOD:
829 case TYPE_INPUT_METHOD_DIALOG:
830 mImeWindowsContainers.addChild(token);
831 break;
832 default:
833 mAboveAppWindowsContainers.addChild(token);
834 break;
835 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700836 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700837 }
838
839 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700840 final WindowToken token = mTokenMap.remove(binder);
841 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800842 token.setExiting();
843 }
844 return token;
845 }
846
847 /** Changes the display the input window token is housed on to this one. */
848 void reParentWindowToken(WindowToken token) {
849 final DisplayContent prevDc = token.getDisplayContent();
850 if (prevDc == this) {
851 return;
852 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800853 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
854 && token.asAppWindowToken() == null) {
855 // Removed the token from the map, but made sure it's not an app token before removing
856 // from parent.
857 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700858 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800859
860 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700861 }
862
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700863 void removeAppToken(IBinder binder) {
864 final WindowToken token = removeWindowToken(binder);
865 if (token == null) {
866 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
867 return;
868 }
869
870 final AppWindowToken appToken = token.asAppWindowToken();
871
872 if (appToken == null) {
873 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
874 return;
875 }
876
877 appToken.onRemovedFromDisplay();
878 }
879
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700880 Display getDisplay() {
881 return mDisplay;
882 }
883
Craig Mautner59c00972012-07-30 12:10:24 -0700884 DisplayInfo getDisplayInfo() {
885 return mDisplayInfo;
886 }
887
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700888 DisplayMetrics getDisplayMetrics() {
889 return mDisplayMetrics;
890 }
891
Andrii Kulian8ee72852017-03-10 10:36:45 -0800892 int getRotation() {
893 return mRotation;
894 }
895
896 void setRotation(int newRotation) {
897 mRotation = newRotation;
898 }
899
900 int getLastOrientation() {
901 return mLastOrientation;
902 }
903
904 void setLastOrientation(int orientation) {
905 mLastOrientation = orientation;
906 }
907
908 boolean getAltOrientation() {
909 return mAltOrientation;
910 }
911
912 void setAltOrientation(boolean altOrientation) {
913 mAltOrientation = altOrientation;
914 }
915
916 int getLastWindowForcedOrientation() {
917 return mLastWindowForcedOrientation;
918 }
919
Andrii Kulian06d07d62017-03-14 11:11:47 -0700920 /**
921 * Update rotation of the display.
922 *
923 * Returns true if the rotation has been changed. In this case YOU MUST CALL
924 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
925 */
926 boolean updateRotationUnchecked(boolean inTransaction) {
927 if (mService.mDeferredRotationPauseCount > 0) {
928 // Rotation updates have been paused temporarily. Defer the update until
929 // updates have been resumed.
930 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
931 return false;
932 }
933
934 ScreenRotationAnimation screenRotationAnimation =
935 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
936 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
937 // Rotation updates cannot be performed while the previous rotation change
938 // animation is still in progress. Skip this update. We will try updating
939 // again after the animation is finished and the display is unfrozen.
940 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
941 return false;
942 }
943 if (mService.mDisplayFrozen) {
944 // Even if the screen rotation animation has finished (e.g. isAnimating
945 // returns false), there is still some time where we haven't yet unfrozen
946 // the display. We also need to abort rotation here.
947 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
948 "Deferring rotation, still finishing previous rotation");
949 return false;
950 }
951
952 if (!mService.mDisplayEnabled) {
953 // No point choosing a rotation if the display is not enabled.
954 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
955 return false;
956 }
957
958 final int oldRotation = mRotation;
959 final int lastOrientation = mLastOrientation;
960 final boolean oldAltOrientation = mAltOrientation;
961 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700962 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700963 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700964
Robert Carr0e007272017-10-02 13:00:55 -0700965 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700966 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
967 if (seamlessRotated != null) {
968 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
969 // to complete (that is, waiting for windows to redraw). It's tempting to check
970 // w.mSeamlessRotationCount but that could be incorrect in the case of
971 // window-removal.
972 return false;
973 }
Robert Carr0e007272017-10-02 13:00:55 -0700974
975 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700976 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700977 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700978 mayRotateSeamlessly = false;
979 }
980 for (int i = 0; i < mService.mSessions.size(); i++) {
981 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
982 mayRotateSeamlessly = false;
983 break;
984 }
985 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700986 }
Robert Carr0e007272017-10-02 13:00:55 -0700987 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700988
989 // TODO: Implement forced rotation changes.
990 // Set mAltOrientation to indicate that the application is receiving
991 // an orientation that has different metrics than it expected.
992 // eg. Portrait instead of Landscape.
993
994 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
995 lastOrientation, rotation);
996
997 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
998 + ", got rotation " + rotation + " which has "
999 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1000
1001 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1002 // No change.
1003 return false;
1004 }
1005
1006 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1007 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1008 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1009
1010 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1011 mService.mWaitingForConfig = true;
1012 }
1013
1014 mRotation = rotation;
1015 mAltOrientation = altOrientation;
1016 if (isDefaultDisplay) {
1017 mService.mPolicy.setRotationLw(rotation);
1018 }
1019
1020 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1021 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1022 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1023 WINDOW_FREEZE_TIMEOUT_DURATION);
1024
1025 setLayoutNeeded();
1026 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001027 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001028
1029 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001030 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001031 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1032 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1033 mDisplayId);
1034 } else {
1035 // The screen rotation animation uses a screenshot to freeze the screen
1036 // while windows resize underneath.
1037 // When we are rotating seamlessly, we allow the elements to transition
1038 // to their rotated state independently and without a freeze required.
1039 screenRotationAnimation = null;
1040
1041 // We have to reset this in case a window was removed before it
1042 // finished seamless rotation.
1043 mService.mSeamlessRotationCount = 0;
1044 }
1045
1046 // We need to update our screen size information to match the new rotation. If the rotation
1047 // has actually changed then this method will return true and, according to the comment at
1048 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1049 // By updating the Display info here it will be available to
1050 // #computeScreenConfiguration() later.
1051 updateDisplayAndOrientation(getConfiguration().uiMode);
1052
1053 if (!inTransaction) {
1054 if (SHOW_TRANSACTIONS) {
1055 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1056 }
1057 mService.openSurfaceTransaction();
1058 }
1059 try {
1060 // NOTE: We disable the rotation in the emulator because
1061 // it doesn't support hardware OpenGL emulation yet.
1062 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1063 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001064 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001065 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1066 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1067 mService.scheduleAnimationLocked();
1068 }
1069 }
1070
1071 if (rotateSeamlessly) {
1072 forAllWindows(w -> {
1073 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1074 }, true /* traverseTopToBottom */);
1075 }
1076
1077 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1078 } finally {
1079 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001080 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001081 if (SHOW_LIGHT_TRANSACTIONS) {
1082 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1083 }
1084 }
1085 }
1086
1087 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001088 if (w.mHasSurface && !rotateSeamlessly) {
1089 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001090 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001091 mService.mRoot.mOrientationChangeComplete = false;
1092 w.mLastFreezeDuration = 0;
1093 }
1094 w.mReportOrientationChanged = true;
1095 }, true /* traverseTopToBottom */);
1096
1097 if (rotateSeamlessly) {
1098 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1099 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1100 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1101 }
1102
1103 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1104 final WindowManagerService.RotationWatcher rotationWatcher
1105 = mService.mRotationWatchers.get(i);
1106 if (rotationWatcher.mDisplayId == mDisplayId) {
1107 try {
1108 rotationWatcher.mWatcher.onRotationChanged(rotation);
1109 } catch (RemoteException e) {
1110 // Ignore
1111 }
1112 }
1113 }
1114
1115 // TODO (multi-display): Magnification is supported only for the default display.
1116 // Announce rotation only if we will not animate as we already have the
1117 // windows in final state. Otherwise, we make this call at the rotation end.
1118 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1119 && isDefaultDisplay) {
1120 mService.mAccessibilityController.onRotationChangedLocked(this);
1121 }
1122
1123 return true;
1124 }
1125
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001126 void configureDisplayPolicy() {
1127 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1128 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1129
1130 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
1131 }
1132
Andrii Kulian06d07d62017-03-14 11:11:47 -07001133 /**
1134 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1135 * changed.
1136 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1137 */
1138 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1139 // Use the effective "visual" dimensions based on current rotation
1140 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1141 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1142 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1143 int dw = realdw;
1144 int dh = realdh;
1145
1146 if (mAltOrientation) {
1147 if (realdw > realdh) {
1148 // Turn landscape into portrait.
1149 int maxw = (int)(realdh/1.3f);
1150 if (maxw < realdw) {
1151 dw = maxw;
1152 }
1153 } else {
1154 // Turn portrait into landscape.
1155 int maxh = (int)(realdw/1.3f);
1156 if (maxh < realdh) {
1157 dh = maxh;
1158 }
1159 }
1160 }
1161
1162 // Update application display metrics.
1163 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
1164 mDisplayId);
1165 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
1166 mDisplayId);
1167 mDisplayInfo.rotation = mRotation;
1168 mDisplayInfo.logicalWidth = dw;
1169 mDisplayInfo.logicalHeight = dh;
1170 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1171 mDisplayInfo.appWidth = appWidth;
1172 mDisplayInfo.appHeight = appHeight;
1173 if (isDefaultDisplay) {
1174 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1175 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1176 }
Adrian Roos1cf585052018-01-03 18:43:27 +01001177 mDisplayInfo.displayCutout = calculateDisplayCutoutForCurrentRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001178 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1179 if (mDisplayScalingDisabled) {
1180 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1181 } else {
1182 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1183 }
1184
1185 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1186 mDisplayInfo);
1187
1188 mBaseDisplayRect.set(0, 0, dw, dh);
1189
1190 if (isDefaultDisplay) {
1191 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1192 mCompatDisplayMetrics);
1193 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001194
1195 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001196 return mDisplayInfo;
1197 }
1198
Adrian Roos1cf585052018-01-03 18:43:27 +01001199 DisplayCutout calculateDisplayCutoutForCurrentRotation() {
1200 final DisplayCutout cutout = mInitialDisplayCutout;
Adrian Roos24264212018-02-19 16:26:15 +01001201 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos1cf585052018-01-03 18:43:27 +01001202 return cutout;
1203 }
Adrian Roos24264212018-02-19 16:26:15 +01001204 if (mRotation == ROTATION_0) {
1205 return cutout.computeSafeInsets(mInitialDisplayWidth, mInitialDisplayHeight);
1206 }
1207 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001208 final Path bounds = cutout.getBounds().getBoundaryPath();
1209 transformPhysicalToLogicalCoordinates(mRotation, mInitialDisplayWidth,
1210 mInitialDisplayHeight, mTmpMatrix);
1211 bounds.transform(mTmpMatrix);
Adrian Roos24264212018-02-19 16:26:15 +01001212 return DisplayCutout.fromBounds(bounds).computeSafeInsets(
1213 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1214 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001215 }
1216
Andrii Kulian06d07d62017-03-14 11:11:47 -07001217 /**
1218 * Compute display configuration based on display properties and policy settings.
1219 * Do not call if mDisplayReady == false.
1220 */
1221 void computeScreenConfiguration(Configuration config) {
1222 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1223
1224 final int dw = displayInfo.logicalWidth;
1225 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001226 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1227 // TODO: Probably best to set this based on some setting in the display content object,
1228 // so the display can be configured for things like fullscreen.
1229 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001230
Andrii Kulian06d07d62017-03-14 11:11:47 -07001231 config.screenWidthDp =
1232 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
1233 config.uiMode, mDisplayId) / mDisplayMetrics.density);
1234 config.screenHeightDp =
1235 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
1236 config.uiMode, mDisplayId) / mDisplayMetrics.density);
Bryce Lee7566d762017-03-30 09:34:15 -07001237
1238 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh, mTmpRect);
1239 final int leftInset = mTmpRect.left;
1240 final int topInset = mTmpRect.top;
1241 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001242 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1243 leftInset + displayInfo.appWidth /* right */,
1244 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001245 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1246 || displayInfo.rotation == Surface.ROTATION_270);
1247
1248 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
1249 mDisplayMetrics.density, config);
1250
1251 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1252 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1253 ? Configuration.SCREENLAYOUT_ROUND_YES
1254 : Configuration.SCREENLAYOUT_ROUND_NO);
1255
1256 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1257 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1258 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1259 dh, mDisplayId);
1260 config.densityDpi = displayInfo.logicalDensityDpi;
1261
1262 config.colorMode =
1263 (displayInfo.isHdr()
1264 ? Configuration.COLOR_MODE_HDR_YES
1265 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001266 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001267 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1268 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1269
1270 // Update the configuration based on available input devices, lid switch,
1271 // and platform configuration.
1272 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1273 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1274 config.navigation = Configuration.NAVIGATION_NONAV;
1275
1276 int keyboardPresence = 0;
1277 int navigationPresence = 0;
1278 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1279 final int len = devices != null ? devices.length : 0;
1280 for (int i = 0; i < len; i++) {
1281 InputDevice device = devices[i];
1282 if (!device.isVirtual()) {
1283 final int sources = device.getSources();
1284 final int presenceFlag = device.isExternal() ?
1285 WindowManagerPolicy.PRESENCE_EXTERNAL :
1286 WindowManagerPolicy.PRESENCE_INTERNAL;
1287
1288 // TODO(multi-display): Configure on per-display basis.
1289 if (mService.mIsTouchDevice) {
1290 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1291 InputDevice.SOURCE_TOUCHSCREEN) {
1292 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1293 }
1294 } else {
1295 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1296 }
1297
1298 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1299 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1300 navigationPresence |= presenceFlag;
1301 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1302 && config.navigation == Configuration.NAVIGATION_NONAV) {
1303 config.navigation = Configuration.NAVIGATION_DPAD;
1304 navigationPresence |= presenceFlag;
1305 }
1306
1307 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1308 config.keyboard = Configuration.KEYBOARD_QWERTY;
1309 keyboardPresence |= presenceFlag;
1310 }
1311 }
1312 }
1313
1314 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1315 config.navigation = Configuration.NAVIGATION_DPAD;
1316 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1317 }
1318
1319 // Determine whether a hard keyboard is available and enabled.
1320 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1321 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1322 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1323 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1324 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1325 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1326 }
1327
1328 // Let the policy update hidden states.
1329 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1330 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1331 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1332 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1333 }
1334
1335 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1336 int displayId) {
1337 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1338 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1339 final int unrotDw, unrotDh;
1340 if (rotated) {
1341 unrotDw = dh;
1342 unrotDh = dw;
1343 } else {
1344 unrotDw = dw;
1345 unrotDh = dh;
1346 }
1347 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1348 displayId);
1349 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1350 displayId);
1351 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1352 displayId);
1353 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1354 displayId);
1355 return sw;
1356 }
1357
1358 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1359 DisplayMetrics dm, int dw, int dh, int displayId) {
1360 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
1361 displayId);
1362 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
1363 uiMode, displayId);
1364 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1365 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1366 if (curSize == 0 || size < curSize) {
1367 curSize = size;
1368 }
1369 return curSize;
1370 }
1371
1372 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1373 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1374
1375 // We need to determine the smallest width that will occur under normal
1376 // operation. To this, start with the base screen size and compute the
1377 // width under the different possible rotations. We need to un-rotate
1378 // the current screen dimensions before doing this.
1379 int unrotDw, unrotDh;
1380 if (rotated) {
1381 unrotDw = dh;
1382 unrotDh = dw;
1383 } else {
1384 unrotDw = dw;
1385 unrotDh = dh;
1386 }
1387 displayInfo.smallestNominalAppWidth = 1<<30;
1388 displayInfo.smallestNominalAppHeight = 1<<30;
1389 displayInfo.largestNominalAppWidth = 0;
1390 displayInfo.largestNominalAppHeight = 0;
1391 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1392 unrotDh);
1393 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1394 unrotDw);
1395 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1396 unrotDh);
1397 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1398 unrotDw);
1399 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1400 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1401 displayId);
1402 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1403 displayId);
1404 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1405 displayId);
1406 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1407 displayId);
1408 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1409 outConfig.screenLayout = sl;
1410 }
1411
1412 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1413 int uiMode, int displayId) {
1414 // Get the app screen size at this rotation.
1415 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId);
1416 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId);
1417
1418 // Compute the screen layout size class for this rotation.
1419 int longSize = w;
1420 int shortSize = h;
1421 if (longSize < shortSize) {
1422 int tmp = longSize;
1423 longSize = shortSize;
1424 shortSize = tmp;
1425 }
1426 longSize = (int)(longSize/density);
1427 shortSize = (int)(shortSize/density);
1428 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1429 }
1430
1431 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1432 int uiMode, int dw, int dh) {
1433 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
1434 displayId);
1435 if (width < displayInfo.smallestNominalAppWidth) {
1436 displayInfo.smallestNominalAppWidth = width;
1437 }
1438 if (width > displayInfo.largestNominalAppWidth) {
1439 displayInfo.largestNominalAppWidth = width;
1440 }
1441 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
1442 displayId);
1443 if (height < displayInfo.smallestNominalAppHeight) {
1444 displayInfo.smallestNominalAppHeight = height;
1445 }
1446 if (height > displayInfo.largestNominalAppHeight) {
1447 displayInfo.largestNominalAppHeight = height;
1448 }
1449 }
1450
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001451 DockedStackDividerController getDockedDividerController() {
1452 return mDividerControllerLocked;
1453 }
1454
Winson Chung655332c2016-10-31 13:14:28 -07001455 PinnedStackController getPinnedStackController() {
1456 return mPinnedStackControllerLocked;
1457 }
1458
Jeff Browna506a6e2013-06-04 00:02:38 -07001459 /**
1460 * Returns true if the specified UID has access to this display.
1461 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001462 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001463 return mDisplay.hasAccess(uid);
1464 }
1465
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001466 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001467 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001468 }
1469
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001470 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001471 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001472 }
1473
Wale Ogunwale61911492017-10-11 08:50:50 -07001474 /**
1475 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1476 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001477 TaskStack getSplitScreenPrimaryStack() {
1478 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001479 return (stack != null && stack.isVisible()) ? stack : null;
1480 }
1481
1482 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001483 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001484 * not visible.
1485 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001486 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1487 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001488 }
1489
1490 TaskStack getPinnedStack() {
1491 return mTaskStackContainers.getPinnedStack();
1492 }
1493
1494 private boolean hasPinnedStack() {
1495 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001496 }
1497
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001498 /**
1499 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1500 * Null is no compatible stack on the display.
1501 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001502 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001503 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1504 }
1505
1506 /**
1507 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1508 * activity type. Null is no compatible stack on the display.
1509 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001510 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001511 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001512 }
1513
Bryce Lee48f4b572017-04-10 10:54:15 -07001514 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001515 TaskStack getTopStack() {
1516 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001517 }
1518
Winson Chunge2d72172018-01-25 17:46:20 +00001519 ArrayList<Task> getVisibleTasks() {
1520 return mTaskStackContainers.getVisibleTasks();
1521 }
1522
Wale Ogunwale61911492017-10-11 08:50:50 -07001523 void onStackWindowingModeChanged(TaskStack stack) {
1524 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001525 }
1526
Andrii Kulian441e4492016-09-29 15:25:00 -07001527 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001528 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001529 super.onConfigurationChanged(newParentConfig);
1530
Andrii Kulian3a507b52016-09-19 18:14:12 -07001531 // The display size information is heavily dependent on the resources in the current
1532 // configuration, so we need to reconfigure it every time the configuration changes.
1533 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1534 mService.reconfigureDisplayLocked(this);
1535
Bryce Leef3c6a472017-11-14 14:53:06 -08001536 final DockedStackDividerController dividerController = getDockedDividerController();
1537
1538 if (dividerController != null) {
1539 getDockedDividerController().onConfigurationChanged();
1540 }
1541
1542 final PinnedStackController pinnedStackController = getPinnedStackController();
1543
1544 if (pinnedStackController != null) {
1545 getPinnedStackController().onConfigurationChanged();
1546 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001547 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001548
Andrii Kulian441e4492016-09-29 15:25:00 -07001549 /**
1550 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1551 * bounds were updated.
1552 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001553 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001554 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1555 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001556 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001557 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001558 }
1559 }
Winson Chung32c566f2017-04-11 18:31:21 -07001560
1561 // If there was no pinned stack, we still need to notify the controller of the display info
1562 // update as a result of the config change. We do this here to consolidate the flow between
1563 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001564 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001565 mPinnedStackControllerLocked.onDisplayInfoChanged();
1566 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001567 }
1568
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001569 @Override
1570 boolean fillsParent() {
1571 return true;
1572 }
1573
1574 @Override
1575 boolean isVisible() {
1576 return true;
1577 }
1578
1579 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001580 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001581 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001582 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001583 }
1584
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001585 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001586 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1587 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1588 // target, or here in order if there isn't an IME target.
1589 if (traverseTopToBottom) {
1590 for (int i = mChildren.size() - 1; i >= 0; --i) {
1591 final DisplayChildWindowContainer child = mChildren.get(i);
1592 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1593 // In this case the Ime windows will be processed above their target so we skip
1594 // here.
1595 continue;
1596 }
1597 if (child.forAllWindows(callback, traverseTopToBottom)) {
1598 return true;
1599 }
1600 }
1601 } else {
1602 final int count = mChildren.size();
1603 for (int i = 0; i < count; i++) {
1604 final DisplayChildWindowContainer child = mChildren.get(i);
1605 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1606 // In this case the Ime windows will be processed above their target so we skip
1607 // here.
1608 continue;
1609 }
1610 if (child.forAllWindows(callback, traverseTopToBottom)) {
1611 return true;
1612 }
1613 }
1614 }
1615 return false;
1616 }
1617
1618 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1619 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1620 }
1621
Wale Ogunwale399c8692017-05-08 14:22:42 -07001622 @Override
1623 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001624 final WindowManagerPolicy policy = mService.mPolicy;
1625
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001626 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001627 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001628 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001629 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001630 // If the display is frozen, some activities may be in the middle of restarting, and
1631 // thus have removed their old window. If the window has the flag to hide the lock
1632 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1633 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001634 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001635 } else if (policy.isKeyguardLocked()) {
1636 // Use the last orientation the while the display is frozen with the keyguard
1637 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1638 // window. We don't want to check the show when locked window directly though as
1639 // things aren't stable while the display is frozen, for example the window could be
1640 // momentarily unavailable due to activity relaunch.
1641 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001642 + "return " + mLastOrientation);
1643 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001644 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001645 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001646 final int orientation = mAboveAppWindowsContainers.getOrientation();
1647 if (orientation != SCREEN_ORIENTATION_UNSET) {
1648 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001649 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001650 }
1651
Wale Ogunwale399c8692017-05-08 14:22:42 -07001652 // Top system windows are not requesting an orientation. Start searching from apps.
1653 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001654 }
1655
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001656 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001657 // Check if display metrics changed and update base values if needed.
1658 updateBaseDisplayMetricsIfNeeded();
1659
Craig Mautner722285e2012-09-07 13:55:58 -07001660 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001661 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001662
Wale Ogunwale61911492017-10-11 08:50:50 -07001663 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1664 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001665 }
Craig Mautner722285e2012-09-07 13:55:58 -07001666 }
1667
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001668 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001669 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1670 if (displayManagerInternal != null) {
1671 // Bootstrap the default logical display from the display manager.
1672 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1673 if (newDisplayInfo != null) {
1674 mDisplayInfo.copyFrom(newDisplayInfo);
1675 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001676 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001677
Andrii Kuliancd097992017-03-23 18:31:59 -07001678 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1679 mDisplayInfo.logicalDensityDpi);
1680 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1681 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1682 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001683 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001684 }
1685
Andrii Kuliancd097992017-03-23 18:31:59 -07001686 /**
1687 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1688 * values.
1689 */
1690 private void updateBaseDisplayMetricsIfNeeded() {
1691 // Get real display metrics without overrides from WM.
1692 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1693 final int orientation = mDisplayInfo.rotation;
1694 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1695 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1696 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1697 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001698 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001699
1700 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1701 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001702 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1703 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001704
1705 if (displayMetricsChanged) {
1706 // Check if display size or density is forced.
1707 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1708 || mBaseDisplayHeight != mInitialDisplayHeight;
1709 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1710
1711 // If there is an override set for base values - use it, otherwise use new values.
1712 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1713 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1714 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1715
1716 // Real display metrics changed, so we should also update initial values.
1717 mInitialDisplayWidth = newWidth;
1718 mInitialDisplayHeight = newHeight;
1719 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001720 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001721 mService.reconfigureDisplayLocked(this);
1722 }
1723 }
1724
Bryce Lee27cec322017-03-21 09:41:37 -07001725 /** Sets the maximum width the screen resolution can be */
1726 void setMaxUiWidth(int width) {
1727 if (DEBUG_DISPLAY) {
1728 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1729 }
1730
1731 mMaxUiWidth = width;
1732
1733 // Update existing metrics.
1734 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1735 }
1736
1737 /** Update base (override) display metrics. */
1738 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1739 mBaseDisplayWidth = baseWidth;
1740 mBaseDisplayHeight = baseHeight;
1741 mBaseDisplayDensity = baseDensity;
1742
1743 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1744 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1745 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1746 mBaseDisplayWidth = mMaxUiWidth;
1747
1748 if (DEBUG_DISPLAY) {
1749 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1750 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1751 + " on display:" + getDisplayId());
1752 }
1753 }
1754
1755 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001756
1757 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001758 }
1759
Wale Ogunwaledb506192017-12-08 10:57:32 -08001760 void getStableRect(Rect out) {
1761 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001762 }
1763
Wale Ogunwale61911492017-10-11 08:50:50 -07001764 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001765 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1766 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001767
Wale Ogunwale61911492017-10-11 08:50:50 -07001768 final TaskStack stack = new TaskStack(mService, stackId, controller);
1769 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001770 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001771 }
1772
Andrii Kulian51c1b672017-04-07 18:39:32 -07001773 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001774 final DisplayContent prevDc = stack.getDisplayContent();
1775 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001776 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1777 + " which is not currently attached to any display");
1778 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001779 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001780 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1781 + " to its current displayId=" + mDisplayId);
1782 }
1783
Wale Ogunwale61911492017-10-11 08:50:50 -07001784 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001785 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001786 }
1787
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001788 @Override
1789 protected void addChild(DisplayChildWindowContainer child,
1790 Comparator<DisplayChildWindowContainer> comparator) {
1791 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1792 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001793
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001794 @Override
1795 protected void addChild(DisplayChildWindowContainer child, int index) {
1796 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1797 }
1798
1799 @Override
1800 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001801 // Only allow removal of direct children from this display if the display is in the process
1802 // of been removed.
1803 if (mRemovingDisplay) {
1804 super.removeChild(child);
1805 return;
1806 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001807 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001808 }
1809
Andrii Kuliand2765632016-12-12 22:26:34 -08001810 @Override
1811 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1812 // Children of the display are statically ordered, so the real intention here is to perform
1813 // the operation on the display and not the static direct children.
1814 getParent().positionChildAt(position, this, includingParents);
1815 }
1816
Winson Chung59a47ded2018-01-25 17:46:06 +00001817 void positionStackAt(int position, TaskStack child) {
1818 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1819 layoutAndAssignWindowLayersIfNeeded();
1820 }
1821
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001822 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001823 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1824 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001825 final int taskId = stack.taskIdFromPoint(x, y);
1826 if (taskId != -1) {
1827 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001828 }
1829 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001830 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001831 }
1832
Chong Zhang8e89b312015-09-09 15:09:30 -07001833 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001834 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001835 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001836 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001837 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001838 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001839 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001840 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1841 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001842 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001843 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001844 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001845
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001846 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1847 if (mTmpTaskForResizePointSearchResult.searchDone) {
1848 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001849 }
1850 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001851 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001852 }
1853
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001854 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001855 // The provided task is the task on this display with focus, so if WindowManagerService's
1856 // focused app is not on this display, focusedTask will be null.
1857 if (focusedTask == null) {
1858 mTouchExcludeRegion.setEmpty();
1859 } else {
1860 mTouchExcludeRegion.set(mBaseDisplayRect);
1861 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1862 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001863 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1864 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001865 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1866 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001867 }
1868 // If we removed the focused task above, add it back and only leave its
1869 // outside touch area in the exclusion. TapDectector is not interested in
1870 // any touch inside the focused task itself.
1871 if (!mTmpRect2.isEmpty()) {
1872 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1873 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001874 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001875 final WindowState inputMethod = mService.mInputMethodWindow;
1876 if (inputMethod != null && inputMethod.isVisibleLw()) {
1877 // If the input method is visible and the user is typing, we don't want these touch
1878 // events to be intercepted and used to change focus. This would likely cause a
1879 // disappearance of the input method.
1880 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001881 if (inputMethod.getDisplayId() == mDisplayId) {
1882 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1883 } else {
1884 // IME is on a different display, so we need to update its tap detector.
1885 // TODO(multidisplay): Remove when IME will always appear on same display.
1886 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1887 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001888 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001889 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001890 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001891 win.getTouchableRegion(mTmpRegion);
1892 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1893 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001894 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1895 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1896 win.amendTapExcludeRegion(mTouchExcludeRegion);
1897 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001898 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001899 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001900 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001901 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001902 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1903 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001904 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001905 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001906 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001907 }
1908
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001909 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001910 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001911 super.switchUser();
1912 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001913 }
1914
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001915 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001916 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1917 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001918 }
1919 }
1920
Wale Ogunwale10124582016-09-15 20:25:50 -07001921 @Override
1922 void removeIfPossible() {
1923 if (isAnimating()) {
1924 mDeferredRemoval = true;
1925 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001926 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001927 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001928 }
1929
Wale Ogunwale10124582016-09-15 20:25:50 -07001930 @Override
1931 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001932 mRemovingDisplay = true;
1933 try {
1934 super.removeImmediately();
1935 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001936 if (mService.canDispatchPointerEvents()) {
1937 if (mTapDetector != null) {
1938 mService.unregisterPointerEventListener(mTapDetector);
1939 }
1940 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1941 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1942 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001943 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001944 mService.mAnimator.removeDisplayLocked(mDisplayId);
Chavi Weingarten38804382018-02-15 21:00:15 +00001945
1946 // The pending transaction won't be applied so we should
1947 // just clean up any surfaces pending destruction.
1948 onPendingTransactionApplied();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001949 } finally {
1950 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001951 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001952
1953 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001954 }
1955
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001956 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001957 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001958 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001959 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1960
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001961 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001962 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001963 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001964 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001965 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001966 }
1967
Andrii Kulian0214ed92017-05-16 13:44:05 -07001968 /** @return 'true' if removal of this display content is deferred due to active animation. */
1969 boolean isRemovalDeferred() {
1970 return mDeferredRemoval;
1971 }
1972
Wale Ogunwale10124582016-09-15 20:25:50 -07001973 boolean animateForIme(float interpolatedValue, float animationTarget,
1974 float dividerAnimationTarget) {
1975 boolean updated = false;
1976
Wale Ogunwale61911492017-10-11 08:50:50 -07001977 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1978 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001979 if (stack == null || !stack.isAdjustedForIme()) {
1980 continue;
1981 }
1982
1983 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1984 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1985 updated = true;
1986 } else {
1987 mDividerControllerLocked.mLastAnimationProgress =
1988 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1989 mDividerControllerLocked.mLastDividerProgress =
1990 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1991 updated |= stack.updateAdjustForIme(
1992 mDividerControllerLocked.mLastAnimationProgress,
1993 mDividerControllerLocked.mLastDividerProgress,
1994 false /* force */);
1995 }
1996 if (interpolatedValue >= 1f) {
1997 stack.endImeAdjustAnimation();
1998 }
1999 }
2000
2001 return updated;
2002 }
2003
2004 boolean clearImeAdjustAnimation() {
2005 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002006 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2007 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002008 if (stack != null && stack.isAdjustedForIme()) {
2009 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2010 changed = true;
2011 }
2012 }
2013 return changed;
2014 }
2015
2016 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002017 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2018 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002019 if (stack.isVisible() && stack.isAdjustedForIme()) {
2020 stack.beginImeAdjustAnimation();
2021 }
2022 }
2023 }
2024
2025 void adjustForImeIfNeeded() {
2026 final WindowState imeWin = mService.mInputMethodWindow;
2027 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2028 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002029 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002030 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2031 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2032 imeTargetStack.getDockSide() : DOCKED_INVALID;
2033 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2034 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2035 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002036 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002037 final boolean imeHeightChanged = imeVisible &&
2038 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2039
2040 // The divider could be adjusted for IME position, or be thinner than usual,
2041 // or both. There are three possible cases:
2042 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2043 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2044 // - If IME is not visible, divider is not moved and is normal width.
2045
2046 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002047 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2048 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002049 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002050 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2051 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002052 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2053 } else {
2054 stack.resetAdjustedForIme(false);
2055 }
2056 }
2057 mDividerControllerLocked.setAdjustedForIme(
2058 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2059 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002060 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2061 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002062 stack.resetAdjustedForIme(!dockVisible);
2063 }
2064 mDividerControllerLocked.setAdjustedForIme(
2065 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2066 }
Winson Chung655332c2016-10-31 13:14:28 -07002067 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002068 }
2069
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002070 /**
2071 * If a window that has an animation specifying a colored background and the current wallpaper
2072 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2073 * suddenly disappear.
2074 */
2075 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002076 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2077 w -> w.mIsWallpaper && w.isVisibleNow());
2078
2079 if (visibleWallpaper != null) {
2080 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002081 }
2082 return winAnimator.mAnimLayer;
2083 }
2084
Wale Ogunwale10124582016-09-15 20:25:50 -07002085 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002086 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2087 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002088 stack.prepareFreezingTaskBounds();
2089 }
2090 }
2091
Wale Ogunwale94744212015-09-21 19:01:47 -07002092 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002093 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002094
2095 // Compute a transform matrix to undo the coordinate space transformation,
2096 // and present the window at the same physical position it previously occupied.
2097 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2098 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2099
2100 mTmpRectF.set(bounds);
2101 mTmpMatrix.mapRect(mTmpRectF);
2102 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002103 }
2104
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002105 static int deltaRotation(int oldRotation, int newRotation) {
2106 int delta = newRotation - oldRotation;
2107 if (delta < 0) delta += 4;
2108 return delta;
2109 }
2110
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002111 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002112 Matrix outMatrix) {
2113 // For rotations without Z-ordering we don't need the target rectangle's position.
2114 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2115 displayHeight, outMatrix);
2116 }
2117
2118 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2119 float displayWidth, float displayHeight, Matrix outMatrix) {
2120 switch (rotation) {
2121 case ROTATION_0:
2122 outMatrix.reset();
2123 break;
2124 case ROTATION_270:
2125 outMatrix.setRotate(270, 0, 0);
2126 outMatrix.postTranslate(0, displayHeight);
2127 outMatrix.postTranslate(rectTop, 0);
2128 break;
2129 case ROTATION_180:
2130 outMatrix.reset();
2131 break;
2132 case ROTATION_90:
2133 outMatrix.setRotate(90, 0, 0);
2134 outMatrix.postTranslate(displayWidth, 0);
2135 outMatrix.postTranslate(-rectTop, rectLeft);
2136 break;
2137 }
2138 }
2139
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002140 @CallSuper
2141 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002142 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002143 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002144 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002145 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002146 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2147 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002148 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002149 }
2150 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2151 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002152 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2153 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002154 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002155 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002156 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2157 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002158 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002159 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002160 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2161 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002162 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002163 }
2164 proto.write(DPI, mBaseDisplayDensity);
2165 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002166 proto.write(ROTATION, mRotation);
2167 final ScreenRotationAnimation screenRotationAnimation =
2168 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2169 if (screenRotationAnimation != null) {
2170 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2171 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002172 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002173 proto.end(token);
2174 }
2175
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002176 @Override
2177 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2178 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002179 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2180 final String subPrefix = " " + prefix;
2181 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2182 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2183 pw.print("dpi");
2184 if (mInitialDisplayWidth != mBaseDisplayWidth
2185 || mInitialDisplayHeight != mBaseDisplayHeight
2186 || mInitialDisplayDensity != mBaseDisplayDensity) {
2187 pw.print(" base=");
2188 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2189 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2190 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002191 if (mDisplayScalingDisabled) {
2192 pw.println(" noscale");
2193 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002194 pw.print(" cur=");
2195 pw.print(mDisplayInfo.logicalWidth);
2196 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2197 pw.print(" app=");
2198 pw.print(mDisplayInfo.appWidth);
2199 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2200 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2201 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2202 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2203 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002204 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002205 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002206 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002207
Craig Mautnerdc548482014-02-05 13:35:24 -08002208 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002209 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002210 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2211 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002212 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002213 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002214
Craig Mautnerdc548482014-02-05 13:35:24 -08002215 pw.println();
2216 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002217 pw.println();
2218 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002219 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002220 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002221 pw.print(" Exiting #"); pw.print(i);
2222 pw.print(' '); pw.print(token);
2223 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002224 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002225 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002226 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002227
Jorim Jaggi31f71702016-05-04 16:43:04 -07002228 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002229
2230 // Dump stack references
2231 final TaskStack homeStack = getHomeStack();
2232 if (homeStack != null) {
2233 pw.println(prefix + "homeStack=" + homeStack.getName());
2234 }
2235 final TaskStack pinnedStack = getPinnedStack();
2236 if (pinnedStack != null) {
2237 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2238 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002239 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002240 if (splitScreenPrimaryStack != null) {
2241 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2242 }
2243
2244 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002245 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002246 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002247 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002248
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002249 pw.println();
2250 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002251 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002252
2253 @Override
2254 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002255 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002256 }
2257
2258 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002259 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002260 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002261
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002262 /** Returns true if the stack in the windowing mode is visible. */
2263 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002264 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002265 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002266 }
2267
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002268 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002269 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002270 final int x = (int) xf;
2271 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002272 final WindowState touchedWin = getWindow(w -> {
2273 final int flags = w.mAttrs.flags;
2274 if (!w.isVisibleLw()) {
2275 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002276 }
2277 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002278 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002279 }
2280
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002281 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002282 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002283 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002284 }
2285
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002286 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002287
2288 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002289 return mTmpRegion.contains(x, y) || touchFlags == 0;
2290 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002291
2292 return touchedWin;
2293 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002294
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002295 boolean canAddToastWindowForUid(int uid) {
2296 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002297 // Also if the app is focused adding more than one toast at
2298 // a time for better backwards compatibility.
2299 final WindowState focusedWindowForUid = getWindow(w ->
2300 w.mOwnerUid == uid && w.isFocused());
2301 if (focusedWindowForUid != null) {
2302 return true;
2303 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002304 final WindowState win = getWindow(w ->
2305 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2306 && !w.mWindowRemovalAllowed);
2307 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002308 }
2309
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002310 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002311 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2312 return;
2313 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002314
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002315 // Used to communicate the old focus to the callback method.
2316 mTmpWindow = oldFocus;
2317
2318 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002319 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002320
2321 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002322 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002323
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002324 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002325
2326 if (mTmpWindow == null) {
2327 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2328 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002329 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002330 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002331 }
2332
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002333 /** Updates the layer assignment of windows on this display. */
2334 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002335 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002336 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002337 if (setLayoutNeeded) {
2338 setLayoutNeeded();
2339 }
Robert Carrb1579c82017-09-05 14:54:47 -07002340
Robert Carrf59b8dd2017-10-02 18:58:36 -07002341 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002342 // the application of this transaction until the animation pass triggers
2343 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2344 // the hiding and showing of surfaces.
2345 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002346 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002347 }
2348
Wale Ogunwale1666e312016-12-16 11:27:18 -08002349 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2350 // moving containers or resizing them. Need to investigate the best way to have it automatically
2351 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002352 void layoutAndAssignWindowLayersIfNeeded() {
2353 mService.mWindowsChanged = true;
2354 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002355
2356 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2357 false /*updateInputWindows*/)) {
2358 assignWindowLayers(false /* setLayoutNeeded */);
2359 }
2360
2361 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2362 mService.mWindowPlacerLocked.performSurfacePlacement();
2363 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2364 }
2365
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002366 /** Returns true if a leaked surface was destroyed */
2367 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002368 // Used to indicate that a surface was leaked.
2369 mTmpWindow = null;
2370 forAllWindows(w -> {
2371 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002372 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002373 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002374 }
2375 if (!mService.mSessions.contains(wsa.mSession)) {
2376 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002377 + w + " surface=" + wsa.mSurfaceController
2378 + " token=" + w.mToken
2379 + " pid=" + w.mSession.mPid
2380 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002381 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002382 mService.mForceRemoves.add(w);
2383 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002384 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002385 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002386 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002387 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002388 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002389 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002390 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002391 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002392 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002393
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002394 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002395 }
2396
2397 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002398 * Determine and return the window that should be the IME target.
2399 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2400 * @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 +00002401 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002402 WindowState computeImeTarget(boolean updateImeTarget) {
2403 if (mService.mInputMethodWindow == null) {
2404 // There isn't an IME so there shouldn't be a target...That was easy!
2405 if (updateImeTarget) {
2406 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2407 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002408 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002409 }
2410 return null;
2411 }
2412
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002413 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2414 // same display. Or even when the current IME/target are not on the same screen as the next
2415 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002416 mUpdateImeTarget = updateImeTarget;
2417 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002418
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002419
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002420 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2421 // to be on top of it, but it is not -really- where input will go. So look down below
2422 // for a real window to target...
2423 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2424 final AppWindowToken token = target.mAppToken;
2425 if (token != null) {
2426 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2427 if (betterTarget != null) {
2428 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002429 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002430 }
2431 }
2432
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002433 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2434 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002435
2436 // Now, a special case -- if the last target's window is in the process of exiting, and is
2437 // above the new target, keep on the last target to avoid flicker. Consider for example a
2438 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2439 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2440 // scrim.
2441 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002442 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2443 && (target == null
2444 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002445 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002446 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002447 }
2448
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002449 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2450 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002451
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002452 if (target == null) {
2453 if (updateImeTarget) {
2454 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2455 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2456 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002457 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002458 }
2459
2460 return null;
2461 }
2462
2463 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002464 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2465 if (token != null) {
2466
2467 // Now some fun for dealing with window animations that modify the Z order. We need
2468 // to look at all windows below the current target that are in this app, finding the
2469 // highest visible one in layering.
2470 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002471 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002472 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002473 }
2474
2475 if (highestTarget != null) {
2476 final AppTransition appTransition = mService.mAppTransition;
2477 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2478 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2479 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002480 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002481
2482 if (appTransition.isTransitionSet()) {
2483 // If we are currently setting up for an animation, hold everything until we
2484 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002485 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002486 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002487 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002488 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002489 // If the window we are currently targeting is involved with an animation,
2490 // and it is on top of the next target we will be over, then hold off on
2491 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002492 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002493 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002494 }
2495 }
2496 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002497
2498 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2499 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002500 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002501 }
2502
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002503 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002504 }
2505
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002506 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002507 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002508 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002509 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002510 }
2511
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002512 mService.mInputMethodTarget = target;
2513 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002514 assignWindowLayers(false /* setLayoutNeeded */);
2515 }
2516
2517 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2518 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2519 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2520 }
2521
2522 // Used to indicate we have reached the first window in the range we are interested in.
2523 mTmpWindow = null;
2524
2525 // TODO: Figure-out a more efficient way to do this.
2526 final WindowState candidate = getWindow(w -> {
2527 if (w == top) {
2528 // Reached the first window in the range we are interested in.
2529 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002530 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002531 if (mTmpWindow == null) {
2532 return false;
2533 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002534
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002535 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2536 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002537 }
2538 // If we reached the bottom of the range of windows we are considering,
2539 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002540 if (w == bottom) {
2541 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002542 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002543 return false;
2544 });
2545
2546 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002547 }
2548
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002549 void setLayoutNeeded() {
2550 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2551 mLayoutNeeded = true;
2552 }
2553
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002554 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002555 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2556 mLayoutNeeded = false;
2557 }
2558
2559 boolean isLayoutNeeded() {
2560 return mLayoutNeeded;
2561 }
2562
Wale Ogunwale02319a62016-09-26 15:21:22 -07002563 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2564 if (mTokenMap.isEmpty()) {
2565 return;
2566 }
2567 pw.println(" Display #" + mDisplayId);
2568 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2569 while (it.hasNext()) {
2570 final WindowToken token = it.next();
2571 pw.print(" ");
2572 pw.print(token);
2573 if (dumpAll) {
2574 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002575 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002576 } else {
2577 pw.println();
2578 }
2579 }
2580 }
2581
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002582 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002583 final int[] index = new int[1];
2584 forAllWindows(w -> {
2585 final WindowStateAnimator wAnim = w.mWinAnimator;
2586 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2587 index[0] = index[0] + 1;
2588 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002589 }
2590
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002591 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002592 forAllWindows(w -> {
2593 w.mWinAnimator.enableSurfaceTrace(fd);
2594 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002595 }
2596
2597 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002598 forAllWindows(w -> {
2599 w.mWinAnimator.disableSurfaceTrace();
2600 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002601 }
2602
Jorim Jaggife762342016-10-13 14:33:27 +02002603 /**
2604 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2605 */
2606 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2607 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002608 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002609 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2610 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002611 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002612 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002613 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002614 }
2615
Wale Ogunwale494009b82016-10-21 09:01:38 -07002616 boolean checkWaitingForWindows() {
2617
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002618 mHaveBootMsg = false;
2619 mHaveApp = false;
2620 mHaveWallpaper = false;
2621 mHaveKeyguard = true;
2622
2623 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002624 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2625 return true;
2626 }
2627 if (w.isDrawnLw()) {
2628 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002629 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002630 } else if (w.mAttrs.type == TYPE_APPLICATION
2631 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002632 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002633 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002634 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002635 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002636 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002637 }
2638 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002639 return false;
2640 });
2641
2642 if (visibleWindow != null) {
2643 // We have a visible window.
2644 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002645 }
2646
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002647 // if the wallpaper service is disabled on the device, we're never going to have
2648 // wallpaper, don't bother waiting for it
2649 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2650 com.android.internal.R.bool.config_enableWallpaperService)
2651 && !mService.mOnlyCore;
2652
Wale Ogunwale494009b82016-10-21 09:01:38 -07002653 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2654 "******** booted=" + mService.mSystemBooted
2655 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002656 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2657 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2658 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002659
2660 // If we are turning on the screen to show the boot message, don't do it until the boot
2661 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002662 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002663 return true;
2664 }
2665
2666 // If we are turning on the screen after the boot is completed normally, don't do so until
2667 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002668 if (mService.mSystemBooted
2669 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002670 return true;
2671 }
2672
2673 return false;
2674 }
2675
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002676 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002677 mTmpWindowAnimator = animator;
2678 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002679 }
2680
2681 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002682 resetAnimationBackgroundAnimator();
2683
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002684 // Used to indicate a detached wallpaper.
2685 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002686 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002687
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002688 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002689
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002690 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002691 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002692 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2693 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002694 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2695 }
2696 }
2697
Wale Ogunwale494009b82016-10-21 09:01:38 -07002698 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002699 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002700 if (imFocus == null) {
2701 return false;
2702 }
2703
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002704 if (DEBUG_INPUT_METHOD) {
2705 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2706 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2707 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002708 }
2709
Wale Ogunwale494009b82016-10-21 09:01:38 -07002710 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2711
2712 if (DEBUG_INPUT_METHOD) {
2713 Slog.i(TAG_WM, "IM target client: " + imeClient);
2714 if (imeClient != null) {
2715 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2716 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2717 }
2718 }
2719
2720 return imeClient != null && imeClient.asBinder() == client.asBinder();
2721 }
2722
2723 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002724 final WindowState win = getWindow(
2725 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2726 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002727 }
2728
2729 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002730 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002731 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002732 final int curValue = w.mSystemUiVisibility;
2733 final int diff = (curValue ^ visibility) & globalDiff;
2734 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002735 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002736 w.mSeq++;
2737 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002738 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002739 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2740 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002741 visibility, newValue, diff);
2742 }
2743 } catch (RemoteException e) {
2744 // so sorry
2745 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002746 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002747 }
2748
2749 void onWindowFreezeTimeout() {
2750 Slog.w(TAG_WM, "Window freeze timeout expired.");
2751 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002752
2753 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002754 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002755 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002756 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002757 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002758 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2759 - mService.mDisplayFreezeTime);
2760 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002761 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002762 mService.mWindowPlacerLocked.performSurfacePlacement();
2763 }
2764
2765 void waitForAllWindowsDrawn() {
2766 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002767 forAllWindows(w -> {
2768 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2769 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2770 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002771 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002772 w.mLastContentInsets.set(-1, -1, -1, -1);
2773 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002774 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002775 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002776 }
2777
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002778 // TODO: Super crazy long method that should be broken down...
2779 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2780
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002781 final int dw = mDisplayInfo.logicalWidth;
2782 final int dh = mDisplayInfo.logicalHeight;
2783 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2784
2785 mTmpUpdateAllDrawn.clear();
2786
2787 int repeats = 0;
2788 do {
2789 repeats++;
2790 if (repeats > 6) {
2791 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2792 clearLayoutNeeded();
2793 break;
2794 }
2795
2796 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2797 pendingLayoutChanges);
2798
Andrii Kulian839def92016-11-02 10:58:58 -07002799 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2800 // the wallpaper window jumping across displays.
2801 // Remove check for default display when there will be support for multiple wallpaper
2802 // targets (on different displays).
2803 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002804 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002805 }
2806
2807 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2808 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2809 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2810 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002811 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002812 }
2813 }
2814
2815 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2816 setLayoutNeeded();
2817 }
2818
2819 // FIRST LOOP: Perform a layout, if needed.
2820 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2821 performLayout(repeats == 1, false /* updateInputWindows */);
2822 } else {
2823 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2824 }
2825
2826 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2827 pendingLayoutChanges = 0;
2828
2829 if (isDefaultDisplay) {
2830 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002831 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002832 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2833 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2834 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2835 }
2836 } while (pendingLayoutChanges != 0);
2837
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002838 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002839
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002840 mTmpRecoveringMemory = recoveringMemory;
2841 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002842 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002843
2844 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002845 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2846 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2847 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002848 true /* inTraversal, must call performTraversalInTrans... below */);
2849
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002850 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2851 if (wallpaperVisible != mLastWallpaperVisible) {
2852 mLastWallpaperVisible = wallpaperVisible;
2853 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2854 }
2855
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002856 while (!mTmpUpdateAllDrawn.isEmpty()) {
2857 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2858 // See if any windows have been drawn, so they (and others associated with them)
2859 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002860 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002861 }
2862
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002863 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002864 }
2865
Bryce Leef3c6a472017-11-14 14:53:06 -08002866 private void updateBounds() {
2867 calculateBounds(mTmpBounds);
2868 setBounds(mTmpBounds);
2869 }
2870
2871 // Determines the current display bounds based on the current state
2872 private void calculateBounds(Rect out) {
2873 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2874 final int orientation = mDisplayInfo.rotation;
2875 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2876 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2877 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2878 int width = mDisplayInfo.logicalWidth;
2879 int left = (physWidth - width) / 2;
2880 int height = mDisplayInfo.logicalHeight;
2881 int top = (physHeight - height) / 2;
2882 out.set(left, top, left + width, top + height);
2883 }
2884
2885 @Override
2886 public void getBounds(Rect out) {
2887 calculateBounds(out);
2888 }
2889
2890 private void getBounds(Rect out, int orientation) {
2891 getBounds(out);
2892
2893 // Rotate the Rect if needed.
2894 final int currentRotation = mDisplayInfo.rotation;
2895 final int rotationDelta = deltaRotation(currentRotation, orientation);
2896 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2897 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2898 mTmpRectF.set(out);
2899 mTmpMatrix.mapRect(mTmpRectF);
2900 mTmpRectF.round(out);
2901 }
2902 }
2903
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002904 void performLayout(boolean initial, boolean updateInputWindows) {
2905 if (!isLayoutNeeded()) {
2906 return;
2907 }
2908 clearLayoutNeeded();
2909
2910 final int dw = mDisplayInfo.logicalWidth;
2911 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002912 if (DEBUG_LAYOUT) {
2913 Slog.v(TAG, "-------------------------------------");
2914 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2915 }
2916
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002917 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
2918 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2919 // display info above...
2920 mDisplayFrames.mRotation = mRotation;
2921 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002922 if (isDefaultDisplay) {
2923 // Not needed on non-default displays.
2924 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2925 mService.mScreenRect.set(0, 0, dw, dh);
2926 }
2927
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002928 int seq = mService.mLayoutSeq + 1;
2929 if (seq < 0) seq = 0;
2930 mService.mLayoutSeq = seq;
2931
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002932 // Used to indicate that we have processed the dream window and all additional windows are
2933 // behind it.
2934 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002935 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002936
2937 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002938 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002939
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002940 // Used to indicate that we have processed the dream window and all additional attached
2941 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002942 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002943 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002944
2945 // Now perform layout of attached windows, which usually depend on the position of the
2946 // window they are attached to. XXX does not deal with windows that are attached to windows
2947 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002948 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002949
2950 // Window frames may have changed. Tell the input dispatcher about it.
2951 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2952 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2953 if (updateInputWindows) {
2954 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2955 }
2956
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002957 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2958 }
2959
2960 /**
2961 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2962 * In portrait mode, it grabs the full screenshot.
2963 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002964 * @param config of the output bitmap
2965 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2966 */
chaviwfbe47df2017-11-10 16:14:49 -08002967 Bitmap screenshotDisplay(Bitmap.Config config, boolean wallpaperOnly) {
2968 synchronized (mService.mWindowMap) {
Jorim Jaggi51304d72017-05-17 17:25:32 +02002969 if (!mService.mPolicy.isScreenOn()) {
chaviwfbe47df2017-11-10 16:14:49 -08002970 if (DEBUG_SCREENSHOT) {
2971 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002972 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002973 return null;
2974 }
2975
chaviwfbe47df2017-11-10 16:14:49 -08002976 if (wallpaperOnly && !shouldScreenshotWallpaper()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002977 return null;
2978 }
2979
chaviwfbe47df2017-11-10 16:14:49 -08002980 int dw = mDisplayInfo.logicalWidth;
2981 int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002982
chaviwfbe47df2017-11-10 16:14:49 -08002983 if (dw <= 0 || dh <= 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002984 return null;
2985 }
2986
chaviwfbe47df2017-11-10 16:14:49 -08002987 final Rect frame = new Rect(0, 0, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002988
2989 // The screenshot API does not apply the current screen rotation.
2990 int rot = mDisplay.getRotation();
2991
2992 if (rot == ROTATION_90 || rot == ROTATION_270) {
2993 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2994 }
2995
chaviwfbe47df2017-11-10 16:14:49 -08002996 // SurfaceFlinger is not aware of orientation, so convert our logical
2997 // crop to SurfaceFlinger's portrait orientation.
2998 convertCropForSurfaceFlinger(frame, rot, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002999
3000 final ScreenRotationAnimation screenRotationAnimation =
3001 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3002 final boolean inRotation = screenRotationAnimation != null &&
3003 screenRotationAnimation.isAnimating();
chaviwfbe47df2017-11-10 16:14:49 -08003004 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003005
Robert Carrb1579c82017-09-05 14:54:47 -07003006 // TODO(b/68392460): We should screenshot Task controls directly
3007 // but it's difficult at the moment as the Task doesn't have the
3008 // correct size set.
chaviwfbe47df2017-11-10 16:14:49 -08003009 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003010 if (bitmap == null) {
Robert Carrb1579c82017-09-05 14:54:47 -07003011 Slog.w(TAG_WM, "Failed to take screenshot");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003012 return null;
3013 }
chaviwfbe47df2017-11-10 16:14:49 -08003014
3015 // Create a copy of the screenshot that is immutable and backed in ashmem.
3016 // This greatly reduces the overhead of passing the bitmap between processes.
3017 final Bitmap ret = bitmap.createAshmemBitmap(config);
3018 bitmap.recycle();
3019 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003020 }
chaviwfbe47df2017-11-10 16:14:49 -08003021 }
3022
3023 private boolean shouldScreenshotWallpaper() {
3024 MutableBoolean screenshotReady = new MutableBoolean(false);
3025
3026 forAllWindows(w -> {
3027 if (!w.mIsWallpaper) {
3028 return false;
3029 }
3030
3031 // Found the wallpaper window
3032 final WindowStateAnimator winAnim = w.mWinAnimator;
3033
3034 if (winAnim.getShown() && winAnim.mLastAlpha > 0f) {
3035 screenshotReady.value = true;
3036 }
3037
3038 return true;
3039 }, true /* traverseTopToBottom */);
3040
3041 return screenshotReady.value;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003042 }
3043
3044 // TODO: Can this use createRotationMatrix()?
3045 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3046 if (rot == Surface.ROTATION_90) {
3047 final int tmp = crop.top;
3048 crop.top = dw - crop.right;
3049 crop.right = crop.bottom;
3050 crop.bottom = dw - crop.left;
3051 crop.left = tmp;
3052 } else if (rot == Surface.ROTATION_180) {
3053 int tmp = crop.top;
3054 crop.top = dh - crop.bottom;
3055 crop.bottom = dh - tmp;
3056 tmp = crop.right;
3057 crop.right = dw - crop.left;
3058 crop.left = dw - tmp;
3059 } else if (rot == Surface.ROTATION_270) {
3060 final int tmp = crop.top;
3061 crop.top = crop.left;
3062 crop.left = dh - crop.bottom;
3063 crop.bottom = crop.right;
3064 crop.right = dh - tmp;
3065 }
3066 }
3067
3068 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003069 // Used to indicate the layout is needed.
3070 mTmpWindow = null;
3071
3072 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003073 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003074 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003075 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003076 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003077 w.setDisplayLayoutNeeded();
3078 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003079 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003080
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003081 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003082 mService.mWindowPlacerLocked.performSurfacePlacement();
3083 }
3084 }
3085
Wale Ogunwale1666e312016-12-16 11:27:18 -08003086 void setExitingTokensHasVisible(boolean hasVisible) {
3087 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3088 mExitingTokens.get(i).hasVisible = hasVisible;
3089 }
3090
3091 // Initialize state of exiting applications.
3092 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3093 }
3094
3095 void removeExistingTokensIfPossible() {
3096 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3097 final WindowToken token = mExitingTokens.get(i);
3098 if (!token.hasVisible) {
3099 mExitingTokens.remove(i);
3100 }
3101 }
3102
3103 // Time to remove any exiting applications?
3104 mTaskStackContainers.removeExistingAppTokensIfPossible();
3105 }
3106
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003107 @Override
3108 void onDescendantOverrideConfigurationChanged() {
3109 setLayoutNeeded();
3110 mService.requestTraversal();
3111 }
3112
David Stevens9440dc82017-03-16 19:00:20 -07003113 boolean okToDisplay() {
3114 if (mDisplayId == DEFAULT_DISPLAY) {
3115 return !mService.mDisplayFrozen
3116 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3117 }
3118 return mDisplayInfo.state == Display.STATE_ON;
3119 }
3120
3121 boolean okToAnimate() {
3122 return okToDisplay() &&
3123 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3124 }
3125
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003126 static final class TaskForResizePointSearchResult {
3127 boolean searchDone;
3128 Task taskForResize;
3129
3130 void reset() {
3131 searchDone = false;
3132 taskForResize = null;
3133 }
3134 }
Robert Carr3b716242016-08-16 16:02:21 -07003135
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003136 private static final class ApplySurfaceChangesTransactionState {
3137 boolean displayHasContent;
3138 boolean obscured;
3139 boolean syswin;
3140 boolean focusDisplayed;
3141 float preferredRefreshRate;
3142 int preferredModeId;
3143
3144 void reset() {
3145 displayHasContent = false;
3146 obscured = false;
3147 syswin = false;
3148 focusDisplayed = false;
3149 preferredRefreshRate = 0;
3150 preferredModeId = 0;
3151 }
3152 }
3153
3154 private static final class ScreenshotApplicationState {
3155 WindowState appWin;
3156 int maxLayer;
3157 int minLayer;
3158 boolean screenshotReady;
3159
3160 void reset(boolean screenshotReady) {
3161 appWin = null;
3162 maxLayer = 0;
3163 minLayer = 0;
3164 this.screenshotReady = screenshotReady;
3165 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3166 }
3167 }
3168
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003169 /**
3170 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3171 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3172 * homogeneous children type which is currently required by sub-classes of
3173 * {@link WindowContainer} class.
3174 */
3175 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3176
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003177 DisplayChildWindowContainer(WindowManagerService service) {
3178 super(service);
3179 }
3180
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003181 @Override
3182 boolean fillsParent() {
3183 return true;
3184 }
3185
3186 @Override
3187 boolean isVisible() {
3188 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003189 }
3190 }
3191
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003192 /**
3193 * Window container class that contains all containers on this display relating to Apps.
3194 * I.e Activities.
3195 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003196 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003197 /**
3198 * A control placed at the appropriate level for transitions to occur.
3199 */
chaviw23ee71c2017-12-18 11:29:41 -08003200 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003201
Robert Carrf7a7ca82017-12-06 13:17:07 -08003202 /**
3203 * Given that the split-screen divider does not have an AppWindowToken, it
3204 * will have to live inside of a "NonAppWindowContainer", in particular
3205 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3206 * it will need to be interleaved with some of our children, appearing on top of
3207 * both docked stacks but underneath any assistant stacks.
3208 *
3209 * To solve this problem we have this anchor control, which will always exist so
3210 * we can always assign it the correct value in our {@link #assignChildLayers}.
3211 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3212 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3213 * events between the two containers.
3214 */
3215 SurfaceControl mSplitScreenDividerAnchor = null;
3216
Wale Ogunwale61911492017-10-11 08:50:50 -07003217 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3218 // through the list to find them.
3219 private TaskStack mHomeStack = null;
3220 private TaskStack mPinnedStack = null;
3221 private TaskStack mSplitScreenPrimaryStack = null;
3222
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003223 TaskStackContainers(WindowManagerService service) {
3224 super(service);
3225 }
3226
Wale Ogunwale61911492017-10-11 08:50:50 -07003227 /**
3228 * Returns the topmost stack on the display that is compatible with the input windowing mode
3229 * and activity type. Null is no compatible stack on the display.
3230 */
3231 TaskStack getStack(int windowingMode, int activityType) {
3232 if (activityType == ACTIVITY_TYPE_HOME) {
3233 return mHomeStack;
3234 }
3235 if (windowingMode == WINDOWING_MODE_PINNED) {
3236 return mPinnedStack;
3237 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3238 return mSplitScreenPrimaryStack;
3239 }
3240 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3241 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003242 if (activityType == ACTIVITY_TYPE_UNDEFINED
3243 && windowingMode == stack.getWindowingMode()) {
3244 // Passing in undefined type means we want to match the topmost stack with the
3245 // windowing mode.
3246 return stack;
3247 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003248 if (stack.isCompatible(windowingMode, activityType)) {
3249 return stack;
3250 }
3251 }
3252 return null;
3253 }
3254
3255 @VisibleForTesting
3256 TaskStack getTopStack() {
3257 return mTaskStackContainers.getChildCount() > 0
3258 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3259 }
3260
3261 TaskStack getHomeStack() {
3262 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3263 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3264 }
3265 return mHomeStack;
3266 }
3267
3268 TaskStack getPinnedStack() {
3269 return mPinnedStack;
3270 }
3271
Matthew Ng64e77cf2017-10-31 14:01:31 -07003272 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003273 return mSplitScreenPrimaryStack;
3274 }
3275
Winson Chunge2d72172018-01-25 17:46:20 +00003276 ArrayList<Task> getVisibleTasks() {
3277 final ArrayList<Task> visibleTasks = new ArrayList<>();
3278 forAllTasks(task -> {
3279 if (task.isVisible()) {
3280 visibleTasks.add(task);
3281 }
3282 });
3283 return visibleTasks;
3284 }
3285
Andrii Kulian839def92016-11-02 10:58:58 -07003286 /**
3287 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003288 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003289 */
3290 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003291 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003292 addChild(stack, onTop);
3293 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003294 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003295
Wale Ogunwale61911492017-10-11 08:50:50 -07003296 void onStackWindowingModeChanged(TaskStack stack) {
3297 removeStackReferenceIfNeeded(stack);
3298 addStackReferenceIfNeeded(stack);
3299 if (stack == mPinnedStack && getTopStack() != stack) {
3300 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3301 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3302 }
3303 }
3304
3305 private void addStackReferenceIfNeeded(TaskStack stack) {
3306 if (stack.isActivityTypeHome()) {
3307 if (mHomeStack != null) {
3308 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3309 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3310 }
3311 mHomeStack = stack;
3312 }
3313 final int windowingMode = stack.getWindowingMode();
3314 if (windowingMode == WINDOWING_MODE_PINNED) {
3315 if (mPinnedStack != null) {
3316 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3317 + mPinnedStack + " already exist on display=" + this
3318 + " stack=" + stack);
3319 }
3320 mPinnedStack = stack;
3321 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3322 if (mSplitScreenPrimaryStack != null) {
3323 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3324 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3325 + " already exist on display=" + this + " stack=" + stack);
3326 }
3327 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003328 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003329 }
3330 }
3331
3332 private void removeStackReferenceIfNeeded(TaskStack stack) {
3333 if (stack == mHomeStack) {
3334 mHomeStack = null;
3335 } else if (stack == mPinnedStack) {
3336 mPinnedStack = null;
3337 } else if (stack == mSplitScreenPrimaryStack) {
3338 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003339 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3340 mService.setDockedStackCreateStateLocked(
3341 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3342 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003343 }
Andrii Kulian839def92016-11-02 10:58:58 -07003344 }
3345
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003346 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003347 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3348 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003349 addChild(stack, addIndex);
3350 setLayoutNeeded();
3351 }
3352
Wale Ogunwale61911492017-10-11 08:50:50 -07003353 @Override
3354 protected void removeChild(TaskStack stack) {
3355 super.removeChild(stack);
3356 removeStackReferenceIfNeeded(stack);
3357 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003358
3359 @Override
3360 boolean isOnTop() {
3361 // Considered always on top
3362 return true;
3363 }
3364
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003365 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003366 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003367 if (child.getWindowConfiguration().isAlwaysOnTop()
3368 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003369 // This stack is always-on-top, override the default behavior.
3370 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3371
3372 // Moving to its current position, as we must call super but we don't want to
3373 // perform any meaningful action.
3374 final int currentPosition = mChildren.indexOf(child);
3375 super.positionChildAt(currentPosition, child, false /* includingParents */);
3376 return;
3377 }
3378
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003379 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3380 super.positionChildAt(targetPosition, child, includingParents);
3381
3382 setLayoutNeeded();
3383 }
3384
3385 /**
3386 * When stack is added or repositioned, find a proper position for it.
3387 * This will make sure that pinned stack always stays on top.
3388 * @param requestedPosition Position requested by caller.
3389 * @param stack Stack to be added or positioned.
3390 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3391 * @return The proper position for the stack.
3392 */
3393 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3394 final int topChildPosition = mChildren.size() - 1;
3395 boolean toTop = requestedPosition == POSITION_TOP;
3396 toTop |= adding ? requestedPosition >= topChildPosition + 1
3397 : requestedPosition >= topChildPosition;
3398 int targetPosition = requestedPosition;
3399
Wale Ogunwale61911492017-10-11 08:50:50 -07003400 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003401 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003402 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003403 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003404 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3405 }
3406
3407 // So, stack is moved just below the pinned stack.
3408 // When we're adding a new stack the target is the current pinned stack position.
3409 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003410 // stack, because WindowContainer#positionAt() first removes element and then adds
3411 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003412 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3413 }
3414
3415 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003416 }
3417
3418 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003419 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3420 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003421 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003422 if (super.forAllWindows(callback, traverseTopToBottom)) {
3423 return true;
3424 }
3425 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3426 return true;
3427 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003428 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003429 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3430 return true;
3431 }
3432 if (super.forAllWindows(callback, traverseTopToBottom)) {
3433 return true;
3434 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003435 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003436 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003437 }
3438
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003439 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003440 boolean traverseTopToBottom) {
3441 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3442 // app tokens.
3443 // TODO: Investigate if we need to continue to do this or if we can just process them
3444 // in-order.
3445 if (traverseTopToBottom) {
3446 for (int i = mChildren.size() - 1; i >= 0; --i) {
3447 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3448 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003449 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3450 traverseTopToBottom)) {
3451 return true;
3452 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003453 }
3454 }
3455 } else {
3456 final int count = mChildren.size();
3457 for (int i = 0; i < count; ++i) {
3458 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3459 final int appTokensCount = appTokens.size();
3460 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003461 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3462 traverseTopToBottom)) {
3463 return true;
3464 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003465 }
3466 }
3467 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003468 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003469 }
3470
Wale Ogunwale1666e312016-12-16 11:27:18 -08003471 void setExitingTokensHasVisible(boolean hasVisible) {
3472 for (int i = mChildren.size() - 1; i >= 0; --i) {
3473 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3474 for (int j = appTokens.size() - 1; j >= 0; --j) {
3475 appTokens.get(j).hasVisible = hasVisible;
3476 }
3477 }
3478 }
3479
3480 void removeExistingAppTokensIfPossible() {
3481 for (int i = mChildren.size() - 1; i >= 0; --i) {
3482 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3483 for (int j = appTokens.size() - 1; j >= 0; --j) {
3484 final AppWindowToken token = appTokens.get(j);
3485 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3486 && (!token.mIsExiting || token.isEmpty())) {
3487 // Make sure there is no animation running on this token, so any windows
3488 // associated with it will be removed as soon as their animations are
3489 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003490 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003491 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3492 "performLayout: App token exiting now removed" + token);
3493 token.removeIfPossible();
3494 }
3495 }
3496 }
3497 }
3498
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003499 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003500 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003501 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3502 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003503 // Apps and their containers are not allowed to specify an orientation while the
3504 // docked or freeform stack is visible...except for the home stack/task if the
3505 // docked stack is minimized and it actually set something.
3506 if (mHomeStack != null && mHomeStack.isVisible()
3507 && mDividerControllerLocked.isMinimizedDock()) {
3508 final int orientation = mHomeStack.getOrientation();
3509 if (orientation != SCREEN_ORIENTATION_UNSET) {
3510 return orientation;
3511 }
3512 }
3513 return SCREEN_ORIENTATION_UNSPECIFIED;
3514 }
3515
3516 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003517 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3518 PackageManager.FEATURE_AUTOMOTIVE);
3519 if (isCar) {
3520 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3521 // allow anything but the default orientation.
3522 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3523 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3524 return SCREEN_ORIENTATION_UNSPECIFIED;
3525 }
3526
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003527 if (orientation != SCREEN_ORIENTATION_UNSET
3528 && orientation != SCREEN_ORIENTATION_BEHIND) {
3529 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3530 "App is requesting an orientation, return " + orientation);
3531 return orientation;
3532 }
3533
3534 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003535 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003536 // The next app has not been requested to be visible, so we keep the current orientation
3537 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003538 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003539 }
Robert Carrb1579c82017-09-05 14:54:47 -07003540
3541 @Override
3542 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003543 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003544
Robert Carr2f8aa392018-01-31 14:46:51 -08003545 for (int i = 0; i < mChildren.size(); i++) {
3546 final TaskStack s = mChildren.get(i);
3547 s.assignChildLayers(t);
3548 }
3549 }
3550
3551 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003552 final int HOME_STACK_STATE = 0;
3553 final int NORMAL_STACK_STATE = 1;
3554 final int ALWAYS_ON_TOP_STATE = 2;
3555
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003556 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003557 int layerForAnimationLayer = 0;
3558
Robert Carrf7a7ca82017-12-06 13:17:07 -08003559 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3560 for (int i = 0; i < mChildren.size(); i++) {
3561 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003562 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3563 continue;
3564 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3565 || s.isAlwaysOnTop())) {
3566 continue;
3567 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3568 continue;
3569 }
3570 s.assignLayer(t, layer++);
3571 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3572 t.setLayer(mSplitScreenDividerAnchor, layer++);
3573 }
3574 if (s.isSelfOrChildAnimating()) {
3575 // Ensure the animation layer ends up above the
3576 // highest animating stack and no higher.
3577 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003578 }
3579 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003580 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003581 if (mAppAnimationLayer != null) {
3582 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003583 }
Robert Carrb1579c82017-09-05 14:54:47 -07003584 }
3585
3586 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003587 SurfaceControl getAppAnimationLayer() {
3588 return mAppAnimationLayer;
3589 }
3590
Robert Carrf7a7ca82017-12-06 13:17:07 -08003591 SurfaceControl getSplitScreenDividerAnchor() {
3592 return mSplitScreenDividerAnchor;
3593 }
3594
chaviw23ee71c2017-12-18 11:29:41 -08003595 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003596 void onParentSet() {
3597 super.onParentSet();
3598 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003599 mAppAnimationLayer = makeChildSurface(null)
3600 .setName("animationLayer")
3601 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003602 mSplitScreenDividerAnchor = makeChildSurface(null)
3603 .setName("splitScreenDividerAnchor")
3604 .build();
3605 getPendingTransaction()
3606 .show(mAppAnimationLayer)
3607 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003608 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003609 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003610 mAppAnimationLayer.destroy();
3611 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003612 mSplitScreenDividerAnchor.destroy();
3613 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003614 }
3615 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003616 }
3617
Robert Carree4d4b92017-11-22 12:21:46 -08003618 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003619 AboveAppWindowContainers(String name, WindowManagerService service) {
3620 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003621 }
3622
3623 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3624 boolean needAssignIme = imeContainer != null
3625 && imeContainer.getSurfaceControl() != null;
3626 for (int j = 0; j < mChildren.size(); ++j) {
3627 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003628
3629 // See {@link mSplitScreenDividerAnchor}
3630 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3631 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3632 continue;
3633 }
Robert Carree4d4b92017-11-22 12:21:46 -08003634 wt.assignLayer(t, j);
3635 wt.assignChildLayers(t);
3636
3637 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3638 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003639
3640 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3641 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003642 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003643 needAssignIme = false;
3644 }
3645 }
3646 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003647 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003648 }
3649 }
3650 }
3651
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003652 /**
3653 * Window container class that contains all containers on this display that are not related to
3654 * Apps. E.g. status bar.
3655 */
Robert Carree4d4b92017-11-22 12:21:46 -08003656 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003657 /**
3658 * Compares two child window tokens returns -1 if the first is lesser than the second in
3659 * terms of z-order and 1 otherwise.
3660 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003661 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003662 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003663 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3664 token1.mOwnerCanManageAppTokens)
3665 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3666 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003667
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003668 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3669 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3670 return false;
3671 }
3672 final int req = w.mAttrs.screenOrientation;
3673 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3674 || req == SCREEN_ORIENTATION_UNSET) {
3675 return false;
3676 }
3677 return true;
3678 };
3679
Wale Ogunwale3a931692016-11-02 16:49:48 -07003680 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003681 private final Dimmer mDimmer = new Dimmer(this);
3682 private final Rect mTmpDimBoundsRect = new Rect();
3683
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003684 NonAppWindowContainers(String name, WindowManagerService service) {
3685 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003686 mName = name;
3687 }
3688
3689 void addChild(WindowToken token) {
3690 addChild(token, mWindowComparator);
3691 }
3692
3693 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003694 int getOrientation() {
3695 final WindowManagerPolicy policy = mService.mPolicy;
3696 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003697 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003698
3699 if (win != null) {
3700 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003701 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003702 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003703 if (mService.mKeyguardGoingAway) {
3704 // Keyguard can't affect the orientation if it is going away...
3705 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3706 return SCREEN_ORIENTATION_UNSET;
3707 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003708 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003709 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003710 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003711 }
3712
Andrii Kulian8ee72852017-03-10 10:36:45 -08003713 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003714
Jorim Jaggi75520d52017-08-24 17:23:19 +02003715 if (policy.isKeyguardShowingAndNotOccluded()
3716 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003717 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003718 }
3719
3720 return SCREEN_ORIENTATION_UNSET;
3721 }
3722
3723 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003724 String getName() {
3725 return mName;
3726 }
chaviwf29223e2018-01-31 13:23:51 -08003727
3728 @Override
3729 Dimmer getDimmer() {
3730 return mDimmer;
3731 }
3732
3733 @Override
3734 void prepareSurfaces() {
3735 mDimmer.resetDimStates();
3736 super.prepareSurfaces();
3737 getBounds(mTmpDimBoundsRect);
3738
3739 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3740 scheduleAnimation();
3741 }
3742 }
Robert Carr3b716242016-08-16 16:02:21 -07003743 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003744
Robert Carr9034d962018-01-04 18:27:42 -08003745 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3746 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3747 super(name, service);
3748 }
3749
3750 @Override
3751 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3752 }
3753 };
3754
Robert Carrb1579c82017-09-05 14:54:47 -07003755 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3756 return mService.makeSurfaceBuilder(s)
3757 .setParent(mWindowingLayer);
3758 }
3759
3760 @Override
3761 SurfaceSession getSession() {
3762 return mSession;
3763 }
3764
3765 @Override
3766 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003767 SurfaceSession s = child != null ? child.getSession() : getSession();
3768 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003769 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003770
3771 if (child == null) {
3772 return b;
3773 }
3774
Robert Carree4d4b92017-11-22 12:21:46 -08003775 return b.setName(child.getName())
3776 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003777 }
3778
3779 /**
3780 * The makeSurface variants are for use by the window-container
3781 * hierarchy. makeOverlay here is a function for various non windowing
3782 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3783 * and other potpourii.
3784 */
3785 SurfaceControl.Builder makeOverlay() {
3786 return mService.makeSurfaceBuilder(mSession)
3787 .setParent(mOverlayLayer);
3788 }
3789
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003790 /**
3791 * Reparents the given surface to mOverlayLayer.
3792 */
3793 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3794 transaction.reparent(surface, mOverlayLayer.getHandle());
3795 }
3796
Robert Carrb1579c82017-09-05 14:54:47 -07003797 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003798 applyMagnificationSpec(getPendingTransaction(), spec);
3799 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003800 }
3801
3802 @Override
3803 void onParentSet() {
3804 // Since we are the top of the SurfaceControl hierarchy here
3805 // we create the root surfaces explicitly rather than chaining
3806 // up as the default implementation in onParentSet does. So we
3807 // explicitly do NOT call super here.
3808 }
3809
3810 @Override
3811 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003812
3813 // These are layers as children of "mWindowingLayer"
3814 mBelowAppWindowsContainers.assignLayer(t, 0);
3815 mTaskStackContainers.assignLayer(t, 1);
3816 mAboveAppWindowsContainers.assignLayer(t, 2);
3817
3818 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003819 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003820
Robert Carree4d4b92017-11-22 12:21:46 -08003821 // In the case where we have an IME target that is not in split-screen
3822 // mode IME assignment is easy. We just need the IME to go directly above
3823 // the target. This way children of the target will naturally go above the IME
3824 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003825 //
Robert Carree4d4b92017-11-22 12:21:46 -08003826 // In the case of split-screen windowing mode, we need to elevate the IME above the
3827 // docked divider while keeping the app itself below the docked divider, so instead
3828 // we use relative layering of the IME targets child windows, and place the
3829 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003830 //
Robert Carree4d4b92017-11-22 12:21:46 -08003831 // In the case where we have no IME target we assign it where it's base layer would
3832 // place it in the AboveAppWindowContainers.
3833 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3834 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003835 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003836 // TODO: We need to use an extra level on the app surface to ensure
3837 // this is always above SurfaceView but always below attached window.
3838 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003839 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003840 }
3841
3842 // Above we have assigned layers to our children, now we ask them to assign
3843 // layers to their children.
3844 mBelowAppWindowsContainers.assignChildLayers(t);
3845 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003846 mAboveAppWindowsContainers.assignChildLayers(t,
3847 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003848 mImeWindowsContainers.assignChildLayers(t);
3849 }
3850
3851 /**
3852 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3853 * that the IME target is one of the docked applications. We'd like the docked divider to be
3854 * above both of the applications, and we'd like the IME to be above the docked divider.
3855 * However we need child windows of the applications to be above the IME (Text drag handles).
3856 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3857 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3858 * with {@link #WindowState#assignLayer}
3859 */
3860 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3861 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3862 }
3863
3864 @Override
Chavi Weingarten38804382018-02-15 21:00:15 +00003865 public void destroyAfterPendingTransaction(SurfaceControl surface) {
3866 mPendingDestroyingSurfaces.add(surface);
3867 }
3868
3869 /**
3870 * Destroys any surfaces that have been put into the pending list with
3871 * {@link #destroyAfterPendingTransaction}.
3872 */
3873 void onPendingTransactionApplied() {
3874 for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) {
3875 mPendingDestroyingSurfaces.get(i).destroy();
3876 }
3877 mPendingDestroyingSurfaces.clear();
3878 }
3879
3880 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003881 void prepareSurfaces() {
3882 final ScreenRotationAnimation screenRotationAnimation =
3883 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3884 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3885 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3886 mPendingTransaction.setMatrix(mWindowingLayer,
3887 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3888 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3889 mPendingTransaction.setPosition(mWindowingLayer,
3890 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3891 mPendingTransaction.setAlpha(mWindowingLayer,
3892 screenRotationAnimation.getEnterTransformation().getAlpha());
3893 }
3894 super.prepareSurfaces();
3895 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003896
3897 void assignStackOrdering(SurfaceControl.Transaction t) {
3898 mTaskStackContainers.assignStackOrdering(t);
3899 }
Craig Mautner59c00972012-07-30 12:10:24 -07003900}