blob: c35c05dc72124f8c25191170624975781cc2b3b6 [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;
Craig Mautner39834192012-09-02 07:47:24 -0700308
Craig Mautnerdc548482014-02-05 13:35:24 -0800309 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700310 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800311
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700312 /** Detect user tapping outside of current focused task bounds .*/
313 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700314
Craig Mautner6601b7b2013-04-29 10:29:11 -0700315 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700316 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700317
Craig Mautner6601b7b2013-04-29 10:29:11 -0700318 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800319 private final Rect mTmpRect = new Rect();
320 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700321 private final RectF mTmpRectF = new RectF();
322 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800323 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700324
Bryce Leef3c6a472017-11-14 14:53:06 -0800325 /** Used for handing back size of display */
326 private final Rect mTmpBounds = new Rect();
327
Craig Mautner95da1082014-02-24 17:54:35 -0800328 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700329 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800330
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700331 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700332 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700333
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800334 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800335 /** A collection of windows that provide tap exclude regions inside of them. */
336 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800337
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000338 private boolean mHaveBootMsg = false;
339 private boolean mHaveApp = false;
340 private boolean mHaveWallpaper = false;
341 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700342
343 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
344
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700345 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
346 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000347 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
348 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700349
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700350 // True if this display is in the process of being removed. Used to determine if the removal of
351 // the display's direct children should be allowed.
352 private boolean mRemovingDisplay = false;
353
Bryce Leed1871262017-06-12 14:12:29 -0700354 // {@code false} if this display is in the processing of being created.
355 private boolean mDisplayReady = false;
356
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800357 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700358
Robert Carrb1579c82017-09-05 14:54:47 -0700359 private final SurfaceSession mSession = new SurfaceSession();
360
361 /**
362 * We organize all top-level Surfaces in to the following layers.
363 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800364 * and omitted from Screen-Magnification, for example the strict mode flash or
365 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700366 * {@link #mWindowingLayer} contains everything else.
367 */
368 private SurfaceControl mOverlayLayer;
369
370 /**
371 * See {@link #mOverlayLayer}
372 */
373 private SurfaceControl mWindowingLayer;
374
375 /**
376 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
377 * <p>
378 * For these surfaces currently we use a surface based on the larger of width or height so we
379 * don't have to resize when rotating the display.
380 */
381 private int mSurfaceSize;
382
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100383 /** Temporary float array to retrieve 3x3 matrix values. */
384 private final float[] mTmpFloats = new float[9];
385
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800386 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
387 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800388 final AppWindowToken atoken = w.mAppToken;
389 if (winAnimator.mDrawState == READY_TO_SHOW) {
390 if (atoken == null || atoken.allDrawn) {
391 if (w.performShowLocked()) {
392 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
393 if (DEBUG_LAYOUT_REPEATS) {
394 mService.mWindowPlacerLocked.debugLayoutRepeats(
395 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
396 }
397 }
398 }
399 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800400 };
401
402 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
403 final WindowStateAnimator winAnimator = w.mWinAnimator;
404 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
405 return;
406 }
407
408 final int flags = w.mAttrs.flags;
409
410 // If this window is animating, make a note that we have an animating window and take
411 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100412 if (winAnimator.isAnimationSet()) {
413 final AnimationAdapter anim = w.getAnimation();
414 if (anim != null) {
415 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800416 mTmpWindow = w;
417 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100418 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800419 if (color != 0) {
420 final TaskStack stack = w.getStack();
421 if (stack != null) {
422 stack.setAnimationBackground(winAnimator, color);
423 }
424 }
425 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800426 }
427
428 // If this window's app token is running a detached wallpaper animation, make a note so
429 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200430 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
431 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
432 if (animation != null) {
433 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800434 mTmpWindow = w;
435 }
436
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200437 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800438 if (color != 0) {
439 final TaskStack stack = w.getStack();
440 if (stack != null) {
441 stack.setAnimationBackground(winAnimator, color);
442 }
443 }
444 }
445 };
446
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800447 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
448 final int lostFocusUid = mTmpWindow.mOwnerUid;
449 final Handler handler = mService.mH;
450 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
451 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
452 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
453 w.mAttrs.hideTimeoutMilliseconds);
454 }
455 }
456 };
457
458 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
459 final AppWindowToken focusedApp = mService.mFocusedApp;
460 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
461 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
462
463 if (!w.canReceiveKeys()) {
464 return false;
465 }
466
467 final AppWindowToken wtoken = w.mAppToken;
468
469 // If this window's application has been removed, just skip it.
470 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
471 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
472 + (wtoken.removed ? "removed" : "sendingToBottom"));
473 return false;
474 }
475
476 if (focusedApp == null) {
477 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
478 + " using new focus @ " + w);
479 mTmpWindow = w;
480 return true;
481 }
482
483 if (!focusedApp.windowsAreFocusable()) {
484 // Current focused app windows aren't focusable...
485 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
486 + " focusable using new focus @ " + w);
487 mTmpWindow = w;
488 return true;
489 }
490
491 // Descend through all of the app tokens and find the first that either matches
492 // win.mAppToken (return win) or mFocusedApp (return null).
493 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
494 if (focusedApp.compareTo(wtoken) > 0) {
495 // App stack below focused app stack. No focus for you!!!
496 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
497 "findFocusedWindow: Reached focused app=" + focusedApp);
498 mTmpWindow = null;
499 return true;
500 }
501 }
502
503 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
504 mTmpWindow = w;
505 return true;
506 };
507
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800508 private final Consumer<WindowState> mPerformLayout = w -> {
509 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
510 // wasting time and funky changes while a window is animating away.
511 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
512 || w.isGoneForLayoutLw();
513
514 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
515 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
516 + " mLayoutAttached=" + w.mLayoutAttached
517 + " screen changed=" + w.isConfigChanged());
518 final AppWindowToken atoken = w.mAppToken;
519 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200520 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800521 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
522 + " parentHidden=" + w.isParentWindowHidden());
523 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200524 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800525 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
526 + " parentHidden=" + w.isParentWindowHidden());
527 }
528
529 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
530 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
531 // since that means "perform layout as normal, just don't display").
532 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
533 || ((w.isConfigChanged() || w.setReportResizeHints())
534 && !w.isGoneForLayoutLw() &&
535 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
536 (w.mHasSurface && w.mAppToken != null &&
537 w.mAppToken.layoutConfigChanges)))) {
538 if (!w.mLayoutAttached) {
539 if (mTmpInitial) {
540 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
541 w.mContentChanged = false;
542 }
543 if (w.mAttrs.type == TYPE_DREAM) {
544 // Don't layout windows behind a dream, so that if it does stuff like hide
545 // the status bar we won't get a bad transition when it goes away.
546 mTmpWindow = w;
547 }
548 w.mLayoutNeeded = false;
549 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200550 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000551 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800552 w.mLayoutSeq = mService.mLayoutSeq;
553
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200554 // If this is the first layout, we need to initialize the last inset values as
555 // otherwise we'd immediately cause an unnecessary resize.
556 if (firstLayout) {
557 w.updateLastInsetValues();
558 }
559
Adrian Roos23df3a32018-03-15 15:41:13 +0100560 if (w.mAppToken != null) {
561 w.mAppToken.layoutLetterbox(w);
562 }
563
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800564 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
565 + " mContainingFrame=" + w.mContainingFrame
566 + " mDisplayFrame=" + w.mDisplayFrame);
567 }
568 }
569 };
570
571 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
572 if (w.mLayoutAttached) {
573 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
574 + " mViewVisibility=" + w.mViewVisibility
575 + " mRelayoutCalled=" + w.mRelayoutCalled);
576 // If this view is GONE, then skip it -- keep the current frame, and let the caller
577 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
578 // windows, since that means "perform layout as normal, just don't display").
579 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
580 return;
581 }
582 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
583 || w.mLayoutNeeded) {
584 if (mTmpInitial) {
585 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
586 w.mContentChanged = false;
587 }
588 w.mLayoutNeeded = false;
589 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000590 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800591 w.mLayoutSeq = mService.mLayoutSeq;
592 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
593 + " mContainingFrame=" + w.mContainingFrame
594 + " mDisplayFrame=" + w.mDisplayFrame);
595 }
596 } else if (w.mAttrs.type == TYPE_DREAM) {
597 // Don't layout windows behind a dream, so that if it does stuff like hide the
598 // status bar we won't get a bad transition when it goes away.
599 mTmpWindow = mTmpWindow2;
600 }
601 };
602
603 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
604 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
605 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
606 return w.canBeImeTarget();
607 };
608
609 private final Consumer<WindowState> mApplyPostLayoutPolicy =
610 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
611 mService.mInputMethodTarget);
612
613 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
614 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
615 final boolean obscuredChanged = w.mObscured !=
616 mTmpApplySurfaceChangesTransactionState.obscured;
617 final RootWindowContainer root = mService.mRoot;
618 // Only used if default window
619 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
620
621 // Update effect.
622 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
623 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
624 final boolean isDisplayed = w.isDisplayedLw();
625
626 if (isDisplayed && w.isObscuringDisplay()) {
627 // This window completely covers everything behind it, so we want to leave all
628 // of them as undimmed (for performance reasons).
629 root.mObscuringWindow = w;
630 mTmpApplySurfaceChangesTransactionState.obscured = true;
631 }
632
633 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
634 root.handleNotObscuredLocked(w,
635 mTmpApplySurfaceChangesTransactionState.obscured,
636 mTmpApplySurfaceChangesTransactionState.syswin);
637
638 if (w.mHasSurface && isDisplayed) {
639 final int type = w.mAttrs.type;
640 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
641 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
642 mTmpApplySurfaceChangesTransactionState.syswin = true;
643 }
644 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
645 && w.mAttrs.preferredRefreshRate != 0) {
646 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
647 = w.mAttrs.preferredRefreshRate;
648 }
649 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
650 && w.mAttrs.preferredDisplayModeId != 0) {
651 mTmpApplySurfaceChangesTransactionState.preferredModeId
652 = w.mAttrs.preferredDisplayModeId;
653 }
654 }
655 }
656
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800657 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
658 && mWallpaperController.isWallpaperTarget(w)) {
659 // This is the wallpaper target and its obscured state changed... make sure the
660 // current wallpaper's visibility has been updated accordingly.
661 mWallpaperController.updateWallpaperVisibility();
662 }
663
chaviw161ea3e2018-01-31 12:01:12 -0800664 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800665
666 final WindowStateAnimator winAnimator = w.mWinAnimator;
667
668 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
669 w.mContentChanged = false;
670
671 // Moved from updateWindowsAndWallpaperLocked().
672 if (w.mHasSurface) {
673 // Take care of the window being ready to display.
674 final boolean committed = winAnimator.commitFinishDrawingLocked();
675 if (isDefaultDisplay && committed) {
676 if (w.mAttrs.type == TYPE_DREAM) {
677 // HACK: When a dream is shown, it may at that point hide the lock screen.
678 // So we need to redo the layout to let the phone window manager make this
679 // happen.
680 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
681 if (DEBUG_LAYOUT_REPEATS) {
682 surfacePlacer.debugLayoutRepeats(
683 "dream and commitFinishDrawingLocked true",
684 pendingLayoutChanges);
685 }
686 }
687 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
688 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
689 "First draw done in potential wallpaper target " + w);
690 root.mWallpaperMayChange = true;
691 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
692 if (DEBUG_LAYOUT_REPEATS) {
693 surfacePlacer.debugLayoutRepeats(
694 "wallpaper and commitFinishDrawingLocked true",
695 pendingLayoutChanges);
696 }
697 }
698 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800699 }
700
701 final AppWindowToken atoken = w.mAppToken;
702 if (atoken != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +0100703 atoken.updateLetterboxSurface(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800704 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
705 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
706 mTmpUpdateAllDrawn.add(atoken);
707 }
708 }
709
710 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
711 && w.isDisplayedLw()) {
712 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
713 }
714
715 w.updateResizingWindowIfNeeded();
716 };
717
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800718 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800719 * Create new {@link DisplayContent} instance, add itself to the root window container and
720 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700721 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800722 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700723 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
724 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700725 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700726 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800727 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100728 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800729 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800730 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
731 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
732 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
733 + " new=" + display);
734 }
735
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700736 mDisplay = display;
737 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700738 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700739 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700740 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700741 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100742 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
743 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700744 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800745 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700746 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700747
Robert Carr74a66a22018-02-23 12:17:51 -0800748 // We use this as our arbitrary surface size for buffer-less parents
749 // that don't impose cropping on their children. It may need to be larger
750 // than the display size because fullscreen windows can be shifted offscreen
751 // due to surfaceInsets. 2 times the largest display dimension feels like an
752 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
753 // layers the ability to match their parent sizes and be able to skip
754 // such arbitrary size settings.
755 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700756
757 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
758 .setSize(mSurfaceSize, mSurfaceSize)
759 .setOpaque(true);
760 mWindowingLayer = b.setName("Display Root").build();
761 mOverlayLayer = b.setName("Display Overlays").build();
762
Robert Carrf59b8dd2017-10-02 18:58:36 -0700763 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700764 .setLayerStack(mWindowingLayer, mDisplayId)
765 .show(mWindowingLayer)
766 .setLayer(mOverlayLayer, 1)
767 .setLayerStack(mOverlayLayer, mDisplayId)
768 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700769 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700770
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700771 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700772 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700773 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700774 super.addChild(mAboveAppWindowsContainers, null);
775 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800776
777 // Add itself as a child to the root container.
778 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700779
780 // TODO(b/62541591): evaluate whether this is the best spot to declare the
781 // {@link DisplayContent} ready for use.
782 mDisplayReady = true;
783 }
784
785 boolean isReady() {
786 // The display is ready when the system and the individual display are both ready.
787 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700788 }
789
790 int getDisplayId() {
791 return mDisplayId;
792 }
793
Wale Ogunwale02319a62016-09-26 15:21:22 -0700794 WindowToken getWindowToken(IBinder binder) {
795 return mTokenMap.get(binder);
796 }
797
798 AppWindowToken getAppWindowToken(IBinder binder) {
799 final WindowToken token = getWindowToken(binder);
800 if (token == null) {
801 return null;
802 }
803 return token.asAppWindowToken();
804 }
805
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700806 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700807 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
808 if (dc != null) {
809 // We currently don't support adding a window token to the display if the display
810 // already has the binder mapped to another token. If there is a use case for supporting
811 // this moving forward we will either need to merge the WindowTokens some how or have
812 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700813 throw new IllegalArgumentException("Can't map token=" + token + " to display="
814 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700815 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700816 if (binder == null) {
817 throw new IllegalArgumentException("Can't map token=" + token + " to display="
818 + getName() + " binder is null");
819 }
820 if (token == null) {
821 throw new IllegalArgumentException("Can't map null token to display="
822 + getName() + " binder=" + binder);
823 }
824
Wale Ogunwale02319a62016-09-26 15:21:22 -0700825 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700826
827 if (token.asAppWindowToken() == null) {
828 // Add non-app token to container hierarchy on the display. App tokens are added through
829 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700830 switch (token.windowType) {
831 case TYPE_WALLPAPER:
832 mBelowAppWindowsContainers.addChild(token);
833 break;
834 case TYPE_INPUT_METHOD:
835 case TYPE_INPUT_METHOD_DIALOG:
836 mImeWindowsContainers.addChild(token);
837 break;
838 default:
839 mAboveAppWindowsContainers.addChild(token);
840 break;
841 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700842 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700843 }
844
845 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700846 final WindowToken token = mTokenMap.remove(binder);
847 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800848 token.setExiting();
849 }
850 return token;
851 }
852
853 /** Changes the display the input window token is housed on to this one. */
854 void reParentWindowToken(WindowToken token) {
855 final DisplayContent prevDc = token.getDisplayContent();
856 if (prevDc == this) {
857 return;
858 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800859 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
860 && token.asAppWindowToken() == null) {
861 // Removed the token from the map, but made sure it's not an app token before removing
862 // from parent.
863 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700864 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800865
866 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700867 }
868
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700869 void removeAppToken(IBinder binder) {
870 final WindowToken token = removeWindowToken(binder);
871 if (token == null) {
872 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
873 return;
874 }
875
876 final AppWindowToken appToken = token.asAppWindowToken();
877
878 if (appToken == null) {
879 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
880 return;
881 }
882
883 appToken.onRemovedFromDisplay();
884 }
885
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700886 Display getDisplay() {
887 return mDisplay;
888 }
889
Craig Mautner59c00972012-07-30 12:10:24 -0700890 DisplayInfo getDisplayInfo() {
891 return mDisplayInfo;
892 }
893
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700894 DisplayMetrics getDisplayMetrics() {
895 return mDisplayMetrics;
896 }
897
Andrii Kulian8ee72852017-03-10 10:36:45 -0800898 int getRotation() {
899 return mRotation;
900 }
901
902 void setRotation(int newRotation) {
903 mRotation = newRotation;
904 }
905
906 int getLastOrientation() {
907 return mLastOrientation;
908 }
909
910 void setLastOrientation(int orientation) {
911 mLastOrientation = orientation;
912 }
913
914 boolean getAltOrientation() {
915 return mAltOrientation;
916 }
917
918 void setAltOrientation(boolean altOrientation) {
919 mAltOrientation = altOrientation;
920 }
921
922 int getLastWindowForcedOrientation() {
923 return mLastWindowForcedOrientation;
924 }
925
Andrii Kulian06d07d62017-03-14 11:11:47 -0700926 /**
927 * Update rotation of the display.
928 *
929 * Returns true if the rotation has been changed. In this case YOU MUST CALL
930 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
931 */
Robert Carrae606b42018-02-15 15:36:23 -0800932 boolean updateRotationUnchecked() {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700933 if (mService.mDeferredRotationPauseCount > 0) {
934 // Rotation updates have been paused temporarily. Defer the update until
935 // updates have been resumed.
936 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
937 return false;
938 }
939
940 ScreenRotationAnimation screenRotationAnimation =
941 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
942 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
943 // Rotation updates cannot be performed while the previous rotation change
944 // animation is still in progress. Skip this update. We will try updating
945 // again after the animation is finished and the display is unfrozen.
946 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
947 return false;
948 }
949 if (mService.mDisplayFrozen) {
950 // Even if the screen rotation animation has finished (e.g. isAnimating
951 // returns false), there is still some time where we haven't yet unfrozen
952 // the display. We also need to abort rotation here.
953 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
954 "Deferring rotation, still finishing previous rotation");
955 return false;
956 }
957
958 if (!mService.mDisplayEnabled) {
959 // No point choosing a rotation if the display is not enabled.
960 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
961 return false;
962 }
963
964 final int oldRotation = mRotation;
965 final int lastOrientation = mLastOrientation;
966 final boolean oldAltOrientation = mAltOrientation;
967 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700968 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700969 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700970
Robert Carr0e007272017-10-02 13:00:55 -0700971 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700972 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
973 if (seamlessRotated != null) {
974 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
975 // to complete (that is, waiting for windows to redraw). It's tempting to check
976 // w.mSeamlessRotationCount but that could be incorrect in the case of
977 // window-removal.
978 return false;
979 }
Robert Carr0e007272017-10-02 13:00:55 -0700980
981 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700982 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700983 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700984 mayRotateSeamlessly = false;
985 }
986 for (int i = 0; i < mService.mSessions.size(); i++) {
987 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
988 mayRotateSeamlessly = false;
989 break;
990 }
991 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700992 }
Robert Carr0e007272017-10-02 13:00:55 -0700993 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700994
995 // TODO: Implement forced rotation changes.
996 // Set mAltOrientation to indicate that the application is receiving
997 // an orientation that has different metrics than it expected.
998 // eg. Portrait instead of Landscape.
999
1000 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
1001 lastOrientation, rotation);
1002
1003 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
1004 + ", got rotation " + rotation + " which has "
1005 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1006
1007 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1008 // No change.
1009 return false;
1010 }
1011
1012 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1013 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1014 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1015
1016 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1017 mService.mWaitingForConfig = true;
1018 }
1019
1020 mRotation = rotation;
1021 mAltOrientation = altOrientation;
1022 if (isDefaultDisplay) {
1023 mService.mPolicy.setRotationLw(rotation);
1024 }
1025
1026 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1027 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1028 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1029 WINDOW_FREEZE_TIMEOUT_DURATION);
1030
1031 setLayoutNeeded();
1032 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001033 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001034
1035 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001036 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001037 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1038 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1039 mDisplayId);
1040 } else {
1041 // The screen rotation animation uses a screenshot to freeze the screen
1042 // while windows resize underneath.
1043 // When we are rotating seamlessly, we allow the elements to transition
1044 // to their rotated state independently and without a freeze required.
1045 screenRotationAnimation = null;
1046
Robert Carrefc75702018-02-16 11:46:16 -08001047 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001048 }
1049
1050 // We need to update our screen size information to match the new rotation. If the rotation
1051 // has actually changed then this method will return true and, according to the comment at
1052 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1053 // By updating the Display info here it will be available to
1054 // #computeScreenConfiguration() later.
1055 updateDisplayAndOrientation(getConfiguration().uiMode);
1056
Robert Carrae606b42018-02-15 15:36:23 -08001057 // NOTE: We disable the rotation in the emulator because
1058 // it doesn't support hardware OpenGL emulation yet.
1059 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1060 && screenRotationAnimation.hasScreenshot()) {
1061 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1062 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1063 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1064 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001065 }
1066 }
1067
Robert Carrae606b42018-02-15 15:36:23 -08001068 if (rotateSeamlessly) {
1069 forAllWindows(w -> {
1070 w.mWinAnimator.seamlesslyRotateWindow(getPendingTransaction(),
1071 oldRotation, rotation);
1072 }, true /* traverseTopToBottom */);
1073 }
1074
1075 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1076 scheduleAnimation();
1077
Andrii Kulian06d07d62017-03-14 11:11:47 -07001078 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001079 if (w.mHasSurface && !rotateSeamlessly) {
1080 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001081 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001082 mService.mRoot.mOrientationChangeComplete = false;
1083 w.mLastFreezeDuration = 0;
1084 }
1085 w.mReportOrientationChanged = true;
1086 }, true /* traverseTopToBottom */);
1087
1088 if (rotateSeamlessly) {
1089 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1090 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1091 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1092 }
1093
1094 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1095 final WindowManagerService.RotationWatcher rotationWatcher
1096 = mService.mRotationWatchers.get(i);
1097 if (rotationWatcher.mDisplayId == mDisplayId) {
1098 try {
1099 rotationWatcher.mWatcher.onRotationChanged(rotation);
1100 } catch (RemoteException e) {
1101 // Ignore
1102 }
1103 }
1104 }
1105
1106 // TODO (multi-display): Magnification is supported only for the default display.
1107 // Announce rotation only if we will not animate as we already have the
1108 // windows in final state. Otherwise, we make this call at the rotation end.
1109 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1110 && isDefaultDisplay) {
1111 mService.mAccessibilityController.onRotationChangedLocked(this);
1112 }
1113
1114 return true;
1115 }
1116
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001117 void configureDisplayPolicy() {
1118 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1119 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1120
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001121 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1122 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001123 }
1124
Andrii Kulian06d07d62017-03-14 11:11:47 -07001125 /**
1126 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1127 * changed.
1128 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1129 */
1130 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1131 // Use the effective "visual" dimensions based on current rotation
1132 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1133 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1134 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1135 int dw = realdw;
1136 int dh = realdh;
1137
1138 if (mAltOrientation) {
1139 if (realdw > realdh) {
1140 // Turn landscape into portrait.
1141 int maxw = (int)(realdh/1.3f);
1142 if (maxw < realdw) {
1143 dw = maxw;
1144 }
1145 } else {
1146 // Turn portrait into landscape.
1147 int maxh = (int)(realdw/1.3f);
1148 if (maxh < realdh) {
1149 dh = maxh;
1150 }
1151 }
1152 }
1153
1154 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001155 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1156 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1157
Andrii Kulian06d07d62017-03-14 11:11:47 -07001158 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001159 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001160 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001161 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001162 mDisplayInfo.rotation = mRotation;
1163 mDisplayInfo.logicalWidth = dw;
1164 mDisplayInfo.logicalHeight = dh;
1165 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1166 mDisplayInfo.appWidth = appWidth;
1167 mDisplayInfo.appHeight = appHeight;
1168 if (isDefaultDisplay) {
1169 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1170 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1171 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001172 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001173 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1174 if (mDisplayScalingDisabled) {
1175 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1176 } else {
1177 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1178 }
1179
1180 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1181 mDisplayInfo);
1182
1183 mBaseDisplayRect.set(0, 0, dw, dh);
1184
1185 if (isDefaultDisplay) {
1186 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1187 mCompatDisplayMetrics);
1188 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001189
1190 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001191 return mDisplayInfo;
1192 }
1193
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001194 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001195 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1196 }
1197
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001198 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001199 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001200 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001201 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001202 }
Adrian Roos11c25582018-02-19 18:06:36 +01001203 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001204 return WmDisplayCutout.computeSafeInsets(
1205 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001206 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001207 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001208 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001209 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1210 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001211 bounds.transform(mTmpMatrix);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001212 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(bounds),
Adrian Roos24264212018-02-19 16:26:15 +01001213 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1214 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001215 }
1216
Andrii Kulian06d07d62017-03-14 11:11:47 -07001217 /**
1218 * Compute display configuration based on display properties and policy settings.
1219 * Do not call if mDisplayReady == false.
1220 */
1221 void computeScreenConfiguration(Configuration config) {
1222 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1223
1224 final int dw = displayInfo.logicalWidth;
1225 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001226 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1227 // TODO: Probably best to set this based on some setting in the display content object,
1228 // so the display can be configured for things like fullscreen.
1229 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001230
Adrian Roos11c25582018-02-19 18:06:36 +01001231 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001232 config.screenWidthDp =
1233 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001234 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001235 config.screenHeightDp =
1236 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001237 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001238
Adrian Roos11c25582018-02-19 18:06:36 +01001239 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1240 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001241 final int leftInset = mTmpRect.left;
1242 final int topInset = mTmpRect.top;
1243 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001244 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1245 leftInset + displayInfo.appWidth /* right */,
1246 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001247 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1248 || displayInfo.rotation == Surface.ROTATION_270);
1249
1250 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001251 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001252
1253 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1254 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1255 ? Configuration.SCREENLAYOUT_ROUND_YES
1256 : Configuration.SCREENLAYOUT_ROUND_NO);
1257
1258 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1259 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1260 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1261 dh, mDisplayId);
1262 config.densityDpi = displayInfo.logicalDensityDpi;
1263
1264 config.colorMode =
1265 (displayInfo.isHdr()
1266 ? Configuration.COLOR_MODE_HDR_YES
1267 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001268 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001269 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1270 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1271
1272 // Update the configuration based on available input devices, lid switch,
1273 // and platform configuration.
1274 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1275 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1276 config.navigation = Configuration.NAVIGATION_NONAV;
1277
1278 int keyboardPresence = 0;
1279 int navigationPresence = 0;
1280 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1281 final int len = devices != null ? devices.length : 0;
1282 for (int i = 0; i < len; i++) {
1283 InputDevice device = devices[i];
1284 if (!device.isVirtual()) {
1285 final int sources = device.getSources();
1286 final int presenceFlag = device.isExternal() ?
1287 WindowManagerPolicy.PRESENCE_EXTERNAL :
1288 WindowManagerPolicy.PRESENCE_INTERNAL;
1289
1290 // TODO(multi-display): Configure on per-display basis.
1291 if (mService.mIsTouchDevice) {
1292 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1293 InputDevice.SOURCE_TOUCHSCREEN) {
1294 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1295 }
1296 } else {
1297 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1298 }
1299
1300 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1301 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1302 navigationPresence |= presenceFlag;
1303 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1304 && config.navigation == Configuration.NAVIGATION_NONAV) {
1305 config.navigation = Configuration.NAVIGATION_DPAD;
1306 navigationPresence |= presenceFlag;
1307 }
1308
1309 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1310 config.keyboard = Configuration.KEYBOARD_QWERTY;
1311 keyboardPresence |= presenceFlag;
1312 }
1313 }
1314 }
1315
1316 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1317 config.navigation = Configuration.NAVIGATION_DPAD;
1318 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1319 }
1320
1321 // Determine whether a hard keyboard is available and enabled.
1322 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1323 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1324 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1325 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1326 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1327 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1328 }
1329
1330 // Let the policy update hidden states.
1331 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1332 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1333 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1334 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1335 }
1336
1337 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1338 int displayId) {
1339 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1340 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1341 final int unrotDw, unrotDh;
1342 if (rotated) {
1343 unrotDw = dh;
1344 unrotDh = dw;
1345 } else {
1346 unrotDw = dw;
1347 unrotDh = dh;
1348 }
1349 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1350 displayId);
1351 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1352 displayId);
1353 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1354 displayId);
1355 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1356 displayId);
1357 return sw;
1358 }
1359
1360 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1361 DisplayMetrics dm, int dw, int dh, int displayId) {
1362 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001363 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001364 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001365 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001366 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1367 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1368 if (curSize == 0 || size < curSize) {
1369 curSize = size;
1370 }
1371 return curSize;
1372 }
1373
1374 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1375 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1376
1377 // We need to determine the smallest width that will occur under normal
1378 // operation. To this, start with the base screen size and compute the
1379 // width under the different possible rotations. We need to un-rotate
1380 // the current screen dimensions before doing this.
1381 int unrotDw, unrotDh;
1382 if (rotated) {
1383 unrotDw = dh;
1384 unrotDh = dw;
1385 } else {
1386 unrotDw = dw;
1387 unrotDh = dh;
1388 }
1389 displayInfo.smallestNominalAppWidth = 1<<30;
1390 displayInfo.smallestNominalAppHeight = 1<<30;
1391 displayInfo.largestNominalAppWidth = 0;
1392 displayInfo.largestNominalAppHeight = 0;
1393 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1394 unrotDh);
1395 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1396 unrotDw);
1397 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1398 unrotDh);
1399 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1400 unrotDw);
1401 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1402 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1403 displayId);
1404 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1405 displayId);
1406 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1407 displayId);
1408 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1409 displayId);
1410 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1411 outConfig.screenLayout = sl;
1412 }
1413
1414 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1415 int uiMode, int displayId) {
1416 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001417 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1418 mDisplayInfo.displayCutout);
1419 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1420 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001421
1422 // Compute the screen layout size class for this rotation.
1423 int longSize = w;
1424 int shortSize = h;
1425 if (longSize < shortSize) {
1426 int tmp = longSize;
1427 longSize = shortSize;
1428 shortSize = tmp;
1429 }
1430 longSize = (int)(longSize/density);
1431 shortSize = (int)(shortSize/density);
1432 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1433 }
1434
1435 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1436 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001437 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1438 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001439 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001440 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001441 if (width < displayInfo.smallestNominalAppWidth) {
1442 displayInfo.smallestNominalAppWidth = width;
1443 }
1444 if (width > displayInfo.largestNominalAppWidth) {
1445 displayInfo.largestNominalAppWidth = width;
1446 }
1447 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001448 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001449 if (height < displayInfo.smallestNominalAppHeight) {
1450 displayInfo.smallestNominalAppHeight = height;
1451 }
1452 if (height > displayInfo.largestNominalAppHeight) {
1453 displayInfo.largestNominalAppHeight = height;
1454 }
1455 }
1456
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001457 DockedStackDividerController getDockedDividerController() {
1458 return mDividerControllerLocked;
1459 }
1460
Winson Chung655332c2016-10-31 13:14:28 -07001461 PinnedStackController getPinnedStackController() {
1462 return mPinnedStackControllerLocked;
1463 }
1464
Jeff Browna506a6e2013-06-04 00:02:38 -07001465 /**
1466 * Returns true if the specified UID has access to this display.
1467 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001468 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001469 return mDisplay.hasAccess(uid);
1470 }
1471
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001472 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001473 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001474 }
1475
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001476 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001477 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001478 }
1479
Wale Ogunwale61911492017-10-11 08:50:50 -07001480 /**
1481 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1482 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001483 TaskStack getSplitScreenPrimaryStack() {
1484 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001485 return (stack != null && stack.isVisible()) ? stack : null;
1486 }
1487
1488 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001489 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001490 * not visible.
1491 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001492 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1493 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001494 }
1495
1496 TaskStack getPinnedStack() {
1497 return mTaskStackContainers.getPinnedStack();
1498 }
1499
1500 private boolean hasPinnedStack() {
1501 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001502 }
1503
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001504 /**
1505 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1506 * Null is no compatible stack on the display.
1507 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001508 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001509 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1510 }
1511
1512 /**
1513 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1514 * activity type. Null is no compatible stack on the display.
1515 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001516 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001517 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001518 }
1519
Bryce Lee48f4b572017-04-10 10:54:15 -07001520 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001521 TaskStack getTopStack() {
1522 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001523 }
1524
Winson Chunge2d72172018-01-25 17:46:20 +00001525 ArrayList<Task> getVisibleTasks() {
1526 return mTaskStackContainers.getVisibleTasks();
1527 }
1528
Wale Ogunwale61911492017-10-11 08:50:50 -07001529 void onStackWindowingModeChanged(TaskStack stack) {
1530 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001531 }
1532
Andrii Kulian441e4492016-09-29 15:25:00 -07001533 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001534 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001535 super.onConfigurationChanged(newParentConfig);
1536
Andrii Kulian3a507b52016-09-19 18:14:12 -07001537 // The display size information is heavily dependent on the resources in the current
1538 // configuration, so we need to reconfigure it every time the configuration changes.
1539 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1540 mService.reconfigureDisplayLocked(this);
1541
Bryce Leef3c6a472017-11-14 14:53:06 -08001542 final DockedStackDividerController dividerController = getDockedDividerController();
1543
1544 if (dividerController != null) {
1545 getDockedDividerController().onConfigurationChanged();
1546 }
1547
1548 final PinnedStackController pinnedStackController = getPinnedStackController();
1549
1550 if (pinnedStackController != null) {
1551 getPinnedStackController().onConfigurationChanged();
1552 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001553 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001554
Andrii Kulian441e4492016-09-29 15:25:00 -07001555 /**
1556 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1557 * bounds were updated.
1558 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001559 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001560 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1561 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001562 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001563 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001564 }
1565 }
Winson Chung32c566f2017-04-11 18:31:21 -07001566
1567 // If there was no pinned stack, we still need to notify the controller of the display info
1568 // update as a result of the config change. We do this here to consolidate the flow between
1569 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001570 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001571 mPinnedStackControllerLocked.onDisplayInfoChanged();
1572 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001573 }
1574
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001575 @Override
1576 boolean fillsParent() {
1577 return true;
1578 }
1579
1580 @Override
1581 boolean isVisible() {
1582 return true;
1583 }
1584
1585 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001586 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001587 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001588 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001589 }
1590
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001591 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001592 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1593 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1594 // target, or here in order if there isn't an IME target.
1595 if (traverseTopToBottom) {
1596 for (int i = mChildren.size() - 1; i >= 0; --i) {
1597 final DisplayChildWindowContainer child = mChildren.get(i);
1598 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1599 // In this case the Ime windows will be processed above their target so we skip
1600 // here.
1601 continue;
1602 }
1603 if (child.forAllWindows(callback, traverseTopToBottom)) {
1604 return true;
1605 }
1606 }
1607 } else {
1608 final int count = mChildren.size();
1609 for (int i = 0; i < count; i++) {
1610 final DisplayChildWindowContainer child = mChildren.get(i);
1611 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1612 // In this case the Ime windows will be processed above their target so we skip
1613 // here.
1614 continue;
1615 }
1616 if (child.forAllWindows(callback, traverseTopToBottom)) {
1617 return true;
1618 }
1619 }
1620 }
1621 return false;
1622 }
1623
1624 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1625 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1626 }
1627
Wale Ogunwale399c8692017-05-08 14:22:42 -07001628 @Override
1629 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001630 final WindowManagerPolicy policy = mService.mPolicy;
1631
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001632 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001633 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001634 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001635 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001636 // If the display is frozen, some activities may be in the middle of restarting, and
1637 // thus have removed their old window. If the window has the flag to hide the lock
1638 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1639 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001640 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001641 } else if (policy.isKeyguardLocked()) {
1642 // Use the last orientation the while the display is frozen with the keyguard
1643 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1644 // window. We don't want to check the show when locked window directly though as
1645 // things aren't stable while the display is frozen, for example the window could be
1646 // momentarily unavailable due to activity relaunch.
1647 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001648 + "return " + mLastOrientation);
1649 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001650 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001651 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001652 final int orientation = mAboveAppWindowsContainers.getOrientation();
1653 if (orientation != SCREEN_ORIENTATION_UNSET) {
1654 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001655 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001656 }
1657
Wale Ogunwale399c8692017-05-08 14:22:42 -07001658 // Top system windows are not requesting an orientation. Start searching from apps.
1659 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001660 }
1661
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001662 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001663 // Check if display metrics changed and update base values if needed.
1664 updateBaseDisplayMetricsIfNeeded();
1665
Craig Mautner722285e2012-09-07 13:55:58 -07001666 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001667 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001668
Wale Ogunwale61911492017-10-11 08:50:50 -07001669 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1670 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001671 }
Craig Mautner722285e2012-09-07 13:55:58 -07001672 }
1673
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001674 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001675 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1676 if (displayManagerInternal != null) {
1677 // Bootstrap the default logical display from the display manager.
1678 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1679 if (newDisplayInfo != null) {
1680 mDisplayInfo.copyFrom(newDisplayInfo);
1681 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001682 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001683
Andrii Kuliancd097992017-03-23 18:31:59 -07001684 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1685 mDisplayInfo.logicalDensityDpi);
1686 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1687 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1688 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001689 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001690 }
1691
Andrii Kuliancd097992017-03-23 18:31:59 -07001692 /**
1693 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1694 * values.
1695 */
1696 private void updateBaseDisplayMetricsIfNeeded() {
1697 // Get real display metrics without overrides from WM.
1698 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1699 final int orientation = mDisplayInfo.rotation;
1700 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1701 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1702 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1703 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001704 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001705
1706 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1707 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001708 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1709 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001710
1711 if (displayMetricsChanged) {
1712 // Check if display size or density is forced.
1713 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1714 || mBaseDisplayHeight != mInitialDisplayHeight;
1715 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1716
1717 // If there is an override set for base values - use it, otherwise use new values.
1718 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1719 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1720 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1721
1722 // Real display metrics changed, so we should also update initial values.
1723 mInitialDisplayWidth = newWidth;
1724 mInitialDisplayHeight = newHeight;
1725 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001726 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001727 mService.reconfigureDisplayLocked(this);
1728 }
1729 }
1730
Bryce Lee27cec322017-03-21 09:41:37 -07001731 /** Sets the maximum width the screen resolution can be */
1732 void setMaxUiWidth(int width) {
1733 if (DEBUG_DISPLAY) {
1734 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1735 }
1736
1737 mMaxUiWidth = width;
1738
1739 // Update existing metrics.
1740 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1741 }
1742
1743 /** Update base (override) display metrics. */
1744 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1745 mBaseDisplayWidth = baseWidth;
1746 mBaseDisplayHeight = baseHeight;
1747 mBaseDisplayDensity = baseDensity;
1748
1749 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1750 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1751 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1752 mBaseDisplayWidth = mMaxUiWidth;
1753
1754 if (DEBUG_DISPLAY) {
1755 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1756 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1757 + " on display:" + getDisplayId());
1758 }
1759 }
1760
1761 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001762
1763 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001764 }
1765
Wale Ogunwaledb506192017-12-08 10:57:32 -08001766 void getStableRect(Rect out) {
1767 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001768 }
1769
Wale Ogunwale61911492017-10-11 08:50:50 -07001770 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001771 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1772 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001773
Wale Ogunwale61911492017-10-11 08:50:50 -07001774 final TaskStack stack = new TaskStack(mService, stackId, controller);
1775 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001776 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001777 }
1778
Andrii Kulian51c1b672017-04-07 18:39:32 -07001779 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001780 final DisplayContent prevDc = stack.getDisplayContent();
1781 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001782 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1783 + " which is not currently attached to any display");
1784 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001785 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001786 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1787 + " to its current displayId=" + mDisplayId);
1788 }
1789
Wale Ogunwale61911492017-10-11 08:50:50 -07001790 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001791 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001792 }
1793
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001794 @Override
1795 protected void addChild(DisplayChildWindowContainer child,
1796 Comparator<DisplayChildWindowContainer> comparator) {
1797 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1798 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001799
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001800 @Override
1801 protected void addChild(DisplayChildWindowContainer child, int index) {
1802 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1803 }
1804
1805 @Override
1806 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001807 // Only allow removal of direct children from this display if the display is in the process
1808 // of been removed.
1809 if (mRemovingDisplay) {
1810 super.removeChild(child);
1811 return;
1812 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001813 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001814 }
1815
Andrii Kuliand2765632016-12-12 22:26:34 -08001816 @Override
1817 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1818 // Children of the display are statically ordered, so the real intention here is to perform
1819 // the operation on the display and not the static direct children.
1820 getParent().positionChildAt(position, this, includingParents);
1821 }
1822
Winson Chung59a47ded2018-01-25 17:46:06 +00001823 void positionStackAt(int position, TaskStack child) {
1824 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1825 layoutAndAssignWindowLayersIfNeeded();
1826 }
1827
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001828 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001829 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1830 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001831 final int taskId = stack.taskIdFromPoint(x, y);
1832 if (taskId != -1) {
1833 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001834 }
1835 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001836 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001837 }
1838
Chong Zhang8e89b312015-09-09 15:09:30 -07001839 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001840 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001841 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001842 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001843 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001844 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001845 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001846 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1847 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001848 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001849 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001850 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001851
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001852 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1853 if (mTmpTaskForResizePointSearchResult.searchDone) {
1854 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001855 }
1856 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001857 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001858 }
1859
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001860 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001861 // The provided task is the task on this display with focus, so if WindowManagerService's
1862 // focused app is not on this display, focusedTask will be null.
1863 if (focusedTask == null) {
1864 mTouchExcludeRegion.setEmpty();
1865 } else {
1866 mTouchExcludeRegion.set(mBaseDisplayRect);
1867 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1868 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001869 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1870 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001871 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1872 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001873 }
1874 // If we removed the focused task above, add it back and only leave its
1875 // outside touch area in the exclusion. TapDectector is not interested in
1876 // any touch inside the focused task itself.
1877 if (!mTmpRect2.isEmpty()) {
1878 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1879 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001880 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001881 final WindowState inputMethod = mService.mInputMethodWindow;
1882 if (inputMethod != null && inputMethod.isVisibleLw()) {
1883 // If the input method is visible and the user is typing, we don't want these touch
1884 // events to be intercepted and used to change focus. This would likely cause a
1885 // disappearance of the input method.
1886 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001887 if (inputMethod.getDisplayId() == mDisplayId) {
1888 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1889 } else {
1890 // IME is on a different display, so we need to update its tap detector.
1891 // TODO(multidisplay): Remove when IME will always appear on same display.
1892 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1893 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001894 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001895 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001896 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001897 win.getTouchableRegion(mTmpRegion);
1898 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1899 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001900 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1901 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1902 win.amendTapExcludeRegion(mTouchExcludeRegion);
1903 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001904 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001905 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001906 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001907 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001908 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1909 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001910 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001911 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001912 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001913 }
1914
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001915 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001916 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001917 super.switchUser();
1918 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001919 }
1920
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001921 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001922 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1923 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001924 }
1925 }
1926
Wale Ogunwale10124582016-09-15 20:25:50 -07001927 @Override
1928 void removeIfPossible() {
1929 if (isAnimating()) {
1930 mDeferredRemoval = true;
1931 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001932 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001933 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001934 }
1935
Wale Ogunwale10124582016-09-15 20:25:50 -07001936 @Override
1937 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001938 mRemovingDisplay = true;
1939 try {
1940 super.removeImmediately();
1941 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001942 if (mService.canDispatchPointerEvents()) {
1943 if (mTapDetector != null) {
1944 mService.unregisterPointerEventListener(mTapDetector);
1945 }
1946 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1947 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1948 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001949 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001950 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001951 } finally {
1952 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001953 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001954
1955 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001956 }
1957
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001958 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001959 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001960 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001961 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1962
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001963 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001964 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001965 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001966 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001967 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001968 }
1969
Andrii Kulian0214ed92017-05-16 13:44:05 -07001970 /** @return 'true' if removal of this display content is deferred due to active animation. */
1971 boolean isRemovalDeferred() {
1972 return mDeferredRemoval;
1973 }
1974
Wale Ogunwale10124582016-09-15 20:25:50 -07001975 boolean animateForIme(float interpolatedValue, float animationTarget,
1976 float dividerAnimationTarget) {
1977 boolean updated = false;
1978
Wale Ogunwale61911492017-10-11 08:50:50 -07001979 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1980 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001981 if (stack == null || !stack.isAdjustedForIme()) {
1982 continue;
1983 }
1984
1985 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1986 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1987 updated = true;
1988 } else {
1989 mDividerControllerLocked.mLastAnimationProgress =
1990 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1991 mDividerControllerLocked.mLastDividerProgress =
1992 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1993 updated |= stack.updateAdjustForIme(
1994 mDividerControllerLocked.mLastAnimationProgress,
1995 mDividerControllerLocked.mLastDividerProgress,
1996 false /* force */);
1997 }
1998 if (interpolatedValue >= 1f) {
1999 stack.endImeAdjustAnimation();
2000 }
2001 }
2002
2003 return updated;
2004 }
2005
2006 boolean clearImeAdjustAnimation() {
2007 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002008 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2009 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002010 if (stack != null && stack.isAdjustedForIme()) {
2011 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2012 changed = true;
2013 }
2014 }
2015 return changed;
2016 }
2017
2018 void beginImeAdjustAnimation() {
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.isVisible() && stack.isAdjustedForIme()) {
2022 stack.beginImeAdjustAnimation();
2023 }
2024 }
2025 }
2026
2027 void adjustForImeIfNeeded() {
2028 final WindowState imeWin = mService.mInputMethodWindow;
2029 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2030 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002031 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002032 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2033 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2034 imeTargetStack.getDockSide() : DOCKED_INVALID;
2035 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2036 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2037 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002038 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002039 final boolean imeHeightChanged = imeVisible &&
2040 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2041
2042 // The divider could be adjusted for IME position, or be thinner than usual,
2043 // or both. There are three possible cases:
2044 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2045 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2046 // - If IME is not visible, divider is not moved and is normal width.
2047
2048 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002049 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2050 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002051 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002052 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2053 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002054 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2055 } else {
2056 stack.resetAdjustedForIme(false);
2057 }
2058 }
2059 mDividerControllerLocked.setAdjustedForIme(
2060 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2061 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002062 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2063 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002064 stack.resetAdjustedForIme(!dockVisible);
2065 }
2066 mDividerControllerLocked.setAdjustedForIme(
2067 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2068 }
Winson Chung655332c2016-10-31 13:14:28 -07002069 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002070 }
2071
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002072 /**
2073 * If a window that has an animation specifying a colored background and the current wallpaper
2074 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2075 * suddenly disappear.
2076 */
2077 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002078 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2079 w -> w.mIsWallpaper && w.isVisibleNow());
2080
2081 if (visibleWallpaper != null) {
2082 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002083 }
2084 return winAnimator.mAnimLayer;
2085 }
2086
Wale Ogunwale10124582016-09-15 20:25:50 -07002087 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002088 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2089 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002090 stack.prepareFreezingTaskBounds();
2091 }
2092 }
2093
Wale Ogunwale94744212015-09-21 19:01:47 -07002094 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002095 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002096
2097 // Compute a transform matrix to undo the coordinate space transformation,
2098 // and present the window at the same physical position it previously occupied.
2099 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2100 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2101
2102 mTmpRectF.set(bounds);
2103 mTmpMatrix.mapRect(mTmpRectF);
2104 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002105 }
2106
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002107 static int deltaRotation(int oldRotation, int newRotation) {
2108 int delta = newRotation - oldRotation;
2109 if (delta < 0) delta += 4;
2110 return delta;
2111 }
2112
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002113 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002114 Matrix outMatrix) {
2115 // For rotations without Z-ordering we don't need the target rectangle's position.
2116 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2117 displayHeight, outMatrix);
2118 }
2119
2120 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2121 float displayWidth, float displayHeight, Matrix outMatrix) {
2122 switch (rotation) {
2123 case ROTATION_0:
2124 outMatrix.reset();
2125 break;
2126 case ROTATION_270:
2127 outMatrix.setRotate(270, 0, 0);
2128 outMatrix.postTranslate(0, displayHeight);
2129 outMatrix.postTranslate(rectTop, 0);
2130 break;
2131 case ROTATION_180:
2132 outMatrix.reset();
2133 break;
2134 case ROTATION_90:
2135 outMatrix.setRotate(90, 0, 0);
2136 outMatrix.postTranslate(displayWidth, 0);
2137 outMatrix.postTranslate(-rectTop, rectLeft);
2138 break;
2139 }
2140 }
2141
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002142 @CallSuper
2143 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002144 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002145 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002146 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002147 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002148 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2149 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002150 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002151 }
2152 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2153 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002154 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2155 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002156 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002157 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002158 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2159 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002160 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002161 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002162 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2163 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002164 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002165 }
2166 proto.write(DPI, mBaseDisplayDensity);
2167 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002168 proto.write(ROTATION, mRotation);
2169 final ScreenRotationAnimation screenRotationAnimation =
2170 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2171 if (screenRotationAnimation != null) {
2172 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2173 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002174 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002175 proto.end(token);
2176 }
2177
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002178 @Override
2179 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2180 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002181 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2182 final String subPrefix = " " + prefix;
2183 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2184 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2185 pw.print("dpi");
2186 if (mInitialDisplayWidth != mBaseDisplayWidth
2187 || mInitialDisplayHeight != mBaseDisplayHeight
2188 || mInitialDisplayDensity != mBaseDisplayDensity) {
2189 pw.print(" base=");
2190 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2191 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2192 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002193 if (mDisplayScalingDisabled) {
2194 pw.println(" noscale");
2195 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002196 pw.print(" cur=");
2197 pw.print(mDisplayInfo.logicalWidth);
2198 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2199 pw.print(" app=");
2200 pw.print(mDisplayInfo.appWidth);
2201 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2202 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2203 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2204 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2205 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002206 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002207 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002208 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002209
Craig Mautnerdc548482014-02-05 13:35:24 -08002210 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002211 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002212 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2213 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002214 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002215 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002216
Craig Mautnerdc548482014-02-05 13:35:24 -08002217 pw.println();
2218 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002219 pw.println();
2220 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002221 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002222 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002223 pw.print(" Exiting #"); pw.print(i);
2224 pw.print(' '); pw.print(token);
2225 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002226 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002227 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002228 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002229
Jorim Jaggi31f71702016-05-04 16:43:04 -07002230 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002231
2232 // Dump stack references
2233 final TaskStack homeStack = getHomeStack();
2234 if (homeStack != null) {
2235 pw.println(prefix + "homeStack=" + homeStack.getName());
2236 }
2237 final TaskStack pinnedStack = getPinnedStack();
2238 if (pinnedStack != null) {
2239 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2240 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002241 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002242 if (splitScreenPrimaryStack != null) {
2243 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2244 }
2245
2246 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002247 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002248 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002249 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002250
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002251 pw.println();
2252 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002253 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002254
2255 @Override
2256 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002257 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002258 }
2259
2260 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002261 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002262 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002263
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002264 /** Returns true if the stack in the windowing mode is visible. */
2265 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002266 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002267 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002268 }
2269
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002270 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002271 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002272 final int x = (int) xf;
2273 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002274 final WindowState touchedWin = getWindow(w -> {
2275 final int flags = w.mAttrs.flags;
2276 if (!w.isVisibleLw()) {
2277 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002278 }
2279 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002280 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002281 }
2282
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002283 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002284 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002285 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002286 }
2287
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002288 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002289
2290 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002291 return mTmpRegion.contains(x, y) || touchFlags == 0;
2292 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002293
2294 return touchedWin;
2295 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002296
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002297 boolean canAddToastWindowForUid(int uid) {
2298 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002299 // Also if the app is focused adding more than one toast at
2300 // a time for better backwards compatibility.
2301 final WindowState focusedWindowForUid = getWindow(w ->
2302 w.mOwnerUid == uid && w.isFocused());
2303 if (focusedWindowForUid != null) {
2304 return true;
2305 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002306 final WindowState win = getWindow(w ->
2307 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2308 && !w.mWindowRemovalAllowed);
2309 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002310 }
2311
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002312 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002313 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2314 return;
2315 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002316
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002317 // Used to communicate the old focus to the callback method.
2318 mTmpWindow = oldFocus;
2319
2320 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002321 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002322
2323 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002324 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002325
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002326 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002327
2328 if (mTmpWindow == null) {
2329 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2330 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002331 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002332 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002333 }
2334
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002335 /** Updates the layer assignment of windows on this display. */
2336 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002337 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002338 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002339 if (setLayoutNeeded) {
2340 setLayoutNeeded();
2341 }
Robert Carrb1579c82017-09-05 14:54:47 -07002342
Robert Carrf59b8dd2017-10-02 18:58:36 -07002343 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002344 // the application of this transaction until the animation pass triggers
2345 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2346 // the hiding and showing of surfaces.
2347 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002348 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002349 }
2350
Wale Ogunwale1666e312016-12-16 11:27:18 -08002351 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2352 // moving containers or resizing them. Need to investigate the best way to have it automatically
2353 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002354 void layoutAndAssignWindowLayersIfNeeded() {
2355 mService.mWindowsChanged = true;
2356 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002357
2358 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2359 false /*updateInputWindows*/)) {
2360 assignWindowLayers(false /* setLayoutNeeded */);
2361 }
2362
2363 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2364 mService.mWindowPlacerLocked.performSurfacePlacement();
2365 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2366 }
2367
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002368 /** Returns true if a leaked surface was destroyed */
2369 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002370 // Used to indicate that a surface was leaked.
2371 mTmpWindow = null;
2372 forAllWindows(w -> {
2373 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002374 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002375 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002376 }
2377 if (!mService.mSessions.contains(wsa.mSession)) {
2378 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002379 + w + " surface=" + wsa.mSurfaceController
2380 + " token=" + w.mToken
2381 + " pid=" + w.mSession.mPid
2382 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002383 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002384 mService.mForceRemoves.add(w);
2385 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002386 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002387 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002388 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002389 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002390 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002391 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002392 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002393 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002394 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002395
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002396 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002397 }
2398
2399 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002400 * Determine and return the window that should be the IME target.
2401 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2402 * @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 +00002403 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002404 WindowState computeImeTarget(boolean updateImeTarget) {
2405 if (mService.mInputMethodWindow == null) {
2406 // There isn't an IME so there shouldn't be a target...That was easy!
2407 if (updateImeTarget) {
2408 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2409 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002410 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002411 }
2412 return null;
2413 }
2414
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002415 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2416 // same display. Or even when the current IME/target are not on the same screen as the next
2417 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002418 mUpdateImeTarget = updateImeTarget;
2419 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002420
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002421
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002422 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2423 // to be on top of it, but it is not -really- where input will go. So look down below
2424 // for a real window to target...
2425 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2426 final AppWindowToken token = target.mAppToken;
2427 if (token != null) {
2428 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2429 if (betterTarget != null) {
2430 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002431 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002432 }
2433 }
2434
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002435 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2436 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002437
2438 // Now, a special case -- if the last target's window is in the process of exiting, and is
2439 // above the new target, keep on the last target to avoid flicker. Consider for example a
2440 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2441 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2442 // scrim.
2443 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002444 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2445 && (target == null
2446 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002447 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002448 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002449 }
2450
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002451 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2452 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002453
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002454 if (target == null) {
2455 if (updateImeTarget) {
2456 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2457 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2458 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002459 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002460 }
2461
2462 return null;
2463 }
2464
2465 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002466 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2467 if (token != null) {
2468
2469 // Now some fun for dealing with window animations that modify the Z order. We need
2470 // to look at all windows below the current target that are in this app, finding the
2471 // highest visible one in layering.
2472 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002473 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002474 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002475 }
2476
2477 if (highestTarget != null) {
2478 final AppTransition appTransition = mService.mAppTransition;
2479 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2480 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2481 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002482 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002483
2484 if (appTransition.isTransitionSet()) {
2485 // If we are currently setting up for an animation, hold everything until we
2486 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002487 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002488 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002489 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002490 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002491 // If the window we are currently targeting is involved with an animation,
2492 // and it is on top of the next target we will be over, then hold off on
2493 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002494 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002495 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002496 }
2497 }
2498 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002499
2500 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2501 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002502 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002503 }
2504
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002505 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002506 }
2507
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002508 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002509 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002510 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002511 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002512 }
2513
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002514 mService.mInputMethodTarget = target;
2515 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002516 assignWindowLayers(false /* setLayoutNeeded */);
2517 }
2518
2519 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2520 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2521 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2522 }
2523
2524 // Used to indicate we have reached the first window in the range we are interested in.
2525 mTmpWindow = null;
2526
2527 // TODO: Figure-out a more efficient way to do this.
2528 final WindowState candidate = getWindow(w -> {
2529 if (w == top) {
2530 // Reached the first window in the range we are interested in.
2531 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002532 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002533 if (mTmpWindow == null) {
2534 return false;
2535 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002536
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002537 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2538 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002539 }
2540 // If we reached the bottom of the range of windows we are considering,
2541 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002542 if (w == bottom) {
2543 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002544 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002545 return false;
2546 });
2547
2548 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002549 }
2550
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002551 void setLayoutNeeded() {
2552 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2553 mLayoutNeeded = true;
2554 }
2555
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002556 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002557 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2558 mLayoutNeeded = false;
2559 }
2560
2561 boolean isLayoutNeeded() {
2562 return mLayoutNeeded;
2563 }
2564
Wale Ogunwale02319a62016-09-26 15:21:22 -07002565 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2566 if (mTokenMap.isEmpty()) {
2567 return;
2568 }
2569 pw.println(" Display #" + mDisplayId);
2570 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2571 while (it.hasNext()) {
2572 final WindowToken token = it.next();
2573 pw.print(" ");
2574 pw.print(token);
2575 if (dumpAll) {
2576 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002577 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002578 } else {
2579 pw.println();
2580 }
2581 }
2582 }
2583
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002584 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002585 final int[] index = new int[1];
2586 forAllWindows(w -> {
2587 final WindowStateAnimator wAnim = w.mWinAnimator;
2588 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2589 index[0] = index[0] + 1;
2590 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002591 }
2592
Jorim Jaggife762342016-10-13 14:33:27 +02002593 /**
2594 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2595 */
2596 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2597 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002598 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002599 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2600 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002601 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002602 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002603 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002604 }
2605
Wale Ogunwale494009b82016-10-21 09:01:38 -07002606 boolean checkWaitingForWindows() {
2607
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002608 mHaveBootMsg = false;
2609 mHaveApp = false;
2610 mHaveWallpaper = false;
2611 mHaveKeyguard = true;
2612
2613 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002614 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2615 return true;
2616 }
2617 if (w.isDrawnLw()) {
2618 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002619 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002620 } else if (w.mAttrs.type == TYPE_APPLICATION
2621 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002622 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002623 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002624 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002625 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002626 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002627 }
2628 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002629 return false;
2630 });
2631
2632 if (visibleWindow != null) {
2633 // We have a visible window.
2634 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002635 }
2636
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002637 // if the wallpaper service is disabled on the device, we're never going to have
2638 // wallpaper, don't bother waiting for it
2639 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2640 com.android.internal.R.bool.config_enableWallpaperService)
2641 && !mService.mOnlyCore;
2642
Wale Ogunwale494009b82016-10-21 09:01:38 -07002643 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2644 "******** booted=" + mService.mSystemBooted
2645 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002646 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2647 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2648 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002649
2650 // If we are turning on the screen to show the boot message, don't do it until the boot
2651 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002652 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002653 return true;
2654 }
2655
2656 // If we are turning on the screen after the boot is completed normally, don't do so until
2657 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002658 if (mService.mSystemBooted
2659 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002660 return true;
2661 }
2662
2663 return false;
2664 }
2665
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002666 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002667 mTmpWindowAnimator = animator;
2668 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002669 }
2670
2671 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002672 resetAnimationBackgroundAnimator();
2673
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002674 // Used to indicate a detached wallpaper.
2675 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002676 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002677
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002678 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002679
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002680 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002681 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002682 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2683 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002684 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2685 }
2686 }
2687
Wale Ogunwale494009b82016-10-21 09:01:38 -07002688 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002689 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002690 if (imFocus == null) {
2691 return false;
2692 }
2693
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002694 if (DEBUG_INPUT_METHOD) {
2695 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2696 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2697 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002698 }
2699
Wale Ogunwale494009b82016-10-21 09:01:38 -07002700 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2701
2702 if (DEBUG_INPUT_METHOD) {
2703 Slog.i(TAG_WM, "IM target client: " + imeClient);
2704 if (imeClient != null) {
2705 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2706 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2707 }
2708 }
2709
2710 return imeClient != null && imeClient.asBinder() == client.asBinder();
2711 }
2712
2713 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002714 final WindowState win = getWindow(
2715 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2716 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002717 }
2718
2719 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002720 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002721 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002722 final int curValue = w.mSystemUiVisibility;
2723 final int diff = (curValue ^ visibility) & globalDiff;
2724 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002725 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002726 w.mSeq++;
2727 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002728 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002729 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2730 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002731 visibility, newValue, diff);
2732 }
2733 } catch (RemoteException e) {
2734 // so sorry
2735 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002736 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002737 }
2738
2739 void onWindowFreezeTimeout() {
2740 Slog.w(TAG_WM, "Window freeze timeout expired.");
2741 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002742
2743 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002744 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002745 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002746 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002747 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002748 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2749 - mService.mDisplayFreezeTime);
2750 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002751 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002752 mService.mWindowPlacerLocked.performSurfacePlacement();
2753 }
2754
2755 void waitForAllWindowsDrawn() {
2756 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002757 forAllWindows(w -> {
2758 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2759 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2760 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002761 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002762 w.mLastContentInsets.set(-1, -1, -1, -1);
2763 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002764 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002765 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002766 }
2767
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002768 // TODO: Super crazy long method that should be broken down...
2769 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2770
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002771 final int dw = mDisplayInfo.logicalWidth;
2772 final int dh = mDisplayInfo.logicalHeight;
2773 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2774
2775 mTmpUpdateAllDrawn.clear();
2776
2777 int repeats = 0;
2778 do {
2779 repeats++;
2780 if (repeats > 6) {
2781 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2782 clearLayoutNeeded();
2783 break;
2784 }
2785
2786 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2787 pendingLayoutChanges);
2788
Andrii Kulian839def92016-11-02 10:58:58 -07002789 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2790 // the wallpaper window jumping across displays.
2791 // Remove check for default display when there will be support for multiple wallpaper
2792 // targets (on different displays).
2793 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002794 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002795 }
2796
2797 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2798 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08002799 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002800 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002801 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002802 }
2803 }
2804
2805 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2806 setLayoutNeeded();
2807 }
2808
2809 // FIRST LOOP: Perform a layout, if needed.
2810 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2811 performLayout(repeats == 1, false /* updateInputWindows */);
2812 } else {
2813 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2814 }
2815
2816 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2817 pendingLayoutChanges = 0;
2818
2819 if (isDefaultDisplay) {
2820 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002821 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002822 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2823 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2824 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2825 }
2826 } while (pendingLayoutChanges != 0);
2827
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002828 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002829
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002830 mTmpRecoveringMemory = recoveringMemory;
2831 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002832 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002833
2834 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002835 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2836 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2837 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002838 true /* inTraversal, must call performTraversalInTrans... below */);
2839
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002840 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2841 if (wallpaperVisible != mLastWallpaperVisible) {
2842 mLastWallpaperVisible = wallpaperVisible;
2843 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2844 }
2845
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002846 while (!mTmpUpdateAllDrawn.isEmpty()) {
2847 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2848 // See if any windows have been drawn, so they (and others associated with them)
2849 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002850 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002851 }
2852
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002853 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002854 }
2855
Bryce Leef3c6a472017-11-14 14:53:06 -08002856 private void updateBounds() {
2857 calculateBounds(mTmpBounds);
2858 setBounds(mTmpBounds);
2859 }
2860
2861 // Determines the current display bounds based on the current state
2862 private void calculateBounds(Rect out) {
2863 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2864 final int orientation = mDisplayInfo.rotation;
2865 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2866 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2867 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2868 int width = mDisplayInfo.logicalWidth;
2869 int left = (physWidth - width) / 2;
2870 int height = mDisplayInfo.logicalHeight;
2871 int top = (physHeight - height) / 2;
2872 out.set(left, top, left + width, top + height);
2873 }
2874
2875 @Override
2876 public void getBounds(Rect out) {
2877 calculateBounds(out);
2878 }
2879
2880 private void getBounds(Rect out, int orientation) {
2881 getBounds(out);
2882
2883 // Rotate the Rect if needed.
2884 final int currentRotation = mDisplayInfo.rotation;
2885 final int rotationDelta = deltaRotation(currentRotation, orientation);
2886 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2887 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2888 mTmpRectF.set(out);
2889 mTmpMatrix.mapRect(mTmpRectF);
2890 mTmpRectF.round(out);
2891 }
2892 }
2893
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002894 void performLayout(boolean initial, boolean updateInputWindows) {
2895 if (!isLayoutNeeded()) {
2896 return;
2897 }
2898 clearLayoutNeeded();
2899
2900 final int dw = mDisplayInfo.logicalWidth;
2901 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002902 if (DEBUG_LAYOUT) {
2903 Slog.v(TAG, "-------------------------------------");
2904 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2905 }
2906
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01002907 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
2908 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002909 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2910 // display info above...
2911 mDisplayFrames.mRotation = mRotation;
2912 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002913 if (isDefaultDisplay) {
2914 // Not needed on non-default displays.
2915 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2916 mService.mScreenRect.set(0, 0, dw, dh);
2917 }
2918
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002919 int seq = mService.mLayoutSeq + 1;
2920 if (seq < 0) seq = 0;
2921 mService.mLayoutSeq = seq;
2922
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002923 // Used to indicate that we have processed the dream window and all additional windows are
2924 // behind it.
2925 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002926 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002927
2928 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002929 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002930
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002931 // Used to indicate that we have processed the dream window and all additional attached
2932 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002933 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002934 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002935
2936 // Now perform layout of attached windows, which usually depend on the position of the
2937 // window they are attached to. XXX does not deal with windows that are attached to windows
2938 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002939 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002940
2941 // Window frames may have changed. Tell the input dispatcher about it.
2942 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2943 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2944 if (updateInputWindows) {
2945 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2946 }
2947
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002948 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2949 }
2950
2951 /**
2952 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2953 * In portrait mode, it grabs the full screenshot.
2954 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002955 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002956 */
chaviw0315a1a2018-03-05 15:28:35 -08002957 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
2958 if (!mService.mPolicy.isScreenOn()) {
2959 if (DEBUG_SCREENSHOT) {
2960 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002961 }
chaviw0315a1a2018-03-05 15:28:35 -08002962 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002963 }
chaviwfbe47df2017-11-10 16:14:49 -08002964
chaviw0315a1a2018-03-05 15:28:35 -08002965 int dw = mDisplayInfo.logicalWidth;
2966 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08002967
chaviw0315a1a2018-03-05 15:28:35 -08002968 if (dw <= 0 || dh <= 0) {
2969 return null;
2970 }
chaviwfbe47df2017-11-10 16:14:49 -08002971
chaviw0315a1a2018-03-05 15:28:35 -08002972 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08002973
chaviw0315a1a2018-03-05 15:28:35 -08002974 // The screenshot API does not apply the current screen rotation.
2975 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08002976
chaviw0315a1a2018-03-05 15:28:35 -08002977 if (rot == ROTATION_90 || rot == ROTATION_270) {
2978 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2979 }
chaviwfbe47df2017-11-10 16:14:49 -08002980
chaviw0315a1a2018-03-05 15:28:35 -08002981 // SurfaceFlinger is not aware of orientation, so convert our logical
2982 // crop to SurfaceFlinger's portrait orientation.
2983 convertCropForSurfaceFlinger(frame, rot, dw, dh);
2984
2985 final ScreenRotationAnimation screenRotationAnimation =
2986 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2987 final boolean inRotation = screenRotationAnimation != null &&
2988 screenRotationAnimation.isAnimating();
2989 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
2990
2991 // TODO(b/68392460): We should screenshot Task controls directly
2992 // but it's difficult at the moment as the Task doesn't have the
2993 // correct size set.
2994 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
2995 if (bitmap == null) {
2996 Slog.w(TAG_WM, "Failed to take screenshot");
2997 return null;
2998 }
2999
3000 // Create a copy of the screenshot that is immutable and backed in ashmem.
3001 // This greatly reduces the overhead of passing the bitmap between processes.
3002 final Bitmap ret = bitmap.createAshmemBitmap(config);
3003 bitmap.recycle();
3004 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003005 }
3006
3007 // TODO: Can this use createRotationMatrix()?
3008 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3009 if (rot == Surface.ROTATION_90) {
3010 final int tmp = crop.top;
3011 crop.top = dw - crop.right;
3012 crop.right = crop.bottom;
3013 crop.bottom = dw - crop.left;
3014 crop.left = tmp;
3015 } else if (rot == Surface.ROTATION_180) {
3016 int tmp = crop.top;
3017 crop.top = dh - crop.bottom;
3018 crop.bottom = dh - tmp;
3019 tmp = crop.right;
3020 crop.right = dw - crop.left;
3021 crop.left = dw - tmp;
3022 } else if (rot == Surface.ROTATION_270) {
3023 final int tmp = crop.top;
3024 crop.top = crop.left;
3025 crop.left = dh - crop.bottom;
3026 crop.bottom = crop.right;
3027 crop.right = dh - tmp;
3028 }
3029 }
3030
3031 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003032 // Used to indicate the layout is needed.
3033 mTmpWindow = null;
3034
3035 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003036 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003037 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003038 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003039 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003040 w.setDisplayLayoutNeeded();
3041 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003042 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003043
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003044 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003045 mService.mWindowPlacerLocked.performSurfacePlacement();
3046 }
3047 }
3048
Wale Ogunwale1666e312016-12-16 11:27:18 -08003049 void setExitingTokensHasVisible(boolean hasVisible) {
3050 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3051 mExitingTokens.get(i).hasVisible = hasVisible;
3052 }
3053
3054 // Initialize state of exiting applications.
3055 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3056 }
3057
3058 void removeExistingTokensIfPossible() {
3059 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3060 final WindowToken token = mExitingTokens.get(i);
3061 if (!token.hasVisible) {
3062 mExitingTokens.remove(i);
3063 }
3064 }
3065
3066 // Time to remove any exiting applications?
3067 mTaskStackContainers.removeExistingAppTokensIfPossible();
3068 }
3069
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003070 @Override
3071 void onDescendantOverrideConfigurationChanged() {
3072 setLayoutNeeded();
3073 mService.requestTraversal();
3074 }
3075
David Stevens9440dc82017-03-16 19:00:20 -07003076 boolean okToDisplay() {
3077 if (mDisplayId == DEFAULT_DISPLAY) {
3078 return !mService.mDisplayFrozen
3079 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3080 }
3081 return mDisplayInfo.state == Display.STATE_ON;
3082 }
3083
3084 boolean okToAnimate() {
3085 return okToDisplay() &&
3086 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3087 }
3088
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003089 static final class TaskForResizePointSearchResult {
3090 boolean searchDone;
3091 Task taskForResize;
3092
3093 void reset() {
3094 searchDone = false;
3095 taskForResize = null;
3096 }
3097 }
Robert Carr3b716242016-08-16 16:02:21 -07003098
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003099 private static final class ApplySurfaceChangesTransactionState {
3100 boolean displayHasContent;
3101 boolean obscured;
3102 boolean syswin;
3103 boolean focusDisplayed;
3104 float preferredRefreshRate;
3105 int preferredModeId;
3106
3107 void reset() {
3108 displayHasContent = false;
3109 obscured = false;
3110 syswin = false;
3111 focusDisplayed = false;
3112 preferredRefreshRate = 0;
3113 preferredModeId = 0;
3114 }
3115 }
3116
3117 private static final class ScreenshotApplicationState {
3118 WindowState appWin;
3119 int maxLayer;
3120 int minLayer;
3121 boolean screenshotReady;
3122
3123 void reset(boolean screenshotReady) {
3124 appWin = null;
3125 maxLayer = 0;
3126 minLayer = 0;
3127 this.screenshotReady = screenshotReady;
3128 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3129 }
3130 }
3131
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003132 /**
3133 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3134 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3135 * homogeneous children type which is currently required by sub-classes of
3136 * {@link WindowContainer} class.
3137 */
3138 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3139
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003140 DisplayChildWindowContainer(WindowManagerService service) {
3141 super(service);
3142 }
3143
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003144 @Override
3145 boolean fillsParent() {
3146 return true;
3147 }
3148
3149 @Override
3150 boolean isVisible() {
3151 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003152 }
3153 }
3154
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003155 /**
3156 * Window container class that contains all containers on this display relating to Apps.
3157 * I.e Activities.
3158 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003159 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003160 /**
3161 * A control placed at the appropriate level for transitions to occur.
3162 */
chaviw23ee71c2017-12-18 11:29:41 -08003163 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003164
Robert Carrf7a7ca82017-12-06 13:17:07 -08003165 /**
3166 * Given that the split-screen divider does not have an AppWindowToken, it
3167 * will have to live inside of a "NonAppWindowContainer", in particular
3168 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3169 * it will need to be interleaved with some of our children, appearing on top of
3170 * both docked stacks but underneath any assistant stacks.
3171 *
3172 * To solve this problem we have this anchor control, which will always exist so
3173 * we can always assign it the correct value in our {@link #assignChildLayers}.
3174 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3175 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3176 * events between the two containers.
3177 */
3178 SurfaceControl mSplitScreenDividerAnchor = null;
3179
Wale Ogunwale61911492017-10-11 08:50:50 -07003180 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3181 // through the list to find them.
3182 private TaskStack mHomeStack = null;
3183 private TaskStack mPinnedStack = null;
3184 private TaskStack mSplitScreenPrimaryStack = null;
3185
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003186 TaskStackContainers(WindowManagerService service) {
3187 super(service);
3188 }
3189
Wale Ogunwale61911492017-10-11 08:50:50 -07003190 /**
3191 * Returns the topmost stack on the display that is compatible with the input windowing mode
3192 * and activity type. Null is no compatible stack on the display.
3193 */
3194 TaskStack getStack(int windowingMode, int activityType) {
3195 if (activityType == ACTIVITY_TYPE_HOME) {
3196 return mHomeStack;
3197 }
3198 if (windowingMode == WINDOWING_MODE_PINNED) {
3199 return mPinnedStack;
3200 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3201 return mSplitScreenPrimaryStack;
3202 }
3203 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3204 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003205 if (activityType == ACTIVITY_TYPE_UNDEFINED
3206 && windowingMode == stack.getWindowingMode()) {
3207 // Passing in undefined type means we want to match the topmost stack with the
3208 // windowing mode.
3209 return stack;
3210 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003211 if (stack.isCompatible(windowingMode, activityType)) {
3212 return stack;
3213 }
3214 }
3215 return null;
3216 }
3217
3218 @VisibleForTesting
3219 TaskStack getTopStack() {
3220 return mTaskStackContainers.getChildCount() > 0
3221 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3222 }
3223
3224 TaskStack getHomeStack() {
3225 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3226 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3227 }
3228 return mHomeStack;
3229 }
3230
3231 TaskStack getPinnedStack() {
3232 return mPinnedStack;
3233 }
3234
Matthew Ng64e77cf2017-10-31 14:01:31 -07003235 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003236 return mSplitScreenPrimaryStack;
3237 }
3238
Winson Chunge2d72172018-01-25 17:46:20 +00003239 ArrayList<Task> getVisibleTasks() {
3240 final ArrayList<Task> visibleTasks = new ArrayList<>();
3241 forAllTasks(task -> {
3242 if (task.isVisible()) {
3243 visibleTasks.add(task);
3244 }
3245 });
3246 return visibleTasks;
3247 }
3248
Andrii Kulian839def92016-11-02 10:58:58 -07003249 /**
3250 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003251 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003252 */
3253 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003254 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003255 addChild(stack, onTop);
3256 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003257 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003258
Wale Ogunwale61911492017-10-11 08:50:50 -07003259 void onStackWindowingModeChanged(TaskStack stack) {
3260 removeStackReferenceIfNeeded(stack);
3261 addStackReferenceIfNeeded(stack);
3262 if (stack == mPinnedStack && getTopStack() != stack) {
3263 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3264 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3265 }
3266 }
3267
3268 private void addStackReferenceIfNeeded(TaskStack stack) {
3269 if (stack.isActivityTypeHome()) {
3270 if (mHomeStack != null) {
3271 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3272 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3273 }
3274 mHomeStack = stack;
3275 }
3276 final int windowingMode = stack.getWindowingMode();
3277 if (windowingMode == WINDOWING_MODE_PINNED) {
3278 if (mPinnedStack != null) {
3279 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3280 + mPinnedStack + " already exist on display=" + this
3281 + " stack=" + stack);
3282 }
3283 mPinnedStack = stack;
3284 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3285 if (mSplitScreenPrimaryStack != null) {
3286 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3287 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3288 + " already exist on display=" + this + " stack=" + stack);
3289 }
3290 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003291 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003292 }
3293 }
3294
3295 private void removeStackReferenceIfNeeded(TaskStack stack) {
3296 if (stack == mHomeStack) {
3297 mHomeStack = null;
3298 } else if (stack == mPinnedStack) {
3299 mPinnedStack = null;
3300 } else if (stack == mSplitScreenPrimaryStack) {
3301 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003302 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3303 mService.setDockedStackCreateStateLocked(
3304 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3305 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003306 }
Andrii Kulian839def92016-11-02 10:58:58 -07003307 }
3308
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003309 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003310 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3311 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003312 addChild(stack, addIndex);
3313 setLayoutNeeded();
3314 }
3315
Wale Ogunwale61911492017-10-11 08:50:50 -07003316 @Override
3317 protected void removeChild(TaskStack stack) {
3318 super.removeChild(stack);
3319 removeStackReferenceIfNeeded(stack);
3320 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003321
3322 @Override
3323 boolean isOnTop() {
3324 // Considered always on top
3325 return true;
3326 }
3327
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003328 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003329 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003330 if (child.getWindowConfiguration().isAlwaysOnTop()
3331 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003332 // This stack is always-on-top, override the default behavior.
3333 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3334
3335 // Moving to its current position, as we must call super but we don't want to
3336 // perform any meaningful action.
3337 final int currentPosition = mChildren.indexOf(child);
3338 super.positionChildAt(currentPosition, child, false /* includingParents */);
3339 return;
3340 }
3341
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003342 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3343 super.positionChildAt(targetPosition, child, includingParents);
3344
3345 setLayoutNeeded();
3346 }
3347
3348 /**
3349 * When stack is added or repositioned, find a proper position for it.
3350 * This will make sure that pinned stack always stays on top.
3351 * @param requestedPosition Position requested by caller.
3352 * @param stack Stack to be added or positioned.
3353 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3354 * @return The proper position for the stack.
3355 */
3356 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3357 final int topChildPosition = mChildren.size() - 1;
3358 boolean toTop = requestedPosition == POSITION_TOP;
3359 toTop |= adding ? requestedPosition >= topChildPosition + 1
3360 : requestedPosition >= topChildPosition;
3361 int targetPosition = requestedPosition;
3362
Wale Ogunwale61911492017-10-11 08:50:50 -07003363 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003364 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003365 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003366 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003367 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3368 }
3369
3370 // So, stack is moved just below the pinned stack.
3371 // When we're adding a new stack the target is the current pinned stack position.
3372 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003373 // stack, because WindowContainer#positionAt() first removes element and then adds
3374 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003375 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3376 }
3377
3378 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003379 }
3380
3381 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003382 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3383 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003384 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003385 if (super.forAllWindows(callback, traverseTopToBottom)) {
3386 return true;
3387 }
3388 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3389 return true;
3390 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003391 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003392 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3393 return true;
3394 }
3395 if (super.forAllWindows(callback, traverseTopToBottom)) {
3396 return true;
3397 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003398 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003399 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003400 }
3401
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003402 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003403 boolean traverseTopToBottom) {
3404 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3405 // app tokens.
3406 // TODO: Investigate if we need to continue to do this or if we can just process them
3407 // in-order.
3408 if (traverseTopToBottom) {
3409 for (int i = mChildren.size() - 1; i >= 0; --i) {
3410 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3411 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003412 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3413 traverseTopToBottom)) {
3414 return true;
3415 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003416 }
3417 }
3418 } else {
3419 final int count = mChildren.size();
3420 for (int i = 0; i < count; ++i) {
3421 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3422 final int appTokensCount = appTokens.size();
3423 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003424 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3425 traverseTopToBottom)) {
3426 return true;
3427 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003428 }
3429 }
3430 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003431 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003432 }
3433
Wale Ogunwale1666e312016-12-16 11:27:18 -08003434 void setExitingTokensHasVisible(boolean hasVisible) {
3435 for (int i = mChildren.size() - 1; i >= 0; --i) {
3436 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3437 for (int j = appTokens.size() - 1; j >= 0; --j) {
3438 appTokens.get(j).hasVisible = hasVisible;
3439 }
3440 }
3441 }
3442
3443 void removeExistingAppTokensIfPossible() {
3444 for (int i = mChildren.size() - 1; i >= 0; --i) {
3445 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3446 for (int j = appTokens.size() - 1; j >= 0; --j) {
3447 final AppWindowToken token = appTokens.get(j);
3448 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3449 && (!token.mIsExiting || token.isEmpty())) {
3450 // Make sure there is no animation running on this token, so any windows
3451 // associated with it will be removed as soon as their animations are
3452 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003453 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003454 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3455 "performLayout: App token exiting now removed" + token);
3456 token.removeIfPossible();
3457 }
3458 }
3459 }
3460 }
3461
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003462 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003463 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003464 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3465 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003466 // Apps and their containers are not allowed to specify an orientation while the
3467 // docked or freeform stack is visible...except for the home stack/task if the
3468 // docked stack is minimized and it actually set something.
3469 if (mHomeStack != null && mHomeStack.isVisible()
3470 && mDividerControllerLocked.isMinimizedDock()) {
3471 final int orientation = mHomeStack.getOrientation();
3472 if (orientation != SCREEN_ORIENTATION_UNSET) {
3473 return orientation;
3474 }
3475 }
3476 return SCREEN_ORIENTATION_UNSPECIFIED;
3477 }
3478
3479 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003480 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3481 PackageManager.FEATURE_AUTOMOTIVE);
3482 if (isCar) {
3483 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3484 // allow anything but the default orientation.
3485 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3486 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3487 return SCREEN_ORIENTATION_UNSPECIFIED;
3488 }
3489
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003490 if (orientation != SCREEN_ORIENTATION_UNSET
3491 && orientation != SCREEN_ORIENTATION_BEHIND) {
3492 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3493 "App is requesting an orientation, return " + orientation);
3494 return orientation;
3495 }
3496
3497 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003498 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003499 // The next app has not been requested to be visible, so we keep the current orientation
3500 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003501 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003502 }
Robert Carrb1579c82017-09-05 14:54:47 -07003503
3504 @Override
3505 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003506 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003507
Robert Carr2f8aa392018-01-31 14:46:51 -08003508 for (int i = 0; i < mChildren.size(); i++) {
3509 final TaskStack s = mChildren.get(i);
3510 s.assignChildLayers(t);
3511 }
3512 }
3513
3514 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003515 final int HOME_STACK_STATE = 0;
3516 final int NORMAL_STACK_STATE = 1;
3517 final int ALWAYS_ON_TOP_STATE = 2;
3518
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003519 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003520 int layerForAnimationLayer = 0;
3521
Robert Carrf7a7ca82017-12-06 13:17:07 -08003522 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3523 for (int i = 0; i < mChildren.size(); i++) {
3524 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003525 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3526 continue;
3527 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3528 || s.isAlwaysOnTop())) {
3529 continue;
3530 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3531 continue;
3532 }
3533 s.assignLayer(t, layer++);
3534 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3535 t.setLayer(mSplitScreenDividerAnchor, layer++);
3536 }
Robert Carrb9506032018-02-13 13:54:00 -08003537 if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003538 // Ensure the animation layer ends up above the
3539 // highest animating stack and no higher.
3540 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003541 }
3542 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003543 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003544 if (mAppAnimationLayer != null) {
3545 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003546 }
Robert Carrb1579c82017-09-05 14:54:47 -07003547 }
3548
3549 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003550 SurfaceControl getAppAnimationLayer() {
3551 return mAppAnimationLayer;
3552 }
3553
Robert Carrf7a7ca82017-12-06 13:17:07 -08003554 SurfaceControl getSplitScreenDividerAnchor() {
3555 return mSplitScreenDividerAnchor;
3556 }
3557
chaviw23ee71c2017-12-18 11:29:41 -08003558 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003559 void onParentSet() {
3560 super.onParentSet();
3561 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003562 mAppAnimationLayer = makeChildSurface(null)
3563 .setName("animationLayer")
3564 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003565 mSplitScreenDividerAnchor = makeChildSurface(null)
3566 .setName("splitScreenDividerAnchor")
3567 .build();
3568 getPendingTransaction()
3569 .show(mAppAnimationLayer)
3570 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003571 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003572 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003573 mAppAnimationLayer.destroy();
3574 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003575 mSplitScreenDividerAnchor.destroy();
3576 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003577 }
3578 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003579 }
3580
Robert Carree4d4b92017-11-22 12:21:46 -08003581 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003582 AboveAppWindowContainers(String name, WindowManagerService service) {
3583 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003584 }
3585
Robert Carrb9506032018-02-13 13:54:00 -08003586 @Override
3587 void assignChildLayers(SurfaceControl.Transaction t) {
3588 assignChildLayers(t, null /* imeContainer */);
3589 }
3590
Robert Carree4d4b92017-11-22 12:21:46 -08003591 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3592 boolean needAssignIme = imeContainer != null
3593 && imeContainer.getSurfaceControl() != null;
3594 for (int j = 0; j < mChildren.size(); ++j) {
3595 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003596
3597 // See {@link mSplitScreenDividerAnchor}
3598 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3599 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3600 continue;
3601 }
Robert Carree4d4b92017-11-22 12:21:46 -08003602 wt.assignLayer(t, j);
3603 wt.assignChildLayers(t);
3604
3605 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3606 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003607
3608 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3609 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003610 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003611 needAssignIme = false;
3612 }
3613 }
3614 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003615 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003616 }
3617 }
3618 }
3619
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003620 /**
3621 * Window container class that contains all containers on this display that are not related to
3622 * Apps. E.g. status bar.
3623 */
Robert Carree4d4b92017-11-22 12:21:46 -08003624 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003625 /**
3626 * Compares two child window tokens returns -1 if the first is lesser than the second in
3627 * terms of z-order and 1 otherwise.
3628 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003629 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003630 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003631 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3632 token1.mOwnerCanManageAppTokens)
3633 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3634 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003635
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003636 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3637 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3638 return false;
3639 }
3640 final int req = w.mAttrs.screenOrientation;
3641 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3642 || req == SCREEN_ORIENTATION_UNSET) {
3643 return false;
3644 }
3645 return true;
3646 };
3647
Wale Ogunwale3a931692016-11-02 16:49:48 -07003648 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003649 private final Dimmer mDimmer = new Dimmer(this);
3650 private final Rect mTmpDimBoundsRect = new Rect();
3651
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003652 NonAppWindowContainers(String name, WindowManagerService service) {
3653 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003654 mName = name;
3655 }
3656
3657 void addChild(WindowToken token) {
3658 addChild(token, mWindowComparator);
3659 }
3660
3661 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003662 int getOrientation() {
3663 final WindowManagerPolicy policy = mService.mPolicy;
3664 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003665 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003666
3667 if (win != null) {
3668 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003669 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003670 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003671 if (mService.mKeyguardGoingAway) {
3672 // Keyguard can't affect the orientation if it is going away...
3673 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3674 return SCREEN_ORIENTATION_UNSET;
3675 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003676 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003677 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003678 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003679 }
3680
Andrii Kulian8ee72852017-03-10 10:36:45 -08003681 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003682
Jorim Jaggi75520d52017-08-24 17:23:19 +02003683 if (policy.isKeyguardShowingAndNotOccluded()
3684 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003685 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003686 }
3687
3688 return SCREEN_ORIENTATION_UNSET;
3689 }
3690
3691 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003692 String getName() {
3693 return mName;
3694 }
chaviwf29223e2018-01-31 13:23:51 -08003695
3696 @Override
3697 Dimmer getDimmer() {
3698 return mDimmer;
3699 }
3700
3701 @Override
3702 void prepareSurfaces() {
3703 mDimmer.resetDimStates();
3704 super.prepareSurfaces();
3705 getBounds(mTmpDimBoundsRect);
3706
3707 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3708 scheduleAnimation();
3709 }
3710 }
Robert Carr3b716242016-08-16 16:02:21 -07003711 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003712
Robert Carr9034d962018-01-04 18:27:42 -08003713 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3714 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3715 super(name, service);
3716 }
3717
3718 @Override
3719 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3720 }
3721 };
3722
Robert Carrb1579c82017-09-05 14:54:47 -07003723 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3724 return mService.makeSurfaceBuilder(s)
3725 .setParent(mWindowingLayer);
3726 }
3727
3728 @Override
3729 SurfaceSession getSession() {
3730 return mSession;
3731 }
3732
3733 @Override
3734 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003735 SurfaceSession s = child != null ? child.getSession() : getSession();
3736 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003737 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003738
3739 if (child == null) {
3740 return b;
3741 }
3742
Robert Carree4d4b92017-11-22 12:21:46 -08003743 return b.setName(child.getName())
3744 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003745 }
3746
3747 /**
3748 * The makeSurface variants are for use by the window-container
3749 * hierarchy. makeOverlay here is a function for various non windowing
3750 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3751 * and other potpourii.
3752 */
3753 SurfaceControl.Builder makeOverlay() {
3754 return mService.makeSurfaceBuilder(mSession)
3755 .setParent(mOverlayLayer);
3756 }
3757
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003758 /**
3759 * Reparents the given surface to mOverlayLayer.
3760 */
3761 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3762 transaction.reparent(surface, mOverlayLayer.getHandle());
3763 }
3764
Robert Carrb1579c82017-09-05 14:54:47 -07003765 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003766 applyMagnificationSpec(getPendingTransaction(), spec);
3767 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003768 }
3769
3770 @Override
3771 void onParentSet() {
3772 // Since we are the top of the SurfaceControl hierarchy here
3773 // we create the root surfaces explicitly rather than chaining
3774 // up as the default implementation in onParentSet does. So we
3775 // explicitly do NOT call super here.
3776 }
3777
3778 @Override
3779 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003780
3781 // These are layers as children of "mWindowingLayer"
3782 mBelowAppWindowsContainers.assignLayer(t, 0);
3783 mTaskStackContainers.assignLayer(t, 1);
3784 mAboveAppWindowsContainers.assignLayer(t, 2);
3785
3786 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003787 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003788
Robert Carree4d4b92017-11-22 12:21:46 -08003789 // In the case where we have an IME target that is not in split-screen
3790 // mode IME assignment is easy. We just need the IME to go directly above
3791 // the target. This way children of the target will naturally go above the IME
3792 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003793 //
Robert Carree4d4b92017-11-22 12:21:46 -08003794 // In the case of split-screen windowing mode, we need to elevate the IME above the
3795 // docked divider while keeping the app itself below the docked divider, so instead
3796 // we use relative layering of the IME targets child windows, and place the
3797 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003798 //
Robert Carree4d4b92017-11-22 12:21:46 -08003799 // In the case where we have no IME target we assign it where it's base layer would
3800 // place it in the AboveAppWindowContainers.
3801 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3802 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003803 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003804 // TODO: We need to use an extra level on the app surface to ensure
3805 // this is always above SurfaceView but always below attached window.
3806 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003807 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003808 }
3809
3810 // Above we have assigned layers to our children, now we ask them to assign
3811 // layers to their children.
3812 mBelowAppWindowsContainers.assignChildLayers(t);
3813 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003814 mAboveAppWindowsContainers.assignChildLayers(t,
3815 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003816 mImeWindowsContainers.assignChildLayers(t);
3817 }
3818
3819 /**
3820 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3821 * that the IME target is one of the docked applications. We'd like the docked divider to be
3822 * above both of the applications, and we'd like the IME to be above the docked divider.
3823 * However we need child windows of the applications to be above the IME (Text drag handles).
3824 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3825 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3826 * with {@link #WindowState#assignLayer}
3827 */
3828 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3829 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3830 }
3831
3832 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003833 void prepareSurfaces() {
3834 final ScreenRotationAnimation screenRotationAnimation =
3835 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3836 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3837 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3838 mPendingTransaction.setMatrix(mWindowingLayer,
3839 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3840 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3841 mPendingTransaction.setPosition(mWindowingLayer,
3842 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3843 mPendingTransaction.setAlpha(mWindowingLayer,
3844 screenRotationAnimation.getEnterTransformation().getAlpha());
3845 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003846
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003847 super.prepareSurfaces();
3848 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003849
3850 void assignStackOrdering(SurfaceControl.Transaction t) {
3851 mTaskStackContainers.assignStackOrdering(t);
3852 }
Craig Mautner59c00972012-07-30 12:10:24 -07003853}