blob: ba4ef8e4c9bc28e3092520a4db6fdae3afb6ca61 [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale30e441d2017-11-09 08:28:45 -080019import static android.app.ActivityManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale61911492017-10-11 08:50:50 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070021import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
Wale Ogunwale687b4272017-07-27 02:56:23 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070024import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
25import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070027import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
28import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070029import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
30import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070031import static android.view.Display.DEFAULT_DISPLAY;
32import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070033import static android.view.Surface.ROTATION_0;
34import static android.view.Surface.ROTATION_180;
35import static android.view.Surface.ROTATION_270;
36import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070037import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070038import static android.view.WindowManager.DOCKED_BOTTOM;
39import static android.view.WindowManager.DOCKED_INVALID;
40import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080041import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
43import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070044import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070045import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070046import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
47import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070051import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080052import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070053import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070054import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070055import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070057import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070058import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
59import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070060import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070061import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Adrian Roose99bc052017-11-20 17:55:31 +010062import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
63import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
64import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Adrian Roos1cf585052018-01-03 18:43:27 +010066import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010067import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
Wale Ogunwale1666e312016-12-16 11:27:18 -080068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020076import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070077import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070078import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070079import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070083import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070084import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070085import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080086import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070087import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070088import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
89import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070090import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070091import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -070092import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
93import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070094import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -070095import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070096import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070097import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070098import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070099import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700100import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700101import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700102import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700103import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700104import static com.android.server.wm.proto.DisplayProto.ABOVE_APP_WINDOWS;
105import static com.android.server.wm.proto.DisplayProto.BELOW_APP_WINDOWS;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000106import static com.android.server.wm.proto.DisplayProto.DISPLAY_FRAMES;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700107import static com.android.server.wm.proto.DisplayProto.DISPLAY_INFO;
108import static com.android.server.wm.proto.DisplayProto.DOCKED_STACK_DIVIDER_CONTROLLER;
109import static com.android.server.wm.proto.DisplayProto.DPI;
110import static com.android.server.wm.proto.DisplayProto.ID;
111import static com.android.server.wm.proto.DisplayProto.IME_WINDOWS;
112import static com.android.server.wm.proto.DisplayProto.PINNED_STACK_CONTROLLER;
Steven Timotiusf2d68892017-08-28 17:00:01 -0700113import static com.android.server.wm.proto.DisplayProto.ROTATION;
114import static com.android.server.wm.proto.DisplayProto.SCREEN_ROTATION_ANIMATION;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700115import static com.android.server.wm.proto.DisplayProto.STACKS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700116import static com.android.server.wm.proto.DisplayProto.WINDOW_CONTAINER;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700117
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700118import android.annotation.CallSuper;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700119import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700120import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700121import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700122import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700123import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700124import android.graphics.Matrix;
Adrian Roos1cf585052018-01-03 18:43:27 +0100125import android.graphics.Path;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800126import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700127import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700128import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100129import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700130import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700131import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700132import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700133import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700134import android.os.RemoteException;
135import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100136import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800137import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700138import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700139import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700140import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700141import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100142import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700143import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700144import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700145import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700146import android.view.Surface;
147import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100148import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700149import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700150
Bryce Lee48f4b572017-04-10 10:54:15 -0700151import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800152import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700153import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100154import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100155import com.android.server.wm.utils.RotationCache;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100156import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700157
158import java.io.PrintWriter;
159import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700160import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700161import java.util.HashMap;
162import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700163import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700164import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100165import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800166import java.util.function.Consumer;
167import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700168
Craig Mautner59c00972012-07-30 12:10:24 -0700169/**
170 * Utility class for keeping track of the WindowStates and other pertinent contents of a
171 * particular Display.
172 *
173 * IMPORTANT: No method from this class should ever be used without holding
174 * WindowManagerService.mWindowMap.
175 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700176class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700177 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700178
179 /** Unique identifier of this stack. */
180 private final int mDisplayId;
181
Wale Ogunwale3a931692016-11-02 16:49:48 -0700182 /** The containers below are the only child containers the display can have. */
183 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100184 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700185 // Contains all non-app window containers that should be displayed above the app containers
186 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800187 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100188 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700189 // Contains all non-app window containers that should be displayed below the app containers
190 // (e.g. Wallpaper).
191 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100192 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700193 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
194 // on the IME target. We mainly have this container grouping so we can keep track of all the IME
Robert Carr9034d962018-01-04 18:27:42 -0800195 // window containers together and move them in-sync if/when needed. We use a subclass of
196 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
197 private final NonMagnifiableWindowContainers mImeWindowsContainers =
198 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700199
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000200 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800201 private WindowState mTmpWindow2;
202 private WindowAnimator mTmpWindowAnimator;
203 private boolean mTmpRecoveringMemory;
204 private boolean mUpdateImeTarget;
205 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700206 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700207
Wale Ogunwale02319a62016-09-26 15:21:22 -0700208 // Mapping from a token IBinder to a WindowToken object on this display.
209 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
210
Andrii Kuliancd097992017-03-23 18:31:59 -0700211 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700212 int mInitialDisplayWidth = 0;
213 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700214 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700215
Adrian Roos1cf585052018-01-03 18:43:27 +0100216 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100217 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100218 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100219
Andrii Kuliancd097992017-03-23 18:31:59 -0700220 /**
221 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
222 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
223 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
224 */
Craig Mautner59c00972012-07-30 12:10:24 -0700225 int mBaseDisplayWidth = 0;
226 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700227 /**
228 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
229 * but can be set from Settings or via shell command "adb shell wm density".
230 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
231 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700232 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700233 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700234 private final DisplayInfo mDisplayInfo = new DisplayInfo();
235 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700236 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000237 DisplayFrames mDisplayFrames;
238
Andrii Kulian06d07d62017-03-14 11:11:47 -0700239 /**
240 * For default display it contains real metrics, empty for others.
241 * @see WindowManagerService#createWatermarkInTransaction()
242 */
243 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
244 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
245 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700246
Andrii Kulian06d07d62017-03-14 11:11:47 -0700247 /**
248 * Compat metrics computed based on {@link #mDisplayMetrics}.
249 * @see #updateDisplayAndOrientation(int)
250 */
251 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
252
253 /** The desired scaling factor for compatible apps. */
254 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700255
Andrii Kulian8ee72852017-03-10 10:36:45 -0800256 /**
257 * Current rotation of the display.
258 * Constants as per {@link android.view.Surface.Rotation}.
259 *
Robert Carrae606b42018-02-15 15:36:23 -0800260 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800261 */
262 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700263
Andrii Kulian8ee72852017-03-10 10:36:45 -0800264 /**
265 * Last applied orientation of the display.
266 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
267 *
268 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
269 */
270 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700271
Andrii Kulian8ee72852017-03-10 10:36:45 -0800272 /**
273 * Flag indicating that the application is receiving an orientation that has different metrics
274 * than it expected. E.g. Portrait instead of Landscape.
275 *
Robert Carrae606b42018-02-15 15:36:23 -0800276 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800277 */
278 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700279
Andrii Kulian8ee72852017-03-10 10:36:45 -0800280 /**
281 * Orientation forced by some window. If there is no visible window that specifies orientation
282 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
283 *
284 * @see NonAppWindowContainers#getOrientation()
285 */
286 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700287
Andrii Kulian8ee72852017-03-10 10:36:45 -0800288 /**
289 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
290 * occluded.
291 *
292 * @see NonAppWindowContainers#getOrientation()
293 */
294 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
295
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700296 /**
297 * Keep track of wallpaper visibility to notify changes.
298 */
299 private boolean mLastWallpaperVisible = false;
300
Andrii Kulian06d07d62017-03-14 11:11:47 -0700301 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700302
Craig Mautner39834192012-09-02 07:47:24 -0700303 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700304 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700305 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700306 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800307 boolean isDefaultDisplay;
Andrii Kulianf0379de2018-03-14 16:24:07 -0700308 /**
309 * Flag indicating whether WindowManager should override info for this display in
310 * DisplayManager.
311 */
312 boolean mShouldOverrideDisplayConfiguration = true;
Craig Mautner39834192012-09-02 07:47:24 -0700313
Craig Mautnerdc548482014-02-05 13:35:24 -0800314 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700315 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800316
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700317 /** Detect user tapping outside of current focused task bounds .*/
318 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700319
Craig Mautner6601b7b2013-04-29 10:29:11 -0700320 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700321 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700322
Craig Mautner6601b7b2013-04-29 10:29:11 -0700323 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800324 private final Rect mTmpRect = new Rect();
325 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700326 private final RectF mTmpRectF = new RectF();
327 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800328 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700329
Bryce Leef3c6a472017-11-14 14:53:06 -0800330 /** Used for handing back size of display */
331 private final Rect mTmpBounds = new Rect();
332
Craig Mautner95da1082014-02-24 17:54:35 -0800333 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700334 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800335
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700336 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700337 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700338
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800339 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800340 /** A collection of windows that provide tap exclude regions inside of them. */
341 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800342
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000343 private boolean mHaveBootMsg = false;
344 private boolean mHaveApp = false;
345 private boolean mHaveWallpaper = false;
346 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700347
348 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
349
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700350 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
351 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000352 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
353 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700354
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700355 // True if this display is in the process of being removed. Used to determine if the removal of
356 // the display's direct children should be allowed.
357 private boolean mRemovingDisplay = false;
358
Bryce Leed1871262017-06-12 14:12:29 -0700359 // {@code false} if this display is in the processing of being created.
360 private boolean mDisplayReady = false;
361
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800362 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700363
Robert Carrb1579c82017-09-05 14:54:47 -0700364 private final SurfaceSession mSession = new SurfaceSession();
365
366 /**
367 * We organize all top-level Surfaces in to the following layers.
368 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800369 * and omitted from Screen-Magnification, for example the strict mode flash or
370 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700371 * {@link #mWindowingLayer} contains everything else.
372 */
373 private SurfaceControl mOverlayLayer;
374
375 /**
376 * See {@link #mOverlayLayer}
377 */
378 private SurfaceControl mWindowingLayer;
379
380 /**
381 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
382 * <p>
383 * For these surfaces currently we use a surface based on the larger of width or height so we
384 * don't have to resize when rotating the display.
385 */
386 private int mSurfaceSize;
387
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100388 /** Temporary float array to retrieve 3x3 matrix values. */
389 private final float[] mTmpFloats = new float[9];
390
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800391 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
392 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800393 final AppWindowToken atoken = w.mAppToken;
394 if (winAnimator.mDrawState == READY_TO_SHOW) {
395 if (atoken == null || atoken.allDrawn) {
396 if (w.performShowLocked()) {
397 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
398 if (DEBUG_LAYOUT_REPEATS) {
399 mService.mWindowPlacerLocked.debugLayoutRepeats(
400 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
401 }
402 }
403 }
404 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800405 };
406
407 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
408 final WindowStateAnimator winAnimator = w.mWinAnimator;
409 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
410 return;
411 }
412
413 final int flags = w.mAttrs.flags;
414
415 // If this window is animating, make a note that we have an animating window and take
416 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100417 if (winAnimator.isAnimationSet()) {
418 final AnimationAdapter anim = w.getAnimation();
419 if (anim != null) {
420 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800421 mTmpWindow = w;
422 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100423 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800424 if (color != 0) {
425 final TaskStack stack = w.getStack();
426 if (stack != null) {
427 stack.setAnimationBackground(winAnimator, color);
428 }
429 }
430 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800431 }
432
433 // If this window's app token is running a detached wallpaper animation, make a note so
434 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200435 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
436 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
437 if (animation != null) {
438 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800439 mTmpWindow = w;
440 }
441
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200442 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800443 if (color != 0) {
444 final TaskStack stack = w.getStack();
445 if (stack != null) {
446 stack.setAnimationBackground(winAnimator, color);
447 }
448 }
449 }
450 };
451
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800452 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
453 final int lostFocusUid = mTmpWindow.mOwnerUid;
454 final Handler handler = mService.mH;
455 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
456 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
457 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
458 w.mAttrs.hideTimeoutMilliseconds);
459 }
460 }
461 };
462
463 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
464 final AppWindowToken focusedApp = mService.mFocusedApp;
465 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
466 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
467
468 if (!w.canReceiveKeys()) {
469 return false;
470 }
471
472 final AppWindowToken wtoken = w.mAppToken;
473
474 // If this window's application has been removed, just skip it.
475 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
476 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
477 + (wtoken.removed ? "removed" : "sendingToBottom"));
478 return false;
479 }
480
481 if (focusedApp == null) {
482 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
483 + " using new focus @ " + w);
484 mTmpWindow = w;
485 return true;
486 }
487
488 if (!focusedApp.windowsAreFocusable()) {
489 // Current focused app windows aren't focusable...
490 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
491 + " focusable using new focus @ " + w);
492 mTmpWindow = w;
493 return true;
494 }
495
496 // Descend through all of the app tokens and find the first that either matches
497 // win.mAppToken (return win) or mFocusedApp (return null).
498 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
499 if (focusedApp.compareTo(wtoken) > 0) {
500 // App stack below focused app stack. No focus for you!!!
501 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
502 "findFocusedWindow: Reached focused app=" + focusedApp);
503 mTmpWindow = null;
504 return true;
505 }
506 }
507
508 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
509 mTmpWindow = w;
510 return true;
511 };
512
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800513 private final Consumer<WindowState> mPerformLayout = w -> {
514 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
515 // wasting time and funky changes while a window is animating away.
516 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
517 || w.isGoneForLayoutLw();
518
519 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
520 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
521 + " mLayoutAttached=" + w.mLayoutAttached
522 + " screen changed=" + w.isConfigChanged());
523 final AppWindowToken atoken = w.mAppToken;
524 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200525 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800526 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
527 + " parentHidden=" + w.isParentWindowHidden());
528 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200529 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800530 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
531 + " parentHidden=" + w.isParentWindowHidden());
532 }
533
534 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
535 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
536 // since that means "perform layout as normal, just don't display").
537 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
538 || ((w.isConfigChanged() || w.setReportResizeHints())
539 && !w.isGoneForLayoutLw() &&
540 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
541 (w.mHasSurface && w.mAppToken != null &&
542 w.mAppToken.layoutConfigChanges)))) {
543 if (!w.mLayoutAttached) {
544 if (mTmpInitial) {
545 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
546 w.mContentChanged = false;
547 }
548 if (w.mAttrs.type == TYPE_DREAM) {
549 // Don't layout windows behind a dream, so that if it does stuff like hide
550 // the status bar we won't get a bad transition when it goes away.
551 mTmpWindow = w;
552 }
553 w.mLayoutNeeded = false;
554 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200555 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000556 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800557 w.mLayoutSeq = mService.mLayoutSeq;
558
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200559 // If this is the first layout, we need to initialize the last inset values as
560 // otherwise we'd immediately cause an unnecessary resize.
561 if (firstLayout) {
562 w.updateLastInsetValues();
563 }
564
Adrian Roos23df3a32018-03-15 15:41:13 +0100565 if (w.mAppToken != null) {
566 w.mAppToken.layoutLetterbox(w);
567 }
568
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800569 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
570 + " mContainingFrame=" + w.mContainingFrame
571 + " mDisplayFrame=" + w.mDisplayFrame);
572 }
573 }
574 };
575
576 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
577 if (w.mLayoutAttached) {
578 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
579 + " mViewVisibility=" + w.mViewVisibility
580 + " mRelayoutCalled=" + w.mRelayoutCalled);
581 // If this view is GONE, then skip it -- keep the current frame, and let the caller
582 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
583 // windows, since that means "perform layout as normal, just don't display").
584 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
585 return;
586 }
587 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
588 || w.mLayoutNeeded) {
589 if (mTmpInitial) {
590 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
591 w.mContentChanged = false;
592 }
593 w.mLayoutNeeded = false;
594 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000595 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800596 w.mLayoutSeq = mService.mLayoutSeq;
597 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
598 + " mContainingFrame=" + w.mContainingFrame
599 + " mDisplayFrame=" + w.mDisplayFrame);
600 }
601 } else if (w.mAttrs.type == TYPE_DREAM) {
602 // Don't layout windows behind a dream, so that if it does stuff like hide the
603 // status bar we won't get a bad transition when it goes away.
604 mTmpWindow = mTmpWindow2;
605 }
606 };
607
608 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
609 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
610 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
611 return w.canBeImeTarget();
612 };
613
614 private final Consumer<WindowState> mApplyPostLayoutPolicy =
615 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
616 mService.mInputMethodTarget);
617
618 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
619 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
620 final boolean obscuredChanged = w.mObscured !=
621 mTmpApplySurfaceChangesTransactionState.obscured;
622 final RootWindowContainer root = mService.mRoot;
623 // Only used if default window
624 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
625
626 // Update effect.
627 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
628 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
629 final boolean isDisplayed = w.isDisplayedLw();
630
631 if (isDisplayed && w.isObscuringDisplay()) {
632 // This window completely covers everything behind it, so we want to leave all
633 // of them as undimmed (for performance reasons).
634 root.mObscuringWindow = w;
635 mTmpApplySurfaceChangesTransactionState.obscured = true;
636 }
637
638 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
639 root.handleNotObscuredLocked(w,
640 mTmpApplySurfaceChangesTransactionState.obscured,
641 mTmpApplySurfaceChangesTransactionState.syswin);
642
643 if (w.mHasSurface && isDisplayed) {
644 final int type = w.mAttrs.type;
645 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
646 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
647 mTmpApplySurfaceChangesTransactionState.syswin = true;
648 }
649 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
650 && w.mAttrs.preferredRefreshRate != 0) {
651 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
652 = w.mAttrs.preferredRefreshRate;
653 }
654 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
655 && w.mAttrs.preferredDisplayModeId != 0) {
656 mTmpApplySurfaceChangesTransactionState.preferredModeId
657 = w.mAttrs.preferredDisplayModeId;
658 }
659 }
660 }
661
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800662 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
663 && mWallpaperController.isWallpaperTarget(w)) {
664 // This is the wallpaper target and its obscured state changed... make sure the
665 // current wallpaper's visibility has been updated accordingly.
666 mWallpaperController.updateWallpaperVisibility();
667 }
668
chaviw161ea3e2018-01-31 12:01:12 -0800669 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800670
671 final WindowStateAnimator winAnimator = w.mWinAnimator;
672
673 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
674 w.mContentChanged = false;
675
676 // Moved from updateWindowsAndWallpaperLocked().
677 if (w.mHasSurface) {
678 // Take care of the window being ready to display.
679 final boolean committed = winAnimator.commitFinishDrawingLocked();
680 if (isDefaultDisplay && committed) {
681 if (w.mAttrs.type == TYPE_DREAM) {
682 // HACK: When a dream is shown, it may at that point hide the lock screen.
683 // So we need to redo the layout to let the phone window manager make this
684 // happen.
685 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
686 if (DEBUG_LAYOUT_REPEATS) {
687 surfacePlacer.debugLayoutRepeats(
688 "dream and commitFinishDrawingLocked true",
689 pendingLayoutChanges);
690 }
691 }
692 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
693 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
694 "First draw done in potential wallpaper target " + w);
695 root.mWallpaperMayChange = true;
696 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
697 if (DEBUG_LAYOUT_REPEATS) {
698 surfacePlacer.debugLayoutRepeats(
699 "wallpaper and commitFinishDrawingLocked true",
700 pendingLayoutChanges);
701 }
702 }
703 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800704 }
705
706 final AppWindowToken atoken = w.mAppToken;
707 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100708 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800709 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
710 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
711 mTmpUpdateAllDrawn.add(atoken);
712 }
713 }
714
715 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
716 && w.isDisplayedLw()) {
717 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
718 }
719
720 w.updateResizingWindowIfNeeded();
721 };
722
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800723 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800724 * Create new {@link DisplayContent} instance, add itself to the root window container and
725 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700726 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800727 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700728 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
729 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700730 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700731 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800732 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100733 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800734 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800735 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
736 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
737 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
738 + " new=" + display);
739 }
740
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700741 mDisplay = display;
742 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700743 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700744 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700745 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700746 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100747 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
748 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700749 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800750 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700751 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700752
Robert Carr74a66a22018-02-23 12:17:51 -0800753 // We use this as our arbitrary surface size for buffer-less parents
754 // that don't impose cropping on their children. It may need to be larger
755 // than the display size because fullscreen windows can be shifted offscreen
756 // due to surfaceInsets. 2 times the largest display dimension feels like an
757 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
758 // layers the ability to match their parent sizes and be able to skip
759 // such arbitrary size settings.
760 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700761
762 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
763 .setSize(mSurfaceSize, mSurfaceSize)
764 .setOpaque(true);
765 mWindowingLayer = b.setName("Display Root").build();
766 mOverlayLayer = b.setName("Display Overlays").build();
767
Robert Carrf59b8dd2017-10-02 18:58:36 -0700768 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700769 .setLayerStack(mWindowingLayer, mDisplayId)
770 .show(mWindowingLayer)
771 .setLayer(mOverlayLayer, 1)
772 .setLayerStack(mOverlayLayer, mDisplayId)
773 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700774 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700775
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700776 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700777 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700778 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700779 super.addChild(mAboveAppWindowsContainers, null);
780 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800781
782 // Add itself as a child to the root container.
783 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700784
785 // TODO(b/62541591): evaluate whether this is the best spot to declare the
786 // {@link DisplayContent} ready for use.
787 mDisplayReady = true;
788 }
789
790 boolean isReady() {
791 // The display is ready when the system and the individual display are both ready.
792 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700793 }
794
795 int getDisplayId() {
796 return mDisplayId;
797 }
798
Wale Ogunwale02319a62016-09-26 15:21:22 -0700799 WindowToken getWindowToken(IBinder binder) {
800 return mTokenMap.get(binder);
801 }
802
803 AppWindowToken getAppWindowToken(IBinder binder) {
804 final WindowToken token = getWindowToken(binder);
805 if (token == null) {
806 return null;
807 }
808 return token.asAppWindowToken();
809 }
810
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700811 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700812 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
813 if (dc != null) {
814 // We currently don't support adding a window token to the display if the display
815 // already has the binder mapped to another token. If there is a use case for supporting
816 // this moving forward we will either need to merge the WindowTokens some how or have
817 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700818 throw new IllegalArgumentException("Can't map token=" + token + " to display="
819 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700820 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700821 if (binder == null) {
822 throw new IllegalArgumentException("Can't map token=" + token + " to display="
823 + getName() + " binder is null");
824 }
825 if (token == null) {
826 throw new IllegalArgumentException("Can't map null token to display="
827 + getName() + " binder=" + binder);
828 }
829
Wale Ogunwale02319a62016-09-26 15:21:22 -0700830 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700831
832 if (token.asAppWindowToken() == null) {
833 // Add non-app token to container hierarchy on the display. App tokens are added through
834 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700835 switch (token.windowType) {
836 case TYPE_WALLPAPER:
837 mBelowAppWindowsContainers.addChild(token);
838 break;
839 case TYPE_INPUT_METHOD:
840 case TYPE_INPUT_METHOD_DIALOG:
841 mImeWindowsContainers.addChild(token);
842 break;
843 default:
844 mAboveAppWindowsContainers.addChild(token);
845 break;
846 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700847 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700848 }
849
850 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700851 final WindowToken token = mTokenMap.remove(binder);
852 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800853 token.setExiting();
854 }
855 return token;
856 }
857
858 /** Changes the display the input window token is housed on to this one. */
859 void reParentWindowToken(WindowToken token) {
860 final DisplayContent prevDc = token.getDisplayContent();
861 if (prevDc == this) {
862 return;
863 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800864 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
865 && token.asAppWindowToken() == null) {
866 // Removed the token from the map, but made sure it's not an app token before removing
867 // from parent.
868 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700869 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800870
871 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700872 }
873
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700874 void removeAppToken(IBinder binder) {
875 final WindowToken token = removeWindowToken(binder);
876 if (token == null) {
877 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
878 return;
879 }
880
881 final AppWindowToken appToken = token.asAppWindowToken();
882
883 if (appToken == null) {
884 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
885 return;
886 }
887
888 appToken.onRemovedFromDisplay();
889 }
890
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700891 Display getDisplay() {
892 return mDisplay;
893 }
894
Craig Mautner59c00972012-07-30 12:10:24 -0700895 DisplayInfo getDisplayInfo() {
896 return mDisplayInfo;
897 }
898
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700899 DisplayMetrics getDisplayMetrics() {
900 return mDisplayMetrics;
901 }
902
Andrii Kulian8ee72852017-03-10 10:36:45 -0800903 int getRotation() {
904 return mRotation;
905 }
906
907 void setRotation(int newRotation) {
908 mRotation = newRotation;
909 }
910
911 int getLastOrientation() {
912 return mLastOrientation;
913 }
914
915 void setLastOrientation(int orientation) {
916 mLastOrientation = orientation;
917 }
918
919 boolean getAltOrientation() {
920 return mAltOrientation;
921 }
922
923 void setAltOrientation(boolean altOrientation) {
924 mAltOrientation = altOrientation;
925 }
926
927 int getLastWindowForcedOrientation() {
928 return mLastWindowForcedOrientation;
929 }
930
Andrii Kulian06d07d62017-03-14 11:11:47 -0700931 /**
932 * Update rotation of the display.
933 *
934 * Returns true if the rotation has been changed. In this case YOU MUST CALL
935 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
936 */
Robert Carrae606b42018-02-15 15:36:23 -0800937 boolean updateRotationUnchecked() {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700938 if (mService.mDeferredRotationPauseCount > 0) {
939 // Rotation updates have been paused temporarily. Defer the update until
940 // updates have been resumed.
941 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
942 return false;
943 }
944
945 ScreenRotationAnimation screenRotationAnimation =
946 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
947 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
948 // Rotation updates cannot be performed while the previous rotation change
949 // animation is still in progress. Skip this update. We will try updating
950 // again after the animation is finished and the display is unfrozen.
951 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
952 return false;
953 }
954 if (mService.mDisplayFrozen) {
955 // Even if the screen rotation animation has finished (e.g. isAnimating
956 // returns false), there is still some time where we haven't yet unfrozen
957 // the display. We also need to abort rotation here.
958 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
959 "Deferring rotation, still finishing previous rotation");
960 return false;
961 }
962
963 if (!mService.mDisplayEnabled) {
964 // No point choosing a rotation if the display is not enabled.
965 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
966 return false;
967 }
968
969 final int oldRotation = mRotation;
970 final int lastOrientation = mLastOrientation;
971 final boolean oldAltOrientation = mAltOrientation;
972 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700973 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700974 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700975
Robert Carr0e007272017-10-02 13:00:55 -0700976 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700977 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
978 if (seamlessRotated != null) {
979 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
980 // to complete (that is, waiting for windows to redraw). It's tempting to check
981 // w.mSeamlessRotationCount but that could be incorrect in the case of
982 // window-removal.
983 return false;
984 }
Robert Carr0e007272017-10-02 13:00:55 -0700985
986 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700987 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700988 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700989 mayRotateSeamlessly = false;
990 }
991 for (int i = 0; i < mService.mSessions.size(); i++) {
992 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
993 mayRotateSeamlessly = false;
994 break;
995 }
996 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700997 }
Robert Carr0e007272017-10-02 13:00:55 -0700998 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700999
1000 // TODO: Implement forced rotation changes.
1001 // Set mAltOrientation to indicate that the application is receiving
1002 // an orientation that has different metrics than it expected.
1003 // eg. Portrait instead of Landscape.
1004
1005 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
1006 lastOrientation, rotation);
1007
1008 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
1009 + ", got rotation " + rotation + " which has "
1010 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1011
1012 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1013 // No change.
1014 return false;
1015 }
1016
1017 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1018 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1019 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1020
1021 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1022 mService.mWaitingForConfig = true;
1023 }
1024
1025 mRotation = rotation;
1026 mAltOrientation = altOrientation;
1027 if (isDefaultDisplay) {
1028 mService.mPolicy.setRotationLw(rotation);
1029 }
1030
1031 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1032 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1033 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1034 WINDOW_FREEZE_TIMEOUT_DURATION);
1035
1036 setLayoutNeeded();
1037 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001038 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001039
1040 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001041 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001042 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1043 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1044 mDisplayId);
1045 } else {
1046 // The screen rotation animation uses a screenshot to freeze the screen
1047 // while windows resize underneath.
1048 // When we are rotating seamlessly, we allow the elements to transition
1049 // to their rotated state independently and without a freeze required.
1050 screenRotationAnimation = null;
1051
Robert Carrefc75702018-02-16 11:46:16 -08001052 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001053 }
1054
1055 // We need to update our screen size information to match the new rotation. If the rotation
1056 // has actually changed then this method will return true and, according to the comment at
1057 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1058 // By updating the Display info here it will be available to
1059 // #computeScreenConfiguration() later.
1060 updateDisplayAndOrientation(getConfiguration().uiMode);
1061
Robert Carrae606b42018-02-15 15:36:23 -08001062 // NOTE: We disable the rotation in the emulator because
1063 // it doesn't support hardware OpenGL emulation yet.
1064 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1065 && screenRotationAnimation.hasScreenshot()) {
1066 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1067 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1068 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1069 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001070 }
1071 }
1072
Robert Carrae606b42018-02-15 15:36:23 -08001073 if (rotateSeamlessly) {
1074 forAllWindows(w -> {
1075 w.mWinAnimator.seamlesslyRotateWindow(getPendingTransaction(),
1076 oldRotation, rotation);
1077 }, true /* traverseTopToBottom */);
1078 }
1079
1080 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1081 scheduleAnimation();
1082
Andrii Kulian06d07d62017-03-14 11:11:47 -07001083 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001084 if (w.mHasSurface && !rotateSeamlessly) {
1085 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001086 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001087 mService.mRoot.mOrientationChangeComplete = false;
1088 w.mLastFreezeDuration = 0;
1089 }
1090 w.mReportOrientationChanged = true;
1091 }, true /* traverseTopToBottom */);
1092
1093 if (rotateSeamlessly) {
1094 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1095 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1096 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1097 }
1098
1099 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1100 final WindowManagerService.RotationWatcher rotationWatcher
1101 = mService.mRotationWatchers.get(i);
1102 if (rotationWatcher.mDisplayId == mDisplayId) {
1103 try {
1104 rotationWatcher.mWatcher.onRotationChanged(rotation);
1105 } catch (RemoteException e) {
1106 // Ignore
1107 }
1108 }
1109 }
1110
1111 // TODO (multi-display): Magnification is supported only for the default display.
1112 // Announce rotation only if we will not animate as we already have the
1113 // windows in final state. Otherwise, we make this call at the rotation end.
1114 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1115 && isDefaultDisplay) {
1116 mService.mAccessibilityController.onRotationChangedLocked(this);
1117 }
1118
1119 return true;
1120 }
1121
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001122 void configureDisplayPolicy() {
1123 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1124 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1125
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001126 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1127 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001128 }
1129
Andrii Kulian06d07d62017-03-14 11:11:47 -07001130 /**
1131 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1132 * changed.
1133 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1134 */
1135 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1136 // Use the effective "visual" dimensions based on current rotation
1137 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1138 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1139 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1140 int dw = realdw;
1141 int dh = realdh;
1142
1143 if (mAltOrientation) {
1144 if (realdw > realdh) {
1145 // Turn landscape into portrait.
1146 int maxw = (int)(realdh/1.3f);
1147 if (maxw < realdw) {
1148 dw = maxw;
1149 }
1150 } else {
1151 // Turn portrait into landscape.
1152 int maxh = (int)(realdw/1.3f);
1153 if (maxh < realdh) {
1154 dh = maxh;
1155 }
1156 }
1157 }
1158
1159 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001160 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1161 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1162
Andrii Kulian06d07d62017-03-14 11:11:47 -07001163 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001164 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001165 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001166 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001167 mDisplayInfo.rotation = mRotation;
1168 mDisplayInfo.logicalWidth = dw;
1169 mDisplayInfo.logicalHeight = dh;
1170 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1171 mDisplayInfo.appWidth = appWidth;
1172 mDisplayInfo.appHeight = appHeight;
1173 if (isDefaultDisplay) {
1174 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1175 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1176 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001177 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001178 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1179 if (mDisplayScalingDisabled) {
1180 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1181 } else {
1182 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1183 }
1184
Andrii Kulianf0379de2018-03-14 16:24:07 -07001185 // We usually set the override info in DisplayManager so that we get consistent display
1186 // metrics values when displays are changing and don't send out new values until WM is aware
1187 // of them. However, we don't do this for displays that serve as containers for ActivityView
1188 // because we don't want letter-/pillar-boxing during resize.
1189 final DisplayInfo overrideDisplayInfo = mShouldOverrideDisplayConfiguration
1190 ? mDisplayInfo : null;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001191 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
Andrii Kulianf0379de2018-03-14 16:24:07 -07001192 overrideDisplayInfo);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001193
1194 mBaseDisplayRect.set(0, 0, dw, dh);
1195
1196 if (isDefaultDisplay) {
1197 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1198 mCompatDisplayMetrics);
1199 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001200
1201 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001202 return mDisplayInfo;
1203 }
1204
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001205 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001206 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1207 }
1208
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001209 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001210 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001211 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001212 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001213 }
Adrian Roos11c25582018-02-19 18:06:36 +01001214 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001215 return WmDisplayCutout.computeSafeInsets(
1216 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001217 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001218 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001219 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001220 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1221 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001222 bounds.transform(mTmpMatrix);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001223 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(bounds),
Adrian Roos24264212018-02-19 16:26:15 +01001224 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1225 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001226 }
1227
Andrii Kulian06d07d62017-03-14 11:11:47 -07001228 /**
1229 * Compute display configuration based on display properties and policy settings.
1230 * Do not call if mDisplayReady == false.
1231 */
1232 void computeScreenConfiguration(Configuration config) {
1233 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1234
1235 final int dw = displayInfo.logicalWidth;
1236 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001237 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1238 // TODO: Probably best to set this based on some setting in the display content object,
1239 // so the display can be configured for things like fullscreen.
1240 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001241
Adrian Roos11c25582018-02-19 18:06:36 +01001242 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001243 config.screenWidthDp =
1244 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001245 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001246 config.screenHeightDp =
1247 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001248 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001249
Adrian Roos11c25582018-02-19 18:06:36 +01001250 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1251 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001252 final int leftInset = mTmpRect.left;
1253 final int topInset = mTmpRect.top;
1254 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001255 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1256 leftInset + displayInfo.appWidth /* right */,
1257 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001258 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1259 || displayInfo.rotation == Surface.ROTATION_270);
1260
1261 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001262 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001263
1264 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1265 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1266 ? Configuration.SCREENLAYOUT_ROUND_YES
1267 : Configuration.SCREENLAYOUT_ROUND_NO);
1268
1269 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1270 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1271 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1272 dh, mDisplayId);
1273 config.densityDpi = displayInfo.logicalDensityDpi;
1274
1275 config.colorMode =
1276 (displayInfo.isHdr()
1277 ? Configuration.COLOR_MODE_HDR_YES
1278 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001279 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001280 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1281 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1282
1283 // Update the configuration based on available input devices, lid switch,
1284 // and platform configuration.
1285 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1286 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1287 config.navigation = Configuration.NAVIGATION_NONAV;
1288
1289 int keyboardPresence = 0;
1290 int navigationPresence = 0;
1291 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1292 final int len = devices != null ? devices.length : 0;
1293 for (int i = 0; i < len; i++) {
1294 InputDevice device = devices[i];
1295 if (!device.isVirtual()) {
1296 final int sources = device.getSources();
1297 final int presenceFlag = device.isExternal() ?
1298 WindowManagerPolicy.PRESENCE_EXTERNAL :
1299 WindowManagerPolicy.PRESENCE_INTERNAL;
1300
1301 // TODO(multi-display): Configure on per-display basis.
1302 if (mService.mIsTouchDevice) {
1303 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1304 InputDevice.SOURCE_TOUCHSCREEN) {
1305 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1306 }
1307 } else {
1308 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1309 }
1310
1311 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1312 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1313 navigationPresence |= presenceFlag;
1314 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1315 && config.navigation == Configuration.NAVIGATION_NONAV) {
1316 config.navigation = Configuration.NAVIGATION_DPAD;
1317 navigationPresence |= presenceFlag;
1318 }
1319
1320 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1321 config.keyboard = Configuration.KEYBOARD_QWERTY;
1322 keyboardPresence |= presenceFlag;
1323 }
1324 }
1325 }
1326
1327 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1328 config.navigation = Configuration.NAVIGATION_DPAD;
1329 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1330 }
1331
1332 // Determine whether a hard keyboard is available and enabled.
1333 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1334 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1335 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1336 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1337 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1338 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1339 }
1340
1341 // Let the policy update hidden states.
1342 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1343 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1344 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1345 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1346 }
1347
1348 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1349 int displayId) {
1350 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1351 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1352 final int unrotDw, unrotDh;
1353 if (rotated) {
1354 unrotDw = dh;
1355 unrotDh = dw;
1356 } else {
1357 unrotDw = dw;
1358 unrotDh = dh;
1359 }
1360 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1361 displayId);
1362 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1363 displayId);
1364 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1365 displayId);
1366 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1367 displayId);
1368 return sw;
1369 }
1370
1371 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1372 DisplayMetrics dm, int dw, int dh, int displayId) {
1373 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001374 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001375 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001376 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001377 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1378 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1379 if (curSize == 0 || size < curSize) {
1380 curSize = size;
1381 }
1382 return curSize;
1383 }
1384
1385 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1386 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1387
1388 // We need to determine the smallest width that will occur under normal
1389 // operation. To this, start with the base screen size and compute the
1390 // width under the different possible rotations. We need to un-rotate
1391 // the current screen dimensions before doing this.
1392 int unrotDw, unrotDh;
1393 if (rotated) {
1394 unrotDw = dh;
1395 unrotDh = dw;
1396 } else {
1397 unrotDw = dw;
1398 unrotDh = dh;
1399 }
1400 displayInfo.smallestNominalAppWidth = 1<<30;
1401 displayInfo.smallestNominalAppHeight = 1<<30;
1402 displayInfo.largestNominalAppWidth = 0;
1403 displayInfo.largestNominalAppHeight = 0;
1404 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1405 unrotDh);
1406 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1407 unrotDw);
1408 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1409 unrotDh);
1410 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1411 unrotDw);
1412 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1413 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1414 displayId);
1415 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1416 displayId);
1417 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1418 displayId);
1419 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1420 displayId);
1421 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1422 outConfig.screenLayout = sl;
1423 }
1424
1425 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1426 int uiMode, int displayId) {
1427 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001428 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1429 mDisplayInfo.displayCutout);
1430 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1431 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001432
1433 // Compute the screen layout size class for this rotation.
1434 int longSize = w;
1435 int shortSize = h;
1436 if (longSize < shortSize) {
1437 int tmp = longSize;
1438 longSize = shortSize;
1439 shortSize = tmp;
1440 }
1441 longSize = (int)(longSize/density);
1442 shortSize = (int)(shortSize/density);
1443 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1444 }
1445
1446 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1447 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001448 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1449 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001450 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001451 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001452 if (width < displayInfo.smallestNominalAppWidth) {
1453 displayInfo.smallestNominalAppWidth = width;
1454 }
1455 if (width > displayInfo.largestNominalAppWidth) {
1456 displayInfo.largestNominalAppWidth = width;
1457 }
1458 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001459 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001460 if (height < displayInfo.smallestNominalAppHeight) {
1461 displayInfo.smallestNominalAppHeight = height;
1462 }
1463 if (height > displayInfo.largestNominalAppHeight) {
1464 displayInfo.largestNominalAppHeight = height;
1465 }
1466 }
1467
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001468 DockedStackDividerController getDockedDividerController() {
1469 return mDividerControllerLocked;
1470 }
1471
Winson Chung655332c2016-10-31 13:14:28 -07001472 PinnedStackController getPinnedStackController() {
1473 return mPinnedStackControllerLocked;
1474 }
1475
Jeff Browna506a6e2013-06-04 00:02:38 -07001476 /**
1477 * Returns true if the specified UID has access to this display.
1478 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001479 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001480 return mDisplay.hasAccess(uid);
1481 }
1482
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001483 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001484 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001485 }
1486
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001487 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001488 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001489 }
1490
Wale Ogunwale61911492017-10-11 08:50:50 -07001491 /**
1492 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1493 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001494 TaskStack getSplitScreenPrimaryStack() {
1495 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001496 return (stack != null && stack.isVisible()) ? stack : null;
1497 }
1498
1499 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001500 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001501 * not visible.
1502 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001503 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1504 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001505 }
1506
1507 TaskStack getPinnedStack() {
1508 return mTaskStackContainers.getPinnedStack();
1509 }
1510
1511 private boolean hasPinnedStack() {
1512 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001513 }
1514
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001515 /**
1516 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1517 * Null is no compatible stack on the display.
1518 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001519 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001520 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1521 }
1522
1523 /**
1524 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1525 * activity type. Null is no compatible stack on the display.
1526 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001527 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001528 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001529 }
1530
Bryce Lee48f4b572017-04-10 10:54:15 -07001531 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001532 TaskStack getTopStack() {
1533 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001534 }
1535
Winson Chunge2d72172018-01-25 17:46:20 +00001536 ArrayList<Task> getVisibleTasks() {
1537 return mTaskStackContainers.getVisibleTasks();
1538 }
1539
Wale Ogunwale61911492017-10-11 08:50:50 -07001540 void onStackWindowingModeChanged(TaskStack stack) {
1541 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001542 }
1543
Andrii Kulian441e4492016-09-29 15:25:00 -07001544 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001545 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001546 super.onConfigurationChanged(newParentConfig);
1547
Andrii Kulian3a507b52016-09-19 18:14:12 -07001548 // The display size information is heavily dependent on the resources in the current
1549 // configuration, so we need to reconfigure it every time the configuration changes.
1550 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1551 mService.reconfigureDisplayLocked(this);
1552
Bryce Leef3c6a472017-11-14 14:53:06 -08001553 final DockedStackDividerController dividerController = getDockedDividerController();
1554
1555 if (dividerController != null) {
1556 getDockedDividerController().onConfigurationChanged();
1557 }
1558
1559 final PinnedStackController pinnedStackController = getPinnedStackController();
1560
1561 if (pinnedStackController != null) {
1562 getPinnedStackController().onConfigurationChanged();
1563 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001564 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001565
Andrii Kulian441e4492016-09-29 15:25:00 -07001566 /**
1567 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1568 * bounds were updated.
1569 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001570 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001571 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1572 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001573 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001574 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001575 }
1576 }
Winson Chung32c566f2017-04-11 18:31:21 -07001577
1578 // If there was no pinned stack, we still need to notify the controller of the display info
1579 // update as a result of the config change. We do this here to consolidate the flow between
1580 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001581 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001582 mPinnedStackControllerLocked.onDisplayInfoChanged();
1583 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001584 }
1585
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001586 @Override
1587 boolean fillsParent() {
1588 return true;
1589 }
1590
1591 @Override
1592 boolean isVisible() {
1593 return true;
1594 }
1595
1596 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001597 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001598 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001599 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001600 }
1601
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001602 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001603 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1604 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1605 // target, or here in order if there isn't an IME target.
1606 if (traverseTopToBottom) {
1607 for (int i = mChildren.size() - 1; i >= 0; --i) {
1608 final DisplayChildWindowContainer child = mChildren.get(i);
1609 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1610 // In this case the Ime windows will be processed above their target so we skip
1611 // here.
1612 continue;
1613 }
1614 if (child.forAllWindows(callback, traverseTopToBottom)) {
1615 return true;
1616 }
1617 }
1618 } else {
1619 final int count = mChildren.size();
1620 for (int i = 0; i < count; i++) {
1621 final DisplayChildWindowContainer child = mChildren.get(i);
1622 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1623 // In this case the Ime windows will be processed above their target so we skip
1624 // here.
1625 continue;
1626 }
1627 if (child.forAllWindows(callback, traverseTopToBottom)) {
1628 return true;
1629 }
1630 }
1631 }
1632 return false;
1633 }
1634
1635 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1636 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1637 }
1638
Wale Ogunwale399c8692017-05-08 14:22:42 -07001639 @Override
1640 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001641 final WindowManagerPolicy policy = mService.mPolicy;
1642
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001643 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001644 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001645 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001646 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001647 // If the display is frozen, some activities may be in the middle of restarting, and
1648 // thus have removed their old window. If the window has the flag to hide the lock
1649 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1650 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001651 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001652 } else if (policy.isKeyguardLocked()) {
1653 // Use the last orientation the while the display is frozen with the keyguard
1654 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1655 // window. We don't want to check the show when locked window directly though as
1656 // things aren't stable while the display is frozen, for example the window could be
1657 // momentarily unavailable due to activity relaunch.
1658 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001659 + "return " + mLastOrientation);
1660 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001661 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001662 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001663 final int orientation = mAboveAppWindowsContainers.getOrientation();
1664 if (orientation != SCREEN_ORIENTATION_UNSET) {
1665 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001666 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001667 }
1668
Wale Ogunwale399c8692017-05-08 14:22:42 -07001669 // Top system windows are not requesting an orientation. Start searching from apps.
1670 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001671 }
1672
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001673 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001674 // Check if display metrics changed and update base values if needed.
1675 updateBaseDisplayMetricsIfNeeded();
1676
Craig Mautner722285e2012-09-07 13:55:58 -07001677 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001678 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001679
Wale Ogunwale61911492017-10-11 08:50:50 -07001680 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1681 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001682 }
Craig Mautner722285e2012-09-07 13:55:58 -07001683 }
1684
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001685 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001686 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1687 if (displayManagerInternal != null) {
1688 // Bootstrap the default logical display from the display manager.
1689 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1690 if (newDisplayInfo != null) {
1691 mDisplayInfo.copyFrom(newDisplayInfo);
1692 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001693 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001694
Andrii Kuliancd097992017-03-23 18:31:59 -07001695 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1696 mDisplayInfo.logicalDensityDpi);
1697 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1698 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1699 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001700 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001701 }
1702
Andrii Kuliancd097992017-03-23 18:31:59 -07001703 /**
1704 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1705 * values.
1706 */
1707 private void updateBaseDisplayMetricsIfNeeded() {
1708 // Get real display metrics without overrides from WM.
1709 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1710 final int orientation = mDisplayInfo.rotation;
1711 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1712 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1713 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1714 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001715 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001716
1717 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1718 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001719 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1720 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001721
1722 if (displayMetricsChanged) {
1723 // Check if display size or density is forced.
1724 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1725 || mBaseDisplayHeight != mInitialDisplayHeight;
1726 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1727
1728 // If there is an override set for base values - use it, otherwise use new values.
1729 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1730 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1731 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1732
1733 // Real display metrics changed, so we should also update initial values.
1734 mInitialDisplayWidth = newWidth;
1735 mInitialDisplayHeight = newHeight;
1736 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001737 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001738 mService.reconfigureDisplayLocked(this);
1739 }
1740 }
1741
Bryce Lee27cec322017-03-21 09:41:37 -07001742 /** Sets the maximum width the screen resolution can be */
1743 void setMaxUiWidth(int width) {
1744 if (DEBUG_DISPLAY) {
1745 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1746 }
1747
1748 mMaxUiWidth = width;
1749
1750 // Update existing metrics.
1751 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1752 }
1753
1754 /** Update base (override) display metrics. */
1755 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1756 mBaseDisplayWidth = baseWidth;
1757 mBaseDisplayHeight = baseHeight;
1758 mBaseDisplayDensity = baseDensity;
1759
1760 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1761 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1762 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1763 mBaseDisplayWidth = mMaxUiWidth;
1764
1765 if (DEBUG_DISPLAY) {
1766 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1767 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1768 + " on display:" + getDisplayId());
1769 }
1770 }
1771
1772 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001773
1774 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001775 }
1776
Wale Ogunwaledb506192017-12-08 10:57:32 -08001777 void getStableRect(Rect out) {
1778 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001779 }
1780
Wale Ogunwale61911492017-10-11 08:50:50 -07001781 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001782 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1783 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001784
Wale Ogunwale61911492017-10-11 08:50:50 -07001785 final TaskStack stack = new TaskStack(mService, stackId, controller);
1786 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001787 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001788 }
1789
Andrii Kulian51c1b672017-04-07 18:39:32 -07001790 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001791 final DisplayContent prevDc = stack.getDisplayContent();
1792 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001793 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1794 + " which is not currently attached to any display");
1795 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001796 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001797 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1798 + " to its current displayId=" + mDisplayId);
1799 }
1800
Wale Ogunwale61911492017-10-11 08:50:50 -07001801 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001802 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001803 }
1804
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001805 @Override
1806 protected void addChild(DisplayChildWindowContainer child,
1807 Comparator<DisplayChildWindowContainer> comparator) {
1808 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1809 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001810
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001811 @Override
1812 protected void addChild(DisplayChildWindowContainer child, int index) {
1813 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1814 }
1815
1816 @Override
1817 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001818 // Only allow removal of direct children from this display if the display is in the process
1819 // of been removed.
1820 if (mRemovingDisplay) {
1821 super.removeChild(child);
1822 return;
1823 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001824 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001825 }
1826
Andrii Kuliand2765632016-12-12 22:26:34 -08001827 @Override
1828 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1829 // Children of the display are statically ordered, so the real intention here is to perform
1830 // the operation on the display and not the static direct children.
1831 getParent().positionChildAt(position, this, includingParents);
1832 }
1833
Winson Chung59a47ded2018-01-25 17:46:06 +00001834 void positionStackAt(int position, TaskStack child) {
1835 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1836 layoutAndAssignWindowLayersIfNeeded();
1837 }
1838
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001839 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001840 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1841 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001842 final int taskId = stack.taskIdFromPoint(x, y);
1843 if (taskId != -1) {
1844 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001845 }
1846 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001847 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001848 }
1849
Chong Zhang8e89b312015-09-09 15:09:30 -07001850 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001851 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001852 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001853 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001854 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001855 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001856 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001857 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1858 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001859 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001860 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001861 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001862
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001863 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1864 if (mTmpTaskForResizePointSearchResult.searchDone) {
1865 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001866 }
1867 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001868 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001869 }
1870
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001871 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001872 // The provided task is the task on this display with focus, so if WindowManagerService's
1873 // focused app is not on this display, focusedTask will be null.
1874 if (focusedTask == null) {
1875 mTouchExcludeRegion.setEmpty();
1876 } else {
1877 mTouchExcludeRegion.set(mBaseDisplayRect);
1878 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1879 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001880 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1881 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001882 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1883 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001884 }
1885 // If we removed the focused task above, add it back and only leave its
1886 // outside touch area in the exclusion. TapDectector is not interested in
1887 // any touch inside the focused task itself.
1888 if (!mTmpRect2.isEmpty()) {
1889 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1890 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001891 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001892 final WindowState inputMethod = mService.mInputMethodWindow;
1893 if (inputMethod != null && inputMethod.isVisibleLw()) {
1894 // If the input method is visible and the user is typing, we don't want these touch
1895 // events to be intercepted and used to change focus. This would likely cause a
1896 // disappearance of the input method.
1897 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001898 if (inputMethod.getDisplayId() == mDisplayId) {
1899 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1900 } else {
1901 // IME is on a different display, so we need to update its tap detector.
1902 // TODO(multidisplay): Remove when IME will always appear on same display.
1903 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1904 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001905 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001906 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001907 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001908 win.getTouchableRegion(mTmpRegion);
1909 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1910 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001911 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1912 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1913 win.amendTapExcludeRegion(mTouchExcludeRegion);
1914 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001915 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001916 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001917 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001918 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001919 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1920 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001921 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001922 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001923 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001924 }
1925
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001926 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001927 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001928 super.switchUser();
1929 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001930 }
1931
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001932 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001933 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1934 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001935 }
1936 }
1937
Wale Ogunwale10124582016-09-15 20:25:50 -07001938 @Override
1939 void removeIfPossible() {
1940 if (isAnimating()) {
1941 mDeferredRemoval = true;
1942 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001943 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001944 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001945 }
1946
Wale Ogunwale10124582016-09-15 20:25:50 -07001947 @Override
1948 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001949 mRemovingDisplay = true;
1950 try {
1951 super.removeImmediately();
1952 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001953 if (mService.canDispatchPointerEvents()) {
1954 if (mTapDetector != null) {
1955 mService.unregisterPointerEventListener(mTapDetector);
1956 }
1957 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1958 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1959 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001960 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001961 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001962 } finally {
1963 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001964 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001965
1966 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001967 }
1968
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001969 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001970 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001971 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001972 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1973
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001974 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001975 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001976 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001977 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001978 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001979 }
1980
Andrii Kulian0214ed92017-05-16 13:44:05 -07001981 /** @return 'true' if removal of this display content is deferred due to active animation. */
1982 boolean isRemovalDeferred() {
1983 return mDeferredRemoval;
1984 }
1985
Wale Ogunwale10124582016-09-15 20:25:50 -07001986 boolean animateForIme(float interpolatedValue, float animationTarget,
1987 float dividerAnimationTarget) {
1988 boolean updated = false;
1989
Wale Ogunwale61911492017-10-11 08:50:50 -07001990 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1991 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001992 if (stack == null || !stack.isAdjustedForIme()) {
1993 continue;
1994 }
1995
1996 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1997 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1998 updated = true;
1999 } else {
2000 mDividerControllerLocked.mLastAnimationProgress =
2001 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2002 mDividerControllerLocked.mLastDividerProgress =
2003 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2004 updated |= stack.updateAdjustForIme(
2005 mDividerControllerLocked.mLastAnimationProgress,
2006 mDividerControllerLocked.mLastDividerProgress,
2007 false /* force */);
2008 }
2009 if (interpolatedValue >= 1f) {
2010 stack.endImeAdjustAnimation();
2011 }
2012 }
2013
2014 return updated;
2015 }
2016
2017 boolean clearImeAdjustAnimation() {
2018 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002019 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2020 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002021 if (stack != null && stack.isAdjustedForIme()) {
2022 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2023 changed = true;
2024 }
2025 }
2026 return changed;
2027 }
2028
2029 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002030 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2031 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002032 if (stack.isVisible() && stack.isAdjustedForIme()) {
2033 stack.beginImeAdjustAnimation();
2034 }
2035 }
2036 }
2037
2038 void adjustForImeIfNeeded() {
2039 final WindowState imeWin = mService.mInputMethodWindow;
2040 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2041 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002042 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002043 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2044 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2045 imeTargetStack.getDockSide() : DOCKED_INVALID;
2046 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2047 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2048 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002049 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002050 final boolean imeHeightChanged = imeVisible &&
2051 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2052
2053 // The divider could be adjusted for IME position, or be thinner than usual,
2054 // or both. There are three possible cases:
2055 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2056 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2057 // - If IME is not visible, divider is not moved and is normal width.
2058
2059 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002060 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2061 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002062 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002063 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2064 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002065 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2066 } else {
2067 stack.resetAdjustedForIme(false);
2068 }
2069 }
2070 mDividerControllerLocked.setAdjustedForIme(
2071 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2072 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002073 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2074 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002075 stack.resetAdjustedForIme(!dockVisible);
2076 }
2077 mDividerControllerLocked.setAdjustedForIme(
2078 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2079 }
Winson Chung655332c2016-10-31 13:14:28 -07002080 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002081 }
2082
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002083 /**
2084 * If a window that has an animation specifying a colored background and the current wallpaper
2085 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2086 * suddenly disappear.
2087 */
2088 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002089 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2090 w -> w.mIsWallpaper && w.isVisibleNow());
2091
2092 if (visibleWallpaper != null) {
2093 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002094 }
2095 return winAnimator.mAnimLayer;
2096 }
2097
Wale Ogunwale10124582016-09-15 20:25:50 -07002098 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002099 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2100 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002101 stack.prepareFreezingTaskBounds();
2102 }
2103 }
2104
Wale Ogunwale94744212015-09-21 19:01:47 -07002105 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002106 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002107
2108 // Compute a transform matrix to undo the coordinate space transformation,
2109 // and present the window at the same physical position it previously occupied.
2110 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2111 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2112
2113 mTmpRectF.set(bounds);
2114 mTmpMatrix.mapRect(mTmpRectF);
2115 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002116 }
2117
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002118 static int deltaRotation(int oldRotation, int newRotation) {
2119 int delta = newRotation - oldRotation;
2120 if (delta < 0) delta += 4;
2121 return delta;
2122 }
2123
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002124 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002125 Matrix outMatrix) {
2126 // For rotations without Z-ordering we don't need the target rectangle's position.
2127 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2128 displayHeight, outMatrix);
2129 }
2130
2131 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2132 float displayWidth, float displayHeight, Matrix outMatrix) {
2133 switch (rotation) {
2134 case ROTATION_0:
2135 outMatrix.reset();
2136 break;
2137 case ROTATION_270:
2138 outMatrix.setRotate(270, 0, 0);
2139 outMatrix.postTranslate(0, displayHeight);
2140 outMatrix.postTranslate(rectTop, 0);
2141 break;
2142 case ROTATION_180:
2143 outMatrix.reset();
2144 break;
2145 case ROTATION_90:
2146 outMatrix.setRotate(90, 0, 0);
2147 outMatrix.postTranslate(displayWidth, 0);
2148 outMatrix.postTranslate(-rectTop, rectLeft);
2149 break;
2150 }
2151 }
2152
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002153 @CallSuper
2154 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002155 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002156 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002157 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002158 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002159 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2160 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002161 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002162 }
2163 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2164 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002165 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2166 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002167 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002168 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002169 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2170 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002171 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002172 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002173 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2174 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002175 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002176 }
2177 proto.write(DPI, mBaseDisplayDensity);
2178 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002179 proto.write(ROTATION, mRotation);
2180 final ScreenRotationAnimation screenRotationAnimation =
2181 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2182 if (screenRotationAnimation != null) {
2183 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2184 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002185 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002186 proto.end(token);
2187 }
2188
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002189 @Override
2190 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2191 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002192 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2193 final String subPrefix = " " + prefix;
2194 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2195 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2196 pw.print("dpi");
2197 if (mInitialDisplayWidth != mBaseDisplayWidth
2198 || mInitialDisplayHeight != mBaseDisplayHeight
2199 || mInitialDisplayDensity != mBaseDisplayDensity) {
2200 pw.print(" base=");
2201 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2202 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2203 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002204 if (mDisplayScalingDisabled) {
2205 pw.println(" noscale");
2206 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002207 pw.print(" cur=");
2208 pw.print(mDisplayInfo.logicalWidth);
2209 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2210 pw.print(" app=");
2211 pw.print(mDisplayInfo.appWidth);
2212 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2213 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2214 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2215 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2216 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002217 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002218 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002219 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002220
Craig Mautnerdc548482014-02-05 13:35:24 -08002221 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002222 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002223 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2224 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002225 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002226 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002227
Craig Mautnerdc548482014-02-05 13:35:24 -08002228 pw.println();
2229 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002230 pw.println();
2231 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002232 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002233 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002234 pw.print(" Exiting #"); pw.print(i);
2235 pw.print(' '); pw.print(token);
2236 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002237 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002238 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002239 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002240
Jorim Jaggi31f71702016-05-04 16:43:04 -07002241 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002242
2243 // Dump stack references
2244 final TaskStack homeStack = getHomeStack();
2245 if (homeStack != null) {
2246 pw.println(prefix + "homeStack=" + homeStack.getName());
2247 }
2248 final TaskStack pinnedStack = getPinnedStack();
2249 if (pinnedStack != null) {
2250 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2251 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002252 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002253 if (splitScreenPrimaryStack != null) {
2254 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2255 }
2256
2257 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002258 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002259 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002260 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002261
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002262 pw.println();
2263 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002264 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002265
2266 @Override
2267 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002268 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002269 }
2270
2271 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002272 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002273 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002274
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002275 /** Returns true if the stack in the windowing mode is visible. */
2276 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002277 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002278 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002279 }
2280
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002281 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002282 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002283 final int x = (int) xf;
2284 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002285 final WindowState touchedWin = getWindow(w -> {
2286 final int flags = w.mAttrs.flags;
2287 if (!w.isVisibleLw()) {
2288 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002289 }
2290 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002291 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002292 }
2293
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002294 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002295 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002296 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002297 }
2298
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002299 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002300
2301 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002302 return mTmpRegion.contains(x, y) || touchFlags == 0;
2303 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002304
2305 return touchedWin;
2306 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002307
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002308 boolean canAddToastWindowForUid(int uid) {
2309 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002310 // Also if the app is focused adding more than one toast at
2311 // a time for better backwards compatibility.
2312 final WindowState focusedWindowForUid = getWindow(w ->
2313 w.mOwnerUid == uid && w.isFocused());
2314 if (focusedWindowForUid != null) {
2315 return true;
2316 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002317 final WindowState win = getWindow(w ->
2318 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2319 && !w.mWindowRemovalAllowed);
2320 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002321 }
2322
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002323 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002324 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2325 return;
2326 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002327
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002328 // Used to communicate the old focus to the callback method.
2329 mTmpWindow = oldFocus;
2330
2331 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002332 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002333
2334 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002335 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002336
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002337 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002338
2339 if (mTmpWindow == null) {
2340 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2341 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002342 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002343 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002344 }
2345
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002346 /** Updates the layer assignment of windows on this display. */
2347 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002348 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002349 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002350 if (setLayoutNeeded) {
2351 setLayoutNeeded();
2352 }
Robert Carrb1579c82017-09-05 14:54:47 -07002353
Robert Carrf59b8dd2017-10-02 18:58:36 -07002354 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002355 // the application of this transaction until the animation pass triggers
2356 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2357 // the hiding and showing of surfaces.
2358 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002359 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002360 }
2361
Wale Ogunwale1666e312016-12-16 11:27:18 -08002362 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2363 // moving containers or resizing them. Need to investigate the best way to have it automatically
2364 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002365 void layoutAndAssignWindowLayersIfNeeded() {
2366 mService.mWindowsChanged = true;
2367 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002368
2369 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2370 false /*updateInputWindows*/)) {
2371 assignWindowLayers(false /* setLayoutNeeded */);
2372 }
2373
2374 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2375 mService.mWindowPlacerLocked.performSurfacePlacement();
2376 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2377 }
2378
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002379 /** Returns true if a leaked surface was destroyed */
2380 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002381 // Used to indicate that a surface was leaked.
2382 mTmpWindow = null;
2383 forAllWindows(w -> {
2384 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002385 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002386 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002387 }
2388 if (!mService.mSessions.contains(wsa.mSession)) {
2389 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002390 + w + " surface=" + wsa.mSurfaceController
2391 + " token=" + w.mToken
2392 + " pid=" + w.mSession.mPid
2393 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002394 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002395 mService.mForceRemoves.add(w);
2396 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002397 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002398 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002399 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002400 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002401 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002402 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002403 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002404 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002405 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002406
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002407 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002408 }
2409
2410 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002411 * Determine and return the window that should be the IME target.
2412 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2413 * @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 +00002414 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002415 WindowState computeImeTarget(boolean updateImeTarget) {
2416 if (mService.mInputMethodWindow == null) {
2417 // There isn't an IME so there shouldn't be a target...That was easy!
2418 if (updateImeTarget) {
2419 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2420 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002421 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002422 }
2423 return null;
2424 }
2425
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002426 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2427 // same display. Or even when the current IME/target are not on the same screen as the next
2428 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002429 mUpdateImeTarget = updateImeTarget;
2430 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002431
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002432
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002433 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2434 // to be on top of it, but it is not -really- where input will go. So look down below
2435 // for a real window to target...
2436 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2437 final AppWindowToken token = target.mAppToken;
2438 if (token != null) {
2439 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2440 if (betterTarget != null) {
2441 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002442 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002443 }
2444 }
2445
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002446 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2447 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002448
2449 // Now, a special case -- if the last target's window is in the process of exiting, and is
2450 // above the new target, keep on the last target to avoid flicker. Consider for example a
2451 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2452 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2453 // scrim.
2454 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002455 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2456 && (target == null
2457 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002458 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002459 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002460 }
2461
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002462 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2463 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002464
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002465 if (target == null) {
2466 if (updateImeTarget) {
2467 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2468 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2469 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002470 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002471 }
2472
2473 return null;
2474 }
2475
2476 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002477 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2478 if (token != null) {
2479
2480 // Now some fun for dealing with window animations that modify the Z order. We need
2481 // to look at all windows below the current target that are in this app, finding the
2482 // highest visible one in layering.
2483 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002484 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002485 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002486 }
2487
2488 if (highestTarget != null) {
2489 final AppTransition appTransition = mService.mAppTransition;
2490 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2491 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2492 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002493 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002494
2495 if (appTransition.isTransitionSet()) {
2496 // If we are currently setting up for an animation, hold everything until we
2497 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002498 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002499 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002500 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002501 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002502 // If the window we are currently targeting is involved with an animation,
2503 // and it is on top of the next target we will be over, then hold off on
2504 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002505 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002506 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002507 }
2508 }
2509 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002510
2511 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2512 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002513 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002514 }
2515
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002516 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002517 }
2518
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002519 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002520 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002521 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002522 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002523 }
2524
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002525 mService.mInputMethodTarget = target;
2526 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002527 assignWindowLayers(false /* setLayoutNeeded */);
2528 }
2529
2530 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2531 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2532 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2533 }
2534
2535 // Used to indicate we have reached the first window in the range we are interested in.
2536 mTmpWindow = null;
2537
2538 // TODO: Figure-out a more efficient way to do this.
2539 final WindowState candidate = getWindow(w -> {
2540 if (w == top) {
2541 // Reached the first window in the range we are interested in.
2542 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002543 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002544 if (mTmpWindow == null) {
2545 return false;
2546 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002547
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002548 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2549 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002550 }
2551 // If we reached the bottom of the range of windows we are considering,
2552 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002553 if (w == bottom) {
2554 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002555 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002556 return false;
2557 });
2558
2559 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002560 }
2561
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002562 void setLayoutNeeded() {
2563 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2564 mLayoutNeeded = true;
2565 }
2566
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002567 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002568 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2569 mLayoutNeeded = false;
2570 }
2571
2572 boolean isLayoutNeeded() {
2573 return mLayoutNeeded;
2574 }
2575
Wale Ogunwale02319a62016-09-26 15:21:22 -07002576 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2577 if (mTokenMap.isEmpty()) {
2578 return;
2579 }
2580 pw.println(" Display #" + mDisplayId);
2581 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2582 while (it.hasNext()) {
2583 final WindowToken token = it.next();
2584 pw.print(" ");
2585 pw.print(token);
2586 if (dumpAll) {
2587 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002588 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002589 } else {
2590 pw.println();
2591 }
2592 }
2593 }
2594
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002595 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002596 final int[] index = new int[1];
2597 forAllWindows(w -> {
2598 final WindowStateAnimator wAnim = w.mWinAnimator;
2599 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2600 index[0] = index[0] + 1;
2601 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002602 }
2603
Jorim Jaggife762342016-10-13 14:33:27 +02002604 /**
2605 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2606 */
2607 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2608 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002609 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002610 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2611 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002612 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002613 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002614 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002615 }
2616
Wale Ogunwale494009b82016-10-21 09:01:38 -07002617 boolean checkWaitingForWindows() {
2618
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002619 mHaveBootMsg = false;
2620 mHaveApp = false;
2621 mHaveWallpaper = false;
2622 mHaveKeyguard = true;
2623
2624 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002625 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2626 return true;
2627 }
2628 if (w.isDrawnLw()) {
2629 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002630 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002631 } else if (w.mAttrs.type == TYPE_APPLICATION
2632 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002633 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002634 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002635 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002636 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002637 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002638 }
2639 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002640 return false;
2641 });
2642
2643 if (visibleWindow != null) {
2644 // We have a visible window.
2645 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002646 }
2647
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002648 // if the wallpaper service is disabled on the device, we're never going to have
2649 // wallpaper, don't bother waiting for it
2650 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2651 com.android.internal.R.bool.config_enableWallpaperService)
2652 && !mService.mOnlyCore;
2653
Wale Ogunwale494009b82016-10-21 09:01:38 -07002654 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2655 "******** booted=" + mService.mSystemBooted
2656 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002657 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2658 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2659 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002660
2661 // If we are turning on the screen to show the boot message, don't do it until the boot
2662 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002663 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002664 return true;
2665 }
2666
2667 // If we are turning on the screen after the boot is completed normally, don't do so until
2668 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002669 if (mService.mSystemBooted
2670 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002671 return true;
2672 }
2673
2674 return false;
2675 }
2676
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002677 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002678 mTmpWindowAnimator = animator;
2679 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002680 }
2681
2682 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002683 resetAnimationBackgroundAnimator();
2684
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002685 // Used to indicate a detached wallpaper.
2686 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002687 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002688
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002689 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002690
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002691 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002692 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002693 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2694 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002695 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2696 }
2697 }
2698
Wale Ogunwale494009b82016-10-21 09:01:38 -07002699 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002700 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002701 if (imFocus == null) {
2702 return false;
2703 }
2704
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002705 if (DEBUG_INPUT_METHOD) {
2706 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2707 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2708 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002709 }
2710
Wale Ogunwale494009b82016-10-21 09:01:38 -07002711 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2712
2713 if (DEBUG_INPUT_METHOD) {
2714 Slog.i(TAG_WM, "IM target client: " + imeClient);
2715 if (imeClient != null) {
2716 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2717 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2718 }
2719 }
2720
2721 return imeClient != null && imeClient.asBinder() == client.asBinder();
2722 }
2723
2724 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002725 final WindowState win = getWindow(
2726 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2727 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002728 }
2729
2730 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002731 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002732 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002733 final int curValue = w.mSystemUiVisibility;
2734 final int diff = (curValue ^ visibility) & globalDiff;
2735 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002736 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002737 w.mSeq++;
2738 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002739 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002740 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2741 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002742 visibility, newValue, diff);
2743 }
2744 } catch (RemoteException e) {
2745 // so sorry
2746 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002747 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002748 }
2749
2750 void onWindowFreezeTimeout() {
2751 Slog.w(TAG_WM, "Window freeze timeout expired.");
2752 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002753
2754 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002755 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002756 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002757 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002758 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002759 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2760 - mService.mDisplayFreezeTime);
2761 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002762 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002763 mService.mWindowPlacerLocked.performSurfacePlacement();
2764 }
2765
2766 void waitForAllWindowsDrawn() {
2767 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002768 forAllWindows(w -> {
2769 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2770 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2771 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002772 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002773 w.mLastContentInsets.set(-1, -1, -1, -1);
2774 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002775 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002776 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002777 }
2778
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002779 // TODO: Super crazy long method that should be broken down...
2780 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2781
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002782 final int dw = mDisplayInfo.logicalWidth;
2783 final int dh = mDisplayInfo.logicalHeight;
2784 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2785
2786 mTmpUpdateAllDrawn.clear();
2787
2788 int repeats = 0;
2789 do {
2790 repeats++;
2791 if (repeats > 6) {
2792 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2793 clearLayoutNeeded();
2794 break;
2795 }
2796
2797 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2798 pendingLayoutChanges);
2799
Andrii Kulian839def92016-11-02 10:58:58 -07002800 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2801 // the wallpaper window jumping across displays.
2802 // Remove check for default display when there will be support for multiple wallpaper
2803 // targets (on different displays).
2804 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002805 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002806 }
2807
2808 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2809 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08002810 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002811 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002812 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002813 }
2814 }
2815
2816 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2817 setLayoutNeeded();
2818 }
2819
2820 // FIRST LOOP: Perform a layout, if needed.
2821 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2822 performLayout(repeats == 1, false /* updateInputWindows */);
2823 } else {
2824 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2825 }
2826
2827 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2828 pendingLayoutChanges = 0;
2829
2830 if (isDefaultDisplay) {
2831 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002832 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002833 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2834 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2835 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2836 }
2837 } while (pendingLayoutChanges != 0);
2838
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002839 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002840
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002841 mTmpRecoveringMemory = recoveringMemory;
2842 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002843 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002844
2845 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002846 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2847 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2848 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002849 true /* inTraversal, must call performTraversalInTrans... below */);
2850
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002851 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2852 if (wallpaperVisible != mLastWallpaperVisible) {
2853 mLastWallpaperVisible = wallpaperVisible;
2854 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2855 }
2856
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002857 while (!mTmpUpdateAllDrawn.isEmpty()) {
2858 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2859 // See if any windows have been drawn, so they (and others associated with them)
2860 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002861 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002862 }
2863
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002864 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002865 }
2866
Bryce Leef3c6a472017-11-14 14:53:06 -08002867 private void updateBounds() {
2868 calculateBounds(mTmpBounds);
2869 setBounds(mTmpBounds);
2870 }
2871
2872 // Determines the current display bounds based on the current state
2873 private void calculateBounds(Rect out) {
2874 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2875 final int orientation = mDisplayInfo.rotation;
2876 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2877 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2878 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2879 int width = mDisplayInfo.logicalWidth;
2880 int left = (physWidth - width) / 2;
2881 int height = mDisplayInfo.logicalHeight;
2882 int top = (physHeight - height) / 2;
2883 out.set(left, top, left + width, top + height);
2884 }
2885
2886 @Override
2887 public void getBounds(Rect out) {
2888 calculateBounds(out);
2889 }
2890
2891 private void getBounds(Rect out, int orientation) {
2892 getBounds(out);
2893
2894 // Rotate the Rect if needed.
2895 final int currentRotation = mDisplayInfo.rotation;
2896 final int rotationDelta = deltaRotation(currentRotation, orientation);
2897 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2898 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2899 mTmpRectF.set(out);
2900 mTmpMatrix.mapRect(mTmpRectF);
2901 mTmpRectF.round(out);
2902 }
2903 }
2904
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002905 void performLayout(boolean initial, boolean updateInputWindows) {
2906 if (!isLayoutNeeded()) {
2907 return;
2908 }
2909 clearLayoutNeeded();
2910
2911 final int dw = mDisplayInfo.logicalWidth;
2912 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002913 if (DEBUG_LAYOUT) {
2914 Slog.v(TAG, "-------------------------------------");
2915 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2916 }
2917
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01002918 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
2919 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002920 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2921 // display info above...
2922 mDisplayFrames.mRotation = mRotation;
2923 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002924 if (isDefaultDisplay) {
2925 // Not needed on non-default displays.
2926 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2927 mService.mScreenRect.set(0, 0, dw, dh);
2928 }
2929
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002930 int seq = mService.mLayoutSeq + 1;
2931 if (seq < 0) seq = 0;
2932 mService.mLayoutSeq = seq;
2933
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002934 // Used to indicate that we have processed the dream window and all additional windows are
2935 // behind it.
2936 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002937 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002938
2939 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002940 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002941
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002942 // Used to indicate that we have processed the dream window and all additional attached
2943 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002944 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002945 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002946
2947 // Now perform layout of attached windows, which usually depend on the position of the
2948 // window they are attached to. XXX does not deal with windows that are attached to windows
2949 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002950 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002951
2952 // Window frames may have changed. Tell the input dispatcher about it.
2953 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2954 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2955 if (updateInputWindows) {
2956 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2957 }
2958
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002959 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2960 }
2961
2962 /**
2963 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2964 * In portrait mode, it grabs the full screenshot.
2965 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002966 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002967 */
chaviw0315a1a2018-03-05 15:28:35 -08002968 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
2969 if (!mService.mPolicy.isScreenOn()) {
2970 if (DEBUG_SCREENSHOT) {
2971 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002972 }
chaviw0315a1a2018-03-05 15:28:35 -08002973 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002974 }
chaviwfbe47df2017-11-10 16:14:49 -08002975
chaviw0315a1a2018-03-05 15:28:35 -08002976 int dw = mDisplayInfo.logicalWidth;
2977 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08002978
chaviw0315a1a2018-03-05 15:28:35 -08002979 if (dw <= 0 || dh <= 0) {
2980 return null;
2981 }
chaviwfbe47df2017-11-10 16:14:49 -08002982
chaviw0315a1a2018-03-05 15:28:35 -08002983 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08002984
chaviw0315a1a2018-03-05 15:28:35 -08002985 // The screenshot API does not apply the current screen rotation.
2986 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08002987
chaviw0315a1a2018-03-05 15:28:35 -08002988 if (rot == ROTATION_90 || rot == ROTATION_270) {
2989 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2990 }
chaviwfbe47df2017-11-10 16:14:49 -08002991
chaviw0315a1a2018-03-05 15:28:35 -08002992 // SurfaceFlinger is not aware of orientation, so convert our logical
2993 // crop to SurfaceFlinger's portrait orientation.
2994 convertCropForSurfaceFlinger(frame, rot, dw, dh);
2995
2996 final ScreenRotationAnimation screenRotationAnimation =
2997 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2998 final boolean inRotation = screenRotationAnimation != null &&
2999 screenRotationAnimation.isAnimating();
3000 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3001
3002 // TODO(b/68392460): We should screenshot Task controls directly
3003 // but it's difficult at the moment as the Task doesn't have the
3004 // correct size set.
3005 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3006 if (bitmap == null) {
3007 Slog.w(TAG_WM, "Failed to take screenshot");
3008 return null;
3009 }
3010
3011 // Create a copy of the screenshot that is immutable and backed in ashmem.
3012 // This greatly reduces the overhead of passing the bitmap between processes.
3013 final Bitmap ret = bitmap.createAshmemBitmap(config);
3014 bitmap.recycle();
3015 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003016 }
3017
3018 // TODO: Can this use createRotationMatrix()?
3019 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3020 if (rot == Surface.ROTATION_90) {
3021 final int tmp = crop.top;
3022 crop.top = dw - crop.right;
3023 crop.right = crop.bottom;
3024 crop.bottom = dw - crop.left;
3025 crop.left = tmp;
3026 } else if (rot == Surface.ROTATION_180) {
3027 int tmp = crop.top;
3028 crop.top = dh - crop.bottom;
3029 crop.bottom = dh - tmp;
3030 tmp = crop.right;
3031 crop.right = dw - crop.left;
3032 crop.left = dw - tmp;
3033 } else if (rot == Surface.ROTATION_270) {
3034 final int tmp = crop.top;
3035 crop.top = crop.left;
3036 crop.left = dh - crop.bottom;
3037 crop.bottom = crop.right;
3038 crop.right = dh - tmp;
3039 }
3040 }
3041
3042 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003043 // Used to indicate the layout is needed.
3044 mTmpWindow = null;
3045
3046 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003047 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003048 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003049 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003050 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003051 w.setDisplayLayoutNeeded();
3052 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003053 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003054
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003055 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003056 mService.mWindowPlacerLocked.performSurfacePlacement();
3057 }
3058 }
3059
Wale Ogunwale1666e312016-12-16 11:27:18 -08003060 void setExitingTokensHasVisible(boolean hasVisible) {
3061 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3062 mExitingTokens.get(i).hasVisible = hasVisible;
3063 }
3064
3065 // Initialize state of exiting applications.
3066 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3067 }
3068
3069 void removeExistingTokensIfPossible() {
3070 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3071 final WindowToken token = mExitingTokens.get(i);
3072 if (!token.hasVisible) {
3073 mExitingTokens.remove(i);
3074 }
3075 }
3076
3077 // Time to remove any exiting applications?
3078 mTaskStackContainers.removeExistingAppTokensIfPossible();
3079 }
3080
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003081 @Override
3082 void onDescendantOverrideConfigurationChanged() {
3083 setLayoutNeeded();
3084 mService.requestTraversal();
3085 }
3086
David Stevens9440dc82017-03-16 19:00:20 -07003087 boolean okToDisplay() {
3088 if (mDisplayId == DEFAULT_DISPLAY) {
3089 return !mService.mDisplayFrozen
3090 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3091 }
3092 return mDisplayInfo.state == Display.STATE_ON;
3093 }
3094
3095 boolean okToAnimate() {
3096 return okToDisplay() &&
3097 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3098 }
3099
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003100 static final class TaskForResizePointSearchResult {
3101 boolean searchDone;
3102 Task taskForResize;
3103
3104 void reset() {
3105 searchDone = false;
3106 taskForResize = null;
3107 }
3108 }
Robert Carr3b716242016-08-16 16:02:21 -07003109
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003110 private static final class ApplySurfaceChangesTransactionState {
3111 boolean displayHasContent;
3112 boolean obscured;
3113 boolean syswin;
3114 boolean focusDisplayed;
3115 float preferredRefreshRate;
3116 int preferredModeId;
3117
3118 void reset() {
3119 displayHasContent = false;
3120 obscured = false;
3121 syswin = false;
3122 focusDisplayed = false;
3123 preferredRefreshRate = 0;
3124 preferredModeId = 0;
3125 }
3126 }
3127
3128 private static final class ScreenshotApplicationState {
3129 WindowState appWin;
3130 int maxLayer;
3131 int minLayer;
3132 boolean screenshotReady;
3133
3134 void reset(boolean screenshotReady) {
3135 appWin = null;
3136 maxLayer = 0;
3137 minLayer = 0;
3138 this.screenshotReady = screenshotReady;
3139 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3140 }
3141 }
3142
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003143 /**
3144 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3145 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3146 * homogeneous children type which is currently required by sub-classes of
3147 * {@link WindowContainer} class.
3148 */
3149 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3150
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003151 DisplayChildWindowContainer(WindowManagerService service) {
3152 super(service);
3153 }
3154
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003155 @Override
3156 boolean fillsParent() {
3157 return true;
3158 }
3159
3160 @Override
3161 boolean isVisible() {
3162 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003163 }
3164 }
3165
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003166 /**
3167 * Window container class that contains all containers on this display relating to Apps.
3168 * I.e Activities.
3169 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003170 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003171 /**
3172 * A control placed at the appropriate level for transitions to occur.
3173 */
chaviw23ee71c2017-12-18 11:29:41 -08003174 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003175
Robert Carrf7a7ca82017-12-06 13:17:07 -08003176 /**
3177 * Given that the split-screen divider does not have an AppWindowToken, it
3178 * will have to live inside of a "NonAppWindowContainer", in particular
3179 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3180 * it will need to be interleaved with some of our children, appearing on top of
3181 * both docked stacks but underneath any assistant stacks.
3182 *
3183 * To solve this problem we have this anchor control, which will always exist so
3184 * we can always assign it the correct value in our {@link #assignChildLayers}.
3185 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3186 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3187 * events between the two containers.
3188 */
3189 SurfaceControl mSplitScreenDividerAnchor = null;
3190
Wale Ogunwale61911492017-10-11 08:50:50 -07003191 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3192 // through the list to find them.
3193 private TaskStack mHomeStack = null;
3194 private TaskStack mPinnedStack = null;
3195 private TaskStack mSplitScreenPrimaryStack = null;
3196
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003197 TaskStackContainers(WindowManagerService service) {
3198 super(service);
3199 }
3200
Wale Ogunwale61911492017-10-11 08:50:50 -07003201 /**
3202 * Returns the topmost stack on the display that is compatible with the input windowing mode
3203 * and activity type. Null is no compatible stack on the display.
3204 */
3205 TaskStack getStack(int windowingMode, int activityType) {
3206 if (activityType == ACTIVITY_TYPE_HOME) {
3207 return mHomeStack;
3208 }
3209 if (windowingMode == WINDOWING_MODE_PINNED) {
3210 return mPinnedStack;
3211 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3212 return mSplitScreenPrimaryStack;
3213 }
3214 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3215 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003216 if (activityType == ACTIVITY_TYPE_UNDEFINED
3217 && windowingMode == stack.getWindowingMode()) {
3218 // Passing in undefined type means we want to match the topmost stack with the
3219 // windowing mode.
3220 return stack;
3221 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003222 if (stack.isCompatible(windowingMode, activityType)) {
3223 return stack;
3224 }
3225 }
3226 return null;
3227 }
3228
3229 @VisibleForTesting
3230 TaskStack getTopStack() {
3231 return mTaskStackContainers.getChildCount() > 0
3232 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3233 }
3234
3235 TaskStack getHomeStack() {
3236 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3237 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3238 }
3239 return mHomeStack;
3240 }
3241
3242 TaskStack getPinnedStack() {
3243 return mPinnedStack;
3244 }
3245
Matthew Ng64e77cf2017-10-31 14:01:31 -07003246 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003247 return mSplitScreenPrimaryStack;
3248 }
3249
Winson Chunge2d72172018-01-25 17:46:20 +00003250 ArrayList<Task> getVisibleTasks() {
3251 final ArrayList<Task> visibleTasks = new ArrayList<>();
3252 forAllTasks(task -> {
3253 if (task.isVisible()) {
3254 visibleTasks.add(task);
3255 }
3256 });
3257 return visibleTasks;
3258 }
3259
Andrii Kulian839def92016-11-02 10:58:58 -07003260 /**
3261 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003262 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003263 */
3264 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003265 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003266 addChild(stack, onTop);
3267 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003268 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003269
Wale Ogunwale61911492017-10-11 08:50:50 -07003270 void onStackWindowingModeChanged(TaskStack stack) {
3271 removeStackReferenceIfNeeded(stack);
3272 addStackReferenceIfNeeded(stack);
3273 if (stack == mPinnedStack && getTopStack() != stack) {
3274 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3275 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3276 }
3277 }
3278
3279 private void addStackReferenceIfNeeded(TaskStack stack) {
3280 if (stack.isActivityTypeHome()) {
3281 if (mHomeStack != null) {
3282 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3283 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3284 }
3285 mHomeStack = stack;
3286 }
3287 final int windowingMode = stack.getWindowingMode();
3288 if (windowingMode == WINDOWING_MODE_PINNED) {
3289 if (mPinnedStack != null) {
3290 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3291 + mPinnedStack + " already exist on display=" + this
3292 + " stack=" + stack);
3293 }
3294 mPinnedStack = stack;
3295 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3296 if (mSplitScreenPrimaryStack != null) {
3297 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3298 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3299 + " already exist on display=" + this + " stack=" + stack);
3300 }
3301 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003302 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003303 }
3304 }
3305
3306 private void removeStackReferenceIfNeeded(TaskStack stack) {
3307 if (stack == mHomeStack) {
3308 mHomeStack = null;
3309 } else if (stack == mPinnedStack) {
3310 mPinnedStack = null;
3311 } else if (stack == mSplitScreenPrimaryStack) {
3312 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003313 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3314 mService.setDockedStackCreateStateLocked(
3315 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3316 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003317 }
Andrii Kulian839def92016-11-02 10:58:58 -07003318 }
3319
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003320 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003321 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3322 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003323 addChild(stack, addIndex);
3324 setLayoutNeeded();
3325 }
3326
Wale Ogunwale61911492017-10-11 08:50:50 -07003327 @Override
3328 protected void removeChild(TaskStack stack) {
3329 super.removeChild(stack);
3330 removeStackReferenceIfNeeded(stack);
3331 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003332
3333 @Override
3334 boolean isOnTop() {
3335 // Considered always on top
3336 return true;
3337 }
3338
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003339 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003340 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003341 if (child.getWindowConfiguration().isAlwaysOnTop()
3342 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003343 // This stack is always-on-top, override the default behavior.
3344 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3345
3346 // Moving to its current position, as we must call super but we don't want to
3347 // perform any meaningful action.
3348 final int currentPosition = mChildren.indexOf(child);
3349 super.positionChildAt(currentPosition, child, false /* includingParents */);
3350 return;
3351 }
3352
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003353 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3354 super.positionChildAt(targetPosition, child, includingParents);
3355
3356 setLayoutNeeded();
3357 }
3358
3359 /**
3360 * When stack is added or repositioned, find a proper position for it.
3361 * This will make sure that pinned stack always stays on top.
3362 * @param requestedPosition Position requested by caller.
3363 * @param stack Stack to be added or positioned.
3364 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3365 * @return The proper position for the stack.
3366 */
3367 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3368 final int topChildPosition = mChildren.size() - 1;
3369 boolean toTop = requestedPosition == POSITION_TOP;
3370 toTop |= adding ? requestedPosition >= topChildPosition + 1
3371 : requestedPosition >= topChildPosition;
3372 int targetPosition = requestedPosition;
3373
Wale Ogunwale61911492017-10-11 08:50:50 -07003374 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003375 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003376 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003377 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003378 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3379 }
3380
3381 // So, stack is moved just below the pinned stack.
3382 // When we're adding a new stack the target is the current pinned stack position.
3383 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003384 // stack, because WindowContainer#positionAt() first removes element and then adds
3385 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003386 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3387 }
3388
3389 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003390 }
3391
3392 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003393 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3394 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003395 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003396 if (super.forAllWindows(callback, traverseTopToBottom)) {
3397 return true;
3398 }
3399 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3400 return true;
3401 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003402 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003403 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3404 return true;
3405 }
3406 if (super.forAllWindows(callback, traverseTopToBottom)) {
3407 return true;
3408 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003409 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003410 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003411 }
3412
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003413 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003414 boolean traverseTopToBottom) {
3415 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3416 // app tokens.
3417 // TODO: Investigate if we need to continue to do this or if we can just process them
3418 // in-order.
3419 if (traverseTopToBottom) {
3420 for (int i = mChildren.size() - 1; i >= 0; --i) {
3421 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3422 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003423 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3424 traverseTopToBottom)) {
3425 return true;
3426 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003427 }
3428 }
3429 } else {
3430 final int count = mChildren.size();
3431 for (int i = 0; i < count; ++i) {
3432 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3433 final int appTokensCount = appTokens.size();
3434 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003435 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3436 traverseTopToBottom)) {
3437 return true;
3438 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003439 }
3440 }
3441 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003442 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003443 }
3444
Wale Ogunwale1666e312016-12-16 11:27:18 -08003445 void setExitingTokensHasVisible(boolean hasVisible) {
3446 for (int i = mChildren.size() - 1; i >= 0; --i) {
3447 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3448 for (int j = appTokens.size() - 1; j >= 0; --j) {
3449 appTokens.get(j).hasVisible = hasVisible;
3450 }
3451 }
3452 }
3453
3454 void removeExistingAppTokensIfPossible() {
3455 for (int i = mChildren.size() - 1; i >= 0; --i) {
3456 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3457 for (int j = appTokens.size() - 1; j >= 0; --j) {
3458 final AppWindowToken token = appTokens.get(j);
3459 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3460 && (!token.mIsExiting || token.isEmpty())) {
3461 // Make sure there is no animation running on this token, so any windows
3462 // associated with it will be removed as soon as their animations are
3463 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003464 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003465 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3466 "performLayout: App token exiting now removed" + token);
3467 token.removeIfPossible();
3468 }
3469 }
3470 }
3471 }
3472
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003473 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003474 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003475 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3476 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003477 // Apps and their containers are not allowed to specify an orientation while the
3478 // docked or freeform stack is visible...except for the home stack/task if the
3479 // docked stack is minimized and it actually set something.
3480 if (mHomeStack != null && mHomeStack.isVisible()
3481 && mDividerControllerLocked.isMinimizedDock()) {
3482 final int orientation = mHomeStack.getOrientation();
3483 if (orientation != SCREEN_ORIENTATION_UNSET) {
3484 return orientation;
3485 }
3486 }
3487 return SCREEN_ORIENTATION_UNSPECIFIED;
3488 }
3489
3490 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003491 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3492 PackageManager.FEATURE_AUTOMOTIVE);
3493 if (isCar) {
3494 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3495 // allow anything but the default orientation.
3496 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3497 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3498 return SCREEN_ORIENTATION_UNSPECIFIED;
3499 }
3500
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003501 if (orientation != SCREEN_ORIENTATION_UNSET
3502 && orientation != SCREEN_ORIENTATION_BEHIND) {
3503 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3504 "App is requesting an orientation, return " + orientation);
3505 return orientation;
3506 }
3507
3508 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003509 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003510 // The next app has not been requested to be visible, so we keep the current orientation
3511 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003512 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003513 }
Robert Carrb1579c82017-09-05 14:54:47 -07003514
3515 @Override
3516 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003517 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003518
Robert Carr2f8aa392018-01-31 14:46:51 -08003519 for (int i = 0; i < mChildren.size(); i++) {
3520 final TaskStack s = mChildren.get(i);
3521 s.assignChildLayers(t);
3522 }
3523 }
3524
3525 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003526 final int HOME_STACK_STATE = 0;
3527 final int NORMAL_STACK_STATE = 1;
3528 final int ALWAYS_ON_TOP_STATE = 2;
3529
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003530 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003531 int layerForAnimationLayer = 0;
3532
Robert Carrf7a7ca82017-12-06 13:17:07 -08003533 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3534 for (int i = 0; i < mChildren.size(); i++) {
3535 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003536 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3537 continue;
3538 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3539 || s.isAlwaysOnTop())) {
3540 continue;
3541 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3542 continue;
3543 }
3544 s.assignLayer(t, layer++);
3545 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3546 t.setLayer(mSplitScreenDividerAnchor, layer++);
3547 }
Robert Carrb9506032018-02-13 13:54:00 -08003548 if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003549 // Ensure the animation layer ends up above the
3550 // highest animating stack and no higher.
3551 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003552 }
3553 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003554 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003555 if (mAppAnimationLayer != null) {
3556 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003557 }
Robert Carrb1579c82017-09-05 14:54:47 -07003558 }
3559
3560 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003561 SurfaceControl getAppAnimationLayer() {
3562 return mAppAnimationLayer;
3563 }
3564
Robert Carrf7a7ca82017-12-06 13:17:07 -08003565 SurfaceControl getSplitScreenDividerAnchor() {
3566 return mSplitScreenDividerAnchor;
3567 }
3568
chaviw23ee71c2017-12-18 11:29:41 -08003569 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003570 void onParentSet() {
3571 super.onParentSet();
3572 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003573 mAppAnimationLayer = makeChildSurface(null)
3574 .setName("animationLayer")
3575 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003576 mSplitScreenDividerAnchor = makeChildSurface(null)
3577 .setName("splitScreenDividerAnchor")
3578 .build();
3579 getPendingTransaction()
3580 .show(mAppAnimationLayer)
3581 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003582 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003583 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003584 mAppAnimationLayer.destroy();
3585 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003586 mSplitScreenDividerAnchor.destroy();
3587 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003588 }
3589 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003590 }
3591
Robert Carree4d4b92017-11-22 12:21:46 -08003592 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003593 AboveAppWindowContainers(String name, WindowManagerService service) {
3594 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003595 }
3596
Robert Carrb9506032018-02-13 13:54:00 -08003597 @Override
3598 void assignChildLayers(SurfaceControl.Transaction t) {
3599 assignChildLayers(t, null /* imeContainer */);
3600 }
3601
Robert Carree4d4b92017-11-22 12:21:46 -08003602 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3603 boolean needAssignIme = imeContainer != null
3604 && imeContainer.getSurfaceControl() != null;
3605 for (int j = 0; j < mChildren.size(); ++j) {
3606 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003607
3608 // See {@link mSplitScreenDividerAnchor}
3609 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3610 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3611 continue;
3612 }
Robert Carree4d4b92017-11-22 12:21:46 -08003613 wt.assignLayer(t, j);
3614 wt.assignChildLayers(t);
3615
3616 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3617 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003618
3619 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3620 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003621 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003622 needAssignIme = false;
3623 }
3624 }
3625 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003626 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003627 }
3628 }
3629 }
3630
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003631 /**
3632 * Window container class that contains all containers on this display that are not related to
3633 * Apps. E.g. status bar.
3634 */
Robert Carree4d4b92017-11-22 12:21:46 -08003635 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003636 /**
3637 * Compares two child window tokens returns -1 if the first is lesser than the second in
3638 * terms of z-order and 1 otherwise.
3639 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003640 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003641 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003642 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3643 token1.mOwnerCanManageAppTokens)
3644 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3645 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003646
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003647 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3648 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3649 return false;
3650 }
3651 final int req = w.mAttrs.screenOrientation;
3652 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3653 || req == SCREEN_ORIENTATION_UNSET) {
3654 return false;
3655 }
3656 return true;
3657 };
3658
Wale Ogunwale3a931692016-11-02 16:49:48 -07003659 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003660 private final Dimmer mDimmer = new Dimmer(this);
3661 private final Rect mTmpDimBoundsRect = new Rect();
3662
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003663 NonAppWindowContainers(String name, WindowManagerService service) {
3664 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003665 mName = name;
3666 }
3667
3668 void addChild(WindowToken token) {
3669 addChild(token, mWindowComparator);
3670 }
3671
3672 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003673 int getOrientation() {
3674 final WindowManagerPolicy policy = mService.mPolicy;
3675 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003676 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003677
3678 if (win != null) {
3679 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003680 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003681 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003682 if (mService.mKeyguardGoingAway) {
3683 // Keyguard can't affect the orientation if it is going away...
3684 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3685 return SCREEN_ORIENTATION_UNSET;
3686 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003687 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003688 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003689 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003690 }
3691
Andrii Kulian8ee72852017-03-10 10:36:45 -08003692 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003693
Jorim Jaggi75520d52017-08-24 17:23:19 +02003694 if (policy.isKeyguardShowingAndNotOccluded()
3695 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003696 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003697 }
3698
3699 return SCREEN_ORIENTATION_UNSET;
3700 }
3701
3702 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003703 String getName() {
3704 return mName;
3705 }
chaviwf29223e2018-01-31 13:23:51 -08003706
3707 @Override
3708 Dimmer getDimmer() {
3709 return mDimmer;
3710 }
3711
3712 @Override
3713 void prepareSurfaces() {
3714 mDimmer.resetDimStates();
3715 super.prepareSurfaces();
3716 getBounds(mTmpDimBoundsRect);
3717
3718 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3719 scheduleAnimation();
3720 }
3721 }
Robert Carr3b716242016-08-16 16:02:21 -07003722 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003723
Robert Carr9034d962018-01-04 18:27:42 -08003724 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3725 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3726 super(name, service);
3727 }
3728
3729 @Override
3730 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3731 }
3732 };
3733
Robert Carrb1579c82017-09-05 14:54:47 -07003734 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3735 return mService.makeSurfaceBuilder(s)
3736 .setParent(mWindowingLayer);
3737 }
3738
3739 @Override
3740 SurfaceSession getSession() {
3741 return mSession;
3742 }
3743
3744 @Override
3745 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003746 SurfaceSession s = child != null ? child.getSession() : getSession();
3747 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003748 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003749
3750 if (child == null) {
3751 return b;
3752 }
3753
Robert Carree4d4b92017-11-22 12:21:46 -08003754 return b.setName(child.getName())
3755 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003756 }
3757
3758 /**
3759 * The makeSurface variants are for use by the window-container
3760 * hierarchy. makeOverlay here is a function for various non windowing
3761 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3762 * and other potpourii.
3763 */
3764 SurfaceControl.Builder makeOverlay() {
3765 return mService.makeSurfaceBuilder(mSession)
3766 .setParent(mOverlayLayer);
3767 }
3768
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003769 /**
3770 * Reparents the given surface to mOverlayLayer.
3771 */
3772 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3773 transaction.reparent(surface, mOverlayLayer.getHandle());
3774 }
3775
Robert Carrb1579c82017-09-05 14:54:47 -07003776 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003777 applyMagnificationSpec(getPendingTransaction(), spec);
3778 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003779 }
3780
3781 @Override
3782 void onParentSet() {
3783 // Since we are the top of the SurfaceControl hierarchy here
3784 // we create the root surfaces explicitly rather than chaining
3785 // up as the default implementation in onParentSet does. So we
3786 // explicitly do NOT call super here.
3787 }
3788
3789 @Override
3790 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003791
3792 // These are layers as children of "mWindowingLayer"
3793 mBelowAppWindowsContainers.assignLayer(t, 0);
3794 mTaskStackContainers.assignLayer(t, 1);
3795 mAboveAppWindowsContainers.assignLayer(t, 2);
3796
3797 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003798 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003799
Robert Carree4d4b92017-11-22 12:21:46 -08003800 // In the case where we have an IME target that is not in split-screen
3801 // mode IME assignment is easy. We just need the IME to go directly above
3802 // the target. This way children of the target will naturally go above the IME
3803 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003804 //
Robert Carree4d4b92017-11-22 12:21:46 -08003805 // In the case of split-screen windowing mode, we need to elevate the IME above the
3806 // docked divider while keeping the app itself below the docked divider, so instead
3807 // we use relative layering of the IME targets child windows, and place the
3808 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003809 //
Robert Carr234b6332018-03-20 13:38:16 -07003810 // In the case the IME target is animating, the animation Z order may be different
3811 // than the WindowContainer Z order, so it's difficult to be sure we have the correct
3812 // IME target. In this case we just layer the IME over all transitions by placing it in the
3813 // above applications layer.
3814 //
Robert Carree4d4b92017-11-22 12:21:46 -08003815 // In the case where we have no IME target we assign it where it's base layer would
3816 // place it in the AboveAppWindowContainers.
Robert Carr234b6332018-03-20 13:38:16 -07003817 if (imeTarget != null && !(imeTarget.inSplitScreenWindowingMode()
3818 || imeTarget.mToken.isAppAnimating())
Robert Carree4d4b92017-11-22 12:21:46 -08003819 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003820 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003821 // TODO: We need to use an extra level on the app surface to ensure
3822 // this is always above SurfaceView but always below attached window.
3823 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003824 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003825 }
3826
3827 // Above we have assigned layers to our children, now we ask them to assign
3828 // layers to their children.
3829 mBelowAppWindowsContainers.assignChildLayers(t);
3830 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003831 mAboveAppWindowsContainers.assignChildLayers(t,
3832 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003833 mImeWindowsContainers.assignChildLayers(t);
3834 }
3835
3836 /**
3837 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3838 * that the IME target is one of the docked applications. We'd like the docked divider to be
3839 * above both of the applications, and we'd like the IME to be above the docked divider.
3840 * However we need child windows of the applications to be above the IME (Text drag handles).
3841 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3842 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3843 * with {@link #WindowState#assignLayer}
3844 */
3845 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3846 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3847 }
3848
3849 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003850 void prepareSurfaces() {
3851 final ScreenRotationAnimation screenRotationAnimation =
3852 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3853 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3854 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3855 mPendingTransaction.setMatrix(mWindowingLayer,
3856 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3857 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3858 mPendingTransaction.setPosition(mWindowingLayer,
3859 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3860 mPendingTransaction.setAlpha(mWindowingLayer,
3861 screenRotationAnimation.getEnterTransformation().getAlpha());
3862 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003863
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003864 super.prepareSurfaces();
3865 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003866
3867 void assignStackOrdering(SurfaceControl.Transaction t) {
3868 mTaskStackContainers.assignStackOrdering(t);
3869 }
Craig Mautner59c00972012-07-30 12:10:24 -07003870}