blob: 332bdb7fa8fb203e3bf0673766228c84ef2da414 [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;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700141import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700142import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700143import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100144import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700145import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700146import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700147import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700148import android.view.Surface;
149import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100150import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700151import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700152
Bryce Lee48f4b572017-04-10 10:54:15 -0700153import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800154import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700155import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100156import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100157import com.android.server.wm.utils.RotationCache;
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;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100219 private final RotationCache<DisplayCutout, DisplayCutout> mDisplayCutoutCache
220 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100221
Andrii Kuliancd097992017-03-23 18:31:59 -0700222 /**
223 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
224 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
225 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
226 */
Craig Mautner59c00972012-07-30 12:10:24 -0700227 int mBaseDisplayWidth = 0;
228 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700229 /**
230 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
231 * but can be set from Settings or via shell command "adb shell wm density".
232 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
233 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700234 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700235 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700236 private final DisplayInfo mDisplayInfo = new DisplayInfo();
237 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700238 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000239 DisplayFrames mDisplayFrames;
240
Andrii Kulian06d07d62017-03-14 11:11:47 -0700241 /**
242 * For default display it contains real metrics, empty for others.
243 * @see WindowManagerService#createWatermarkInTransaction()
244 */
245 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
246 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
247 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700248
Andrii Kulian06d07d62017-03-14 11:11:47 -0700249 /**
250 * Compat metrics computed based on {@link #mDisplayMetrics}.
251 * @see #updateDisplayAndOrientation(int)
252 */
253 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
254
255 /** The desired scaling factor for compatible apps. */
256 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700257
Andrii Kulian8ee72852017-03-10 10:36:45 -0800258 /**
259 * Current rotation of the display.
260 * Constants as per {@link android.view.Surface.Rotation}.
261 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700262 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800263 */
264 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700265
Andrii Kulian8ee72852017-03-10 10:36:45 -0800266 /**
267 * Last applied orientation of the display.
268 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
269 *
270 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
271 */
272 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700273
Andrii Kulian8ee72852017-03-10 10:36:45 -0800274 /**
275 * Flag indicating that the application is receiving an orientation that has different metrics
276 * than it expected. E.g. Portrait instead of Landscape.
277 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700278 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800279 */
280 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700281
Andrii Kulian8ee72852017-03-10 10:36:45 -0800282 /**
283 * Orientation forced by some window. If there is no visible window that specifies orientation
284 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
285 *
286 * @see NonAppWindowContainers#getOrientation()
287 */
288 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700289
Andrii Kulian8ee72852017-03-10 10:36:45 -0800290 /**
291 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
292 * occluded.
293 *
294 * @see NonAppWindowContainers#getOrientation()
295 */
296 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
297
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700298 /**
299 * Keep track of wallpaper visibility to notify changes.
300 */
301 private boolean mLastWallpaperVisible = false;
302
Andrii Kulian06d07d62017-03-14 11:11:47 -0700303 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700304
Craig Mautner39834192012-09-02 07:47:24 -0700305 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700306 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700307 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700308 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800309 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700310
Craig Mautnerdc548482014-02-05 13:35:24 -0800311 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700312 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800313
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700314 /** Detect user tapping outside of current focused task bounds .*/
315 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700316
Craig Mautner6601b7b2013-04-29 10:29:11 -0700317 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700318 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700319
Craig Mautner6601b7b2013-04-29 10:29:11 -0700320 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800321 private final Rect mTmpRect = new Rect();
322 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700323 private final RectF mTmpRectF = new RectF();
324 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800325 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700326
Bryce Leef3c6a472017-11-14 14:53:06 -0800327 /** Used for handing back size of display */
328 private final Rect mTmpBounds = new Rect();
329
Craig Mautner95da1082014-02-24 17:54:35 -0800330 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700331 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800332
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700333 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700334 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700335
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800336 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800337 /** A collection of windows that provide tap exclude regions inside of them. */
338 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800339
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000340 private boolean mHaveBootMsg = false;
341 private boolean mHaveApp = false;
342 private boolean mHaveWallpaper = false;
343 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700344
345 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
346
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700347 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
348 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000349 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
350 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700351
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700352 // True if this display is in the process of being removed. Used to determine if the removal of
353 // the display's direct children should be allowed.
354 private boolean mRemovingDisplay = false;
355
Bryce Leed1871262017-06-12 14:12:29 -0700356 // {@code false} if this display is in the processing of being created.
357 private boolean mDisplayReady = false;
358
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800359 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700360
Robert Carrb1579c82017-09-05 14:54:47 -0700361 private final SurfaceSession mSession = new SurfaceSession();
362
363 /**
364 * We organize all top-level Surfaces in to the following layers.
365 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800366 * and omitted from Screen-Magnification, for example the strict mode flash or
367 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700368 * {@link #mWindowingLayer} contains everything else.
369 */
370 private SurfaceControl mOverlayLayer;
371
372 /**
373 * See {@link #mOverlayLayer}
374 */
375 private SurfaceControl mWindowingLayer;
376
377 /**
378 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
379 * <p>
380 * For these surfaces currently we use a surface based on the larger of width or height so we
381 * don't have to resize when rotating the display.
382 */
383 private int mSurfaceSize;
384
Chavi Weingarten38804382018-02-15 21:00:15 +0000385 /**
386 * A list of surfaces to be destroyed after {@link #mPendingTransaction} is applied.
387 */
388 private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>();
389
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100390 /** Temporary float array to retrieve 3x3 matrix values. */
391 private final float[] mTmpFloats = new float[9];
392
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800393 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
394 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800395 final AppWindowToken atoken = w.mAppToken;
396 if (winAnimator.mDrawState == READY_TO_SHOW) {
397 if (atoken == null || atoken.allDrawn) {
398 if (w.performShowLocked()) {
399 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
400 if (DEBUG_LAYOUT_REPEATS) {
401 mService.mWindowPlacerLocked.debugLayoutRepeats(
402 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
403 }
404 }
405 }
406 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800407 };
408
409 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
410 final WindowStateAnimator winAnimator = w.mWinAnimator;
411 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
412 return;
413 }
414
415 final int flags = w.mAttrs.flags;
416
417 // If this window is animating, make a note that we have an animating window and take
418 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100419 if (winAnimator.isAnimationSet()) {
420 final AnimationAdapter anim = w.getAnimation();
421 if (anim != null) {
422 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800423 mTmpWindow = w;
424 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100425 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800426 if (color != 0) {
427 final TaskStack stack = w.getStack();
428 if (stack != null) {
429 stack.setAnimationBackground(winAnimator, color);
430 }
431 }
432 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800433 }
434
435 // If this window's app token is running a detached wallpaper animation, make a note so
436 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200437 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
438 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
439 if (animation != null) {
440 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800441 mTmpWindow = w;
442 }
443
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200444 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800445 if (color != 0) {
446 final TaskStack stack = w.getStack();
447 if (stack != null) {
448 stack.setAnimationBackground(winAnimator, color);
449 }
450 }
451 }
452 };
453
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800454 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
455 final int lostFocusUid = mTmpWindow.mOwnerUid;
456 final Handler handler = mService.mH;
457 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
458 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
459 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
460 w.mAttrs.hideTimeoutMilliseconds);
461 }
462 }
463 };
464
465 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
466 final AppWindowToken focusedApp = mService.mFocusedApp;
467 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
468 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
469
470 if (!w.canReceiveKeys()) {
471 return false;
472 }
473
474 final AppWindowToken wtoken = w.mAppToken;
475
476 // If this window's application has been removed, just skip it.
477 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
478 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
479 + (wtoken.removed ? "removed" : "sendingToBottom"));
480 return false;
481 }
482
483 if (focusedApp == null) {
484 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
485 + " using new focus @ " + w);
486 mTmpWindow = w;
487 return true;
488 }
489
490 if (!focusedApp.windowsAreFocusable()) {
491 // Current focused app windows aren't focusable...
492 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
493 + " focusable using new focus @ " + w);
494 mTmpWindow = w;
495 return true;
496 }
497
498 // Descend through all of the app tokens and find the first that either matches
499 // win.mAppToken (return win) or mFocusedApp (return null).
500 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
501 if (focusedApp.compareTo(wtoken) > 0) {
502 // App stack below focused app stack. No focus for you!!!
503 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
504 "findFocusedWindow: Reached focused app=" + focusedApp);
505 mTmpWindow = null;
506 return true;
507 }
508 }
509
510 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
511 mTmpWindow = w;
512 return true;
513 };
514
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800515 private final Consumer<WindowState> mPerformLayout = w -> {
516 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
517 // wasting time and funky changes while a window is animating away.
518 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
519 || w.isGoneForLayoutLw();
520
521 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
522 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
523 + " mLayoutAttached=" + w.mLayoutAttached
524 + " screen changed=" + w.isConfigChanged());
525 final AppWindowToken atoken = w.mAppToken;
526 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200527 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800528 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
529 + " parentHidden=" + w.isParentWindowHidden());
530 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200531 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800532 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
533 + " parentHidden=" + w.isParentWindowHidden());
534 }
535
536 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
537 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
538 // since that means "perform layout as normal, just don't display").
539 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
540 || ((w.isConfigChanged() || w.setReportResizeHints())
541 && !w.isGoneForLayoutLw() &&
542 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
543 (w.mHasSurface && w.mAppToken != null &&
544 w.mAppToken.layoutConfigChanges)))) {
545 if (!w.mLayoutAttached) {
546 if (mTmpInitial) {
547 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
548 w.mContentChanged = false;
549 }
550 if (w.mAttrs.type == TYPE_DREAM) {
551 // Don't layout windows behind a dream, so that if it does stuff like hide
552 // the status bar we won't get a bad transition when it goes away.
553 mTmpWindow = w;
554 }
555 w.mLayoutNeeded = false;
556 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200557 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000558 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800559 w.mLayoutSeq = mService.mLayoutSeq;
560
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200561 // If this is the first layout, we need to initialize the last inset values as
562 // otherwise we'd immediately cause an unnecessary resize.
563 if (firstLayout) {
564 w.updateLastInsetValues();
565 }
566
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800567 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
568 + " mContainingFrame=" + w.mContainingFrame
569 + " mDisplayFrame=" + w.mDisplayFrame);
570 }
571 }
572 };
573
574 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
575 if (w.mLayoutAttached) {
576 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
577 + " mViewVisibility=" + w.mViewVisibility
578 + " mRelayoutCalled=" + w.mRelayoutCalled);
579 // If this view is GONE, then skip it -- keep the current frame, and let the caller
580 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
581 // windows, since that means "perform layout as normal, just don't display").
582 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
583 return;
584 }
585 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
586 || w.mLayoutNeeded) {
587 if (mTmpInitial) {
588 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
589 w.mContentChanged = false;
590 }
591 w.mLayoutNeeded = false;
592 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000593 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800594 w.mLayoutSeq = mService.mLayoutSeq;
595 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
596 + " mContainingFrame=" + w.mContainingFrame
597 + " mDisplayFrame=" + w.mDisplayFrame);
598 }
599 } else if (w.mAttrs.type == TYPE_DREAM) {
600 // Don't layout windows behind a dream, so that if it does stuff like hide the
601 // status bar we won't get a bad transition when it goes away.
602 mTmpWindow = mTmpWindow2;
603 }
604 };
605
606 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
607 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
608 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
609 return w.canBeImeTarget();
610 };
611
612 private final Consumer<WindowState> mApplyPostLayoutPolicy =
613 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
614 mService.mInputMethodTarget);
615
616 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
617 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
618 final boolean obscuredChanged = w.mObscured !=
619 mTmpApplySurfaceChangesTransactionState.obscured;
620 final RootWindowContainer root = mService.mRoot;
621 // Only used if default window
622 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
623
624 // Update effect.
625 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
626 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
627 final boolean isDisplayed = w.isDisplayedLw();
628
629 if (isDisplayed && w.isObscuringDisplay()) {
630 // This window completely covers everything behind it, so we want to leave all
631 // of them as undimmed (for performance reasons).
632 root.mObscuringWindow = w;
633 mTmpApplySurfaceChangesTransactionState.obscured = true;
634 }
635
636 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
637 root.handleNotObscuredLocked(w,
638 mTmpApplySurfaceChangesTransactionState.obscured,
639 mTmpApplySurfaceChangesTransactionState.syswin);
640
641 if (w.mHasSurface && isDisplayed) {
642 final int type = w.mAttrs.type;
643 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
644 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
645 mTmpApplySurfaceChangesTransactionState.syswin = true;
646 }
647 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
648 && w.mAttrs.preferredRefreshRate != 0) {
649 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
650 = w.mAttrs.preferredRefreshRate;
651 }
652 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
653 && w.mAttrs.preferredDisplayModeId != 0) {
654 mTmpApplySurfaceChangesTransactionState.preferredModeId
655 = w.mAttrs.preferredDisplayModeId;
656 }
657 }
658 }
659
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800660 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
661 && mWallpaperController.isWallpaperTarget(w)) {
662 // This is the wallpaper target and its obscured state changed... make sure the
663 // current wallpaper's visibility has been updated accordingly.
664 mWallpaperController.updateWallpaperVisibility();
665 }
666
chaviw161ea3e2018-01-31 12:01:12 -0800667 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800668
669 final WindowStateAnimator winAnimator = w.mWinAnimator;
670
671 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
672 w.mContentChanged = false;
673
674 // Moved from updateWindowsAndWallpaperLocked().
675 if (w.mHasSurface) {
676 // Take care of the window being ready to display.
677 final boolean committed = winAnimator.commitFinishDrawingLocked();
678 if (isDefaultDisplay && committed) {
679 if (w.mAttrs.type == TYPE_DREAM) {
680 // HACK: When a dream is shown, it may at that point hide the lock screen.
681 // So we need to redo the layout to let the phone window manager make this
682 // happen.
683 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
684 if (DEBUG_LAYOUT_REPEATS) {
685 surfacePlacer.debugLayoutRepeats(
686 "dream and commitFinishDrawingLocked true",
687 pendingLayoutChanges);
688 }
689 }
690 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
691 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
692 "First draw done in potential wallpaper target " + w);
693 root.mWallpaperMayChange = true;
694 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
695 if (DEBUG_LAYOUT_REPEATS) {
696 surfacePlacer.debugLayoutRepeats(
697 "wallpaper and commitFinishDrawingLocked true",
698 pendingLayoutChanges);
699 }
700 }
701 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800702 }
703
704 final AppWindowToken atoken = w.mAppToken;
705 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100706 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800707 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
708 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
709 mTmpUpdateAllDrawn.add(atoken);
710 }
711 }
712
713 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
714 && w.isDisplayedLw()) {
715 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
716 }
717
718 w.updateResizingWindowIfNeeded();
719 };
720
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800721 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800722 * Create new {@link DisplayContent} instance, add itself to the root window container and
723 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700724 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800725 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700726 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
727 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700728 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700729 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800730 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100731 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800732 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800733 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
734 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
735 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
736 + " new=" + display);
737 }
738
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700739 mDisplay = display;
740 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700741 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700742 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700743 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700744 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000745 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700746 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800747 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700748 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700749
Robert Carr74a66a22018-02-23 12:17:51 -0800750 // We use this as our arbitrary surface size for buffer-less parents
751 // that don't impose cropping on their children. It may need to be larger
752 // than the display size because fullscreen windows can be shifted offscreen
753 // due to surfaceInsets. 2 times the largest display dimension feels like an
754 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
755 // layers the ability to match their parent sizes and be able to skip
756 // such arbitrary size settings.
757 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700758
759 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
760 .setSize(mSurfaceSize, mSurfaceSize)
761 .setOpaque(true);
762 mWindowingLayer = b.setName("Display Root").build();
763 mOverlayLayer = b.setName("Display Overlays").build();
764
Robert Carrf59b8dd2017-10-02 18:58:36 -0700765 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700766 .setLayerStack(mWindowingLayer, mDisplayId)
767 .show(mWindowingLayer)
768 .setLayer(mOverlayLayer, 1)
769 .setLayerStack(mOverlayLayer, mDisplayId)
770 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700771 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700772
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700773 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700774 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700775 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700776 super.addChild(mAboveAppWindowsContainers, null);
777 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800778
779 // Add itself as a child to the root container.
780 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700781
782 // TODO(b/62541591): evaluate whether this is the best spot to declare the
783 // {@link DisplayContent} ready for use.
784 mDisplayReady = true;
785 }
786
787 boolean isReady() {
788 // The display is ready when the system and the individual display are both ready.
789 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700790 }
791
792 int getDisplayId() {
793 return mDisplayId;
794 }
795
Wale Ogunwale02319a62016-09-26 15:21:22 -0700796 WindowToken getWindowToken(IBinder binder) {
797 return mTokenMap.get(binder);
798 }
799
800 AppWindowToken getAppWindowToken(IBinder binder) {
801 final WindowToken token = getWindowToken(binder);
802 if (token == null) {
803 return null;
804 }
805 return token.asAppWindowToken();
806 }
807
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700808 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700809 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
810 if (dc != null) {
811 // We currently don't support adding a window token to the display if the display
812 // already has the binder mapped to another token. If there is a use case for supporting
813 // this moving forward we will either need to merge the WindowTokens some how or have
814 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700815 throw new IllegalArgumentException("Can't map token=" + token + " to display="
816 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700817 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700818 if (binder == null) {
819 throw new IllegalArgumentException("Can't map token=" + token + " to display="
820 + getName() + " binder is null");
821 }
822 if (token == null) {
823 throw new IllegalArgumentException("Can't map null token to display="
824 + getName() + " binder=" + binder);
825 }
826
Wale Ogunwale02319a62016-09-26 15:21:22 -0700827 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700828
829 if (token.asAppWindowToken() == null) {
830 // Add non-app token to container hierarchy on the display. App tokens are added through
831 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700832 switch (token.windowType) {
833 case TYPE_WALLPAPER:
834 mBelowAppWindowsContainers.addChild(token);
835 break;
836 case TYPE_INPUT_METHOD:
837 case TYPE_INPUT_METHOD_DIALOG:
838 mImeWindowsContainers.addChild(token);
839 break;
840 default:
841 mAboveAppWindowsContainers.addChild(token);
842 break;
843 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700844 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700845 }
846
847 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700848 final WindowToken token = mTokenMap.remove(binder);
849 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800850 token.setExiting();
851 }
852 return token;
853 }
854
855 /** Changes the display the input window token is housed on to this one. */
856 void reParentWindowToken(WindowToken token) {
857 final DisplayContent prevDc = token.getDisplayContent();
858 if (prevDc == this) {
859 return;
860 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800861 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
862 && token.asAppWindowToken() == null) {
863 // Removed the token from the map, but made sure it's not an app token before removing
864 // from parent.
865 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700866 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800867
868 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700869 }
870
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700871 void removeAppToken(IBinder binder) {
872 final WindowToken token = removeWindowToken(binder);
873 if (token == null) {
874 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
875 return;
876 }
877
878 final AppWindowToken appToken = token.asAppWindowToken();
879
880 if (appToken == null) {
881 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
882 return;
883 }
884
885 appToken.onRemovedFromDisplay();
886 }
887
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700888 Display getDisplay() {
889 return mDisplay;
890 }
891
Craig Mautner59c00972012-07-30 12:10:24 -0700892 DisplayInfo getDisplayInfo() {
893 return mDisplayInfo;
894 }
895
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700896 DisplayMetrics getDisplayMetrics() {
897 return mDisplayMetrics;
898 }
899
Andrii Kulian8ee72852017-03-10 10:36:45 -0800900 int getRotation() {
901 return mRotation;
902 }
903
904 void setRotation(int newRotation) {
905 mRotation = newRotation;
906 }
907
908 int getLastOrientation() {
909 return mLastOrientation;
910 }
911
912 void setLastOrientation(int orientation) {
913 mLastOrientation = orientation;
914 }
915
916 boolean getAltOrientation() {
917 return mAltOrientation;
918 }
919
920 void setAltOrientation(boolean altOrientation) {
921 mAltOrientation = altOrientation;
922 }
923
924 int getLastWindowForcedOrientation() {
925 return mLastWindowForcedOrientation;
926 }
927
Andrii Kulian06d07d62017-03-14 11:11:47 -0700928 /**
929 * Update rotation of the display.
930 *
931 * Returns true if the rotation has been changed. In this case YOU MUST CALL
932 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
933 */
934 boolean updateRotationUnchecked(boolean inTransaction) {
935 if (mService.mDeferredRotationPauseCount > 0) {
936 // Rotation updates have been paused temporarily. Defer the update until
937 // updates have been resumed.
938 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
939 return false;
940 }
941
942 ScreenRotationAnimation screenRotationAnimation =
943 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
944 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
945 // Rotation updates cannot be performed while the previous rotation change
946 // animation is still in progress. Skip this update. We will try updating
947 // again after the animation is finished and the display is unfrozen.
948 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
949 return false;
950 }
951 if (mService.mDisplayFrozen) {
952 // Even if the screen rotation animation has finished (e.g. isAnimating
953 // returns false), there is still some time where we haven't yet unfrozen
954 // the display. We also need to abort rotation here.
955 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
956 "Deferring rotation, still finishing previous rotation");
957 return false;
958 }
959
960 if (!mService.mDisplayEnabled) {
961 // No point choosing a rotation if the display is not enabled.
962 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
963 return false;
964 }
965
966 final int oldRotation = mRotation;
967 final int lastOrientation = mLastOrientation;
968 final boolean oldAltOrientation = mAltOrientation;
969 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700970 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700971 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700972
Robert Carr0e007272017-10-02 13:00:55 -0700973 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700974 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
975 if (seamlessRotated != null) {
976 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
977 // to complete (that is, waiting for windows to redraw). It's tempting to check
978 // w.mSeamlessRotationCount but that could be incorrect in the case of
979 // window-removal.
980 return false;
981 }
Robert Carr0e007272017-10-02 13:00:55 -0700982
983 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700984 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700985 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700986 mayRotateSeamlessly = false;
987 }
988 for (int i = 0; i < mService.mSessions.size(); i++) {
989 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
990 mayRotateSeamlessly = false;
991 break;
992 }
993 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700994 }
Robert Carr0e007272017-10-02 13:00:55 -0700995 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700996
997 // TODO: Implement forced rotation changes.
998 // Set mAltOrientation to indicate that the application is receiving
999 // an orientation that has different metrics than it expected.
1000 // eg. Portrait instead of Landscape.
1001
1002 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
1003 lastOrientation, rotation);
1004
1005 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
1006 + ", got rotation " + rotation + " which has "
1007 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1008
1009 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1010 // No change.
1011 return false;
1012 }
1013
1014 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1015 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1016 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1017
1018 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1019 mService.mWaitingForConfig = true;
1020 }
1021
1022 mRotation = rotation;
1023 mAltOrientation = altOrientation;
1024 if (isDefaultDisplay) {
1025 mService.mPolicy.setRotationLw(rotation);
1026 }
1027
1028 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1029 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1030 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1031 WINDOW_FREEZE_TIMEOUT_DURATION);
1032
1033 setLayoutNeeded();
1034 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001035 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001036
1037 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001038 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001039 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1040 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1041 mDisplayId);
1042 } else {
1043 // The screen rotation animation uses a screenshot to freeze the screen
1044 // while windows resize underneath.
1045 // When we are rotating seamlessly, we allow the elements to transition
1046 // to their rotated state independently and without a freeze required.
1047 screenRotationAnimation = null;
1048
1049 // We have to reset this in case a window was removed before it
1050 // finished seamless rotation.
1051 mService.mSeamlessRotationCount = 0;
1052 }
1053
1054 // We need to update our screen size information to match the new rotation. If the rotation
1055 // has actually changed then this method will return true and, according to the comment at
1056 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1057 // By updating the Display info here it will be available to
1058 // #computeScreenConfiguration() later.
1059 updateDisplayAndOrientation(getConfiguration().uiMode);
1060
1061 if (!inTransaction) {
1062 if (SHOW_TRANSACTIONS) {
1063 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1064 }
1065 mService.openSurfaceTransaction();
1066 }
1067 try {
1068 // NOTE: We disable the rotation in the emulator because
1069 // it doesn't support hardware OpenGL emulation yet.
1070 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1071 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001072 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001073 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1074 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1075 mService.scheduleAnimationLocked();
1076 }
1077 }
1078
1079 if (rotateSeamlessly) {
1080 forAllWindows(w -> {
1081 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1082 }, true /* traverseTopToBottom */);
1083 }
1084
1085 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1086 } finally {
1087 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001088 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001089 if (SHOW_LIGHT_TRANSACTIONS) {
1090 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1091 }
1092 }
1093 }
1094
1095 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001096 if (w.mHasSurface && !rotateSeamlessly) {
1097 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001098 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001099 mService.mRoot.mOrientationChangeComplete = false;
1100 w.mLastFreezeDuration = 0;
1101 }
1102 w.mReportOrientationChanged = true;
1103 }, true /* traverseTopToBottom */);
1104
1105 if (rotateSeamlessly) {
1106 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1107 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1108 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1109 }
1110
1111 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1112 final WindowManagerService.RotationWatcher rotationWatcher
1113 = mService.mRotationWatchers.get(i);
1114 if (rotationWatcher.mDisplayId == mDisplayId) {
1115 try {
1116 rotationWatcher.mWatcher.onRotationChanged(rotation);
1117 } catch (RemoteException e) {
1118 // Ignore
1119 }
1120 }
1121 }
1122
1123 // TODO (multi-display): Magnification is supported only for the default display.
1124 // Announce rotation only if we will not animate as we already have the
1125 // windows in final state. Otherwise, we make this call at the rotation end.
1126 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1127 && isDefaultDisplay) {
1128 mService.mAccessibilityController.onRotationChangedLocked(this);
1129 }
1130
1131 return true;
1132 }
1133
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001134 void configureDisplayPolicy() {
1135 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1136 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1137
1138 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
1139 }
1140
Andrii Kulian06d07d62017-03-14 11:11:47 -07001141 /**
1142 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1143 * changed.
1144 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1145 */
1146 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1147 // Use the effective "visual" dimensions based on current rotation
1148 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1149 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1150 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1151 int dw = realdw;
1152 int dh = realdh;
1153
1154 if (mAltOrientation) {
1155 if (realdw > realdh) {
1156 // Turn landscape into portrait.
1157 int maxw = (int)(realdh/1.3f);
1158 if (maxw < realdw) {
1159 dw = maxw;
1160 }
1161 } else {
1162 // Turn portrait into landscape.
1163 int maxh = (int)(realdw/1.3f);
1164 if (maxh < realdh) {
1165 dh = maxh;
1166 }
1167 }
1168 }
1169
1170 // Update application display metrics.
Adrian Roos11c25582018-02-19 18:06:36 +01001171 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1172 mRotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001173 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001174 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001175 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001176 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001177 mDisplayInfo.rotation = mRotation;
1178 mDisplayInfo.logicalWidth = dw;
1179 mDisplayInfo.logicalHeight = dh;
1180 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1181 mDisplayInfo.appWidth = appWidth;
1182 mDisplayInfo.appHeight = appHeight;
1183 if (isDefaultDisplay) {
1184 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1185 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1186 }
Adrian Roos11c25582018-02-19 18:06:36 +01001187 mDisplayInfo.displayCutout = displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001188 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1189 if (mDisplayScalingDisabled) {
1190 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1191 } else {
1192 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1193 }
1194
1195 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1196 mDisplayInfo);
1197
1198 mBaseDisplayRect.set(0, 0, dw, dh);
1199
1200 if (isDefaultDisplay) {
1201 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1202 mCompatDisplayMetrics);
1203 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001204
1205 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001206 return mDisplayInfo;
1207 }
1208
Adrian Roos11c25582018-02-19 18:06:36 +01001209 DisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001210 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1211 }
1212
1213 private DisplayCutout calculateDisplayCutoutForRotationUncached(
1214 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001215 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos1cf585052018-01-03 18:43:27 +01001216 return cutout;
1217 }
Adrian Roos11c25582018-02-19 18:06:36 +01001218 if (rotation == ROTATION_0) {
Adrian Roos24264212018-02-19 16:26:15 +01001219 return cutout.computeSafeInsets(mInitialDisplayWidth, mInitialDisplayHeight);
1220 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001221 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001222 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001223 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1224 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001225 bounds.transform(mTmpMatrix);
Adrian Roos24264212018-02-19 16:26:15 +01001226 return DisplayCutout.fromBounds(bounds).computeSafeInsets(
1227 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1228 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001229 }
1230
Andrii Kulian06d07d62017-03-14 11:11:47 -07001231 /**
1232 * Compute display configuration based on display properties and policy settings.
1233 * Do not call if mDisplayReady == false.
1234 */
1235 void computeScreenConfiguration(Configuration config) {
1236 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1237
1238 final int dw = displayInfo.logicalWidth;
1239 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001240 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1241 // TODO: Probably best to set this based on some setting in the display content object,
1242 // so the display can be configured for things like fullscreen.
1243 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001244
Adrian Roos11c25582018-02-19 18:06:36 +01001245 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001246 config.screenWidthDp =
1247 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001248 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001249 config.screenHeightDp =
1250 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001251 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001252
Adrian Roos11c25582018-02-19 18:06:36 +01001253 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1254 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001255 final int leftInset = mTmpRect.left;
1256 final int topInset = mTmpRect.top;
1257 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001258 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1259 leftInset + displayInfo.appWidth /* right */,
1260 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001261 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1262 || displayInfo.rotation == Surface.ROTATION_270);
1263
1264 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001265 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001266
1267 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1268 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1269 ? Configuration.SCREENLAYOUT_ROUND_YES
1270 : Configuration.SCREENLAYOUT_ROUND_NO);
1271
1272 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1273 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1274 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1275 dh, mDisplayId);
1276 config.densityDpi = displayInfo.logicalDensityDpi;
1277
1278 config.colorMode =
1279 (displayInfo.isHdr()
1280 ? Configuration.COLOR_MODE_HDR_YES
1281 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001282 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001283 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1284 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1285
1286 // Update the configuration based on available input devices, lid switch,
1287 // and platform configuration.
1288 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1289 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1290 config.navigation = Configuration.NAVIGATION_NONAV;
1291
1292 int keyboardPresence = 0;
1293 int navigationPresence = 0;
1294 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1295 final int len = devices != null ? devices.length : 0;
1296 for (int i = 0; i < len; i++) {
1297 InputDevice device = devices[i];
1298 if (!device.isVirtual()) {
1299 final int sources = device.getSources();
1300 final int presenceFlag = device.isExternal() ?
1301 WindowManagerPolicy.PRESENCE_EXTERNAL :
1302 WindowManagerPolicy.PRESENCE_INTERNAL;
1303
1304 // TODO(multi-display): Configure on per-display basis.
1305 if (mService.mIsTouchDevice) {
1306 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1307 InputDevice.SOURCE_TOUCHSCREEN) {
1308 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1309 }
1310 } else {
1311 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1312 }
1313
1314 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1315 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1316 navigationPresence |= presenceFlag;
1317 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1318 && config.navigation == Configuration.NAVIGATION_NONAV) {
1319 config.navigation = Configuration.NAVIGATION_DPAD;
1320 navigationPresence |= presenceFlag;
1321 }
1322
1323 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1324 config.keyboard = Configuration.KEYBOARD_QWERTY;
1325 keyboardPresence |= presenceFlag;
1326 }
1327 }
1328 }
1329
1330 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1331 config.navigation = Configuration.NAVIGATION_DPAD;
1332 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1333 }
1334
1335 // Determine whether a hard keyboard is available and enabled.
1336 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1337 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1338 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1339 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1340 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1341 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1342 }
1343
1344 // Let the policy update hidden states.
1345 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1346 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1347 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1348 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1349 }
1350
1351 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1352 int displayId) {
1353 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1354 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1355 final int unrotDw, unrotDh;
1356 if (rotated) {
1357 unrotDw = dh;
1358 unrotDh = dw;
1359 } else {
1360 unrotDw = dw;
1361 unrotDh = dh;
1362 }
1363 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1364 displayId);
1365 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1366 displayId);
1367 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1368 displayId);
1369 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1370 displayId);
1371 return sw;
1372 }
1373
1374 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1375 DisplayMetrics dm, int dw, int dh, int displayId) {
1376 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001377 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001378 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001379 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001380 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1381 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1382 if (curSize == 0 || size < curSize) {
1383 curSize = size;
1384 }
1385 return curSize;
1386 }
1387
1388 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1389 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1390
1391 // We need to determine the smallest width that will occur under normal
1392 // operation. To this, start with the base screen size and compute the
1393 // width under the different possible rotations. We need to un-rotate
1394 // the current screen dimensions before doing this.
1395 int unrotDw, unrotDh;
1396 if (rotated) {
1397 unrotDw = dh;
1398 unrotDh = dw;
1399 } else {
1400 unrotDw = dw;
1401 unrotDh = dh;
1402 }
1403 displayInfo.smallestNominalAppWidth = 1<<30;
1404 displayInfo.smallestNominalAppHeight = 1<<30;
1405 displayInfo.largestNominalAppWidth = 0;
1406 displayInfo.largestNominalAppHeight = 0;
1407 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1408 unrotDh);
1409 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1410 unrotDw);
1411 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1412 unrotDh);
1413 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1414 unrotDw);
1415 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1416 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1417 displayId);
1418 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1419 displayId);
1420 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1421 displayId);
1422 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1423 displayId);
1424 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1425 outConfig.screenLayout = sl;
1426 }
1427
1428 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1429 int uiMode, int displayId) {
1430 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001431 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1432 mDisplayInfo.displayCutout);
1433 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1434 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001435
1436 // Compute the screen layout size class for this rotation.
1437 int longSize = w;
1438 int shortSize = h;
1439 if (longSize < shortSize) {
1440 int tmp = longSize;
1441 longSize = shortSize;
1442 shortSize = tmp;
1443 }
1444 longSize = (int)(longSize/density);
1445 shortSize = (int)(shortSize/density);
1446 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1447 }
1448
1449 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1450 int uiMode, int dw, int dh) {
Adrian Roos11c25582018-02-19 18:06:36 +01001451 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001452 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001453 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001454 if (width < displayInfo.smallestNominalAppWidth) {
1455 displayInfo.smallestNominalAppWidth = width;
1456 }
1457 if (width > displayInfo.largestNominalAppWidth) {
1458 displayInfo.largestNominalAppWidth = width;
1459 }
1460 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001461 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001462 if (height < displayInfo.smallestNominalAppHeight) {
1463 displayInfo.smallestNominalAppHeight = height;
1464 }
1465 if (height > displayInfo.largestNominalAppHeight) {
1466 displayInfo.largestNominalAppHeight = height;
1467 }
1468 }
1469
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001470 DockedStackDividerController getDockedDividerController() {
1471 return mDividerControllerLocked;
1472 }
1473
Winson Chung655332c2016-10-31 13:14:28 -07001474 PinnedStackController getPinnedStackController() {
1475 return mPinnedStackControllerLocked;
1476 }
1477
Jeff Browna506a6e2013-06-04 00:02:38 -07001478 /**
1479 * Returns true if the specified UID has access to this display.
1480 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001481 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001482 return mDisplay.hasAccess(uid);
1483 }
1484
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001485 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001486 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001487 }
1488
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001489 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001490 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001491 }
1492
Wale Ogunwale61911492017-10-11 08:50:50 -07001493 /**
1494 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1495 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001496 TaskStack getSplitScreenPrimaryStack() {
1497 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001498 return (stack != null && stack.isVisible()) ? stack : null;
1499 }
1500
1501 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001502 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001503 * not visible.
1504 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001505 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1506 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001507 }
1508
1509 TaskStack getPinnedStack() {
1510 return mTaskStackContainers.getPinnedStack();
1511 }
1512
1513 private boolean hasPinnedStack() {
1514 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001515 }
1516
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001517 /**
1518 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1519 * Null is no compatible stack on the display.
1520 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001521 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001522 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1523 }
1524
1525 /**
1526 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1527 * activity type. Null is no compatible stack on the display.
1528 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001529 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001530 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001531 }
1532
Bryce Lee48f4b572017-04-10 10:54:15 -07001533 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001534 TaskStack getTopStack() {
1535 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001536 }
1537
Winson Chunge2d72172018-01-25 17:46:20 +00001538 ArrayList<Task> getVisibleTasks() {
1539 return mTaskStackContainers.getVisibleTasks();
1540 }
1541
Wale Ogunwale61911492017-10-11 08:50:50 -07001542 void onStackWindowingModeChanged(TaskStack stack) {
1543 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001544 }
1545
Andrii Kulian441e4492016-09-29 15:25:00 -07001546 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001547 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001548 super.onConfigurationChanged(newParentConfig);
1549
Andrii Kulian3a507b52016-09-19 18:14:12 -07001550 // The display size information is heavily dependent on the resources in the current
1551 // configuration, so we need to reconfigure it every time the configuration changes.
1552 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1553 mService.reconfigureDisplayLocked(this);
1554
Bryce Leef3c6a472017-11-14 14:53:06 -08001555 final DockedStackDividerController dividerController = getDockedDividerController();
1556
1557 if (dividerController != null) {
1558 getDockedDividerController().onConfigurationChanged();
1559 }
1560
1561 final PinnedStackController pinnedStackController = getPinnedStackController();
1562
1563 if (pinnedStackController != null) {
1564 getPinnedStackController().onConfigurationChanged();
1565 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001566 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001567
Andrii Kulian441e4492016-09-29 15:25:00 -07001568 /**
1569 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1570 * bounds were updated.
1571 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001572 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001573 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1574 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001575 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001576 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001577 }
1578 }
Winson Chung32c566f2017-04-11 18:31:21 -07001579
1580 // If there was no pinned stack, we still need to notify the controller of the display info
1581 // update as a result of the config change. We do this here to consolidate the flow between
1582 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001583 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001584 mPinnedStackControllerLocked.onDisplayInfoChanged();
1585 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001586 }
1587
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001588 @Override
1589 boolean fillsParent() {
1590 return true;
1591 }
1592
1593 @Override
1594 boolean isVisible() {
1595 return true;
1596 }
1597
1598 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001599 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001600 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001601 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001602 }
1603
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001604 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001605 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1606 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1607 // target, or here in order if there isn't an IME target.
1608 if (traverseTopToBottom) {
1609 for (int i = mChildren.size() - 1; i >= 0; --i) {
1610 final DisplayChildWindowContainer child = mChildren.get(i);
1611 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1612 // In this case the Ime windows will be processed above their target so we skip
1613 // here.
1614 continue;
1615 }
1616 if (child.forAllWindows(callback, traverseTopToBottom)) {
1617 return true;
1618 }
1619 }
1620 } else {
1621 final int count = mChildren.size();
1622 for (int i = 0; i < count; i++) {
1623 final DisplayChildWindowContainer child = mChildren.get(i);
1624 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1625 // In this case the Ime windows will be processed above their target so we skip
1626 // here.
1627 continue;
1628 }
1629 if (child.forAllWindows(callback, traverseTopToBottom)) {
1630 return true;
1631 }
1632 }
1633 }
1634 return false;
1635 }
1636
1637 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1638 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1639 }
1640
Wale Ogunwale399c8692017-05-08 14:22:42 -07001641 @Override
1642 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001643 final WindowManagerPolicy policy = mService.mPolicy;
1644
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001645 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001646 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001647 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001648 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001649 // If the display is frozen, some activities may be in the middle of restarting, and
1650 // thus have removed their old window. If the window has the flag to hide the lock
1651 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1652 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001653 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001654 } else if (policy.isKeyguardLocked()) {
1655 // Use the last orientation the while the display is frozen with the keyguard
1656 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1657 // window. We don't want to check the show when locked window directly though as
1658 // things aren't stable while the display is frozen, for example the window could be
1659 // momentarily unavailable due to activity relaunch.
1660 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001661 + "return " + mLastOrientation);
1662 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001663 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001664 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001665 final int orientation = mAboveAppWindowsContainers.getOrientation();
1666 if (orientation != SCREEN_ORIENTATION_UNSET) {
1667 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001668 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001669 }
1670
Wale Ogunwale399c8692017-05-08 14:22:42 -07001671 // Top system windows are not requesting an orientation. Start searching from apps.
1672 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001673 }
1674
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001675 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001676 // Check if display metrics changed and update base values if needed.
1677 updateBaseDisplayMetricsIfNeeded();
1678
Craig Mautner722285e2012-09-07 13:55:58 -07001679 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001680 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001681
Wale Ogunwale61911492017-10-11 08:50:50 -07001682 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1683 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001684 }
Craig Mautner722285e2012-09-07 13:55:58 -07001685 }
1686
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001687 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001688 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1689 if (displayManagerInternal != null) {
1690 // Bootstrap the default logical display from the display manager.
1691 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1692 if (newDisplayInfo != null) {
1693 mDisplayInfo.copyFrom(newDisplayInfo);
1694 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001695 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001696
Andrii Kuliancd097992017-03-23 18:31:59 -07001697 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1698 mDisplayInfo.logicalDensityDpi);
1699 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1700 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1701 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001702 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001703 }
1704
Andrii Kuliancd097992017-03-23 18:31:59 -07001705 /**
1706 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1707 * values.
1708 */
1709 private void updateBaseDisplayMetricsIfNeeded() {
1710 // Get real display metrics without overrides from WM.
1711 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1712 final int orientation = mDisplayInfo.rotation;
1713 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1714 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1715 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1716 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001717 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001718
1719 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1720 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001721 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1722 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001723
1724 if (displayMetricsChanged) {
1725 // Check if display size or density is forced.
1726 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1727 || mBaseDisplayHeight != mInitialDisplayHeight;
1728 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1729
1730 // If there is an override set for base values - use it, otherwise use new values.
1731 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1732 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1733 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1734
1735 // Real display metrics changed, so we should also update initial values.
1736 mInitialDisplayWidth = newWidth;
1737 mInitialDisplayHeight = newHeight;
1738 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001739 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001740 mService.reconfigureDisplayLocked(this);
1741 }
1742 }
1743
Bryce Lee27cec322017-03-21 09:41:37 -07001744 /** Sets the maximum width the screen resolution can be */
1745 void setMaxUiWidth(int width) {
1746 if (DEBUG_DISPLAY) {
1747 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1748 }
1749
1750 mMaxUiWidth = width;
1751
1752 // Update existing metrics.
1753 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1754 }
1755
1756 /** Update base (override) display metrics. */
1757 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1758 mBaseDisplayWidth = baseWidth;
1759 mBaseDisplayHeight = baseHeight;
1760 mBaseDisplayDensity = baseDensity;
1761
1762 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1763 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1764 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1765 mBaseDisplayWidth = mMaxUiWidth;
1766
1767 if (DEBUG_DISPLAY) {
1768 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1769 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1770 + " on display:" + getDisplayId());
1771 }
1772 }
1773
1774 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001775
1776 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001777 }
1778
Wale Ogunwaledb506192017-12-08 10:57:32 -08001779 void getStableRect(Rect out) {
1780 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001781 }
1782
Wale Ogunwale61911492017-10-11 08:50:50 -07001783 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001784 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1785 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001786
Wale Ogunwale61911492017-10-11 08:50:50 -07001787 final TaskStack stack = new TaskStack(mService, stackId, controller);
1788 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001789 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001790 }
1791
Andrii Kulian51c1b672017-04-07 18:39:32 -07001792 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001793 final DisplayContent prevDc = stack.getDisplayContent();
1794 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001795 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1796 + " which is not currently attached to any display");
1797 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001798 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001799 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1800 + " to its current displayId=" + mDisplayId);
1801 }
1802
Wale Ogunwale61911492017-10-11 08:50:50 -07001803 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001804 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001805 }
1806
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001807 @Override
1808 protected void addChild(DisplayChildWindowContainer child,
1809 Comparator<DisplayChildWindowContainer> comparator) {
1810 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1811 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001812
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001813 @Override
1814 protected void addChild(DisplayChildWindowContainer child, int index) {
1815 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1816 }
1817
1818 @Override
1819 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001820 // Only allow removal of direct children from this display if the display is in the process
1821 // of been removed.
1822 if (mRemovingDisplay) {
1823 super.removeChild(child);
1824 return;
1825 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001826 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001827 }
1828
Andrii Kuliand2765632016-12-12 22:26:34 -08001829 @Override
1830 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1831 // Children of the display are statically ordered, so the real intention here is to perform
1832 // the operation on the display and not the static direct children.
1833 getParent().positionChildAt(position, this, includingParents);
1834 }
1835
Winson Chung59a47ded2018-01-25 17:46:06 +00001836 void positionStackAt(int position, TaskStack child) {
1837 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1838 layoutAndAssignWindowLayersIfNeeded();
1839 }
1840
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001841 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001842 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1843 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001844 final int taskId = stack.taskIdFromPoint(x, y);
1845 if (taskId != -1) {
1846 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001847 }
1848 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001849 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001850 }
1851
Chong Zhang8e89b312015-09-09 15:09:30 -07001852 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001853 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001854 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001855 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001856 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001857 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001858 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001859 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1860 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001861 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001862 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001863 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001864
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001865 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1866 if (mTmpTaskForResizePointSearchResult.searchDone) {
1867 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001868 }
1869 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001870 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001871 }
1872
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001873 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001874 // The provided task is the task on this display with focus, so if WindowManagerService's
1875 // focused app is not on this display, focusedTask will be null.
1876 if (focusedTask == null) {
1877 mTouchExcludeRegion.setEmpty();
1878 } else {
1879 mTouchExcludeRegion.set(mBaseDisplayRect);
1880 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1881 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001882 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1883 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001884 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1885 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001886 }
1887 // If we removed the focused task above, add it back and only leave its
1888 // outside touch area in the exclusion. TapDectector is not interested in
1889 // any touch inside the focused task itself.
1890 if (!mTmpRect2.isEmpty()) {
1891 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1892 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001893 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001894 final WindowState inputMethod = mService.mInputMethodWindow;
1895 if (inputMethod != null && inputMethod.isVisibleLw()) {
1896 // If the input method is visible and the user is typing, we don't want these touch
1897 // events to be intercepted and used to change focus. This would likely cause a
1898 // disappearance of the input method.
1899 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001900 if (inputMethod.getDisplayId() == mDisplayId) {
1901 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1902 } else {
1903 // IME is on a different display, so we need to update its tap detector.
1904 // TODO(multidisplay): Remove when IME will always appear on same display.
1905 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1906 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001907 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001908 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001909 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001910 win.getTouchableRegion(mTmpRegion);
1911 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1912 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001913 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1914 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1915 win.amendTapExcludeRegion(mTouchExcludeRegion);
1916 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001917 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001918 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001919 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001920 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001921 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1922 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001923 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001924 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001925 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001926 }
1927
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001928 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001929 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001930 super.switchUser();
1931 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001932 }
1933
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001934 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001935 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1936 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001937 }
1938 }
1939
Wale Ogunwale10124582016-09-15 20:25:50 -07001940 @Override
1941 void removeIfPossible() {
1942 if (isAnimating()) {
1943 mDeferredRemoval = true;
1944 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001945 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001946 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001947 }
1948
Wale Ogunwale10124582016-09-15 20:25:50 -07001949 @Override
1950 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001951 mRemovingDisplay = true;
1952 try {
1953 super.removeImmediately();
1954 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001955 if (mService.canDispatchPointerEvents()) {
1956 if (mTapDetector != null) {
1957 mService.unregisterPointerEventListener(mTapDetector);
1958 }
1959 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1960 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1961 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001962 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001963 mService.mAnimator.removeDisplayLocked(mDisplayId);
Chavi Weingarten38804382018-02-15 21:00:15 +00001964
1965 // The pending transaction won't be applied so we should
1966 // just clean up any surfaces pending destruction.
1967 onPendingTransactionApplied();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001968 } finally {
1969 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001970 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001971
1972 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001973 }
1974
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001975 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001976 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001977 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001978 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1979
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001980 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001981 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001982 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001983 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001984 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001985 }
1986
Andrii Kulian0214ed92017-05-16 13:44:05 -07001987 /** @return 'true' if removal of this display content is deferred due to active animation. */
1988 boolean isRemovalDeferred() {
1989 return mDeferredRemoval;
1990 }
1991
Wale Ogunwale10124582016-09-15 20:25:50 -07001992 boolean animateForIme(float interpolatedValue, float animationTarget,
1993 float dividerAnimationTarget) {
1994 boolean updated = false;
1995
Wale Ogunwale61911492017-10-11 08:50:50 -07001996 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1997 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001998 if (stack == null || !stack.isAdjustedForIme()) {
1999 continue;
2000 }
2001
2002 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
2003 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2004 updated = true;
2005 } else {
2006 mDividerControllerLocked.mLastAnimationProgress =
2007 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2008 mDividerControllerLocked.mLastDividerProgress =
2009 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2010 updated |= stack.updateAdjustForIme(
2011 mDividerControllerLocked.mLastAnimationProgress,
2012 mDividerControllerLocked.mLastDividerProgress,
2013 false /* force */);
2014 }
2015 if (interpolatedValue >= 1f) {
2016 stack.endImeAdjustAnimation();
2017 }
2018 }
2019
2020 return updated;
2021 }
2022
2023 boolean clearImeAdjustAnimation() {
2024 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002025 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2026 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002027 if (stack != null && stack.isAdjustedForIme()) {
2028 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2029 changed = true;
2030 }
2031 }
2032 return changed;
2033 }
2034
2035 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002036 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2037 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002038 if (stack.isVisible() && stack.isAdjustedForIme()) {
2039 stack.beginImeAdjustAnimation();
2040 }
2041 }
2042 }
2043
2044 void adjustForImeIfNeeded() {
2045 final WindowState imeWin = mService.mInputMethodWindow;
2046 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2047 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002048 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002049 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2050 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2051 imeTargetStack.getDockSide() : DOCKED_INVALID;
2052 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2053 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2054 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002055 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002056 final boolean imeHeightChanged = imeVisible &&
2057 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2058
2059 // The divider could be adjusted for IME position, or be thinner than usual,
2060 // or both. There are three possible cases:
2061 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2062 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2063 // - If IME is not visible, divider is not moved and is normal width.
2064
2065 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002066 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2067 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002068 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002069 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2070 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002071 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2072 } else {
2073 stack.resetAdjustedForIme(false);
2074 }
2075 }
2076 mDividerControllerLocked.setAdjustedForIme(
2077 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2078 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002079 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2080 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002081 stack.resetAdjustedForIme(!dockVisible);
2082 }
2083 mDividerControllerLocked.setAdjustedForIme(
2084 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2085 }
Winson Chung655332c2016-10-31 13:14:28 -07002086 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002087 }
2088
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002089 /**
2090 * If a window that has an animation specifying a colored background and the current wallpaper
2091 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2092 * suddenly disappear.
2093 */
2094 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002095 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2096 w -> w.mIsWallpaper && w.isVisibleNow());
2097
2098 if (visibleWallpaper != null) {
2099 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002100 }
2101 return winAnimator.mAnimLayer;
2102 }
2103
Wale Ogunwale10124582016-09-15 20:25:50 -07002104 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002105 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2106 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002107 stack.prepareFreezingTaskBounds();
2108 }
2109 }
2110
Wale Ogunwale94744212015-09-21 19:01:47 -07002111 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002112 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002113
2114 // Compute a transform matrix to undo the coordinate space transformation,
2115 // and present the window at the same physical position it previously occupied.
2116 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2117 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2118
2119 mTmpRectF.set(bounds);
2120 mTmpMatrix.mapRect(mTmpRectF);
2121 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002122 }
2123
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002124 static int deltaRotation(int oldRotation, int newRotation) {
2125 int delta = newRotation - oldRotation;
2126 if (delta < 0) delta += 4;
2127 return delta;
2128 }
2129
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002130 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002131 Matrix outMatrix) {
2132 // For rotations without Z-ordering we don't need the target rectangle's position.
2133 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2134 displayHeight, outMatrix);
2135 }
2136
2137 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2138 float displayWidth, float displayHeight, Matrix outMatrix) {
2139 switch (rotation) {
2140 case ROTATION_0:
2141 outMatrix.reset();
2142 break;
2143 case ROTATION_270:
2144 outMatrix.setRotate(270, 0, 0);
2145 outMatrix.postTranslate(0, displayHeight);
2146 outMatrix.postTranslate(rectTop, 0);
2147 break;
2148 case ROTATION_180:
2149 outMatrix.reset();
2150 break;
2151 case ROTATION_90:
2152 outMatrix.setRotate(90, 0, 0);
2153 outMatrix.postTranslate(displayWidth, 0);
2154 outMatrix.postTranslate(-rectTop, rectLeft);
2155 break;
2156 }
2157 }
2158
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002159 @CallSuper
2160 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002161 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002162 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002163 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002164 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002165 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2166 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002167 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002168 }
2169 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2170 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002171 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2172 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002173 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002174 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002175 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2176 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002177 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002178 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002179 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2180 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002181 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002182 }
2183 proto.write(DPI, mBaseDisplayDensity);
2184 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002185 proto.write(ROTATION, mRotation);
2186 final ScreenRotationAnimation screenRotationAnimation =
2187 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2188 if (screenRotationAnimation != null) {
2189 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2190 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002191 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002192 proto.end(token);
2193 }
2194
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002195 @Override
2196 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2197 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002198 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2199 final String subPrefix = " " + prefix;
2200 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2201 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2202 pw.print("dpi");
2203 if (mInitialDisplayWidth != mBaseDisplayWidth
2204 || mInitialDisplayHeight != mBaseDisplayHeight
2205 || mInitialDisplayDensity != mBaseDisplayDensity) {
2206 pw.print(" base=");
2207 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2208 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2209 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002210 if (mDisplayScalingDisabled) {
2211 pw.println(" noscale");
2212 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002213 pw.print(" cur=");
2214 pw.print(mDisplayInfo.logicalWidth);
2215 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2216 pw.print(" app=");
2217 pw.print(mDisplayInfo.appWidth);
2218 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2219 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2220 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2221 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2222 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002223 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002224 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002225 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002226
Craig Mautnerdc548482014-02-05 13:35:24 -08002227 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002228 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002229 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2230 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002231 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002232 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002233
Craig Mautnerdc548482014-02-05 13:35:24 -08002234 pw.println();
2235 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002236 pw.println();
2237 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002238 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002239 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002240 pw.print(" Exiting #"); pw.print(i);
2241 pw.print(' '); pw.print(token);
2242 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002243 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002244 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002245 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002246
Jorim Jaggi31f71702016-05-04 16:43:04 -07002247 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002248
2249 // Dump stack references
2250 final TaskStack homeStack = getHomeStack();
2251 if (homeStack != null) {
2252 pw.println(prefix + "homeStack=" + homeStack.getName());
2253 }
2254 final TaskStack pinnedStack = getPinnedStack();
2255 if (pinnedStack != null) {
2256 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2257 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002258 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002259 if (splitScreenPrimaryStack != null) {
2260 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2261 }
2262
2263 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002264 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002265 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002266 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002267
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002268 pw.println();
2269 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002270 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002271
2272 @Override
2273 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002274 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002275 }
2276
2277 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002278 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002279 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002280
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002281 /** Returns true if the stack in the windowing mode is visible. */
2282 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002283 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002284 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002285 }
2286
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002287 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002288 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002289 final int x = (int) xf;
2290 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002291 final WindowState touchedWin = getWindow(w -> {
2292 final int flags = w.mAttrs.flags;
2293 if (!w.isVisibleLw()) {
2294 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002295 }
2296 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002297 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002298 }
2299
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002300 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002301 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002302 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002303 }
2304
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002305 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002306
2307 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002308 return mTmpRegion.contains(x, y) || touchFlags == 0;
2309 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002310
2311 return touchedWin;
2312 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002313
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002314 boolean canAddToastWindowForUid(int uid) {
2315 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002316 // Also if the app is focused adding more than one toast at
2317 // a time for better backwards compatibility.
2318 final WindowState focusedWindowForUid = getWindow(w ->
2319 w.mOwnerUid == uid && w.isFocused());
2320 if (focusedWindowForUid != null) {
2321 return true;
2322 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002323 final WindowState win = getWindow(w ->
2324 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2325 && !w.mWindowRemovalAllowed);
2326 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002327 }
2328
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002329 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002330 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2331 return;
2332 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002333
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002334 // Used to communicate the old focus to the callback method.
2335 mTmpWindow = oldFocus;
2336
2337 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002338 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002339
2340 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002341 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002342
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002343 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002344
2345 if (mTmpWindow == null) {
2346 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2347 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002348 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002349 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002350 }
2351
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002352 /** Updates the layer assignment of windows on this display. */
2353 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002354 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002355 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002356 if (setLayoutNeeded) {
2357 setLayoutNeeded();
2358 }
Robert Carrb1579c82017-09-05 14:54:47 -07002359
Robert Carrf59b8dd2017-10-02 18:58:36 -07002360 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002361 // the application of this transaction until the animation pass triggers
2362 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2363 // the hiding and showing of surfaces.
2364 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002365 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002366 }
2367
Wale Ogunwale1666e312016-12-16 11:27:18 -08002368 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2369 // moving containers or resizing them. Need to investigate the best way to have it automatically
2370 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002371 void layoutAndAssignWindowLayersIfNeeded() {
2372 mService.mWindowsChanged = true;
2373 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002374
2375 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2376 false /*updateInputWindows*/)) {
2377 assignWindowLayers(false /* setLayoutNeeded */);
2378 }
2379
2380 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2381 mService.mWindowPlacerLocked.performSurfacePlacement();
2382 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2383 }
2384
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002385 /** Returns true if a leaked surface was destroyed */
2386 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002387 // Used to indicate that a surface was leaked.
2388 mTmpWindow = null;
2389 forAllWindows(w -> {
2390 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002391 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002392 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002393 }
2394 if (!mService.mSessions.contains(wsa.mSession)) {
2395 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002396 + w + " surface=" + wsa.mSurfaceController
2397 + " token=" + w.mToken
2398 + " pid=" + w.mSession.mPid
2399 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002400 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002401 mService.mForceRemoves.add(w);
2402 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002403 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002404 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002405 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002406 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002407 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002408 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002409 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002410 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002411 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002412
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002413 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002414 }
2415
2416 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002417 * Determine and return the window that should be the IME target.
2418 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2419 * @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 +00002420 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002421 WindowState computeImeTarget(boolean updateImeTarget) {
2422 if (mService.mInputMethodWindow == null) {
2423 // There isn't an IME so there shouldn't be a target...That was easy!
2424 if (updateImeTarget) {
2425 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2426 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002427 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002428 }
2429 return null;
2430 }
2431
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002432 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2433 // same display. Or even when the current IME/target are not on the same screen as the next
2434 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002435 mUpdateImeTarget = updateImeTarget;
2436 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002437
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002438
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002439 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2440 // to be on top of it, but it is not -really- where input will go. So look down below
2441 // for a real window to target...
2442 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2443 final AppWindowToken token = target.mAppToken;
2444 if (token != null) {
2445 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2446 if (betterTarget != null) {
2447 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002448 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002449 }
2450 }
2451
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002452 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2453 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002454
2455 // Now, a special case -- if the last target's window is in the process of exiting, and is
2456 // above the new target, keep on the last target to avoid flicker. Consider for example a
2457 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2458 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2459 // scrim.
2460 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002461 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2462 && (target == null
2463 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002464 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002465 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002466 }
2467
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002468 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2469 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002470
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002471 if (target == null) {
2472 if (updateImeTarget) {
2473 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2474 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2475 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002476 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002477 }
2478
2479 return null;
2480 }
2481
2482 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002483 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2484 if (token != null) {
2485
2486 // Now some fun for dealing with window animations that modify the Z order. We need
2487 // to look at all windows below the current target that are in this app, finding the
2488 // highest visible one in layering.
2489 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002490 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002491 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002492 }
2493
2494 if (highestTarget != null) {
2495 final AppTransition appTransition = mService.mAppTransition;
2496 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2497 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2498 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002499 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002500
2501 if (appTransition.isTransitionSet()) {
2502 // If we are currently setting up for an animation, hold everything until we
2503 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002504 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002505 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002506 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002507 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002508 // If the window we are currently targeting is involved with an animation,
2509 // and it is on top of the next target we will be over, then hold off on
2510 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002511 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002512 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002513 }
2514 }
2515 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002516
2517 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2518 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002519 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002520 }
2521
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002522 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002523 }
2524
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002525 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002526 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002527 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002528 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002529 }
2530
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002531 mService.mInputMethodTarget = target;
2532 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002533 assignWindowLayers(false /* setLayoutNeeded */);
2534 }
2535
2536 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2537 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2538 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2539 }
2540
2541 // Used to indicate we have reached the first window in the range we are interested in.
2542 mTmpWindow = null;
2543
2544 // TODO: Figure-out a more efficient way to do this.
2545 final WindowState candidate = getWindow(w -> {
2546 if (w == top) {
2547 // Reached the first window in the range we are interested in.
2548 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002549 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002550 if (mTmpWindow == null) {
2551 return false;
2552 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002553
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002554 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2555 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002556 }
2557 // If we reached the bottom of the range of windows we are considering,
2558 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002559 if (w == bottom) {
2560 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002561 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002562 return false;
2563 });
2564
2565 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002566 }
2567
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002568 void setLayoutNeeded() {
2569 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2570 mLayoutNeeded = true;
2571 }
2572
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002573 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002574 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2575 mLayoutNeeded = false;
2576 }
2577
2578 boolean isLayoutNeeded() {
2579 return mLayoutNeeded;
2580 }
2581
Wale Ogunwale02319a62016-09-26 15:21:22 -07002582 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2583 if (mTokenMap.isEmpty()) {
2584 return;
2585 }
2586 pw.println(" Display #" + mDisplayId);
2587 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2588 while (it.hasNext()) {
2589 final WindowToken token = it.next();
2590 pw.print(" ");
2591 pw.print(token);
2592 if (dumpAll) {
2593 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002594 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002595 } else {
2596 pw.println();
2597 }
2598 }
2599 }
2600
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002601 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002602 final int[] index = new int[1];
2603 forAllWindows(w -> {
2604 final WindowStateAnimator wAnim = w.mWinAnimator;
2605 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2606 index[0] = index[0] + 1;
2607 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002608 }
2609
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002610 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002611 forAllWindows(w -> {
2612 w.mWinAnimator.enableSurfaceTrace(fd);
2613 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002614 }
2615
2616 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002617 forAllWindows(w -> {
2618 w.mWinAnimator.disableSurfaceTrace();
2619 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002620 }
2621
Jorim Jaggife762342016-10-13 14:33:27 +02002622 /**
2623 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2624 */
2625 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2626 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002627 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002628 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2629 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002630 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002631 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002632 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002633 }
2634
Wale Ogunwale494009b82016-10-21 09:01:38 -07002635 boolean checkWaitingForWindows() {
2636
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002637 mHaveBootMsg = false;
2638 mHaveApp = false;
2639 mHaveWallpaper = false;
2640 mHaveKeyguard = true;
2641
2642 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002643 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2644 return true;
2645 }
2646 if (w.isDrawnLw()) {
2647 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002648 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002649 } else if (w.mAttrs.type == TYPE_APPLICATION
2650 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002651 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002652 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002653 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002654 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002655 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002656 }
2657 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002658 return false;
2659 });
2660
2661 if (visibleWindow != null) {
2662 // We have a visible window.
2663 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002664 }
2665
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002666 // if the wallpaper service is disabled on the device, we're never going to have
2667 // wallpaper, don't bother waiting for it
2668 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2669 com.android.internal.R.bool.config_enableWallpaperService)
2670 && !mService.mOnlyCore;
2671
Wale Ogunwale494009b82016-10-21 09:01:38 -07002672 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2673 "******** booted=" + mService.mSystemBooted
2674 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002675 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2676 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2677 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002678
2679 // If we are turning on the screen to show the boot message, don't do it until the boot
2680 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002681 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002682 return true;
2683 }
2684
2685 // If we are turning on the screen after the boot is completed normally, don't do so until
2686 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002687 if (mService.mSystemBooted
2688 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002689 return true;
2690 }
2691
2692 return false;
2693 }
2694
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002695 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002696 mTmpWindowAnimator = animator;
2697 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002698 }
2699
2700 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002701 resetAnimationBackgroundAnimator();
2702
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002703 // Used to indicate a detached wallpaper.
2704 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002705 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002706
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002707 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002708
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002709 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002710 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002711 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2712 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002713 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2714 }
2715 }
2716
Wale Ogunwale494009b82016-10-21 09:01:38 -07002717 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002718 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002719 if (imFocus == null) {
2720 return false;
2721 }
2722
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002723 if (DEBUG_INPUT_METHOD) {
2724 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2725 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2726 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002727 }
2728
Wale Ogunwale494009b82016-10-21 09:01:38 -07002729 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2730
2731 if (DEBUG_INPUT_METHOD) {
2732 Slog.i(TAG_WM, "IM target client: " + imeClient);
2733 if (imeClient != null) {
2734 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2735 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2736 }
2737 }
2738
2739 return imeClient != null && imeClient.asBinder() == client.asBinder();
2740 }
2741
2742 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002743 final WindowState win = getWindow(
2744 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2745 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002746 }
2747
2748 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002749 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002750 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002751 final int curValue = w.mSystemUiVisibility;
2752 final int diff = (curValue ^ visibility) & globalDiff;
2753 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002754 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002755 w.mSeq++;
2756 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002757 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002758 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2759 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002760 visibility, newValue, diff);
2761 }
2762 } catch (RemoteException e) {
2763 // so sorry
2764 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002765 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002766 }
2767
2768 void onWindowFreezeTimeout() {
2769 Slog.w(TAG_WM, "Window freeze timeout expired.");
2770 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002771
2772 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002773 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002774 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002775 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002776 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002777 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2778 - mService.mDisplayFreezeTime);
2779 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002780 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002781 mService.mWindowPlacerLocked.performSurfacePlacement();
2782 }
2783
2784 void waitForAllWindowsDrawn() {
2785 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002786 forAllWindows(w -> {
2787 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2788 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2789 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002790 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002791 w.mLastContentInsets.set(-1, -1, -1, -1);
2792 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002793 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002794 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002795 }
2796
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002797 // TODO: Super crazy long method that should be broken down...
2798 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2799
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002800 final int dw = mDisplayInfo.logicalWidth;
2801 final int dh = mDisplayInfo.logicalHeight;
2802 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2803
2804 mTmpUpdateAllDrawn.clear();
2805
2806 int repeats = 0;
2807 do {
2808 repeats++;
2809 if (repeats > 6) {
2810 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2811 clearLayoutNeeded();
2812 break;
2813 }
2814
2815 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2816 pendingLayoutChanges);
2817
Andrii Kulian839def92016-11-02 10:58:58 -07002818 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2819 // the wallpaper window jumping across displays.
2820 // Remove check for default display when there will be support for multiple wallpaper
2821 // targets (on different displays).
2822 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002823 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002824 }
2825
2826 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2827 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2828 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2829 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002830 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002831 }
2832 }
2833
2834 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2835 setLayoutNeeded();
2836 }
2837
2838 // FIRST LOOP: Perform a layout, if needed.
2839 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2840 performLayout(repeats == 1, false /* updateInputWindows */);
2841 } else {
2842 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2843 }
2844
2845 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2846 pendingLayoutChanges = 0;
2847
2848 if (isDefaultDisplay) {
2849 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002850 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002851 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2852 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2853 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2854 }
2855 } while (pendingLayoutChanges != 0);
2856
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002857 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002858
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002859 mTmpRecoveringMemory = recoveringMemory;
2860 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002861 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002862
2863 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002864 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2865 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2866 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002867 true /* inTraversal, must call performTraversalInTrans... below */);
2868
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002869 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2870 if (wallpaperVisible != mLastWallpaperVisible) {
2871 mLastWallpaperVisible = wallpaperVisible;
2872 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2873 }
2874
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002875 while (!mTmpUpdateAllDrawn.isEmpty()) {
2876 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2877 // See if any windows have been drawn, so they (and others associated with them)
2878 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002879 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002880 }
2881
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002882 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002883 }
2884
Bryce Leef3c6a472017-11-14 14:53:06 -08002885 private void updateBounds() {
2886 calculateBounds(mTmpBounds);
2887 setBounds(mTmpBounds);
2888 }
2889
2890 // Determines the current display bounds based on the current state
2891 private void calculateBounds(Rect out) {
2892 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2893 final int orientation = mDisplayInfo.rotation;
2894 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2895 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2896 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2897 int width = mDisplayInfo.logicalWidth;
2898 int left = (physWidth - width) / 2;
2899 int height = mDisplayInfo.logicalHeight;
2900 int top = (physHeight - height) / 2;
2901 out.set(left, top, left + width, top + height);
2902 }
2903
2904 @Override
2905 public void getBounds(Rect out) {
2906 calculateBounds(out);
2907 }
2908
2909 private void getBounds(Rect out, int orientation) {
2910 getBounds(out);
2911
2912 // Rotate the Rect if needed.
2913 final int currentRotation = mDisplayInfo.rotation;
2914 final int rotationDelta = deltaRotation(currentRotation, orientation);
2915 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2916 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2917 mTmpRectF.set(out);
2918 mTmpMatrix.mapRect(mTmpRectF);
2919 mTmpRectF.round(out);
2920 }
2921 }
2922
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002923 void performLayout(boolean initial, boolean updateInputWindows) {
2924 if (!isLayoutNeeded()) {
2925 return;
2926 }
2927 clearLayoutNeeded();
2928
2929 final int dw = mDisplayInfo.logicalWidth;
2930 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002931 if (DEBUG_LAYOUT) {
2932 Slog.v(TAG, "-------------------------------------");
2933 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2934 }
2935
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002936 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
2937 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2938 // display info above...
2939 mDisplayFrames.mRotation = mRotation;
2940 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002941 if (isDefaultDisplay) {
2942 // Not needed on non-default displays.
2943 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2944 mService.mScreenRect.set(0, 0, dw, dh);
2945 }
2946
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002947 int seq = mService.mLayoutSeq + 1;
2948 if (seq < 0) seq = 0;
2949 mService.mLayoutSeq = seq;
2950
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002951 // Used to indicate that we have processed the dream window and all additional windows are
2952 // behind it.
2953 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002954 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002955
2956 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002957 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002958
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002959 // Used to indicate that we have processed the dream window and all additional attached
2960 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002961 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002962 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002963
2964 // Now perform layout of attached windows, which usually depend on the position of the
2965 // window they are attached to. XXX does not deal with windows that are attached to windows
2966 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002967 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002968
2969 // Window frames may have changed. Tell the input dispatcher about it.
2970 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2971 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2972 if (updateInputWindows) {
2973 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2974 }
2975
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002976 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2977 }
2978
2979 /**
2980 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2981 * In portrait mode, it grabs the full screenshot.
2982 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002983 * @param config of the output bitmap
2984 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2985 */
chaviwfbe47df2017-11-10 16:14:49 -08002986 Bitmap screenshotDisplay(Bitmap.Config config, boolean wallpaperOnly) {
2987 synchronized (mService.mWindowMap) {
Jorim Jaggi51304d72017-05-17 17:25:32 +02002988 if (!mService.mPolicy.isScreenOn()) {
chaviwfbe47df2017-11-10 16:14:49 -08002989 if (DEBUG_SCREENSHOT) {
2990 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002991 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002992 return null;
2993 }
2994
chaviwfbe47df2017-11-10 16:14:49 -08002995 if (wallpaperOnly && !shouldScreenshotWallpaper()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002996 return null;
2997 }
2998
chaviwfbe47df2017-11-10 16:14:49 -08002999 int dw = mDisplayInfo.logicalWidth;
3000 int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003001
chaviwfbe47df2017-11-10 16:14:49 -08003002 if (dw <= 0 || dh <= 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003003 return null;
3004 }
3005
chaviwfbe47df2017-11-10 16:14:49 -08003006 final Rect frame = new Rect(0, 0, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003007
3008 // The screenshot API does not apply the current screen rotation.
3009 int rot = mDisplay.getRotation();
3010
3011 if (rot == ROTATION_90 || rot == ROTATION_270) {
3012 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3013 }
3014
chaviwfbe47df2017-11-10 16:14:49 -08003015 // SurfaceFlinger is not aware of orientation, so convert our logical
3016 // crop to SurfaceFlinger's portrait orientation.
3017 convertCropForSurfaceFlinger(frame, rot, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003018
3019 final ScreenRotationAnimation screenRotationAnimation =
3020 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3021 final boolean inRotation = screenRotationAnimation != null &&
3022 screenRotationAnimation.isAnimating();
chaviwfbe47df2017-11-10 16:14:49 -08003023 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003024
Robert Carrb1579c82017-09-05 14:54:47 -07003025 // TODO(b/68392460): We should screenshot Task controls directly
3026 // but it's difficult at the moment as the Task doesn't have the
3027 // correct size set.
chaviwfbe47df2017-11-10 16:14:49 -08003028 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003029 if (bitmap == null) {
Robert Carrb1579c82017-09-05 14:54:47 -07003030 Slog.w(TAG_WM, "Failed to take screenshot");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003031 return null;
3032 }
chaviwfbe47df2017-11-10 16:14:49 -08003033
3034 // Create a copy of the screenshot that is immutable and backed in ashmem.
3035 // This greatly reduces the overhead of passing the bitmap between processes.
3036 final Bitmap ret = bitmap.createAshmemBitmap(config);
3037 bitmap.recycle();
3038 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003039 }
chaviwfbe47df2017-11-10 16:14:49 -08003040 }
3041
3042 private boolean shouldScreenshotWallpaper() {
3043 MutableBoolean screenshotReady = new MutableBoolean(false);
3044
3045 forAllWindows(w -> {
3046 if (!w.mIsWallpaper) {
3047 return false;
3048 }
3049
3050 // Found the wallpaper window
3051 final WindowStateAnimator winAnim = w.mWinAnimator;
3052
3053 if (winAnim.getShown() && winAnim.mLastAlpha > 0f) {
3054 screenshotReady.value = true;
3055 }
3056
3057 return true;
3058 }, true /* traverseTopToBottom */);
3059
3060 return screenshotReady.value;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003061 }
3062
3063 // TODO: Can this use createRotationMatrix()?
3064 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3065 if (rot == Surface.ROTATION_90) {
3066 final int tmp = crop.top;
3067 crop.top = dw - crop.right;
3068 crop.right = crop.bottom;
3069 crop.bottom = dw - crop.left;
3070 crop.left = tmp;
3071 } else if (rot == Surface.ROTATION_180) {
3072 int tmp = crop.top;
3073 crop.top = dh - crop.bottom;
3074 crop.bottom = dh - tmp;
3075 tmp = crop.right;
3076 crop.right = dw - crop.left;
3077 crop.left = dw - tmp;
3078 } else if (rot == Surface.ROTATION_270) {
3079 final int tmp = crop.top;
3080 crop.top = crop.left;
3081 crop.left = dh - crop.bottom;
3082 crop.bottom = crop.right;
3083 crop.right = dh - tmp;
3084 }
3085 }
3086
3087 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003088 // Used to indicate the layout is needed.
3089 mTmpWindow = null;
3090
3091 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003092 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003093 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003094 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003095 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003096 w.setDisplayLayoutNeeded();
3097 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003098 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003099
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003100 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003101 mService.mWindowPlacerLocked.performSurfacePlacement();
3102 }
3103 }
3104
Wale Ogunwale1666e312016-12-16 11:27:18 -08003105 void setExitingTokensHasVisible(boolean hasVisible) {
3106 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3107 mExitingTokens.get(i).hasVisible = hasVisible;
3108 }
3109
3110 // Initialize state of exiting applications.
3111 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3112 }
3113
3114 void removeExistingTokensIfPossible() {
3115 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3116 final WindowToken token = mExitingTokens.get(i);
3117 if (!token.hasVisible) {
3118 mExitingTokens.remove(i);
3119 }
3120 }
3121
3122 // Time to remove any exiting applications?
3123 mTaskStackContainers.removeExistingAppTokensIfPossible();
3124 }
3125
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003126 @Override
3127 void onDescendantOverrideConfigurationChanged() {
3128 setLayoutNeeded();
3129 mService.requestTraversal();
3130 }
3131
David Stevens9440dc82017-03-16 19:00:20 -07003132 boolean okToDisplay() {
3133 if (mDisplayId == DEFAULT_DISPLAY) {
3134 return !mService.mDisplayFrozen
3135 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3136 }
3137 return mDisplayInfo.state == Display.STATE_ON;
3138 }
3139
3140 boolean okToAnimate() {
3141 return okToDisplay() &&
3142 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3143 }
3144
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003145 static final class TaskForResizePointSearchResult {
3146 boolean searchDone;
3147 Task taskForResize;
3148
3149 void reset() {
3150 searchDone = false;
3151 taskForResize = null;
3152 }
3153 }
Robert Carr3b716242016-08-16 16:02:21 -07003154
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003155 private static final class ApplySurfaceChangesTransactionState {
3156 boolean displayHasContent;
3157 boolean obscured;
3158 boolean syswin;
3159 boolean focusDisplayed;
3160 float preferredRefreshRate;
3161 int preferredModeId;
3162
3163 void reset() {
3164 displayHasContent = false;
3165 obscured = false;
3166 syswin = false;
3167 focusDisplayed = false;
3168 preferredRefreshRate = 0;
3169 preferredModeId = 0;
3170 }
3171 }
3172
3173 private static final class ScreenshotApplicationState {
3174 WindowState appWin;
3175 int maxLayer;
3176 int minLayer;
3177 boolean screenshotReady;
3178
3179 void reset(boolean screenshotReady) {
3180 appWin = null;
3181 maxLayer = 0;
3182 minLayer = 0;
3183 this.screenshotReady = screenshotReady;
3184 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3185 }
3186 }
3187
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003188 /**
3189 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3190 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3191 * homogeneous children type which is currently required by sub-classes of
3192 * {@link WindowContainer} class.
3193 */
3194 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3195
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003196 DisplayChildWindowContainer(WindowManagerService service) {
3197 super(service);
3198 }
3199
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003200 @Override
3201 boolean fillsParent() {
3202 return true;
3203 }
3204
3205 @Override
3206 boolean isVisible() {
3207 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003208 }
3209 }
3210
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003211 /**
3212 * Window container class that contains all containers on this display relating to Apps.
3213 * I.e Activities.
3214 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003215 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003216 /**
3217 * A control placed at the appropriate level for transitions to occur.
3218 */
chaviw23ee71c2017-12-18 11:29:41 -08003219 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003220
Robert Carrf7a7ca82017-12-06 13:17:07 -08003221 /**
3222 * Given that the split-screen divider does not have an AppWindowToken, it
3223 * will have to live inside of a "NonAppWindowContainer", in particular
3224 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3225 * it will need to be interleaved with some of our children, appearing on top of
3226 * both docked stacks but underneath any assistant stacks.
3227 *
3228 * To solve this problem we have this anchor control, which will always exist so
3229 * we can always assign it the correct value in our {@link #assignChildLayers}.
3230 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3231 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3232 * events between the two containers.
3233 */
3234 SurfaceControl mSplitScreenDividerAnchor = null;
3235
Wale Ogunwale61911492017-10-11 08:50:50 -07003236 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3237 // through the list to find them.
3238 private TaskStack mHomeStack = null;
3239 private TaskStack mPinnedStack = null;
3240 private TaskStack mSplitScreenPrimaryStack = null;
3241
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003242 TaskStackContainers(WindowManagerService service) {
3243 super(service);
3244 }
3245
Wale Ogunwale61911492017-10-11 08:50:50 -07003246 /**
3247 * Returns the topmost stack on the display that is compatible with the input windowing mode
3248 * and activity type. Null is no compatible stack on the display.
3249 */
3250 TaskStack getStack(int windowingMode, int activityType) {
3251 if (activityType == ACTIVITY_TYPE_HOME) {
3252 return mHomeStack;
3253 }
3254 if (windowingMode == WINDOWING_MODE_PINNED) {
3255 return mPinnedStack;
3256 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3257 return mSplitScreenPrimaryStack;
3258 }
3259 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3260 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003261 if (activityType == ACTIVITY_TYPE_UNDEFINED
3262 && windowingMode == stack.getWindowingMode()) {
3263 // Passing in undefined type means we want to match the topmost stack with the
3264 // windowing mode.
3265 return stack;
3266 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003267 if (stack.isCompatible(windowingMode, activityType)) {
3268 return stack;
3269 }
3270 }
3271 return null;
3272 }
3273
3274 @VisibleForTesting
3275 TaskStack getTopStack() {
3276 return mTaskStackContainers.getChildCount() > 0
3277 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3278 }
3279
3280 TaskStack getHomeStack() {
3281 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3282 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3283 }
3284 return mHomeStack;
3285 }
3286
3287 TaskStack getPinnedStack() {
3288 return mPinnedStack;
3289 }
3290
Matthew Ng64e77cf2017-10-31 14:01:31 -07003291 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003292 return mSplitScreenPrimaryStack;
3293 }
3294
Winson Chunge2d72172018-01-25 17:46:20 +00003295 ArrayList<Task> getVisibleTasks() {
3296 final ArrayList<Task> visibleTasks = new ArrayList<>();
3297 forAllTasks(task -> {
3298 if (task.isVisible()) {
3299 visibleTasks.add(task);
3300 }
3301 });
3302 return visibleTasks;
3303 }
3304
Andrii Kulian839def92016-11-02 10:58:58 -07003305 /**
3306 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003307 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003308 */
3309 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003310 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003311 addChild(stack, onTop);
3312 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003313 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003314
Wale Ogunwale61911492017-10-11 08:50:50 -07003315 void onStackWindowingModeChanged(TaskStack stack) {
3316 removeStackReferenceIfNeeded(stack);
3317 addStackReferenceIfNeeded(stack);
3318 if (stack == mPinnedStack && getTopStack() != stack) {
3319 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3320 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3321 }
3322 }
3323
3324 private void addStackReferenceIfNeeded(TaskStack stack) {
3325 if (stack.isActivityTypeHome()) {
3326 if (mHomeStack != null) {
3327 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3328 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3329 }
3330 mHomeStack = stack;
3331 }
3332 final int windowingMode = stack.getWindowingMode();
3333 if (windowingMode == WINDOWING_MODE_PINNED) {
3334 if (mPinnedStack != null) {
3335 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3336 + mPinnedStack + " already exist on display=" + this
3337 + " stack=" + stack);
3338 }
3339 mPinnedStack = stack;
3340 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3341 if (mSplitScreenPrimaryStack != null) {
3342 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3343 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3344 + " already exist on display=" + this + " stack=" + stack);
3345 }
3346 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003347 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003348 }
3349 }
3350
3351 private void removeStackReferenceIfNeeded(TaskStack stack) {
3352 if (stack == mHomeStack) {
3353 mHomeStack = null;
3354 } else if (stack == mPinnedStack) {
3355 mPinnedStack = null;
3356 } else if (stack == mSplitScreenPrimaryStack) {
3357 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003358 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3359 mService.setDockedStackCreateStateLocked(
3360 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3361 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003362 }
Andrii Kulian839def92016-11-02 10:58:58 -07003363 }
3364
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003365 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003366 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3367 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003368 addChild(stack, addIndex);
3369 setLayoutNeeded();
3370 }
3371
Wale Ogunwale61911492017-10-11 08:50:50 -07003372 @Override
3373 protected void removeChild(TaskStack stack) {
3374 super.removeChild(stack);
3375 removeStackReferenceIfNeeded(stack);
3376 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003377
3378 @Override
3379 boolean isOnTop() {
3380 // Considered always on top
3381 return true;
3382 }
3383
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003384 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003385 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003386 if (child.getWindowConfiguration().isAlwaysOnTop()
3387 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003388 // This stack is always-on-top, override the default behavior.
3389 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3390
3391 // Moving to its current position, as we must call super but we don't want to
3392 // perform any meaningful action.
3393 final int currentPosition = mChildren.indexOf(child);
3394 super.positionChildAt(currentPosition, child, false /* includingParents */);
3395 return;
3396 }
3397
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003398 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3399 super.positionChildAt(targetPosition, child, includingParents);
3400
3401 setLayoutNeeded();
3402 }
3403
3404 /**
3405 * When stack is added or repositioned, find a proper position for it.
3406 * This will make sure that pinned stack always stays on top.
3407 * @param requestedPosition Position requested by caller.
3408 * @param stack Stack to be added or positioned.
3409 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3410 * @return The proper position for the stack.
3411 */
3412 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3413 final int topChildPosition = mChildren.size() - 1;
3414 boolean toTop = requestedPosition == POSITION_TOP;
3415 toTop |= adding ? requestedPosition >= topChildPosition + 1
3416 : requestedPosition >= topChildPosition;
3417 int targetPosition = requestedPosition;
3418
Wale Ogunwale61911492017-10-11 08:50:50 -07003419 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003420 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003421 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003422 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003423 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3424 }
3425
3426 // So, stack is moved just below the pinned stack.
3427 // When we're adding a new stack the target is the current pinned stack position.
3428 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003429 // stack, because WindowContainer#positionAt() first removes element and then adds
3430 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003431 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3432 }
3433
3434 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003435 }
3436
3437 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003438 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3439 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003440 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003441 if (super.forAllWindows(callback, traverseTopToBottom)) {
3442 return true;
3443 }
3444 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3445 return true;
3446 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003447 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003448 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3449 return true;
3450 }
3451 if (super.forAllWindows(callback, traverseTopToBottom)) {
3452 return true;
3453 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003454 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003455 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003456 }
3457
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003458 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003459 boolean traverseTopToBottom) {
3460 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3461 // app tokens.
3462 // TODO: Investigate if we need to continue to do this or if we can just process them
3463 // in-order.
3464 if (traverseTopToBottom) {
3465 for (int i = mChildren.size() - 1; i >= 0; --i) {
3466 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3467 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003468 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3469 traverseTopToBottom)) {
3470 return true;
3471 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003472 }
3473 }
3474 } else {
3475 final int count = mChildren.size();
3476 for (int i = 0; i < count; ++i) {
3477 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3478 final int appTokensCount = appTokens.size();
3479 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003480 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3481 traverseTopToBottom)) {
3482 return true;
3483 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003484 }
3485 }
3486 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003487 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003488 }
3489
Wale Ogunwale1666e312016-12-16 11:27:18 -08003490 void setExitingTokensHasVisible(boolean hasVisible) {
3491 for (int i = mChildren.size() - 1; i >= 0; --i) {
3492 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3493 for (int j = appTokens.size() - 1; j >= 0; --j) {
3494 appTokens.get(j).hasVisible = hasVisible;
3495 }
3496 }
3497 }
3498
3499 void removeExistingAppTokensIfPossible() {
3500 for (int i = mChildren.size() - 1; i >= 0; --i) {
3501 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3502 for (int j = appTokens.size() - 1; j >= 0; --j) {
3503 final AppWindowToken token = appTokens.get(j);
3504 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3505 && (!token.mIsExiting || token.isEmpty())) {
3506 // Make sure there is no animation running on this token, so any windows
3507 // associated with it will be removed as soon as their animations are
3508 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003509 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003510 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3511 "performLayout: App token exiting now removed" + token);
3512 token.removeIfPossible();
3513 }
3514 }
3515 }
3516 }
3517
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003518 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003519 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003520 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3521 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003522 // Apps and their containers are not allowed to specify an orientation while the
3523 // docked or freeform stack is visible...except for the home stack/task if the
3524 // docked stack is minimized and it actually set something.
3525 if (mHomeStack != null && mHomeStack.isVisible()
3526 && mDividerControllerLocked.isMinimizedDock()) {
3527 final int orientation = mHomeStack.getOrientation();
3528 if (orientation != SCREEN_ORIENTATION_UNSET) {
3529 return orientation;
3530 }
3531 }
3532 return SCREEN_ORIENTATION_UNSPECIFIED;
3533 }
3534
3535 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003536 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3537 PackageManager.FEATURE_AUTOMOTIVE);
3538 if (isCar) {
3539 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3540 // allow anything but the default orientation.
3541 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3542 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3543 return SCREEN_ORIENTATION_UNSPECIFIED;
3544 }
3545
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003546 if (orientation != SCREEN_ORIENTATION_UNSET
3547 && orientation != SCREEN_ORIENTATION_BEHIND) {
3548 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3549 "App is requesting an orientation, return " + orientation);
3550 return orientation;
3551 }
3552
3553 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003554 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003555 // The next app has not been requested to be visible, so we keep the current orientation
3556 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003557 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003558 }
Robert Carrb1579c82017-09-05 14:54:47 -07003559
3560 @Override
3561 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003562 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003563
Robert Carr2f8aa392018-01-31 14:46:51 -08003564 for (int i = 0; i < mChildren.size(); i++) {
3565 final TaskStack s = mChildren.get(i);
3566 s.assignChildLayers(t);
3567 }
3568 }
3569
3570 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003571 final int HOME_STACK_STATE = 0;
3572 final int NORMAL_STACK_STATE = 1;
3573 final int ALWAYS_ON_TOP_STATE = 2;
3574
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003575 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003576 int layerForAnimationLayer = 0;
3577
Robert Carrf7a7ca82017-12-06 13:17:07 -08003578 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3579 for (int i = 0; i < mChildren.size(); i++) {
3580 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003581 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3582 continue;
3583 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3584 || s.isAlwaysOnTop())) {
3585 continue;
3586 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3587 continue;
3588 }
3589 s.assignLayer(t, layer++);
3590 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3591 t.setLayer(mSplitScreenDividerAnchor, layer++);
3592 }
Robert Carrb9506032018-02-13 13:54:00 -08003593 if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003594 // Ensure the animation layer ends up above the
3595 // highest animating stack and no higher.
3596 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003597 }
3598 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003599 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003600 if (mAppAnimationLayer != null) {
3601 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003602 }
Robert Carrb1579c82017-09-05 14:54:47 -07003603 }
3604
3605 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003606 SurfaceControl getAppAnimationLayer() {
3607 return mAppAnimationLayer;
3608 }
3609
Robert Carrf7a7ca82017-12-06 13:17:07 -08003610 SurfaceControl getSplitScreenDividerAnchor() {
3611 return mSplitScreenDividerAnchor;
3612 }
3613
chaviw23ee71c2017-12-18 11:29:41 -08003614 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003615 void onParentSet() {
3616 super.onParentSet();
3617 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003618 mAppAnimationLayer = makeChildSurface(null)
3619 .setName("animationLayer")
3620 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003621 mSplitScreenDividerAnchor = makeChildSurface(null)
3622 .setName("splitScreenDividerAnchor")
3623 .build();
3624 getPendingTransaction()
3625 .show(mAppAnimationLayer)
3626 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003627 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003628 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003629 mAppAnimationLayer.destroy();
3630 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003631 mSplitScreenDividerAnchor.destroy();
3632 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003633 }
3634 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003635 }
3636
Robert Carree4d4b92017-11-22 12:21:46 -08003637 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003638 AboveAppWindowContainers(String name, WindowManagerService service) {
3639 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003640 }
3641
Robert Carrb9506032018-02-13 13:54:00 -08003642 @Override
3643 void assignChildLayers(SurfaceControl.Transaction t) {
3644 assignChildLayers(t, null /* imeContainer */);
3645 }
3646
Robert Carree4d4b92017-11-22 12:21:46 -08003647 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3648 boolean needAssignIme = imeContainer != null
3649 && imeContainer.getSurfaceControl() != null;
3650 for (int j = 0; j < mChildren.size(); ++j) {
3651 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003652
3653 // See {@link mSplitScreenDividerAnchor}
3654 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3655 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3656 continue;
3657 }
Robert Carree4d4b92017-11-22 12:21:46 -08003658 wt.assignLayer(t, j);
3659 wt.assignChildLayers(t);
3660
3661 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3662 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003663
3664 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3665 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003666 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003667 needAssignIme = false;
3668 }
3669 }
3670 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003671 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003672 }
3673 }
3674 }
3675
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003676 /**
3677 * Window container class that contains all containers on this display that are not related to
3678 * Apps. E.g. status bar.
3679 */
Robert Carree4d4b92017-11-22 12:21:46 -08003680 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003681 /**
3682 * Compares two child window tokens returns -1 if the first is lesser than the second in
3683 * terms of z-order and 1 otherwise.
3684 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003685 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003686 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003687 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3688 token1.mOwnerCanManageAppTokens)
3689 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3690 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003691
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003692 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3693 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3694 return false;
3695 }
3696 final int req = w.mAttrs.screenOrientation;
3697 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3698 || req == SCREEN_ORIENTATION_UNSET) {
3699 return false;
3700 }
3701 return true;
3702 };
3703
Wale Ogunwale3a931692016-11-02 16:49:48 -07003704 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003705 private final Dimmer mDimmer = new Dimmer(this);
3706 private final Rect mTmpDimBoundsRect = new Rect();
3707
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003708 NonAppWindowContainers(String name, WindowManagerService service) {
3709 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003710 mName = name;
3711 }
3712
3713 void addChild(WindowToken token) {
3714 addChild(token, mWindowComparator);
3715 }
3716
3717 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003718 int getOrientation() {
3719 final WindowManagerPolicy policy = mService.mPolicy;
3720 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003721 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003722
3723 if (win != null) {
3724 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003725 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003726 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003727 if (mService.mKeyguardGoingAway) {
3728 // Keyguard can't affect the orientation if it is going away...
3729 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3730 return SCREEN_ORIENTATION_UNSET;
3731 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003732 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003733 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003734 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003735 }
3736
Andrii Kulian8ee72852017-03-10 10:36:45 -08003737 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003738
Jorim Jaggi75520d52017-08-24 17:23:19 +02003739 if (policy.isKeyguardShowingAndNotOccluded()
3740 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003741 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003742 }
3743
3744 return SCREEN_ORIENTATION_UNSET;
3745 }
3746
3747 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003748 String getName() {
3749 return mName;
3750 }
chaviwf29223e2018-01-31 13:23:51 -08003751
3752 @Override
3753 Dimmer getDimmer() {
3754 return mDimmer;
3755 }
3756
3757 @Override
3758 void prepareSurfaces() {
3759 mDimmer.resetDimStates();
3760 super.prepareSurfaces();
3761 getBounds(mTmpDimBoundsRect);
3762
3763 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3764 scheduleAnimation();
3765 }
3766 }
Robert Carr3b716242016-08-16 16:02:21 -07003767 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003768
Robert Carr9034d962018-01-04 18:27:42 -08003769 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3770 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3771 super(name, service);
3772 }
3773
3774 @Override
3775 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3776 }
3777 };
3778
Robert Carrb1579c82017-09-05 14:54:47 -07003779 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3780 return mService.makeSurfaceBuilder(s)
3781 .setParent(mWindowingLayer);
3782 }
3783
3784 @Override
3785 SurfaceSession getSession() {
3786 return mSession;
3787 }
3788
3789 @Override
3790 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003791 SurfaceSession s = child != null ? child.getSession() : getSession();
3792 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003793 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003794
3795 if (child == null) {
3796 return b;
3797 }
3798
Robert Carree4d4b92017-11-22 12:21:46 -08003799 return b.setName(child.getName())
3800 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003801 }
3802
3803 /**
3804 * The makeSurface variants are for use by the window-container
3805 * hierarchy. makeOverlay here is a function for various non windowing
3806 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3807 * and other potpourii.
3808 */
3809 SurfaceControl.Builder makeOverlay() {
3810 return mService.makeSurfaceBuilder(mSession)
3811 .setParent(mOverlayLayer);
3812 }
3813
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003814 /**
3815 * Reparents the given surface to mOverlayLayer.
3816 */
3817 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3818 transaction.reparent(surface, mOverlayLayer.getHandle());
3819 }
3820
Robert Carrb1579c82017-09-05 14:54:47 -07003821 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003822 applyMagnificationSpec(getPendingTransaction(), spec);
3823 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003824 }
3825
3826 @Override
3827 void onParentSet() {
3828 // Since we are the top of the SurfaceControl hierarchy here
3829 // we create the root surfaces explicitly rather than chaining
3830 // up as the default implementation in onParentSet does. So we
3831 // explicitly do NOT call super here.
3832 }
3833
3834 @Override
3835 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003836
3837 // These are layers as children of "mWindowingLayer"
3838 mBelowAppWindowsContainers.assignLayer(t, 0);
3839 mTaskStackContainers.assignLayer(t, 1);
3840 mAboveAppWindowsContainers.assignLayer(t, 2);
3841
3842 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003843 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003844
Robert Carree4d4b92017-11-22 12:21:46 -08003845 // In the case where we have an IME target that is not in split-screen
3846 // mode IME assignment is easy. We just need the IME to go directly above
3847 // the target. This way children of the target will naturally go above the IME
3848 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003849 //
Robert Carree4d4b92017-11-22 12:21:46 -08003850 // In the case of split-screen windowing mode, we need to elevate the IME above the
3851 // docked divider while keeping the app itself below the docked divider, so instead
3852 // we use relative layering of the IME targets child windows, and place the
3853 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003854 //
Robert Carree4d4b92017-11-22 12:21:46 -08003855 // In the case where we have no IME target we assign it where it's base layer would
3856 // place it in the AboveAppWindowContainers.
3857 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3858 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003859 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003860 // TODO: We need to use an extra level on the app surface to ensure
3861 // this is always above SurfaceView but always below attached window.
3862 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003863 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003864 }
3865
3866 // Above we have assigned layers to our children, now we ask them to assign
3867 // layers to their children.
3868 mBelowAppWindowsContainers.assignChildLayers(t);
3869 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003870 mAboveAppWindowsContainers.assignChildLayers(t,
3871 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003872 mImeWindowsContainers.assignChildLayers(t);
3873 }
3874
3875 /**
3876 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3877 * that the IME target is one of the docked applications. We'd like the docked divider to be
3878 * above both of the applications, and we'd like the IME to be above the docked divider.
3879 * However we need child windows of the applications to be above the IME (Text drag handles).
3880 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3881 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3882 * with {@link #WindowState#assignLayer}
3883 */
3884 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3885 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3886 }
3887
3888 @Override
Chavi Weingarten38804382018-02-15 21:00:15 +00003889 public void destroyAfterPendingTransaction(SurfaceControl surface) {
3890 mPendingDestroyingSurfaces.add(surface);
3891 }
3892
3893 /**
3894 * Destroys any surfaces that have been put into the pending list with
3895 * {@link #destroyAfterPendingTransaction}.
3896 */
3897 void onPendingTransactionApplied() {
3898 for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) {
3899 mPendingDestroyingSurfaces.get(i).destroy();
3900 }
3901 mPendingDestroyingSurfaces.clear();
3902 }
3903
3904 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003905 void prepareSurfaces() {
3906 final ScreenRotationAnimation screenRotationAnimation =
3907 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3908 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3909 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3910 mPendingTransaction.setMatrix(mWindowingLayer,
3911 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3912 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3913 mPendingTransaction.setPosition(mWindowingLayer,
3914 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3915 mPendingTransaction.setAlpha(mWindowingLayer,
3916 screenRotationAnimation.getEnterTransformation().getAlpha());
3917 }
3918 super.prepareSurfaces();
3919 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003920
3921 void assignStackOrdering(SurfaceControl.Transaction t) {
3922 mTaskStackContainers.assignStackOrdering(t);
3923 }
Craig Mautner59c00972012-07-30 12:10:24 -07003924}