blob: 7b5e8b8139b4a5aa4e402f28586b39a0aeb82010 [file] [log] [blame]
Craig Mautner59c00972012-07-30 12:10:24 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale30e441d2017-11-09 08:28:45 -080019import static android.app.ActivityManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
Wale Ogunwale61911492017-10-11 08:50:50 -070020import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070021import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
Wale Ogunwale44f036f2017-09-29 05:09:09 -070022import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
Wale Ogunwale687b4272017-07-27 02:56:23 -070023import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
Wale Ogunwaleb62139d2017-09-20 15:37:35 -070024import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
25import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Wale Ogunwalea77e1462016-09-28 10:09:46 -070026import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070027import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
28import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale687b4272017-07-27 02:56:23 -070029import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
30import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070031import static android.view.Display.DEFAULT_DISPLAY;
32import static android.view.Display.FLAG_PRIVATE;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -070033import static android.view.Surface.ROTATION_0;
34import static android.view.Surface.ROTATION_180;
35import static android.view.Surface.ROTATION_270;
36import static android.view.Surface.ROTATION_90;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070037import static android.view.View.GONE;
Wale Ogunwale10124582016-09-15 20:25:50 -070038import static android.view.WindowManager.DOCKED_BOTTOM;
39import static android.view.WindowManager.DOCKED_INVALID;
40import static android.view.WindowManager.DOCKED_TOP;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -080041import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
42import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
43import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Wale Ogunwale494009b82016-10-21 09:01:38 -070044import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070045import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070046import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
47import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Wale Ogunwale494009b82016-10-21 09:01:38 -070049import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070050import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale494009b82016-10-21 09:01:38 -070051import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Robert Carrf7a7ca82017-12-06 13:17:07 -080052import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwale494009b82016-10-21 09:01:38 -070053import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070054import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Wale Ogunwale3a931692016-11-02 16:49:48 -070055import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Wale Ogunwale494009b82016-10-21 09:01:38 -070057import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070058import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
59import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
Svetoslav Ganovaa076532016-08-01 19:16:43 -070060import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Wale Ogunwaleec731152016-09-08 20:18:57 -070061import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Adrian Roose99bc052017-11-20 17:55:31 +010062import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
63import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
64import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
65import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Adrian Roos1cf585052018-01-03 18:43:27 +010066import static com.android.server.wm.utils.CoordinateTransforms.transformPhysicalToLogicalCoordinates;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010067import static android.view.WindowManager.TRANSIT_KEYGUARD_UNOCCLUDE;
Wale Ogunwale1666e312016-12-16 11:27:18 -080068import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070069import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_BOOT;
Wale Ogunwale10124582016-09-15 20:25:50 -070070import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -070071import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070073import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -070074import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070075import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggife762342016-10-13 14:33:27 +020076import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070077import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
Wale Ogunwale494009b82016-10-21 09:01:38 -070078import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREEN_ON;
Andrii Kulian839def92016-11-02 10:58:58 -070079import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
Wale Ogunwale1666e312016-12-16 11:27:18 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070081import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070082import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070083import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACTIONS;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -070084import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070085import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -070086import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080087import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Andrii Kulian06d07d62017-03-14 11:11:47 -070088import static com.android.server.wm.WindowManagerService.CUSTOM_SCREEN_ROTATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070089import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
90import static com.android.server.wm.WindowManagerService.H.UPDATE_DOCKED_STACK_DIVIDER;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -070091import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070092import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
Andrii Kulian06d07d62017-03-14 11:11:47 -070093import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
94import static com.android.server.wm.WindowManagerService.SEAMLESS_ROTATION_TIMEOUT_DURATION;
Wale Ogunwalef7cab102016-10-25 15:25:14 -070095import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Andrii Kulian06d07d62017-03-14 11:11:47 -070096import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_ACTIVE;
Wale Ogunwale494009b82016-10-21 09:01:38 -070097import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Andrii Kulian06d07d62017-03-14 11:11:47 -070098import static com.android.server.wm.WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION;
Wale Ogunwale19e452e2016-10-12 12:36:29 -070099import static com.android.server.wm.WindowManagerService.dipToPixel;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700100import static com.android.server.wm.WindowManagerService.logSurface;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700101import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700102import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700103import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700104import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import static com.android.server.wm.proto.DisplayProto.ABOVE_APP_WINDOWS;
106import static com.android.server.wm.proto.DisplayProto.BELOW_APP_WINDOWS;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000107import static com.android.server.wm.proto.DisplayProto.DISPLAY_FRAMES;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700108import static com.android.server.wm.proto.DisplayProto.DISPLAY_INFO;
109import static com.android.server.wm.proto.DisplayProto.DOCKED_STACK_DIVIDER_CONTROLLER;
110import static com.android.server.wm.proto.DisplayProto.DPI;
111import static com.android.server.wm.proto.DisplayProto.ID;
112import static com.android.server.wm.proto.DisplayProto.IME_WINDOWS;
113import static com.android.server.wm.proto.DisplayProto.PINNED_STACK_CONTROLLER;
Steven Timotiusf2d68892017-08-28 17:00:01 -0700114import static com.android.server.wm.proto.DisplayProto.ROTATION;
115import static com.android.server.wm.proto.DisplayProto.SCREEN_ROTATION_ANIMATION;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700116import static com.android.server.wm.proto.DisplayProto.STACKS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700117import static com.android.server.wm.proto.DisplayProto.WINDOW_CONTAINER;
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -0700118
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700119import android.annotation.CallSuper;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700120import android.annotation.NonNull;
Dean Harding3e5a1522017-10-06 09:19:01 -0700121import android.content.pm.PackageManager;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700122import android.content.res.CompatibilityInfo;
Andrii Kulian441e4492016-09-29 15:25:00 -0700123import android.content.res.Configuration;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700124import android.graphics.Bitmap;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700125import android.graphics.Matrix;
Adrian Roos1cf585052018-01-03 18:43:27 +0100126import android.graphics.Path;
Craig Mautnerc00204b2013-03-05 15:02:14 -0800127import android.graphics.Rect;
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700128import android.graphics.RectF;
Craig Mautner6601b7b2013-04-29 10:29:11 -0700129import android.graphics.Region;
Jorim Jaggid47e7e12016-03-01 09:57:38 +0100130import android.graphics.Region.Op;
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700131import android.hardware.display.DisplayManagerInternal;
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700132import android.os.Debug;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700133import android.os.Handler;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700134import android.os.IBinder;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700135import android.os.RemoteException;
136import android.os.SystemClock;
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100137import android.os.Trace;
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800138import android.util.ArraySet;
Chong Zhang8e89b312015-09-09 15:09:30 -0700139import android.util.DisplayMetrics;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700140import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700141import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700142import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100143import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700144import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700145import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700146import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700147import android.view.Surface;
148import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100149import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700150import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700151
Bryce Lee48f4b572017-04-10 10:54:15 -0700152import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800153import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700154import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100155import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100156import com.android.server.wm.utils.RotationCache;
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 Roos2aa0fcd2018-02-19 18:07:49 +0100217 private final RotationCache<DisplayCutout, DisplayCutout> mDisplayCutoutCache
218 = 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 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700260 * @see #updateRotationUnchecked(boolean)
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 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700276 * @see #updateRotationUnchecked(boolean)
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
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800560 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
561 + " mContainingFrame=" + w.mContainingFrame
562 + " mDisplayFrame=" + w.mDisplayFrame);
563 }
564 }
565 };
566
567 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
568 if (w.mLayoutAttached) {
569 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
570 + " mViewVisibility=" + w.mViewVisibility
571 + " mRelayoutCalled=" + w.mRelayoutCalled);
572 // If this view is GONE, then skip it -- keep the current frame, and let the caller
573 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
574 // windows, since that means "perform layout as normal, just don't display").
575 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
576 return;
577 }
578 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
579 || w.mLayoutNeeded) {
580 if (mTmpInitial) {
581 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
582 w.mContentChanged = false;
583 }
584 w.mLayoutNeeded = false;
585 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000586 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800587 w.mLayoutSeq = mService.mLayoutSeq;
588 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
589 + " mContainingFrame=" + w.mContainingFrame
590 + " mDisplayFrame=" + w.mDisplayFrame);
591 }
592 } else if (w.mAttrs.type == TYPE_DREAM) {
593 // Don't layout windows behind a dream, so that if it does stuff like hide the
594 // status bar we won't get a bad transition when it goes away.
595 mTmpWindow = mTmpWindow2;
596 }
597 };
598
599 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
600 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
601 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
602 return w.canBeImeTarget();
603 };
604
605 private final Consumer<WindowState> mApplyPostLayoutPolicy =
606 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
607 mService.mInputMethodTarget);
608
609 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
610 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
611 final boolean obscuredChanged = w.mObscured !=
612 mTmpApplySurfaceChangesTransactionState.obscured;
613 final RootWindowContainer root = mService.mRoot;
614 // Only used if default window
615 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
616
617 // Update effect.
618 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
619 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
620 final boolean isDisplayed = w.isDisplayedLw();
621
622 if (isDisplayed && w.isObscuringDisplay()) {
623 // This window completely covers everything behind it, so we want to leave all
624 // of them as undimmed (for performance reasons).
625 root.mObscuringWindow = w;
626 mTmpApplySurfaceChangesTransactionState.obscured = true;
627 }
628
629 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
630 root.handleNotObscuredLocked(w,
631 mTmpApplySurfaceChangesTransactionState.obscured,
632 mTmpApplySurfaceChangesTransactionState.syswin);
633
634 if (w.mHasSurface && isDisplayed) {
635 final int type = w.mAttrs.type;
636 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
637 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
638 mTmpApplySurfaceChangesTransactionState.syswin = true;
639 }
640 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
641 && w.mAttrs.preferredRefreshRate != 0) {
642 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
643 = w.mAttrs.preferredRefreshRate;
644 }
645 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
646 && w.mAttrs.preferredDisplayModeId != 0) {
647 mTmpApplySurfaceChangesTransactionState.preferredModeId
648 = w.mAttrs.preferredDisplayModeId;
649 }
650 }
651 }
652
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800653 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
654 && mWallpaperController.isWallpaperTarget(w)) {
655 // This is the wallpaper target and its obscured state changed... make sure the
656 // current wallpaper's visibility has been updated accordingly.
657 mWallpaperController.updateWallpaperVisibility();
658 }
659
chaviw161ea3e2018-01-31 12:01:12 -0800660 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800661
662 final WindowStateAnimator winAnimator = w.mWinAnimator;
663
664 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
665 w.mContentChanged = false;
666
667 // Moved from updateWindowsAndWallpaperLocked().
668 if (w.mHasSurface) {
669 // Take care of the window being ready to display.
670 final boolean committed = winAnimator.commitFinishDrawingLocked();
671 if (isDefaultDisplay && committed) {
672 if (w.mAttrs.type == TYPE_DREAM) {
673 // HACK: When a dream is shown, it may at that point hide the lock screen.
674 // So we need to redo the layout to let the phone window manager make this
675 // happen.
676 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
677 if (DEBUG_LAYOUT_REPEATS) {
678 surfacePlacer.debugLayoutRepeats(
679 "dream and commitFinishDrawingLocked true",
680 pendingLayoutChanges);
681 }
682 }
683 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
684 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
685 "First draw done in potential wallpaper target " + w);
686 root.mWallpaperMayChange = true;
687 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
688 if (DEBUG_LAYOUT_REPEATS) {
689 surfacePlacer.debugLayoutRepeats(
690 "wallpaper and commitFinishDrawingLocked true",
691 pendingLayoutChanges);
692 }
693 }
694 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800695 }
696
697 final AppWindowToken atoken = w.mAppToken;
698 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100699 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800700 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
701 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
702 mTmpUpdateAllDrawn.add(atoken);
703 }
704 }
705
706 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
707 && w.isDisplayedLw()) {
708 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
709 }
710
711 w.updateResizingWindowIfNeeded();
712 };
713
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800714 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800715 * Create new {@link DisplayContent} instance, add itself to the root window container and
716 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700717 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800718 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700719 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
720 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700721 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700722 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800723 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100724 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800725 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800726 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
727 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
728 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
729 + " new=" + display);
730 }
731
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700732 mDisplay = display;
733 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700734 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700735 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700736 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700737 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000738 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700739 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800740 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700741 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700742
Robert Carr74a66a22018-02-23 12:17:51 -0800743 // We use this as our arbitrary surface size for buffer-less parents
744 // that don't impose cropping on their children. It may need to be larger
745 // than the display size because fullscreen windows can be shifted offscreen
746 // due to surfaceInsets. 2 times the largest display dimension feels like an
747 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
748 // layers the ability to match their parent sizes and be able to skip
749 // such arbitrary size settings.
750 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700751
752 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
753 .setSize(mSurfaceSize, mSurfaceSize)
754 .setOpaque(true);
755 mWindowingLayer = b.setName("Display Root").build();
756 mOverlayLayer = b.setName("Display Overlays").build();
757
Robert Carrf59b8dd2017-10-02 18:58:36 -0700758 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700759 .setLayerStack(mWindowingLayer, mDisplayId)
760 .show(mWindowingLayer)
761 .setLayer(mOverlayLayer, 1)
762 .setLayerStack(mOverlayLayer, mDisplayId)
763 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700764 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700765
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700766 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700767 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700768 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700769 super.addChild(mAboveAppWindowsContainers, null);
770 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800771
772 // Add itself as a child to the root container.
773 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700774
775 // TODO(b/62541591): evaluate whether this is the best spot to declare the
776 // {@link DisplayContent} ready for use.
777 mDisplayReady = true;
778 }
779
780 boolean isReady() {
781 // The display is ready when the system and the individual display are both ready.
782 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700783 }
784
785 int getDisplayId() {
786 return mDisplayId;
787 }
788
Wale Ogunwale02319a62016-09-26 15:21:22 -0700789 WindowToken getWindowToken(IBinder binder) {
790 return mTokenMap.get(binder);
791 }
792
793 AppWindowToken getAppWindowToken(IBinder binder) {
794 final WindowToken token = getWindowToken(binder);
795 if (token == null) {
796 return null;
797 }
798 return token.asAppWindowToken();
799 }
800
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700801 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700802 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
803 if (dc != null) {
804 // We currently don't support adding a window token to the display if the display
805 // already has the binder mapped to another token. If there is a use case for supporting
806 // this moving forward we will either need to merge the WindowTokens some how or have
807 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700808 throw new IllegalArgumentException("Can't map token=" + token + " to display="
809 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700810 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700811 if (binder == null) {
812 throw new IllegalArgumentException("Can't map token=" + token + " to display="
813 + getName() + " binder is null");
814 }
815 if (token == null) {
816 throw new IllegalArgumentException("Can't map null token to display="
817 + getName() + " binder=" + binder);
818 }
819
Wale Ogunwale02319a62016-09-26 15:21:22 -0700820 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700821
822 if (token.asAppWindowToken() == null) {
823 // Add non-app token to container hierarchy on the display. App tokens are added through
824 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700825 switch (token.windowType) {
826 case TYPE_WALLPAPER:
827 mBelowAppWindowsContainers.addChild(token);
828 break;
829 case TYPE_INPUT_METHOD:
830 case TYPE_INPUT_METHOD_DIALOG:
831 mImeWindowsContainers.addChild(token);
832 break;
833 default:
834 mAboveAppWindowsContainers.addChild(token);
835 break;
836 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700837 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700838 }
839
840 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700841 final WindowToken token = mTokenMap.remove(binder);
842 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800843 token.setExiting();
844 }
845 return token;
846 }
847
848 /** Changes the display the input window token is housed on to this one. */
849 void reParentWindowToken(WindowToken token) {
850 final DisplayContent prevDc = token.getDisplayContent();
851 if (prevDc == this) {
852 return;
853 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800854 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
855 && token.asAppWindowToken() == null) {
856 // Removed the token from the map, but made sure it's not an app token before removing
857 // from parent.
858 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700859 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800860
861 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700862 }
863
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700864 void removeAppToken(IBinder binder) {
865 final WindowToken token = removeWindowToken(binder);
866 if (token == null) {
867 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
868 return;
869 }
870
871 final AppWindowToken appToken = token.asAppWindowToken();
872
873 if (appToken == null) {
874 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
875 return;
876 }
877
878 appToken.onRemovedFromDisplay();
879 }
880
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700881 Display getDisplay() {
882 return mDisplay;
883 }
884
Craig Mautner59c00972012-07-30 12:10:24 -0700885 DisplayInfo getDisplayInfo() {
886 return mDisplayInfo;
887 }
888
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700889 DisplayMetrics getDisplayMetrics() {
890 return mDisplayMetrics;
891 }
892
Andrii Kulian8ee72852017-03-10 10:36:45 -0800893 int getRotation() {
894 return mRotation;
895 }
896
897 void setRotation(int newRotation) {
898 mRotation = newRotation;
899 }
900
901 int getLastOrientation() {
902 return mLastOrientation;
903 }
904
905 void setLastOrientation(int orientation) {
906 mLastOrientation = orientation;
907 }
908
909 boolean getAltOrientation() {
910 return mAltOrientation;
911 }
912
913 void setAltOrientation(boolean altOrientation) {
914 mAltOrientation = altOrientation;
915 }
916
917 int getLastWindowForcedOrientation() {
918 return mLastWindowForcedOrientation;
919 }
920
Andrii Kulian06d07d62017-03-14 11:11:47 -0700921 /**
922 * Update rotation of the display.
923 *
924 * Returns true if the rotation has been changed. In this case YOU MUST CALL
925 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
926 */
927 boolean updateRotationUnchecked(boolean inTransaction) {
928 if (mService.mDeferredRotationPauseCount > 0) {
929 // Rotation updates have been paused temporarily. Defer the update until
930 // updates have been resumed.
931 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
932 return false;
933 }
934
935 ScreenRotationAnimation screenRotationAnimation =
936 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
937 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
938 // Rotation updates cannot be performed while the previous rotation change
939 // animation is still in progress. Skip this update. We will try updating
940 // again after the animation is finished and the display is unfrozen.
941 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
942 return false;
943 }
944 if (mService.mDisplayFrozen) {
945 // Even if the screen rotation animation has finished (e.g. isAnimating
946 // returns false), there is still some time where we haven't yet unfrozen
947 // the display. We also need to abort rotation here.
948 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
949 "Deferring rotation, still finishing previous rotation");
950 return false;
951 }
952
953 if (!mService.mDisplayEnabled) {
954 // No point choosing a rotation if the display is not enabled.
955 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
956 return false;
957 }
958
959 final int oldRotation = mRotation;
960 final int lastOrientation = mLastOrientation;
961 final boolean oldAltOrientation = mAltOrientation;
962 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700963 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700964 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700965
Robert Carr0e007272017-10-02 13:00:55 -0700966 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700967 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
968 if (seamlessRotated != null) {
969 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
970 // to complete (that is, waiting for windows to redraw). It's tempting to check
971 // w.mSeamlessRotationCount but that could be incorrect in the case of
972 // window-removal.
973 return false;
974 }
Robert Carr0e007272017-10-02 13:00:55 -0700975
976 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700977 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700978 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700979 mayRotateSeamlessly = false;
980 }
981 for (int i = 0; i < mService.mSessions.size(); i++) {
982 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
983 mayRotateSeamlessly = false;
984 break;
985 }
986 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700987 }
Robert Carr0e007272017-10-02 13:00:55 -0700988 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700989
990 // TODO: Implement forced rotation changes.
991 // Set mAltOrientation to indicate that the application is receiving
992 // an orientation that has different metrics than it expected.
993 // eg. Portrait instead of Landscape.
994
995 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
996 lastOrientation, rotation);
997
998 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
999 + ", got rotation " + rotation + " which has "
1000 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1001
1002 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1003 // No change.
1004 return false;
1005 }
1006
1007 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1008 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1009 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1010
1011 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1012 mService.mWaitingForConfig = true;
1013 }
1014
1015 mRotation = rotation;
1016 mAltOrientation = altOrientation;
1017 if (isDefaultDisplay) {
1018 mService.mPolicy.setRotationLw(rotation);
1019 }
1020
1021 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1022 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1023 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1024 WINDOW_FREEZE_TIMEOUT_DURATION);
1025
1026 setLayoutNeeded();
1027 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001028 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001029
1030 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001031 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001032 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1033 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1034 mDisplayId);
1035 } else {
1036 // The screen rotation animation uses a screenshot to freeze the screen
1037 // while windows resize underneath.
1038 // When we are rotating seamlessly, we allow the elements to transition
1039 // to their rotated state independently and without a freeze required.
1040 screenRotationAnimation = null;
1041
1042 // We have to reset this in case a window was removed before it
1043 // finished seamless rotation.
1044 mService.mSeamlessRotationCount = 0;
1045 }
1046
1047 // We need to update our screen size information to match the new rotation. If the rotation
1048 // has actually changed then this method will return true and, according to the comment at
1049 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1050 // By updating the Display info here it will be available to
1051 // #computeScreenConfiguration() later.
1052 updateDisplayAndOrientation(getConfiguration().uiMode);
1053
1054 if (!inTransaction) {
1055 if (SHOW_TRANSACTIONS) {
1056 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1057 }
1058 mService.openSurfaceTransaction();
1059 }
1060 try {
1061 // NOTE: We disable the rotation in the emulator because
1062 // it doesn't support hardware OpenGL emulation yet.
1063 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1064 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001065 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001066 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1067 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1068 mService.scheduleAnimationLocked();
1069 }
1070 }
1071
1072 if (rotateSeamlessly) {
1073 forAllWindows(w -> {
1074 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1075 }, true /* traverseTopToBottom */);
1076 }
1077
1078 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1079 } finally {
1080 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001081 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001082 if (SHOW_LIGHT_TRANSACTIONS) {
1083 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1084 }
1085 }
1086 }
1087
1088 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001089 if (w.mHasSurface && !rotateSeamlessly) {
1090 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001091 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001092 mService.mRoot.mOrientationChangeComplete = false;
1093 w.mLastFreezeDuration = 0;
1094 }
1095 w.mReportOrientationChanged = true;
1096 }, true /* traverseTopToBottom */);
1097
1098 if (rotateSeamlessly) {
1099 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1100 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1101 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1102 }
1103
1104 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1105 final WindowManagerService.RotationWatcher rotationWatcher
1106 = mService.mRotationWatchers.get(i);
1107 if (rotationWatcher.mDisplayId == mDisplayId) {
1108 try {
1109 rotationWatcher.mWatcher.onRotationChanged(rotation);
1110 } catch (RemoteException e) {
1111 // Ignore
1112 }
1113 }
1114 }
1115
1116 // TODO (multi-display): Magnification is supported only for the default display.
1117 // Announce rotation only if we will not animate as we already have the
1118 // windows in final state. Otherwise, we make this call at the rotation end.
1119 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1120 && isDefaultDisplay) {
1121 mService.mAccessibilityController.onRotationChangedLocked(this);
1122 }
1123
1124 return true;
1125 }
1126
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001127 void configureDisplayPolicy() {
1128 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1129 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1130
1131 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
1132 }
1133
Andrii Kulian06d07d62017-03-14 11:11:47 -07001134 /**
1135 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1136 * changed.
1137 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1138 */
1139 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1140 // Use the effective "visual" dimensions based on current rotation
1141 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1142 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1143 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1144 int dw = realdw;
1145 int dh = realdh;
1146
1147 if (mAltOrientation) {
1148 if (realdw > realdh) {
1149 // Turn landscape into portrait.
1150 int maxw = (int)(realdh/1.3f);
1151 if (maxw < realdw) {
1152 dw = maxw;
1153 }
1154 } else {
1155 // Turn portrait into landscape.
1156 int maxh = (int)(realdw/1.3f);
1157 if (maxh < realdh) {
1158 dh = maxh;
1159 }
1160 }
1161 }
1162
1163 // Update application display metrics.
Adrian Roos11c25582018-02-19 18:06:36 +01001164 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1165 mRotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001166 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001167 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001168 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001169 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001170 mDisplayInfo.rotation = mRotation;
1171 mDisplayInfo.logicalWidth = dw;
1172 mDisplayInfo.logicalHeight = dh;
1173 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1174 mDisplayInfo.appWidth = appWidth;
1175 mDisplayInfo.appHeight = appHeight;
1176 if (isDefaultDisplay) {
1177 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1178 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1179 }
Adrian Roos11c25582018-02-19 18:06:36 +01001180 mDisplayInfo.displayCutout = displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001181 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1182 if (mDisplayScalingDisabled) {
1183 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1184 } else {
1185 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1186 }
1187
1188 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1189 mDisplayInfo);
1190
1191 mBaseDisplayRect.set(0, 0, dw, dh);
1192
1193 if (isDefaultDisplay) {
1194 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1195 mCompatDisplayMetrics);
1196 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001197
1198 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001199 return mDisplayInfo;
1200 }
1201
Adrian Roos11c25582018-02-19 18:06:36 +01001202 DisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001203 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1204 }
1205
1206 private DisplayCutout calculateDisplayCutoutForRotationUncached(
1207 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001208 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos1cf585052018-01-03 18:43:27 +01001209 return cutout;
1210 }
Adrian Roos11c25582018-02-19 18:06:36 +01001211 if (rotation == ROTATION_0) {
Adrian Roos24264212018-02-19 16:26:15 +01001212 return cutout.computeSafeInsets(mInitialDisplayWidth, mInitialDisplayHeight);
1213 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001214 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001215 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001216 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1217 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001218 bounds.transform(mTmpMatrix);
Adrian Roos24264212018-02-19 16:26:15 +01001219 return DisplayCutout.fromBounds(bounds).computeSafeInsets(
1220 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1221 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001222 }
1223
Andrii Kulian06d07d62017-03-14 11:11:47 -07001224 /**
1225 * Compute display configuration based on display properties and policy settings.
1226 * Do not call if mDisplayReady == false.
1227 */
1228 void computeScreenConfiguration(Configuration config) {
1229 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1230
1231 final int dw = displayInfo.logicalWidth;
1232 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001233 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1234 // TODO: Probably best to set this based on some setting in the display content object,
1235 // so the display can be configured for things like fullscreen.
1236 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001237
Adrian Roos11c25582018-02-19 18:06:36 +01001238 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001239 config.screenWidthDp =
1240 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001241 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001242 config.screenHeightDp =
1243 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001244 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001245
Adrian Roos11c25582018-02-19 18:06:36 +01001246 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1247 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001248 final int leftInset = mTmpRect.left;
1249 final int topInset = mTmpRect.top;
1250 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001251 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1252 leftInset + displayInfo.appWidth /* right */,
1253 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001254 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1255 || displayInfo.rotation == Surface.ROTATION_270);
1256
1257 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001258 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001259
1260 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1261 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1262 ? Configuration.SCREENLAYOUT_ROUND_YES
1263 : Configuration.SCREENLAYOUT_ROUND_NO);
1264
1265 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1266 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1267 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1268 dh, mDisplayId);
1269 config.densityDpi = displayInfo.logicalDensityDpi;
1270
1271 config.colorMode =
1272 (displayInfo.isHdr()
1273 ? Configuration.COLOR_MODE_HDR_YES
1274 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001275 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001276 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1277 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1278
1279 // Update the configuration based on available input devices, lid switch,
1280 // and platform configuration.
1281 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1282 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1283 config.navigation = Configuration.NAVIGATION_NONAV;
1284
1285 int keyboardPresence = 0;
1286 int navigationPresence = 0;
1287 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1288 final int len = devices != null ? devices.length : 0;
1289 for (int i = 0; i < len; i++) {
1290 InputDevice device = devices[i];
1291 if (!device.isVirtual()) {
1292 final int sources = device.getSources();
1293 final int presenceFlag = device.isExternal() ?
1294 WindowManagerPolicy.PRESENCE_EXTERNAL :
1295 WindowManagerPolicy.PRESENCE_INTERNAL;
1296
1297 // TODO(multi-display): Configure on per-display basis.
1298 if (mService.mIsTouchDevice) {
1299 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1300 InputDevice.SOURCE_TOUCHSCREEN) {
1301 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1302 }
1303 } else {
1304 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1305 }
1306
1307 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1308 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1309 navigationPresence |= presenceFlag;
1310 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1311 && config.navigation == Configuration.NAVIGATION_NONAV) {
1312 config.navigation = Configuration.NAVIGATION_DPAD;
1313 navigationPresence |= presenceFlag;
1314 }
1315
1316 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1317 config.keyboard = Configuration.KEYBOARD_QWERTY;
1318 keyboardPresence |= presenceFlag;
1319 }
1320 }
1321 }
1322
1323 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1324 config.navigation = Configuration.NAVIGATION_DPAD;
1325 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1326 }
1327
1328 // Determine whether a hard keyboard is available and enabled.
1329 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1330 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1331 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1332 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1333 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1334 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1335 }
1336
1337 // Let the policy update hidden states.
1338 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1339 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1340 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1341 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1342 }
1343
1344 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1345 int displayId) {
1346 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1347 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1348 final int unrotDw, unrotDh;
1349 if (rotated) {
1350 unrotDw = dh;
1351 unrotDh = dw;
1352 } else {
1353 unrotDw = dw;
1354 unrotDh = dh;
1355 }
1356 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1357 displayId);
1358 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1359 displayId);
1360 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1361 displayId);
1362 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1363 displayId);
1364 return sw;
1365 }
1366
1367 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1368 DisplayMetrics dm, int dw, int dh, int displayId) {
1369 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001370 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001371 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001372 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001373 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1374 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1375 if (curSize == 0 || size < curSize) {
1376 curSize = size;
1377 }
1378 return curSize;
1379 }
1380
1381 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1382 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1383
1384 // We need to determine the smallest width that will occur under normal
1385 // operation. To this, start with the base screen size and compute the
1386 // width under the different possible rotations. We need to un-rotate
1387 // the current screen dimensions before doing this.
1388 int unrotDw, unrotDh;
1389 if (rotated) {
1390 unrotDw = dh;
1391 unrotDh = dw;
1392 } else {
1393 unrotDw = dw;
1394 unrotDh = dh;
1395 }
1396 displayInfo.smallestNominalAppWidth = 1<<30;
1397 displayInfo.smallestNominalAppHeight = 1<<30;
1398 displayInfo.largestNominalAppWidth = 0;
1399 displayInfo.largestNominalAppHeight = 0;
1400 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1401 unrotDh);
1402 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1403 unrotDw);
1404 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1405 unrotDh);
1406 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1407 unrotDw);
1408 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1409 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1410 displayId);
1411 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1412 displayId);
1413 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1414 displayId);
1415 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1416 displayId);
1417 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1418 outConfig.screenLayout = sl;
1419 }
1420
1421 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1422 int uiMode, int displayId) {
1423 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001424 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1425 mDisplayInfo.displayCutout);
1426 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1427 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001428
1429 // Compute the screen layout size class for this rotation.
1430 int longSize = w;
1431 int shortSize = h;
1432 if (longSize < shortSize) {
1433 int tmp = longSize;
1434 longSize = shortSize;
1435 shortSize = tmp;
1436 }
1437 longSize = (int)(longSize/density);
1438 shortSize = (int)(shortSize/density);
1439 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1440 }
1441
1442 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1443 int uiMode, int dw, int dh) {
Adrian Roos11c25582018-02-19 18:06:36 +01001444 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001445 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001446 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001447 if (width < displayInfo.smallestNominalAppWidth) {
1448 displayInfo.smallestNominalAppWidth = width;
1449 }
1450 if (width > displayInfo.largestNominalAppWidth) {
1451 displayInfo.largestNominalAppWidth = width;
1452 }
1453 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001454 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001455 if (height < displayInfo.smallestNominalAppHeight) {
1456 displayInfo.smallestNominalAppHeight = height;
1457 }
1458 if (height > displayInfo.largestNominalAppHeight) {
1459 displayInfo.largestNominalAppHeight = height;
1460 }
1461 }
1462
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001463 DockedStackDividerController getDockedDividerController() {
1464 return mDividerControllerLocked;
1465 }
1466
Winson Chung655332c2016-10-31 13:14:28 -07001467 PinnedStackController getPinnedStackController() {
1468 return mPinnedStackControllerLocked;
1469 }
1470
Jeff Browna506a6e2013-06-04 00:02:38 -07001471 /**
1472 * Returns true if the specified UID has access to this display.
1473 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001474 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001475 return mDisplay.hasAccess(uid);
1476 }
1477
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001478 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001479 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001480 }
1481
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001482 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001483 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001484 }
1485
Wale Ogunwale61911492017-10-11 08:50:50 -07001486 /**
1487 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1488 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001489 TaskStack getSplitScreenPrimaryStack() {
1490 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001491 return (stack != null && stack.isVisible()) ? stack : null;
1492 }
1493
1494 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001495 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001496 * not visible.
1497 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001498 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1499 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001500 }
1501
1502 TaskStack getPinnedStack() {
1503 return mTaskStackContainers.getPinnedStack();
1504 }
1505
1506 private boolean hasPinnedStack() {
1507 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001508 }
1509
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001510 /**
1511 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1512 * Null is no compatible stack on the display.
1513 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001514 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001515 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1516 }
1517
1518 /**
1519 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1520 * activity type. Null is no compatible stack on the display.
1521 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001522 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001523 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001524 }
1525
Bryce Lee48f4b572017-04-10 10:54:15 -07001526 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001527 TaskStack getTopStack() {
1528 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001529 }
1530
Winson Chunge2d72172018-01-25 17:46:20 +00001531 ArrayList<Task> getVisibleTasks() {
1532 return mTaskStackContainers.getVisibleTasks();
1533 }
1534
Wale Ogunwale61911492017-10-11 08:50:50 -07001535 void onStackWindowingModeChanged(TaskStack stack) {
1536 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001537 }
1538
Andrii Kulian441e4492016-09-29 15:25:00 -07001539 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001540 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001541 super.onConfigurationChanged(newParentConfig);
1542
Andrii Kulian3a507b52016-09-19 18:14:12 -07001543 // The display size information is heavily dependent on the resources in the current
1544 // configuration, so we need to reconfigure it every time the configuration changes.
1545 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1546 mService.reconfigureDisplayLocked(this);
1547
Bryce Leef3c6a472017-11-14 14:53:06 -08001548 final DockedStackDividerController dividerController = getDockedDividerController();
1549
1550 if (dividerController != null) {
1551 getDockedDividerController().onConfigurationChanged();
1552 }
1553
1554 final PinnedStackController pinnedStackController = getPinnedStackController();
1555
1556 if (pinnedStackController != null) {
1557 getPinnedStackController().onConfigurationChanged();
1558 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001559 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001560
Andrii Kulian441e4492016-09-29 15:25:00 -07001561 /**
1562 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1563 * bounds were updated.
1564 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001565 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001566 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1567 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001568 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001569 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001570 }
1571 }
Winson Chung32c566f2017-04-11 18:31:21 -07001572
1573 // If there was no pinned stack, we still need to notify the controller of the display info
1574 // update as a result of the config change. We do this here to consolidate the flow between
1575 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001576 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001577 mPinnedStackControllerLocked.onDisplayInfoChanged();
1578 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001579 }
1580
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001581 @Override
1582 boolean fillsParent() {
1583 return true;
1584 }
1585
1586 @Override
1587 boolean isVisible() {
1588 return true;
1589 }
1590
1591 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001592 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001593 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001594 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001595 }
1596
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001597 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001598 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1599 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1600 // target, or here in order if there isn't an IME target.
1601 if (traverseTopToBottom) {
1602 for (int i = mChildren.size() - 1; i >= 0; --i) {
1603 final DisplayChildWindowContainer child = mChildren.get(i);
1604 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1605 // In this case the Ime windows will be processed above their target so we skip
1606 // here.
1607 continue;
1608 }
1609 if (child.forAllWindows(callback, traverseTopToBottom)) {
1610 return true;
1611 }
1612 }
1613 } else {
1614 final int count = mChildren.size();
1615 for (int i = 0; i < count; i++) {
1616 final DisplayChildWindowContainer child = mChildren.get(i);
1617 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1618 // In this case the Ime windows will be processed above their target so we skip
1619 // here.
1620 continue;
1621 }
1622 if (child.forAllWindows(callback, traverseTopToBottom)) {
1623 return true;
1624 }
1625 }
1626 }
1627 return false;
1628 }
1629
1630 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1631 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1632 }
1633
Wale Ogunwale399c8692017-05-08 14:22:42 -07001634 @Override
1635 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001636 final WindowManagerPolicy policy = mService.mPolicy;
1637
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001638 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001639 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001640 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001641 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001642 // If the display is frozen, some activities may be in the middle of restarting, and
1643 // thus have removed their old window. If the window has the flag to hide the lock
1644 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1645 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001646 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001647 } else if (policy.isKeyguardLocked()) {
1648 // Use the last orientation the while the display is frozen with the keyguard
1649 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1650 // window. We don't want to check the show when locked window directly though as
1651 // things aren't stable while the display is frozen, for example the window could be
1652 // momentarily unavailable due to activity relaunch.
1653 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001654 + "return " + mLastOrientation);
1655 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001656 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001657 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001658 final int orientation = mAboveAppWindowsContainers.getOrientation();
1659 if (orientation != SCREEN_ORIENTATION_UNSET) {
1660 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001661 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001662 }
1663
Wale Ogunwale399c8692017-05-08 14:22:42 -07001664 // Top system windows are not requesting an orientation. Start searching from apps.
1665 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001666 }
1667
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001668 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001669 // Check if display metrics changed and update base values if needed.
1670 updateBaseDisplayMetricsIfNeeded();
1671
Craig Mautner722285e2012-09-07 13:55:58 -07001672 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001673 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001674
Wale Ogunwale61911492017-10-11 08:50:50 -07001675 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1676 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001677 }
Craig Mautner722285e2012-09-07 13:55:58 -07001678 }
1679
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001680 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001681 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1682 if (displayManagerInternal != null) {
1683 // Bootstrap the default logical display from the display manager.
1684 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1685 if (newDisplayInfo != null) {
1686 mDisplayInfo.copyFrom(newDisplayInfo);
1687 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001688 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001689
Andrii Kuliancd097992017-03-23 18:31:59 -07001690 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1691 mDisplayInfo.logicalDensityDpi);
1692 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1693 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1694 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001695 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001696 }
1697
Andrii Kuliancd097992017-03-23 18:31:59 -07001698 /**
1699 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1700 * values.
1701 */
1702 private void updateBaseDisplayMetricsIfNeeded() {
1703 // Get real display metrics without overrides from WM.
1704 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1705 final int orientation = mDisplayInfo.rotation;
1706 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1707 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1708 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1709 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001710 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001711
1712 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1713 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001714 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1715 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001716
1717 if (displayMetricsChanged) {
1718 // Check if display size or density is forced.
1719 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1720 || mBaseDisplayHeight != mInitialDisplayHeight;
1721 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1722
1723 // If there is an override set for base values - use it, otherwise use new values.
1724 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1725 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1726 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1727
1728 // Real display metrics changed, so we should also update initial values.
1729 mInitialDisplayWidth = newWidth;
1730 mInitialDisplayHeight = newHeight;
1731 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001732 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001733 mService.reconfigureDisplayLocked(this);
1734 }
1735 }
1736
Bryce Lee27cec322017-03-21 09:41:37 -07001737 /** Sets the maximum width the screen resolution can be */
1738 void setMaxUiWidth(int width) {
1739 if (DEBUG_DISPLAY) {
1740 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1741 }
1742
1743 mMaxUiWidth = width;
1744
1745 // Update existing metrics.
1746 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1747 }
1748
1749 /** Update base (override) display metrics. */
1750 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1751 mBaseDisplayWidth = baseWidth;
1752 mBaseDisplayHeight = baseHeight;
1753 mBaseDisplayDensity = baseDensity;
1754
1755 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1756 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1757 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1758 mBaseDisplayWidth = mMaxUiWidth;
1759
1760 if (DEBUG_DISPLAY) {
1761 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1762 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1763 + " on display:" + getDisplayId());
1764 }
1765 }
1766
1767 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001768
1769 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001770 }
1771
Wale Ogunwaledb506192017-12-08 10:57:32 -08001772 void getStableRect(Rect out) {
1773 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001774 }
1775
Wale Ogunwale61911492017-10-11 08:50:50 -07001776 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001777 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1778 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001779
Wale Ogunwale61911492017-10-11 08:50:50 -07001780 final TaskStack stack = new TaskStack(mService, stackId, controller);
1781 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001782 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001783 }
1784
Andrii Kulian51c1b672017-04-07 18:39:32 -07001785 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001786 final DisplayContent prevDc = stack.getDisplayContent();
1787 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001788 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1789 + " which is not currently attached to any display");
1790 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001791 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001792 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1793 + " to its current displayId=" + mDisplayId);
1794 }
1795
Wale Ogunwale61911492017-10-11 08:50:50 -07001796 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001797 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001798 }
1799
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001800 @Override
1801 protected void addChild(DisplayChildWindowContainer child,
1802 Comparator<DisplayChildWindowContainer> comparator) {
1803 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1804 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001805
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001806 @Override
1807 protected void addChild(DisplayChildWindowContainer child, int index) {
1808 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1809 }
1810
1811 @Override
1812 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001813 // Only allow removal of direct children from this display if the display is in the process
1814 // of been removed.
1815 if (mRemovingDisplay) {
1816 super.removeChild(child);
1817 return;
1818 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001819 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001820 }
1821
Andrii Kuliand2765632016-12-12 22:26:34 -08001822 @Override
1823 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1824 // Children of the display are statically ordered, so the real intention here is to perform
1825 // the operation on the display and not the static direct children.
1826 getParent().positionChildAt(position, this, includingParents);
1827 }
1828
Winson Chung59a47ded2018-01-25 17:46:06 +00001829 void positionStackAt(int position, TaskStack child) {
1830 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1831 layoutAndAssignWindowLayersIfNeeded();
1832 }
1833
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001834 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001835 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1836 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001837 final int taskId = stack.taskIdFromPoint(x, y);
1838 if (taskId != -1) {
1839 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001840 }
1841 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001842 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001843 }
1844
Chong Zhang8e89b312015-09-09 15:09:30 -07001845 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001846 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001847 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001848 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001849 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001850 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001851 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001852 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1853 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001854 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001855 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001856 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001857
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001858 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1859 if (mTmpTaskForResizePointSearchResult.searchDone) {
1860 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001861 }
1862 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001863 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001864 }
1865
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001866 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001867 // The provided task is the task on this display with focus, so if WindowManagerService's
1868 // focused app is not on this display, focusedTask will be null.
1869 if (focusedTask == null) {
1870 mTouchExcludeRegion.setEmpty();
1871 } else {
1872 mTouchExcludeRegion.set(mBaseDisplayRect);
1873 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1874 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001875 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1876 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001877 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1878 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001879 }
1880 // If we removed the focused task above, add it back and only leave its
1881 // outside touch area in the exclusion. TapDectector is not interested in
1882 // any touch inside the focused task itself.
1883 if (!mTmpRect2.isEmpty()) {
1884 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1885 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001886 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001887 final WindowState inputMethod = mService.mInputMethodWindow;
1888 if (inputMethod != null && inputMethod.isVisibleLw()) {
1889 // If the input method is visible and the user is typing, we don't want these touch
1890 // events to be intercepted and used to change focus. This would likely cause a
1891 // disappearance of the input method.
1892 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001893 if (inputMethod.getDisplayId() == mDisplayId) {
1894 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1895 } else {
1896 // IME is on a different display, so we need to update its tap detector.
1897 // TODO(multidisplay): Remove when IME will always appear on same display.
1898 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1899 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001900 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001901 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001902 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001903 win.getTouchableRegion(mTmpRegion);
1904 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1905 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001906 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1907 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1908 win.amendTapExcludeRegion(mTouchExcludeRegion);
1909 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001910 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001911 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001912 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001913 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001914 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1915 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001916 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001917 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001918 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001919 }
1920
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001921 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001922 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001923 super.switchUser();
1924 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001925 }
1926
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001927 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001928 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1929 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001930 }
1931 }
1932
Wale Ogunwale10124582016-09-15 20:25:50 -07001933 @Override
1934 void removeIfPossible() {
1935 if (isAnimating()) {
1936 mDeferredRemoval = true;
1937 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001938 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001939 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001940 }
1941
Wale Ogunwale10124582016-09-15 20:25:50 -07001942 @Override
1943 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001944 mRemovingDisplay = true;
1945 try {
1946 super.removeImmediately();
1947 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001948 if (mService.canDispatchPointerEvents()) {
1949 if (mTapDetector != null) {
1950 mService.unregisterPointerEventListener(mTapDetector);
1951 }
1952 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1953 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1954 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001955 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001956 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001957 } finally {
1958 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001959 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001960
1961 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001962 }
1963
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001964 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001965 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001966 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001967 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1968
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001969 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001970 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001971 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001972 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001973 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001974 }
1975
Andrii Kulian0214ed92017-05-16 13:44:05 -07001976 /** @return 'true' if removal of this display content is deferred due to active animation. */
1977 boolean isRemovalDeferred() {
1978 return mDeferredRemoval;
1979 }
1980
Wale Ogunwale10124582016-09-15 20:25:50 -07001981 boolean animateForIme(float interpolatedValue, float animationTarget,
1982 float dividerAnimationTarget) {
1983 boolean updated = false;
1984
Wale Ogunwale61911492017-10-11 08:50:50 -07001985 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1986 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001987 if (stack == null || !stack.isAdjustedForIme()) {
1988 continue;
1989 }
1990
1991 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1992 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1993 updated = true;
1994 } else {
1995 mDividerControllerLocked.mLastAnimationProgress =
1996 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1997 mDividerControllerLocked.mLastDividerProgress =
1998 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1999 updated |= stack.updateAdjustForIme(
2000 mDividerControllerLocked.mLastAnimationProgress,
2001 mDividerControllerLocked.mLastDividerProgress,
2002 false /* force */);
2003 }
2004 if (interpolatedValue >= 1f) {
2005 stack.endImeAdjustAnimation();
2006 }
2007 }
2008
2009 return updated;
2010 }
2011
2012 boolean clearImeAdjustAnimation() {
2013 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002014 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2015 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002016 if (stack != null && stack.isAdjustedForIme()) {
2017 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2018 changed = true;
2019 }
2020 }
2021 return changed;
2022 }
2023
2024 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002025 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2026 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002027 if (stack.isVisible() && stack.isAdjustedForIme()) {
2028 stack.beginImeAdjustAnimation();
2029 }
2030 }
2031 }
2032
2033 void adjustForImeIfNeeded() {
2034 final WindowState imeWin = mService.mInputMethodWindow;
2035 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2036 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002037 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002038 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2039 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2040 imeTargetStack.getDockSide() : DOCKED_INVALID;
2041 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2042 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2043 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002044 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002045 final boolean imeHeightChanged = imeVisible &&
2046 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2047
2048 // The divider could be adjusted for IME position, or be thinner than usual,
2049 // or both. There are three possible cases:
2050 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2051 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2052 // - If IME is not visible, divider is not moved and is normal width.
2053
2054 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002055 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2056 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002057 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002058 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2059 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002060 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2061 } else {
2062 stack.resetAdjustedForIme(false);
2063 }
2064 }
2065 mDividerControllerLocked.setAdjustedForIme(
2066 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2067 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002068 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2069 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002070 stack.resetAdjustedForIme(!dockVisible);
2071 }
2072 mDividerControllerLocked.setAdjustedForIme(
2073 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2074 }
Winson Chung655332c2016-10-31 13:14:28 -07002075 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002076 }
2077
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002078 /**
2079 * If a window that has an animation specifying a colored background and the current wallpaper
2080 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2081 * suddenly disappear.
2082 */
2083 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002084 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2085 w -> w.mIsWallpaper && w.isVisibleNow());
2086
2087 if (visibleWallpaper != null) {
2088 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002089 }
2090 return winAnimator.mAnimLayer;
2091 }
2092
Wale Ogunwale10124582016-09-15 20:25:50 -07002093 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002094 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2095 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002096 stack.prepareFreezingTaskBounds();
2097 }
2098 }
2099
Wale Ogunwale94744212015-09-21 19:01:47 -07002100 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002101 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002102
2103 // Compute a transform matrix to undo the coordinate space transformation,
2104 // and present the window at the same physical position it previously occupied.
2105 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2106 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2107
2108 mTmpRectF.set(bounds);
2109 mTmpMatrix.mapRect(mTmpRectF);
2110 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002111 }
2112
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002113 static int deltaRotation(int oldRotation, int newRotation) {
2114 int delta = newRotation - oldRotation;
2115 if (delta < 0) delta += 4;
2116 return delta;
2117 }
2118
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002119 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002120 Matrix outMatrix) {
2121 // For rotations without Z-ordering we don't need the target rectangle's position.
2122 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2123 displayHeight, outMatrix);
2124 }
2125
2126 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2127 float displayWidth, float displayHeight, Matrix outMatrix) {
2128 switch (rotation) {
2129 case ROTATION_0:
2130 outMatrix.reset();
2131 break;
2132 case ROTATION_270:
2133 outMatrix.setRotate(270, 0, 0);
2134 outMatrix.postTranslate(0, displayHeight);
2135 outMatrix.postTranslate(rectTop, 0);
2136 break;
2137 case ROTATION_180:
2138 outMatrix.reset();
2139 break;
2140 case ROTATION_90:
2141 outMatrix.setRotate(90, 0, 0);
2142 outMatrix.postTranslate(displayWidth, 0);
2143 outMatrix.postTranslate(-rectTop, rectLeft);
2144 break;
2145 }
2146 }
2147
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002148 @CallSuper
2149 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002150 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002151 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002152 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002153 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002154 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2155 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002156 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002157 }
2158 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2159 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002160 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2161 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002162 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002163 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002164 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2165 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002166 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002167 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002168 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2169 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002170 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002171 }
2172 proto.write(DPI, mBaseDisplayDensity);
2173 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002174 proto.write(ROTATION, mRotation);
2175 final ScreenRotationAnimation screenRotationAnimation =
2176 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2177 if (screenRotationAnimation != null) {
2178 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2179 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002180 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002181 proto.end(token);
2182 }
2183
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002184 @Override
2185 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2186 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002187 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2188 final String subPrefix = " " + prefix;
2189 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2190 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2191 pw.print("dpi");
2192 if (mInitialDisplayWidth != mBaseDisplayWidth
2193 || mInitialDisplayHeight != mBaseDisplayHeight
2194 || mInitialDisplayDensity != mBaseDisplayDensity) {
2195 pw.print(" base=");
2196 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2197 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2198 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002199 if (mDisplayScalingDisabled) {
2200 pw.println(" noscale");
2201 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002202 pw.print(" cur=");
2203 pw.print(mDisplayInfo.logicalWidth);
2204 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2205 pw.print(" app=");
2206 pw.print(mDisplayInfo.appWidth);
2207 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2208 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2209 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2210 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2211 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002212 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002213 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002214 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002215
Craig Mautnerdc548482014-02-05 13:35:24 -08002216 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002217 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002218 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2219 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002220 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002221 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002222
Craig Mautnerdc548482014-02-05 13:35:24 -08002223 pw.println();
2224 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002225 pw.println();
2226 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002227 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002228 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002229 pw.print(" Exiting #"); pw.print(i);
2230 pw.print(' '); pw.print(token);
2231 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002232 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002233 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002234 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002235
Jorim Jaggi31f71702016-05-04 16:43:04 -07002236 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002237
2238 // Dump stack references
2239 final TaskStack homeStack = getHomeStack();
2240 if (homeStack != null) {
2241 pw.println(prefix + "homeStack=" + homeStack.getName());
2242 }
2243 final TaskStack pinnedStack = getPinnedStack();
2244 if (pinnedStack != null) {
2245 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2246 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002247 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002248 if (splitScreenPrimaryStack != null) {
2249 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2250 }
2251
2252 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002253 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002254 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002255 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002256
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002257 pw.println();
2258 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002259 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002260
2261 @Override
2262 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002263 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002264 }
2265
2266 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002267 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002268 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002269
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002270 /** Returns true if the stack in the windowing mode is visible. */
2271 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002272 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002273 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002274 }
2275
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002276 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002277 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002278 final int x = (int) xf;
2279 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002280 final WindowState touchedWin = getWindow(w -> {
2281 final int flags = w.mAttrs.flags;
2282 if (!w.isVisibleLw()) {
2283 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002284 }
2285 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002286 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002287 }
2288
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002289 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002290 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002291 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002292 }
2293
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002294 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002295
2296 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002297 return mTmpRegion.contains(x, y) || touchFlags == 0;
2298 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002299
2300 return touchedWin;
2301 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002302
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002303 boolean canAddToastWindowForUid(int uid) {
2304 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002305 // Also if the app is focused adding more than one toast at
2306 // a time for better backwards compatibility.
2307 final WindowState focusedWindowForUid = getWindow(w ->
2308 w.mOwnerUid == uid && w.isFocused());
2309 if (focusedWindowForUid != null) {
2310 return true;
2311 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002312 final WindowState win = getWindow(w ->
2313 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2314 && !w.mWindowRemovalAllowed);
2315 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002316 }
2317
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002318 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002319 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2320 return;
2321 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002322
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002323 // Used to communicate the old focus to the callback method.
2324 mTmpWindow = oldFocus;
2325
2326 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002327 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002328
2329 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002330 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002331
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002332 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002333
2334 if (mTmpWindow == null) {
2335 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2336 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002337 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002338 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002339 }
2340
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002341 /** Updates the layer assignment of windows on this display. */
2342 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002343 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002344 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002345 if (setLayoutNeeded) {
2346 setLayoutNeeded();
2347 }
Robert Carrb1579c82017-09-05 14:54:47 -07002348
Robert Carrf59b8dd2017-10-02 18:58:36 -07002349 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002350 // the application of this transaction until the animation pass triggers
2351 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2352 // the hiding and showing of surfaces.
2353 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002354 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002355 }
2356
Wale Ogunwale1666e312016-12-16 11:27:18 -08002357 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2358 // moving containers or resizing them. Need to investigate the best way to have it automatically
2359 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002360 void layoutAndAssignWindowLayersIfNeeded() {
2361 mService.mWindowsChanged = true;
2362 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002363
2364 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2365 false /*updateInputWindows*/)) {
2366 assignWindowLayers(false /* setLayoutNeeded */);
2367 }
2368
2369 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2370 mService.mWindowPlacerLocked.performSurfacePlacement();
2371 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2372 }
2373
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002374 /** Returns true if a leaked surface was destroyed */
2375 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002376 // Used to indicate that a surface was leaked.
2377 mTmpWindow = null;
2378 forAllWindows(w -> {
2379 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002380 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002381 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002382 }
2383 if (!mService.mSessions.contains(wsa.mSession)) {
2384 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002385 + w + " surface=" + wsa.mSurfaceController
2386 + " token=" + w.mToken
2387 + " pid=" + w.mSession.mPid
2388 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002389 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002390 mService.mForceRemoves.add(w);
2391 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002392 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002393 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002394 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002395 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002396 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002397 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002398 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002399 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002400 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002401
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002402 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002403 }
2404
2405 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002406 * Determine and return the window that should be the IME target.
2407 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2408 * @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 +00002409 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002410 WindowState computeImeTarget(boolean updateImeTarget) {
2411 if (mService.mInputMethodWindow == null) {
2412 // There isn't an IME so there shouldn't be a target...That was easy!
2413 if (updateImeTarget) {
2414 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2415 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002416 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002417 }
2418 return null;
2419 }
2420
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002421 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2422 // same display. Or even when the current IME/target are not on the same screen as the next
2423 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002424 mUpdateImeTarget = updateImeTarget;
2425 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002426
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002427
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002428 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2429 // to be on top of it, but it is not -really- where input will go. So look down below
2430 // for a real window to target...
2431 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2432 final AppWindowToken token = target.mAppToken;
2433 if (token != null) {
2434 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2435 if (betterTarget != null) {
2436 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002437 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002438 }
2439 }
2440
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002441 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2442 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002443
2444 // Now, a special case -- if the last target's window is in the process of exiting, and is
2445 // above the new target, keep on the last target to avoid flicker. Consider for example a
2446 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2447 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2448 // scrim.
2449 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002450 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2451 && (target == null
2452 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002453 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002454 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002455 }
2456
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002457 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2458 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002459
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002460 if (target == null) {
2461 if (updateImeTarget) {
2462 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2463 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2464 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002465 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002466 }
2467
2468 return null;
2469 }
2470
2471 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002472 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2473 if (token != null) {
2474
2475 // Now some fun for dealing with window animations that modify the Z order. We need
2476 // to look at all windows below the current target that are in this app, finding the
2477 // highest visible one in layering.
2478 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002479 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002480 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002481 }
2482
2483 if (highestTarget != null) {
2484 final AppTransition appTransition = mService.mAppTransition;
2485 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2486 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2487 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002488 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002489
2490 if (appTransition.isTransitionSet()) {
2491 // If we are currently setting up for an animation, hold everything until we
2492 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002493 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002494 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002495 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002496 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002497 // If the window we are currently targeting is involved with an animation,
2498 // and it is on top of the next target we will be over, then hold off on
2499 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002500 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002501 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002502 }
2503 }
2504 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002505
2506 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2507 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002508 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002509 }
2510
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002511 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002512 }
2513
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002514 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002515 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002516 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002517 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002518 }
2519
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002520 mService.mInputMethodTarget = target;
2521 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002522 assignWindowLayers(false /* setLayoutNeeded */);
2523 }
2524
2525 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2526 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2527 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2528 }
2529
2530 // Used to indicate we have reached the first window in the range we are interested in.
2531 mTmpWindow = null;
2532
2533 // TODO: Figure-out a more efficient way to do this.
2534 final WindowState candidate = getWindow(w -> {
2535 if (w == top) {
2536 // Reached the first window in the range we are interested in.
2537 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002538 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002539 if (mTmpWindow == null) {
2540 return false;
2541 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002542
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002543 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2544 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002545 }
2546 // If we reached the bottom of the range of windows we are considering,
2547 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002548 if (w == bottom) {
2549 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002550 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002551 return false;
2552 });
2553
2554 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002555 }
2556
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002557 void setLayoutNeeded() {
2558 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2559 mLayoutNeeded = true;
2560 }
2561
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002562 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002563 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2564 mLayoutNeeded = false;
2565 }
2566
2567 boolean isLayoutNeeded() {
2568 return mLayoutNeeded;
2569 }
2570
Wale Ogunwale02319a62016-09-26 15:21:22 -07002571 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2572 if (mTokenMap.isEmpty()) {
2573 return;
2574 }
2575 pw.println(" Display #" + mDisplayId);
2576 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2577 while (it.hasNext()) {
2578 final WindowToken token = it.next();
2579 pw.print(" ");
2580 pw.print(token);
2581 if (dumpAll) {
2582 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002583 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002584 } else {
2585 pw.println();
2586 }
2587 }
2588 }
2589
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002590 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002591 final int[] index = new int[1];
2592 forAllWindows(w -> {
2593 final WindowStateAnimator wAnim = w.mWinAnimator;
2594 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2595 index[0] = index[0] + 1;
2596 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002597 }
2598
Jorim Jaggife762342016-10-13 14:33:27 +02002599 /**
2600 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2601 */
2602 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2603 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002604 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002605 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2606 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002607 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002608 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002609 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002610 }
2611
Wale Ogunwale494009b82016-10-21 09:01:38 -07002612 boolean checkWaitingForWindows() {
2613
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002614 mHaveBootMsg = false;
2615 mHaveApp = false;
2616 mHaveWallpaper = false;
2617 mHaveKeyguard = true;
2618
2619 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002620 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2621 return true;
2622 }
2623 if (w.isDrawnLw()) {
2624 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002625 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002626 } else if (w.mAttrs.type == TYPE_APPLICATION
2627 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002628 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002629 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002630 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002631 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002632 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002633 }
2634 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002635 return false;
2636 });
2637
2638 if (visibleWindow != null) {
2639 // We have a visible window.
2640 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002641 }
2642
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002643 // if the wallpaper service is disabled on the device, we're never going to have
2644 // wallpaper, don't bother waiting for it
2645 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2646 com.android.internal.R.bool.config_enableWallpaperService)
2647 && !mService.mOnlyCore;
2648
Wale Ogunwale494009b82016-10-21 09:01:38 -07002649 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2650 "******** booted=" + mService.mSystemBooted
2651 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002652 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2653 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2654 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002655
2656 // If we are turning on the screen to show the boot message, don't do it until the boot
2657 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002658 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002659 return true;
2660 }
2661
2662 // If we are turning on the screen after the boot is completed normally, don't do so until
2663 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002664 if (mService.mSystemBooted
2665 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002666 return true;
2667 }
2668
2669 return false;
2670 }
2671
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002672 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002673 mTmpWindowAnimator = animator;
2674 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002675 }
2676
2677 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002678 resetAnimationBackgroundAnimator();
2679
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002680 // Used to indicate a detached wallpaper.
2681 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002682 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002683
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002684 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002685
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002686 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002687 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002688 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2689 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002690 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2691 }
2692 }
2693
Wale Ogunwale494009b82016-10-21 09:01:38 -07002694 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002695 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002696 if (imFocus == null) {
2697 return false;
2698 }
2699
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002700 if (DEBUG_INPUT_METHOD) {
2701 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2702 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2703 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002704 }
2705
Wale Ogunwale494009b82016-10-21 09:01:38 -07002706 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2707
2708 if (DEBUG_INPUT_METHOD) {
2709 Slog.i(TAG_WM, "IM target client: " + imeClient);
2710 if (imeClient != null) {
2711 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2712 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2713 }
2714 }
2715
2716 return imeClient != null && imeClient.asBinder() == client.asBinder();
2717 }
2718
2719 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002720 final WindowState win = getWindow(
2721 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2722 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002723 }
2724
2725 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002726 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002727 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002728 final int curValue = w.mSystemUiVisibility;
2729 final int diff = (curValue ^ visibility) & globalDiff;
2730 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002731 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002732 w.mSeq++;
2733 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002734 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002735 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2736 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002737 visibility, newValue, diff);
2738 }
2739 } catch (RemoteException e) {
2740 // so sorry
2741 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002742 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002743 }
2744
2745 void onWindowFreezeTimeout() {
2746 Slog.w(TAG_WM, "Window freeze timeout expired.");
2747 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002748
2749 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002750 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002751 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002752 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002753 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002754 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2755 - mService.mDisplayFreezeTime);
2756 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002757 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002758 mService.mWindowPlacerLocked.performSurfacePlacement();
2759 }
2760
2761 void waitForAllWindowsDrawn() {
2762 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002763 forAllWindows(w -> {
2764 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2765 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2766 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002767 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002768 w.mLastContentInsets.set(-1, -1, -1, -1);
2769 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002770 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002771 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002772 }
2773
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002774 // TODO: Super crazy long method that should be broken down...
2775 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2776
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002777 final int dw = mDisplayInfo.logicalWidth;
2778 final int dh = mDisplayInfo.logicalHeight;
2779 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2780
2781 mTmpUpdateAllDrawn.clear();
2782
2783 int repeats = 0;
2784 do {
2785 repeats++;
2786 if (repeats > 6) {
2787 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2788 clearLayoutNeeded();
2789 break;
2790 }
2791
2792 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2793 pendingLayoutChanges);
2794
Andrii Kulian839def92016-11-02 10:58:58 -07002795 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2796 // the wallpaper window jumping across displays.
2797 // Remove check for default display when there will be support for multiple wallpaper
2798 // targets (on different displays).
2799 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002800 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002801 }
2802
2803 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2804 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2805 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2806 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002807 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002808 }
2809 }
2810
2811 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2812 setLayoutNeeded();
2813 }
2814
2815 // FIRST LOOP: Perform a layout, if needed.
2816 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2817 performLayout(repeats == 1, false /* updateInputWindows */);
2818 } else {
2819 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2820 }
2821
2822 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2823 pendingLayoutChanges = 0;
2824
2825 if (isDefaultDisplay) {
2826 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002827 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002828 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2829 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2830 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2831 }
2832 } while (pendingLayoutChanges != 0);
2833
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002834 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002835
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002836 mTmpRecoveringMemory = recoveringMemory;
2837 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002838 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002839
2840 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002841 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2842 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2843 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002844 true /* inTraversal, must call performTraversalInTrans... below */);
2845
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002846 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2847 if (wallpaperVisible != mLastWallpaperVisible) {
2848 mLastWallpaperVisible = wallpaperVisible;
2849 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2850 }
2851
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002852 while (!mTmpUpdateAllDrawn.isEmpty()) {
2853 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2854 // See if any windows have been drawn, so they (and others associated with them)
2855 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002856 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002857 }
2858
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002859 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002860 }
2861
Bryce Leef3c6a472017-11-14 14:53:06 -08002862 private void updateBounds() {
2863 calculateBounds(mTmpBounds);
2864 setBounds(mTmpBounds);
2865 }
2866
2867 // Determines the current display bounds based on the current state
2868 private void calculateBounds(Rect out) {
2869 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2870 final int orientation = mDisplayInfo.rotation;
2871 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2872 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2873 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2874 int width = mDisplayInfo.logicalWidth;
2875 int left = (physWidth - width) / 2;
2876 int height = mDisplayInfo.logicalHeight;
2877 int top = (physHeight - height) / 2;
2878 out.set(left, top, left + width, top + height);
2879 }
2880
2881 @Override
2882 public void getBounds(Rect out) {
2883 calculateBounds(out);
2884 }
2885
2886 private void getBounds(Rect out, int orientation) {
2887 getBounds(out);
2888
2889 // Rotate the Rect if needed.
2890 final int currentRotation = mDisplayInfo.rotation;
2891 final int rotationDelta = deltaRotation(currentRotation, orientation);
2892 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2893 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2894 mTmpRectF.set(out);
2895 mTmpMatrix.mapRect(mTmpRectF);
2896 mTmpRectF.round(out);
2897 }
2898 }
2899
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002900 void performLayout(boolean initial, boolean updateInputWindows) {
2901 if (!isLayoutNeeded()) {
2902 return;
2903 }
2904 clearLayoutNeeded();
2905
2906 final int dw = mDisplayInfo.logicalWidth;
2907 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002908 if (DEBUG_LAYOUT) {
2909 Slog.v(TAG, "-------------------------------------");
2910 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2911 }
2912
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002913 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
2914 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2915 // display info above...
2916 mDisplayFrames.mRotation = mRotation;
2917 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002918 if (isDefaultDisplay) {
2919 // Not needed on non-default displays.
2920 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2921 mService.mScreenRect.set(0, 0, dw, dh);
2922 }
2923
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002924 int seq = mService.mLayoutSeq + 1;
2925 if (seq < 0) seq = 0;
2926 mService.mLayoutSeq = seq;
2927
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002928 // Used to indicate that we have processed the dream window and all additional windows are
2929 // behind it.
2930 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002931 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002932
2933 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002934 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002935
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002936 // Used to indicate that we have processed the dream window and all additional attached
2937 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002938 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002939 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002940
2941 // Now perform layout of attached windows, which usually depend on the position of the
2942 // window they are attached to. XXX does not deal with windows that are attached to windows
2943 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002944 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002945
2946 // Window frames may have changed. Tell the input dispatcher about it.
2947 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2948 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2949 if (updateInputWindows) {
2950 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2951 }
2952
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002953 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2954 }
2955
2956 /**
2957 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2958 * In portrait mode, it grabs the full screenshot.
2959 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002960 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002961 */
chaviw0315a1a2018-03-05 15:28:35 -08002962 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
2963 if (!mService.mPolicy.isScreenOn()) {
2964 if (DEBUG_SCREENSHOT) {
2965 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002966 }
chaviw0315a1a2018-03-05 15:28:35 -08002967 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002968 }
chaviwfbe47df2017-11-10 16:14:49 -08002969
chaviw0315a1a2018-03-05 15:28:35 -08002970 int dw = mDisplayInfo.logicalWidth;
2971 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08002972
chaviw0315a1a2018-03-05 15:28:35 -08002973 if (dw <= 0 || dh <= 0) {
2974 return null;
2975 }
chaviwfbe47df2017-11-10 16:14:49 -08002976
chaviw0315a1a2018-03-05 15:28:35 -08002977 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08002978
chaviw0315a1a2018-03-05 15:28:35 -08002979 // The screenshot API does not apply the current screen rotation.
2980 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08002981
chaviw0315a1a2018-03-05 15:28:35 -08002982 if (rot == ROTATION_90 || rot == ROTATION_270) {
2983 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2984 }
chaviwfbe47df2017-11-10 16:14:49 -08002985
chaviw0315a1a2018-03-05 15:28:35 -08002986 // SurfaceFlinger is not aware of orientation, so convert our logical
2987 // crop to SurfaceFlinger's portrait orientation.
2988 convertCropForSurfaceFlinger(frame, rot, dw, dh);
2989
2990 final ScreenRotationAnimation screenRotationAnimation =
2991 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2992 final boolean inRotation = screenRotationAnimation != null &&
2993 screenRotationAnimation.isAnimating();
2994 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
2995
2996 // TODO(b/68392460): We should screenshot Task controls directly
2997 // but it's difficult at the moment as the Task doesn't have the
2998 // correct size set.
2999 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3000 if (bitmap == null) {
3001 Slog.w(TAG_WM, "Failed to take screenshot");
3002 return null;
3003 }
3004
3005 // Create a copy of the screenshot that is immutable and backed in ashmem.
3006 // This greatly reduces the overhead of passing the bitmap between processes.
3007 final Bitmap ret = bitmap.createAshmemBitmap(config);
3008 bitmap.recycle();
3009 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003010 }
3011
3012 // TODO: Can this use createRotationMatrix()?
3013 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3014 if (rot == Surface.ROTATION_90) {
3015 final int tmp = crop.top;
3016 crop.top = dw - crop.right;
3017 crop.right = crop.bottom;
3018 crop.bottom = dw - crop.left;
3019 crop.left = tmp;
3020 } else if (rot == Surface.ROTATION_180) {
3021 int tmp = crop.top;
3022 crop.top = dh - crop.bottom;
3023 crop.bottom = dh - tmp;
3024 tmp = crop.right;
3025 crop.right = dw - crop.left;
3026 crop.left = dw - tmp;
3027 } else if (rot == Surface.ROTATION_270) {
3028 final int tmp = crop.top;
3029 crop.top = crop.left;
3030 crop.left = dh - crop.bottom;
3031 crop.bottom = crop.right;
3032 crop.right = dh - tmp;
3033 }
3034 }
3035
3036 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003037 // Used to indicate the layout is needed.
3038 mTmpWindow = null;
3039
3040 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003041 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003042 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003043 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003044 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003045 w.setDisplayLayoutNeeded();
3046 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003047 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003048
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003049 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003050 mService.mWindowPlacerLocked.performSurfacePlacement();
3051 }
3052 }
3053
Wale Ogunwale1666e312016-12-16 11:27:18 -08003054 void setExitingTokensHasVisible(boolean hasVisible) {
3055 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3056 mExitingTokens.get(i).hasVisible = hasVisible;
3057 }
3058
3059 // Initialize state of exiting applications.
3060 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3061 }
3062
3063 void removeExistingTokensIfPossible() {
3064 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3065 final WindowToken token = mExitingTokens.get(i);
3066 if (!token.hasVisible) {
3067 mExitingTokens.remove(i);
3068 }
3069 }
3070
3071 // Time to remove any exiting applications?
3072 mTaskStackContainers.removeExistingAppTokensIfPossible();
3073 }
3074
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003075 @Override
3076 void onDescendantOverrideConfigurationChanged() {
3077 setLayoutNeeded();
3078 mService.requestTraversal();
3079 }
3080
David Stevens9440dc82017-03-16 19:00:20 -07003081 boolean okToDisplay() {
3082 if (mDisplayId == DEFAULT_DISPLAY) {
3083 return !mService.mDisplayFrozen
3084 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3085 }
3086 return mDisplayInfo.state == Display.STATE_ON;
3087 }
3088
3089 boolean okToAnimate() {
3090 return okToDisplay() &&
3091 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3092 }
3093
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003094 static final class TaskForResizePointSearchResult {
3095 boolean searchDone;
3096 Task taskForResize;
3097
3098 void reset() {
3099 searchDone = false;
3100 taskForResize = null;
3101 }
3102 }
Robert Carr3b716242016-08-16 16:02:21 -07003103
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003104 private static final class ApplySurfaceChangesTransactionState {
3105 boolean displayHasContent;
3106 boolean obscured;
3107 boolean syswin;
3108 boolean focusDisplayed;
3109 float preferredRefreshRate;
3110 int preferredModeId;
3111
3112 void reset() {
3113 displayHasContent = false;
3114 obscured = false;
3115 syswin = false;
3116 focusDisplayed = false;
3117 preferredRefreshRate = 0;
3118 preferredModeId = 0;
3119 }
3120 }
3121
3122 private static final class ScreenshotApplicationState {
3123 WindowState appWin;
3124 int maxLayer;
3125 int minLayer;
3126 boolean screenshotReady;
3127
3128 void reset(boolean screenshotReady) {
3129 appWin = null;
3130 maxLayer = 0;
3131 minLayer = 0;
3132 this.screenshotReady = screenshotReady;
3133 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3134 }
3135 }
3136
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003137 /**
3138 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3139 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3140 * homogeneous children type which is currently required by sub-classes of
3141 * {@link WindowContainer} class.
3142 */
3143 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3144
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003145 DisplayChildWindowContainer(WindowManagerService service) {
3146 super(service);
3147 }
3148
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003149 @Override
3150 boolean fillsParent() {
3151 return true;
3152 }
3153
3154 @Override
3155 boolean isVisible() {
3156 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003157 }
3158 }
3159
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003160 /**
3161 * Window container class that contains all containers on this display relating to Apps.
3162 * I.e Activities.
3163 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003164 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003165 /**
3166 * A control placed at the appropriate level for transitions to occur.
3167 */
chaviw23ee71c2017-12-18 11:29:41 -08003168 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003169
Robert Carrf7a7ca82017-12-06 13:17:07 -08003170 /**
3171 * Given that the split-screen divider does not have an AppWindowToken, it
3172 * will have to live inside of a "NonAppWindowContainer", in particular
3173 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3174 * it will need to be interleaved with some of our children, appearing on top of
3175 * both docked stacks but underneath any assistant stacks.
3176 *
3177 * To solve this problem we have this anchor control, which will always exist so
3178 * we can always assign it the correct value in our {@link #assignChildLayers}.
3179 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3180 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3181 * events between the two containers.
3182 */
3183 SurfaceControl mSplitScreenDividerAnchor = null;
3184
Wale Ogunwale61911492017-10-11 08:50:50 -07003185 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3186 // through the list to find them.
3187 private TaskStack mHomeStack = null;
3188 private TaskStack mPinnedStack = null;
3189 private TaskStack mSplitScreenPrimaryStack = null;
3190
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003191 TaskStackContainers(WindowManagerService service) {
3192 super(service);
3193 }
3194
Wale Ogunwale61911492017-10-11 08:50:50 -07003195 /**
3196 * Returns the topmost stack on the display that is compatible with the input windowing mode
3197 * and activity type. Null is no compatible stack on the display.
3198 */
3199 TaskStack getStack(int windowingMode, int activityType) {
3200 if (activityType == ACTIVITY_TYPE_HOME) {
3201 return mHomeStack;
3202 }
3203 if (windowingMode == WINDOWING_MODE_PINNED) {
3204 return mPinnedStack;
3205 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3206 return mSplitScreenPrimaryStack;
3207 }
3208 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3209 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003210 if (activityType == ACTIVITY_TYPE_UNDEFINED
3211 && windowingMode == stack.getWindowingMode()) {
3212 // Passing in undefined type means we want to match the topmost stack with the
3213 // windowing mode.
3214 return stack;
3215 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003216 if (stack.isCompatible(windowingMode, activityType)) {
3217 return stack;
3218 }
3219 }
3220 return null;
3221 }
3222
3223 @VisibleForTesting
3224 TaskStack getTopStack() {
3225 return mTaskStackContainers.getChildCount() > 0
3226 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3227 }
3228
3229 TaskStack getHomeStack() {
3230 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3231 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3232 }
3233 return mHomeStack;
3234 }
3235
3236 TaskStack getPinnedStack() {
3237 return mPinnedStack;
3238 }
3239
Matthew Ng64e77cf2017-10-31 14:01:31 -07003240 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003241 return mSplitScreenPrimaryStack;
3242 }
3243
Winson Chunge2d72172018-01-25 17:46:20 +00003244 ArrayList<Task> getVisibleTasks() {
3245 final ArrayList<Task> visibleTasks = new ArrayList<>();
3246 forAllTasks(task -> {
3247 if (task.isVisible()) {
3248 visibleTasks.add(task);
3249 }
3250 });
3251 return visibleTasks;
3252 }
3253
Andrii Kulian839def92016-11-02 10:58:58 -07003254 /**
3255 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003256 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003257 */
3258 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003259 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003260 addChild(stack, onTop);
3261 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003262 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003263
Wale Ogunwale61911492017-10-11 08:50:50 -07003264 void onStackWindowingModeChanged(TaskStack stack) {
3265 removeStackReferenceIfNeeded(stack);
3266 addStackReferenceIfNeeded(stack);
3267 if (stack == mPinnedStack && getTopStack() != stack) {
3268 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3269 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3270 }
3271 }
3272
3273 private void addStackReferenceIfNeeded(TaskStack stack) {
3274 if (stack.isActivityTypeHome()) {
3275 if (mHomeStack != null) {
3276 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3277 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3278 }
3279 mHomeStack = stack;
3280 }
3281 final int windowingMode = stack.getWindowingMode();
3282 if (windowingMode == WINDOWING_MODE_PINNED) {
3283 if (mPinnedStack != null) {
3284 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3285 + mPinnedStack + " already exist on display=" + this
3286 + " stack=" + stack);
3287 }
3288 mPinnedStack = stack;
3289 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3290 if (mSplitScreenPrimaryStack != null) {
3291 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3292 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3293 + " already exist on display=" + this + " stack=" + stack);
3294 }
3295 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003296 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003297 }
3298 }
3299
3300 private void removeStackReferenceIfNeeded(TaskStack stack) {
3301 if (stack == mHomeStack) {
3302 mHomeStack = null;
3303 } else if (stack == mPinnedStack) {
3304 mPinnedStack = null;
3305 } else if (stack == mSplitScreenPrimaryStack) {
3306 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003307 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3308 mService.setDockedStackCreateStateLocked(
3309 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3310 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003311 }
Andrii Kulian839def92016-11-02 10:58:58 -07003312 }
3313
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003314 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003315 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3316 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003317 addChild(stack, addIndex);
3318 setLayoutNeeded();
3319 }
3320
Wale Ogunwale61911492017-10-11 08:50:50 -07003321 @Override
3322 protected void removeChild(TaskStack stack) {
3323 super.removeChild(stack);
3324 removeStackReferenceIfNeeded(stack);
3325 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003326
3327 @Override
3328 boolean isOnTop() {
3329 // Considered always on top
3330 return true;
3331 }
3332
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003333 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003334 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003335 if (child.getWindowConfiguration().isAlwaysOnTop()
3336 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003337 // This stack is always-on-top, override the default behavior.
3338 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3339
3340 // Moving to its current position, as we must call super but we don't want to
3341 // perform any meaningful action.
3342 final int currentPosition = mChildren.indexOf(child);
3343 super.positionChildAt(currentPosition, child, false /* includingParents */);
3344 return;
3345 }
3346
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003347 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3348 super.positionChildAt(targetPosition, child, includingParents);
3349
3350 setLayoutNeeded();
3351 }
3352
3353 /**
3354 * When stack is added or repositioned, find a proper position for it.
3355 * This will make sure that pinned stack always stays on top.
3356 * @param requestedPosition Position requested by caller.
3357 * @param stack Stack to be added or positioned.
3358 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3359 * @return The proper position for the stack.
3360 */
3361 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3362 final int topChildPosition = mChildren.size() - 1;
3363 boolean toTop = requestedPosition == POSITION_TOP;
3364 toTop |= adding ? requestedPosition >= topChildPosition + 1
3365 : requestedPosition >= topChildPosition;
3366 int targetPosition = requestedPosition;
3367
Wale Ogunwale61911492017-10-11 08:50:50 -07003368 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003369 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003370 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003371 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003372 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3373 }
3374
3375 // So, stack is moved just below the pinned stack.
3376 // When we're adding a new stack the target is the current pinned stack position.
3377 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003378 // stack, because WindowContainer#positionAt() first removes element and then adds
3379 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003380 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3381 }
3382
3383 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003384 }
3385
3386 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003387 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3388 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003389 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003390 if (super.forAllWindows(callback, traverseTopToBottom)) {
3391 return true;
3392 }
3393 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3394 return true;
3395 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003396 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003397 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3398 return true;
3399 }
3400 if (super.forAllWindows(callback, traverseTopToBottom)) {
3401 return true;
3402 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003403 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003404 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003405 }
3406
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003407 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003408 boolean traverseTopToBottom) {
3409 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3410 // app tokens.
3411 // TODO: Investigate if we need to continue to do this or if we can just process them
3412 // in-order.
3413 if (traverseTopToBottom) {
3414 for (int i = mChildren.size() - 1; i >= 0; --i) {
3415 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3416 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003417 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3418 traverseTopToBottom)) {
3419 return true;
3420 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003421 }
3422 }
3423 } else {
3424 final int count = mChildren.size();
3425 for (int i = 0; i < count; ++i) {
3426 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3427 final int appTokensCount = appTokens.size();
3428 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003429 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3430 traverseTopToBottom)) {
3431 return true;
3432 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003433 }
3434 }
3435 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003436 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003437 }
3438
Wale Ogunwale1666e312016-12-16 11:27:18 -08003439 void setExitingTokensHasVisible(boolean hasVisible) {
3440 for (int i = mChildren.size() - 1; i >= 0; --i) {
3441 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3442 for (int j = appTokens.size() - 1; j >= 0; --j) {
3443 appTokens.get(j).hasVisible = hasVisible;
3444 }
3445 }
3446 }
3447
3448 void removeExistingAppTokensIfPossible() {
3449 for (int i = mChildren.size() - 1; i >= 0; --i) {
3450 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3451 for (int j = appTokens.size() - 1; j >= 0; --j) {
3452 final AppWindowToken token = appTokens.get(j);
3453 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3454 && (!token.mIsExiting || token.isEmpty())) {
3455 // Make sure there is no animation running on this token, so any windows
3456 // associated with it will be removed as soon as their animations are
3457 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003458 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003459 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3460 "performLayout: App token exiting now removed" + token);
3461 token.removeIfPossible();
3462 }
3463 }
3464 }
3465 }
3466
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003467 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003468 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003469 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3470 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003471 // Apps and their containers are not allowed to specify an orientation while the
3472 // docked or freeform stack is visible...except for the home stack/task if the
3473 // docked stack is minimized and it actually set something.
3474 if (mHomeStack != null && mHomeStack.isVisible()
3475 && mDividerControllerLocked.isMinimizedDock()) {
3476 final int orientation = mHomeStack.getOrientation();
3477 if (orientation != SCREEN_ORIENTATION_UNSET) {
3478 return orientation;
3479 }
3480 }
3481 return SCREEN_ORIENTATION_UNSPECIFIED;
3482 }
3483
3484 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003485 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3486 PackageManager.FEATURE_AUTOMOTIVE);
3487 if (isCar) {
3488 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3489 // allow anything but the default orientation.
3490 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3491 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3492 return SCREEN_ORIENTATION_UNSPECIFIED;
3493 }
3494
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003495 if (orientation != SCREEN_ORIENTATION_UNSET
3496 && orientation != SCREEN_ORIENTATION_BEHIND) {
3497 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3498 "App is requesting an orientation, return " + orientation);
3499 return orientation;
3500 }
3501
3502 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003503 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003504 // The next app has not been requested to be visible, so we keep the current orientation
3505 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003506 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003507 }
Robert Carrb1579c82017-09-05 14:54:47 -07003508
3509 @Override
3510 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003511 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003512
Robert Carr2f8aa392018-01-31 14:46:51 -08003513 for (int i = 0; i < mChildren.size(); i++) {
3514 final TaskStack s = mChildren.get(i);
3515 s.assignChildLayers(t);
3516 }
3517 }
3518
3519 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003520 final int HOME_STACK_STATE = 0;
3521 final int NORMAL_STACK_STATE = 1;
3522 final int ALWAYS_ON_TOP_STATE = 2;
3523
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003524 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003525 int layerForAnimationLayer = 0;
3526
Robert Carrf7a7ca82017-12-06 13:17:07 -08003527 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3528 for (int i = 0; i < mChildren.size(); i++) {
3529 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003530 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3531 continue;
3532 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3533 || s.isAlwaysOnTop())) {
3534 continue;
3535 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3536 continue;
3537 }
3538 s.assignLayer(t, layer++);
3539 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3540 t.setLayer(mSplitScreenDividerAnchor, layer++);
3541 }
Robert Carrb9506032018-02-13 13:54:00 -08003542 if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003543 // Ensure the animation layer ends up above the
3544 // highest animating stack and no higher.
3545 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003546 }
3547 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003548 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003549 if (mAppAnimationLayer != null) {
3550 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003551 }
Robert Carrb1579c82017-09-05 14:54:47 -07003552 }
3553
3554 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003555 SurfaceControl getAppAnimationLayer() {
3556 return mAppAnimationLayer;
3557 }
3558
Robert Carrf7a7ca82017-12-06 13:17:07 -08003559 SurfaceControl getSplitScreenDividerAnchor() {
3560 return mSplitScreenDividerAnchor;
3561 }
3562
chaviw23ee71c2017-12-18 11:29:41 -08003563 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003564 void onParentSet() {
3565 super.onParentSet();
3566 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003567 mAppAnimationLayer = makeChildSurface(null)
3568 .setName("animationLayer")
3569 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003570 mSplitScreenDividerAnchor = makeChildSurface(null)
3571 .setName("splitScreenDividerAnchor")
3572 .build();
3573 getPendingTransaction()
3574 .show(mAppAnimationLayer)
3575 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003576 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003577 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003578 mAppAnimationLayer.destroy();
3579 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003580 mSplitScreenDividerAnchor.destroy();
3581 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003582 }
3583 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003584 }
3585
Robert Carree4d4b92017-11-22 12:21:46 -08003586 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003587 AboveAppWindowContainers(String name, WindowManagerService service) {
3588 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003589 }
3590
Robert Carrb9506032018-02-13 13:54:00 -08003591 @Override
3592 void assignChildLayers(SurfaceControl.Transaction t) {
3593 assignChildLayers(t, null /* imeContainer */);
3594 }
3595
Robert Carree4d4b92017-11-22 12:21:46 -08003596 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3597 boolean needAssignIme = imeContainer != null
3598 && imeContainer.getSurfaceControl() != null;
3599 for (int j = 0; j < mChildren.size(); ++j) {
3600 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003601
3602 // See {@link mSplitScreenDividerAnchor}
3603 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3604 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3605 continue;
3606 }
Robert Carree4d4b92017-11-22 12:21:46 -08003607 wt.assignLayer(t, j);
3608 wt.assignChildLayers(t);
3609
3610 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3611 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003612
3613 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3614 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003615 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003616 needAssignIme = false;
3617 }
3618 }
3619 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003620 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003621 }
3622 }
3623 }
3624
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003625 /**
3626 * Window container class that contains all containers on this display that are not related to
3627 * Apps. E.g. status bar.
3628 */
Robert Carree4d4b92017-11-22 12:21:46 -08003629 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003630 /**
3631 * Compares two child window tokens returns -1 if the first is lesser than the second in
3632 * terms of z-order and 1 otherwise.
3633 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003634 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003635 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003636 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3637 token1.mOwnerCanManageAppTokens)
3638 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3639 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003640
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003641 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3642 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3643 return false;
3644 }
3645 final int req = w.mAttrs.screenOrientation;
3646 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3647 || req == SCREEN_ORIENTATION_UNSET) {
3648 return false;
3649 }
3650 return true;
3651 };
3652
Wale Ogunwale3a931692016-11-02 16:49:48 -07003653 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003654 private final Dimmer mDimmer = new Dimmer(this);
3655 private final Rect mTmpDimBoundsRect = new Rect();
3656
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003657 NonAppWindowContainers(String name, WindowManagerService service) {
3658 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003659 mName = name;
3660 }
3661
3662 void addChild(WindowToken token) {
3663 addChild(token, mWindowComparator);
3664 }
3665
3666 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003667 int getOrientation() {
3668 final WindowManagerPolicy policy = mService.mPolicy;
3669 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003670 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003671
3672 if (win != null) {
3673 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003674 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003675 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003676 if (mService.mKeyguardGoingAway) {
3677 // Keyguard can't affect the orientation if it is going away...
3678 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3679 return SCREEN_ORIENTATION_UNSET;
3680 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003681 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003682 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003683 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003684 }
3685
Andrii Kulian8ee72852017-03-10 10:36:45 -08003686 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003687
Jorim Jaggi75520d52017-08-24 17:23:19 +02003688 if (policy.isKeyguardShowingAndNotOccluded()
3689 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003690 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003691 }
3692
3693 return SCREEN_ORIENTATION_UNSET;
3694 }
3695
3696 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003697 String getName() {
3698 return mName;
3699 }
chaviwf29223e2018-01-31 13:23:51 -08003700
3701 @Override
3702 Dimmer getDimmer() {
3703 return mDimmer;
3704 }
3705
3706 @Override
3707 void prepareSurfaces() {
3708 mDimmer.resetDimStates();
3709 super.prepareSurfaces();
3710 getBounds(mTmpDimBoundsRect);
3711
3712 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3713 scheduleAnimation();
3714 }
3715 }
Robert Carr3b716242016-08-16 16:02:21 -07003716 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003717
Robert Carr9034d962018-01-04 18:27:42 -08003718 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3719 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3720 super(name, service);
3721 }
3722
3723 @Override
3724 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3725 }
3726 };
3727
Robert Carrb1579c82017-09-05 14:54:47 -07003728 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3729 return mService.makeSurfaceBuilder(s)
3730 .setParent(mWindowingLayer);
3731 }
3732
3733 @Override
3734 SurfaceSession getSession() {
3735 return mSession;
3736 }
3737
3738 @Override
3739 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003740 SurfaceSession s = child != null ? child.getSession() : getSession();
3741 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003742 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003743
3744 if (child == null) {
3745 return b;
3746 }
3747
Robert Carree4d4b92017-11-22 12:21:46 -08003748 return b.setName(child.getName())
3749 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003750 }
3751
3752 /**
3753 * The makeSurface variants are for use by the window-container
3754 * hierarchy. makeOverlay here is a function for various non windowing
3755 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3756 * and other potpourii.
3757 */
3758 SurfaceControl.Builder makeOverlay() {
3759 return mService.makeSurfaceBuilder(mSession)
3760 .setParent(mOverlayLayer);
3761 }
3762
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003763 /**
3764 * Reparents the given surface to mOverlayLayer.
3765 */
3766 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3767 transaction.reparent(surface, mOverlayLayer.getHandle());
3768 }
3769
Robert Carrb1579c82017-09-05 14:54:47 -07003770 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003771 applyMagnificationSpec(getPendingTransaction(), spec);
3772 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003773 }
3774
3775 @Override
3776 void onParentSet() {
3777 // Since we are the top of the SurfaceControl hierarchy here
3778 // we create the root surfaces explicitly rather than chaining
3779 // up as the default implementation in onParentSet does. So we
3780 // explicitly do NOT call super here.
3781 }
3782
3783 @Override
3784 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003785
3786 // These are layers as children of "mWindowingLayer"
3787 mBelowAppWindowsContainers.assignLayer(t, 0);
3788 mTaskStackContainers.assignLayer(t, 1);
3789 mAboveAppWindowsContainers.assignLayer(t, 2);
3790
3791 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003792 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003793
Robert Carree4d4b92017-11-22 12:21:46 -08003794 // In the case where we have an IME target that is not in split-screen
3795 // mode IME assignment is easy. We just need the IME to go directly above
3796 // the target. This way children of the target will naturally go above the IME
3797 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003798 //
Robert Carree4d4b92017-11-22 12:21:46 -08003799 // In the case of split-screen windowing mode, we need to elevate the IME above the
3800 // docked divider while keeping the app itself below the docked divider, so instead
3801 // we use relative layering of the IME targets child windows, and place the
3802 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003803 //
Robert Carree4d4b92017-11-22 12:21:46 -08003804 // In the case where we have no IME target we assign it where it's base layer would
3805 // place it in the AboveAppWindowContainers.
3806 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3807 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003808 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003809 // TODO: We need to use an extra level on the app surface to ensure
3810 // this is always above SurfaceView but always below attached window.
3811 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003812 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003813 }
3814
3815 // Above we have assigned layers to our children, now we ask them to assign
3816 // layers to their children.
3817 mBelowAppWindowsContainers.assignChildLayers(t);
3818 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003819 mAboveAppWindowsContainers.assignChildLayers(t,
3820 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003821 mImeWindowsContainers.assignChildLayers(t);
3822 }
3823
3824 /**
3825 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3826 * that the IME target is one of the docked applications. We'd like the docked divider to be
3827 * above both of the applications, and we'd like the IME to be above the docked divider.
3828 * However we need child windows of the applications to be above the IME (Text drag handles).
3829 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3830 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3831 * with {@link #WindowState#assignLayer}
3832 */
3833 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3834 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3835 }
3836
3837 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003838 void prepareSurfaces() {
3839 final ScreenRotationAnimation screenRotationAnimation =
3840 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3841 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3842 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3843 mPendingTransaction.setMatrix(mWindowingLayer,
3844 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3845 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3846 mPendingTransaction.setPosition(mWindowingLayer,
3847 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3848 mPendingTransaction.setAlpha(mWindowingLayer,
3849 screenRotationAnimation.getEnterTransformation().getAlpha());
3850 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003851
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003852 super.prepareSurfaces();
3853 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003854
3855 void assignStackOrdering(SurfaceControl.Transaction t) {
3856 mTaskStackContainers.assignStackOrdering(t);
3857 }
Craig Mautner59c00972012-07-30 12:10:24 -07003858}