blob: 59babcfe0371df544a82ceeb332d6f8d9f22a2ea [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;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100157import com.android.server.wm.utils.WmDisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700158
159import java.io.PrintWriter;
160import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700161import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700162import java.util.HashMap;
163import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700164import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700165import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100166import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800167import java.util.function.Consumer;
168import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700169
Craig Mautner59c00972012-07-30 12:10:24 -0700170/**
171 * Utility class for keeping track of the WindowStates and other pertinent contents of a
172 * particular Display.
173 *
174 * IMPORTANT: No method from this class should ever be used without holding
175 * WindowManagerService.mWindowMap.
176 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700177class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700178 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700179
180 /** Unique identifier of this stack. */
181 private final int mDisplayId;
182
Wale Ogunwale3a931692016-11-02 16:49:48 -0700183 /** The containers below are the only child containers the display can have. */
184 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100185 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700186 // Contains all non-app window containers that should be displayed above the app containers
187 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800188 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100189 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700190 // Contains all non-app window containers that should be displayed below the app containers
191 // (e.g. Wallpaper).
192 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100193 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700194 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
195 // 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 -0800196 // window containers together and move them in-sync if/when needed. We use a subclass of
197 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
198 private final NonMagnifiableWindowContainers mImeWindowsContainers =
199 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700200
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000201 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800202 private WindowState mTmpWindow2;
203 private WindowAnimator mTmpWindowAnimator;
204 private boolean mTmpRecoveringMemory;
205 private boolean mUpdateImeTarget;
206 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700207 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700208
Wale Ogunwale02319a62016-09-26 15:21:22 -0700209 // Mapping from a token IBinder to a WindowToken object on this display.
210 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
211
Andrii Kuliancd097992017-03-23 18:31:59 -0700212 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700213 int mInitialDisplayWidth = 0;
214 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700215 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700216
Adrian Roos1cf585052018-01-03 18:43:27 +0100217 DisplayCutout mInitialDisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100218 private final RotationCache<DisplayCutout, WmDisplayCutout> mDisplayCutoutCache
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100219 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100220
Andrii Kuliancd097992017-03-23 18:31:59 -0700221 /**
222 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
223 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
224 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
225 */
Craig Mautner59c00972012-07-30 12:10:24 -0700226 int mBaseDisplayWidth = 0;
227 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700228 /**
229 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
230 * but can be set from Settings or via shell command "adb shell wm density".
231 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
232 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700233 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700234 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700235 private final DisplayInfo mDisplayInfo = new DisplayInfo();
236 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700237 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000238 DisplayFrames mDisplayFrames;
239
Andrii Kulian06d07d62017-03-14 11:11:47 -0700240 /**
241 * For default display it contains real metrics, empty for others.
242 * @see WindowManagerService#createWatermarkInTransaction()
243 */
244 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
245 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
246 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700247
Andrii Kulian06d07d62017-03-14 11:11:47 -0700248 /**
249 * Compat metrics computed based on {@link #mDisplayMetrics}.
250 * @see #updateDisplayAndOrientation(int)
251 */
252 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
253
254 /** The desired scaling factor for compatible apps. */
255 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700256
Andrii Kulian8ee72852017-03-10 10:36:45 -0800257 /**
258 * Current rotation of the display.
259 * Constants as per {@link android.view.Surface.Rotation}.
260 *
Robert Carrae606b42018-02-15 15:36:23 -0800261 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800262 */
263 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700264
Andrii Kulian8ee72852017-03-10 10:36:45 -0800265 /**
266 * Last applied orientation of the display.
267 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
268 *
269 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
270 */
271 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700272
Andrii Kulian8ee72852017-03-10 10:36:45 -0800273 /**
274 * Flag indicating that the application is receiving an orientation that has different metrics
275 * than it expected. E.g. Portrait instead of Landscape.
276 *
Robert Carrae606b42018-02-15 15:36:23 -0800277 * @see #updateRotationUnchecked()
Andrii Kulian8ee72852017-03-10 10:36:45 -0800278 */
279 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700280
Andrii Kulian8ee72852017-03-10 10:36:45 -0800281 /**
282 * Orientation forced by some window. If there is no visible window that specifies orientation
283 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
284 *
285 * @see NonAppWindowContainers#getOrientation()
286 */
287 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700288
Andrii Kulian8ee72852017-03-10 10:36:45 -0800289 /**
290 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
291 * occluded.
292 *
293 * @see NonAppWindowContainers#getOrientation()
294 */
295 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
296
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700297 /**
298 * Keep track of wallpaper visibility to notify changes.
299 */
300 private boolean mLastWallpaperVisible = false;
301
Andrii Kulian06d07d62017-03-14 11:11:47 -0700302 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700303
Craig Mautner39834192012-09-02 07:47:24 -0700304 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700305 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700306 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700307 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800308 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700309
Craig Mautnerdc548482014-02-05 13:35:24 -0800310 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700311 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800312
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700313 /** Detect user tapping outside of current focused task bounds .*/
314 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700315
Craig Mautner6601b7b2013-04-29 10:29:11 -0700316 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700317 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700318
Craig Mautner6601b7b2013-04-29 10:29:11 -0700319 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800320 private final Rect mTmpRect = new Rect();
321 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700322 private final RectF mTmpRectF = new RectF();
323 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800324 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700325
Bryce Leef3c6a472017-11-14 14:53:06 -0800326 /** Used for handing back size of display */
327 private final Rect mTmpBounds = new Rect();
328
Craig Mautner95da1082014-02-24 17:54:35 -0800329 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700330 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800331
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700332 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700333 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700334
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800335 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800336 /** A collection of windows that provide tap exclude regions inside of them. */
337 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800338
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000339 private boolean mHaveBootMsg = false;
340 private boolean mHaveApp = false;
341 private boolean mHaveWallpaper = false;
342 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700343
344 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
345
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700346 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
347 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000348 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
349 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700350
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700351 // True if this display is in the process of being removed. Used to determine if the removal of
352 // the display's direct children should be allowed.
353 private boolean mRemovingDisplay = false;
354
Bryce Leed1871262017-06-12 14:12:29 -0700355 // {@code false} if this display is in the processing of being created.
356 private boolean mDisplayReady = false;
357
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800358 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700359
Robert Carrb1579c82017-09-05 14:54:47 -0700360 private final SurfaceSession mSession = new SurfaceSession();
361
362 /**
363 * We organize all top-level Surfaces in to the following layers.
364 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800365 * and omitted from Screen-Magnification, for example the strict mode flash or
366 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700367 * {@link #mWindowingLayer} contains everything else.
368 */
369 private SurfaceControl mOverlayLayer;
370
371 /**
372 * See {@link #mOverlayLayer}
373 */
374 private SurfaceControl mWindowingLayer;
375
376 /**
377 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
378 * <p>
379 * For these surfaces currently we use a surface based on the larger of width or height so we
380 * don't have to resize when rotating the display.
381 */
382 private int mSurfaceSize;
383
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100384 /** Temporary float array to retrieve 3x3 matrix values. */
385 private final float[] mTmpFloats = new float[9];
386
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800387 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
388 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800389 final AppWindowToken atoken = w.mAppToken;
390 if (winAnimator.mDrawState == READY_TO_SHOW) {
391 if (atoken == null || atoken.allDrawn) {
392 if (w.performShowLocked()) {
393 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
394 if (DEBUG_LAYOUT_REPEATS) {
395 mService.mWindowPlacerLocked.debugLayoutRepeats(
396 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
397 }
398 }
399 }
400 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800401 };
402
403 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
404 final WindowStateAnimator winAnimator = w.mWinAnimator;
405 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
406 return;
407 }
408
409 final int flags = w.mAttrs.flags;
410
411 // If this window is animating, make a note that we have an animating window and take
412 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100413 if (winAnimator.isAnimationSet()) {
414 final AnimationAdapter anim = w.getAnimation();
415 if (anim != null) {
416 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800417 mTmpWindow = w;
418 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100419 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800420 if (color != 0) {
421 final TaskStack stack = w.getStack();
422 if (stack != null) {
423 stack.setAnimationBackground(winAnimator, color);
424 }
425 }
426 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800427 }
428
429 // If this window's app token is running a detached wallpaper animation, make a note so
430 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200431 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
432 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
433 if (animation != null) {
434 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800435 mTmpWindow = w;
436 }
437
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200438 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800439 if (color != 0) {
440 final TaskStack stack = w.getStack();
441 if (stack != null) {
442 stack.setAnimationBackground(winAnimator, color);
443 }
444 }
445 }
446 };
447
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800448 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
449 final int lostFocusUid = mTmpWindow.mOwnerUid;
450 final Handler handler = mService.mH;
451 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
452 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
453 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
454 w.mAttrs.hideTimeoutMilliseconds);
455 }
456 }
457 };
458
459 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
460 final AppWindowToken focusedApp = mService.mFocusedApp;
461 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
462 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
463
464 if (!w.canReceiveKeys()) {
465 return false;
466 }
467
468 final AppWindowToken wtoken = w.mAppToken;
469
470 // If this window's application has been removed, just skip it.
471 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
472 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
473 + (wtoken.removed ? "removed" : "sendingToBottom"));
474 return false;
475 }
476
477 if (focusedApp == null) {
478 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
479 + " using new focus @ " + w);
480 mTmpWindow = w;
481 return true;
482 }
483
484 if (!focusedApp.windowsAreFocusable()) {
485 // Current focused app windows aren't focusable...
486 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
487 + " focusable using new focus @ " + w);
488 mTmpWindow = w;
489 return true;
490 }
491
492 // Descend through all of the app tokens and find the first that either matches
493 // win.mAppToken (return win) or mFocusedApp (return null).
494 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
495 if (focusedApp.compareTo(wtoken) > 0) {
496 // App stack below focused app stack. No focus for you!!!
497 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
498 "findFocusedWindow: Reached focused app=" + focusedApp);
499 mTmpWindow = null;
500 return true;
501 }
502 }
503
504 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
505 mTmpWindow = w;
506 return true;
507 };
508
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800509 private final Consumer<WindowState> mPerformLayout = w -> {
510 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
511 // wasting time and funky changes while a window is animating away.
512 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
513 || w.isGoneForLayoutLw();
514
515 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
516 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
517 + " mLayoutAttached=" + w.mLayoutAttached
518 + " screen changed=" + w.isConfigChanged());
519 final AppWindowToken atoken = w.mAppToken;
520 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200521 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800522 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
523 + " parentHidden=" + w.isParentWindowHidden());
524 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200525 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800526 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
527 + " parentHidden=" + w.isParentWindowHidden());
528 }
529
530 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
531 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
532 // since that means "perform layout as normal, just don't display").
533 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
534 || ((w.isConfigChanged() || w.setReportResizeHints())
535 && !w.isGoneForLayoutLw() &&
536 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
537 (w.mHasSurface && w.mAppToken != null &&
538 w.mAppToken.layoutConfigChanges)))) {
539 if (!w.mLayoutAttached) {
540 if (mTmpInitial) {
541 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
542 w.mContentChanged = false;
543 }
544 if (w.mAttrs.type == TYPE_DREAM) {
545 // Don't layout windows behind a dream, so that if it does stuff like hide
546 // the status bar we won't get a bad transition when it goes away.
547 mTmpWindow = w;
548 }
549 w.mLayoutNeeded = false;
550 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200551 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000552 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800553 w.mLayoutSeq = mService.mLayoutSeq;
554
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200555 // If this is the first layout, we need to initialize the last inset values as
556 // otherwise we'd immediately cause an unnecessary resize.
557 if (firstLayout) {
558 w.updateLastInsetValues();
559 }
560
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800561 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
562 + " mContainingFrame=" + w.mContainingFrame
563 + " mDisplayFrame=" + w.mDisplayFrame);
564 }
565 }
566 };
567
568 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
569 if (w.mLayoutAttached) {
570 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
571 + " mViewVisibility=" + w.mViewVisibility
572 + " mRelayoutCalled=" + w.mRelayoutCalled);
573 // If this view is GONE, then skip it -- keep the current frame, and let the caller
574 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
575 // windows, since that means "perform layout as normal, just don't display").
576 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
577 return;
578 }
579 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
580 || w.mLayoutNeeded) {
581 if (mTmpInitial) {
582 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
583 w.mContentChanged = false;
584 }
585 w.mLayoutNeeded = false;
586 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000587 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800588 w.mLayoutSeq = mService.mLayoutSeq;
589 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
590 + " mContainingFrame=" + w.mContainingFrame
591 + " mDisplayFrame=" + w.mDisplayFrame);
592 }
593 } else if (w.mAttrs.type == TYPE_DREAM) {
594 // Don't layout windows behind a dream, so that if it does stuff like hide the
595 // status bar we won't get a bad transition when it goes away.
596 mTmpWindow = mTmpWindow2;
597 }
598 };
599
600 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
601 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
602 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
603 return w.canBeImeTarget();
604 };
605
606 private final Consumer<WindowState> mApplyPostLayoutPolicy =
607 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
608 mService.mInputMethodTarget);
609
610 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
611 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
612 final boolean obscuredChanged = w.mObscured !=
613 mTmpApplySurfaceChangesTransactionState.obscured;
614 final RootWindowContainer root = mService.mRoot;
615 // Only used if default window
616 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
617
618 // Update effect.
619 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
620 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
621 final boolean isDisplayed = w.isDisplayedLw();
622
623 if (isDisplayed && w.isObscuringDisplay()) {
624 // This window completely covers everything behind it, so we want to leave all
625 // of them as undimmed (for performance reasons).
626 root.mObscuringWindow = w;
627 mTmpApplySurfaceChangesTransactionState.obscured = true;
628 }
629
630 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
631 root.handleNotObscuredLocked(w,
632 mTmpApplySurfaceChangesTransactionState.obscured,
633 mTmpApplySurfaceChangesTransactionState.syswin);
634
635 if (w.mHasSurface && isDisplayed) {
636 final int type = w.mAttrs.type;
637 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
638 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
639 mTmpApplySurfaceChangesTransactionState.syswin = true;
640 }
641 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
642 && w.mAttrs.preferredRefreshRate != 0) {
643 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
644 = w.mAttrs.preferredRefreshRate;
645 }
646 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
647 && w.mAttrs.preferredDisplayModeId != 0) {
648 mTmpApplySurfaceChangesTransactionState.preferredModeId
649 = w.mAttrs.preferredDisplayModeId;
650 }
651 }
652 }
653
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800654 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
655 && mWallpaperController.isWallpaperTarget(w)) {
656 // This is the wallpaper target and its obscured state changed... make sure the
657 // current wallpaper's visibility has been updated accordingly.
658 mWallpaperController.updateWallpaperVisibility();
659 }
660
chaviw161ea3e2018-01-31 12:01:12 -0800661 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800662
663 final WindowStateAnimator winAnimator = w.mWinAnimator;
664
665 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
666 w.mContentChanged = false;
667
668 // Moved from updateWindowsAndWallpaperLocked().
669 if (w.mHasSurface) {
670 // Take care of the window being ready to display.
671 final boolean committed = winAnimator.commitFinishDrawingLocked();
672 if (isDefaultDisplay && committed) {
673 if (w.mAttrs.type == TYPE_DREAM) {
674 // HACK: When a dream is shown, it may at that point hide the lock screen.
675 // So we need to redo the layout to let the phone window manager make this
676 // happen.
677 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
678 if (DEBUG_LAYOUT_REPEATS) {
679 surfacePlacer.debugLayoutRepeats(
680 "dream and commitFinishDrawingLocked true",
681 pendingLayoutChanges);
682 }
683 }
684 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
685 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
686 "First draw done in potential wallpaper target " + w);
687 root.mWallpaperMayChange = true;
688 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
689 if (DEBUG_LAYOUT_REPEATS) {
690 surfacePlacer.debugLayoutRepeats(
691 "wallpaper and commitFinishDrawingLocked true",
692 pendingLayoutChanges);
693 }
694 }
695 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800696 }
697
698 final AppWindowToken atoken = w.mAppToken;
699 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100700 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800701 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
702 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
703 mTmpUpdateAllDrawn.add(atoken);
704 }
705 }
706
707 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
708 && w.isDisplayedLw()) {
709 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
710 }
711
712 w.updateResizingWindowIfNeeded();
713 };
714
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800715 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800716 * Create new {@link DisplayContent} instance, add itself to the root window container and
717 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700718 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800719 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700720 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
721 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700722 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700723 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800724 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100725 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800726 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800727 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
728 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
729 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
730 + " new=" + display);
731 }
732
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700733 mDisplay = display;
734 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700735 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700736 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700737 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700738 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100739 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo,
740 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700741 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800742 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700743 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700744
Robert Carr74a66a22018-02-23 12:17:51 -0800745 // We use this as our arbitrary surface size for buffer-less parents
746 // that don't impose cropping on their children. It may need to be larger
747 // than the display size because fullscreen windows can be shifted offscreen
748 // due to surfaceInsets. 2 times the largest display dimension feels like an
749 // appropriately arbitrary number. Eventually we would like to give SurfaceFlinger
750 // layers the ability to match their parent sizes and be able to skip
751 // such arbitrary size settings.
752 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth) * 2;
Robert Carrb1579c82017-09-05 14:54:47 -0700753
754 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
755 .setSize(mSurfaceSize, mSurfaceSize)
756 .setOpaque(true);
757 mWindowingLayer = b.setName("Display Root").build();
758 mOverlayLayer = b.setName("Display Overlays").build();
759
Robert Carrf59b8dd2017-10-02 18:58:36 -0700760 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700761 .setLayerStack(mWindowingLayer, mDisplayId)
762 .show(mWindowingLayer)
763 .setLayer(mOverlayLayer, 1)
764 .setLayerStack(mOverlayLayer, mDisplayId)
765 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700766 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700767
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700768 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700769 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700770 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700771 super.addChild(mAboveAppWindowsContainers, null);
772 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800773
774 // Add itself as a child to the root container.
775 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700776
777 // TODO(b/62541591): evaluate whether this is the best spot to declare the
778 // {@link DisplayContent} ready for use.
779 mDisplayReady = true;
780 }
781
782 boolean isReady() {
783 // The display is ready when the system and the individual display are both ready.
784 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700785 }
786
787 int getDisplayId() {
788 return mDisplayId;
789 }
790
Wale Ogunwale02319a62016-09-26 15:21:22 -0700791 WindowToken getWindowToken(IBinder binder) {
792 return mTokenMap.get(binder);
793 }
794
795 AppWindowToken getAppWindowToken(IBinder binder) {
796 final WindowToken token = getWindowToken(binder);
797 if (token == null) {
798 return null;
799 }
800 return token.asAppWindowToken();
801 }
802
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700803 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700804 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
805 if (dc != null) {
806 // We currently don't support adding a window token to the display if the display
807 // already has the binder mapped to another token. If there is a use case for supporting
808 // this moving forward we will either need to merge the WindowTokens some how or have
809 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700810 throw new IllegalArgumentException("Can't map token=" + token + " to display="
811 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700812 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700813 if (binder == null) {
814 throw new IllegalArgumentException("Can't map token=" + token + " to display="
815 + getName() + " binder is null");
816 }
817 if (token == null) {
818 throw new IllegalArgumentException("Can't map null token to display="
819 + getName() + " binder=" + binder);
820 }
821
Wale Ogunwale02319a62016-09-26 15:21:22 -0700822 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700823
824 if (token.asAppWindowToken() == null) {
825 // Add non-app token to container hierarchy on the display. App tokens are added through
826 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700827 switch (token.windowType) {
828 case TYPE_WALLPAPER:
829 mBelowAppWindowsContainers.addChild(token);
830 break;
831 case TYPE_INPUT_METHOD:
832 case TYPE_INPUT_METHOD_DIALOG:
833 mImeWindowsContainers.addChild(token);
834 break;
835 default:
836 mAboveAppWindowsContainers.addChild(token);
837 break;
838 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700839 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700840 }
841
842 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700843 final WindowToken token = mTokenMap.remove(binder);
844 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800845 token.setExiting();
846 }
847 return token;
848 }
849
850 /** Changes the display the input window token is housed on to this one. */
851 void reParentWindowToken(WindowToken token) {
852 final DisplayContent prevDc = token.getDisplayContent();
853 if (prevDc == this) {
854 return;
855 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800856 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
857 && token.asAppWindowToken() == null) {
858 // Removed the token from the map, but made sure it's not an app token before removing
859 // from parent.
860 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700861 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800862
863 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700864 }
865
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700866 void removeAppToken(IBinder binder) {
867 final WindowToken token = removeWindowToken(binder);
868 if (token == null) {
869 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
870 return;
871 }
872
873 final AppWindowToken appToken = token.asAppWindowToken();
874
875 if (appToken == null) {
876 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
877 return;
878 }
879
880 appToken.onRemovedFromDisplay();
881 }
882
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700883 Display getDisplay() {
884 return mDisplay;
885 }
886
Craig Mautner59c00972012-07-30 12:10:24 -0700887 DisplayInfo getDisplayInfo() {
888 return mDisplayInfo;
889 }
890
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700891 DisplayMetrics getDisplayMetrics() {
892 return mDisplayMetrics;
893 }
894
Andrii Kulian8ee72852017-03-10 10:36:45 -0800895 int getRotation() {
896 return mRotation;
897 }
898
899 void setRotation(int newRotation) {
900 mRotation = newRotation;
901 }
902
903 int getLastOrientation() {
904 return mLastOrientation;
905 }
906
907 void setLastOrientation(int orientation) {
908 mLastOrientation = orientation;
909 }
910
911 boolean getAltOrientation() {
912 return mAltOrientation;
913 }
914
915 void setAltOrientation(boolean altOrientation) {
916 mAltOrientation = altOrientation;
917 }
918
919 int getLastWindowForcedOrientation() {
920 return mLastWindowForcedOrientation;
921 }
922
Andrii Kulian06d07d62017-03-14 11:11:47 -0700923 /**
924 * Update rotation of the display.
925 *
926 * Returns true if the rotation has been changed. In this case YOU MUST CALL
927 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
928 */
Robert Carrae606b42018-02-15 15:36:23 -0800929 boolean updateRotationUnchecked() {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700930 if (mService.mDeferredRotationPauseCount > 0) {
931 // Rotation updates have been paused temporarily. Defer the update until
932 // updates have been resumed.
933 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
934 return false;
935 }
936
937 ScreenRotationAnimation screenRotationAnimation =
938 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
939 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
940 // Rotation updates cannot be performed while the previous rotation change
941 // animation is still in progress. Skip this update. We will try updating
942 // again after the animation is finished and the display is unfrozen.
943 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
944 return false;
945 }
946 if (mService.mDisplayFrozen) {
947 // Even if the screen rotation animation has finished (e.g. isAnimating
948 // returns false), there is still some time where we haven't yet unfrozen
949 // the display. We also need to abort rotation here.
950 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
951 "Deferring rotation, still finishing previous rotation");
952 return false;
953 }
954
955 if (!mService.mDisplayEnabled) {
956 // No point choosing a rotation if the display is not enabled.
957 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
958 return false;
959 }
960
961 final int oldRotation = mRotation;
962 final int lastOrientation = mLastOrientation;
963 final boolean oldAltOrientation = mAltOrientation;
964 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700965 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700966 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700967
Robert Carr0e007272017-10-02 13:00:55 -0700968 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700969 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
970 if (seamlessRotated != null) {
971 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
972 // to complete (that is, waiting for windows to redraw). It's tempting to check
973 // w.mSeamlessRotationCount but that could be incorrect in the case of
974 // window-removal.
975 return false;
976 }
Robert Carr0e007272017-10-02 13:00:55 -0700977
978 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700979 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700980 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700981 mayRotateSeamlessly = false;
982 }
983 for (int i = 0; i < mService.mSessions.size(); i++) {
984 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
985 mayRotateSeamlessly = false;
986 break;
987 }
988 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700989 }
Robert Carr0e007272017-10-02 13:00:55 -0700990 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700991
992 // TODO: Implement forced rotation changes.
993 // Set mAltOrientation to indicate that the application is receiving
994 // an orientation that has different metrics than it expected.
995 // eg. Portrait instead of Landscape.
996
997 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
998 lastOrientation, rotation);
999
1000 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
1001 + ", got rotation " + rotation + " which has "
1002 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1003
1004 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1005 // No change.
1006 return false;
1007 }
1008
1009 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1010 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1011 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1012
1013 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1014 mService.mWaitingForConfig = true;
1015 }
1016
1017 mRotation = rotation;
1018 mAltOrientation = altOrientation;
1019 if (isDefaultDisplay) {
1020 mService.mPolicy.setRotationLw(rotation);
1021 }
1022
1023 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1024 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1025 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1026 WINDOW_FREEZE_TIMEOUT_DURATION);
1027
1028 setLayoutNeeded();
1029 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001030 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001031
1032 if (!rotateSeamlessly) {
Robert Carrae606b42018-02-15 15:36:23 -08001033 mService.startFreezingDisplayLocked(anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001034 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1035 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1036 mDisplayId);
1037 } else {
1038 // The screen rotation animation uses a screenshot to freeze the screen
1039 // while windows resize underneath.
1040 // When we are rotating seamlessly, we allow the elements to transition
1041 // to their rotated state independently and without a freeze required.
1042 screenRotationAnimation = null;
1043
Robert Carrefc75702018-02-16 11:46:16 -08001044 mService.startSeamlessRotation();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001045 }
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
Robert Carrae606b42018-02-15 15:36:23 -08001054 // NOTE: We disable the rotation in the emulator because
1055 // it doesn't support hardware OpenGL emulation yet.
1056 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1057 && screenRotationAnimation.hasScreenshot()) {
1058 if (screenRotationAnimation.setRotation(getPendingTransaction(), rotation,
1059 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1060 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1061 mService.scheduleAnimationLocked();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001062 }
1063 }
1064
Robert Carrae606b42018-02-15 15:36:23 -08001065 if (rotateSeamlessly) {
1066 forAllWindows(w -> {
1067 w.mWinAnimator.seamlesslyRotateWindow(getPendingTransaction(),
1068 oldRotation, rotation);
1069 }, true /* traverseTopToBottom */);
1070 }
1071
1072 mService.mDisplayManagerInternal.performTraversal(getPendingTransaction());
1073 scheduleAnimation();
1074
Andrii Kulian06d07d62017-03-14 11:11:47 -07001075 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001076 if (w.mHasSurface && !rotateSeamlessly) {
1077 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001078 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001079 mService.mRoot.mOrientationChangeComplete = false;
1080 w.mLastFreezeDuration = 0;
1081 }
1082 w.mReportOrientationChanged = true;
1083 }, true /* traverseTopToBottom */);
1084
1085 if (rotateSeamlessly) {
1086 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1087 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1088 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1089 }
1090
1091 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1092 final WindowManagerService.RotationWatcher rotationWatcher
1093 = mService.mRotationWatchers.get(i);
1094 if (rotationWatcher.mDisplayId == mDisplayId) {
1095 try {
1096 rotationWatcher.mWatcher.onRotationChanged(rotation);
1097 } catch (RemoteException e) {
1098 // Ignore
1099 }
1100 }
1101 }
1102
1103 // TODO (multi-display): Magnification is supported only for the default display.
1104 // Announce rotation only if we will not animate as we already have the
1105 // windows in final state. Otherwise, we make this call at the rotation end.
1106 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1107 && isDefaultDisplay) {
1108 mService.mAccessibilityController.onRotationChangedLocked(this);
1109 }
1110
1111 return true;
1112 }
1113
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001114 void configureDisplayPolicy() {
1115 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1116 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1117
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001118 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1119 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001120 }
1121
Andrii Kulian06d07d62017-03-14 11:11:47 -07001122 /**
1123 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1124 * changed.
1125 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1126 */
1127 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1128 // Use the effective "visual" dimensions based on current rotation
1129 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1130 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1131 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1132 int dw = realdw;
1133 int dh = realdh;
1134
1135 if (mAltOrientation) {
1136 if (realdw > realdh) {
1137 // Turn landscape into portrait.
1138 int maxw = (int)(realdh/1.3f);
1139 if (maxw < realdw) {
1140 dw = maxw;
1141 }
1142 } else {
1143 // Turn portrait into landscape.
1144 int maxh = (int)(realdw/1.3f);
1145 if (maxh < realdh) {
1146 dh = maxh;
1147 }
1148 }
1149 }
1150
1151 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001152 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1153 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1154
Andrii Kulian06d07d62017-03-14 11:11:47 -07001155 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001156 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001157 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001158 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001159 mDisplayInfo.rotation = mRotation;
1160 mDisplayInfo.logicalWidth = dw;
1161 mDisplayInfo.logicalHeight = dh;
1162 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1163 mDisplayInfo.appWidth = appWidth;
1164 mDisplayInfo.appHeight = appHeight;
1165 if (isDefaultDisplay) {
1166 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1167 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1168 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001169 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001170 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1171 if (mDisplayScalingDisabled) {
1172 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1173 } else {
1174 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1175 }
1176
1177 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1178 mDisplayInfo);
1179
1180 mBaseDisplayRect.set(0, 0, dw, dh);
1181
1182 if (isDefaultDisplay) {
1183 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1184 mCompatDisplayMetrics);
1185 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001186
1187 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001188 return mDisplayInfo;
1189 }
1190
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001191 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001192 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1193 }
1194
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001195 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001196 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001197 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001198 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001199 }
Adrian Roos11c25582018-02-19 18:06:36 +01001200 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001201 return WmDisplayCutout.computeSafeInsets(
1202 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001203 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001204 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001205 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001206 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1207 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001208 bounds.transform(mTmpMatrix);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001209 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(bounds),
Adrian Roos24264212018-02-19 16:26:15 +01001210 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1211 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001212 }
1213
Andrii Kulian06d07d62017-03-14 11:11:47 -07001214 /**
1215 * Compute display configuration based on display properties and policy settings.
1216 * Do not call if mDisplayReady == false.
1217 */
1218 void computeScreenConfiguration(Configuration config) {
1219 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1220
1221 final int dw = displayInfo.logicalWidth;
1222 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001223 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1224 // TODO: Probably best to set this based on some setting in the display content object,
1225 // so the display can be configured for things like fullscreen.
1226 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001227
Adrian Roos11c25582018-02-19 18:06:36 +01001228 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001229 config.screenWidthDp =
1230 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001231 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001232 config.screenHeightDp =
1233 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001234 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001235
Adrian Roos11c25582018-02-19 18:06:36 +01001236 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1237 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001238 final int leftInset = mTmpRect.left;
1239 final int topInset = mTmpRect.top;
1240 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001241 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1242 leftInset + displayInfo.appWidth /* right */,
1243 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001244 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1245 || displayInfo.rotation == Surface.ROTATION_270);
1246
1247 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001248 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001249
1250 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1251 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1252 ? Configuration.SCREENLAYOUT_ROUND_YES
1253 : Configuration.SCREENLAYOUT_ROUND_NO);
1254
1255 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1256 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1257 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1258 dh, mDisplayId);
1259 config.densityDpi = displayInfo.logicalDensityDpi;
1260
1261 config.colorMode =
1262 (displayInfo.isHdr()
1263 ? Configuration.COLOR_MODE_HDR_YES
1264 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001265 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001266 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1267 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1268
1269 // Update the configuration based on available input devices, lid switch,
1270 // and platform configuration.
1271 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1272 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1273 config.navigation = Configuration.NAVIGATION_NONAV;
1274
1275 int keyboardPresence = 0;
1276 int navigationPresence = 0;
1277 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1278 final int len = devices != null ? devices.length : 0;
1279 for (int i = 0; i < len; i++) {
1280 InputDevice device = devices[i];
1281 if (!device.isVirtual()) {
1282 final int sources = device.getSources();
1283 final int presenceFlag = device.isExternal() ?
1284 WindowManagerPolicy.PRESENCE_EXTERNAL :
1285 WindowManagerPolicy.PRESENCE_INTERNAL;
1286
1287 // TODO(multi-display): Configure on per-display basis.
1288 if (mService.mIsTouchDevice) {
1289 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1290 InputDevice.SOURCE_TOUCHSCREEN) {
1291 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1292 }
1293 } else {
1294 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1295 }
1296
1297 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1298 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1299 navigationPresence |= presenceFlag;
1300 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1301 && config.navigation == Configuration.NAVIGATION_NONAV) {
1302 config.navigation = Configuration.NAVIGATION_DPAD;
1303 navigationPresence |= presenceFlag;
1304 }
1305
1306 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1307 config.keyboard = Configuration.KEYBOARD_QWERTY;
1308 keyboardPresence |= presenceFlag;
1309 }
1310 }
1311 }
1312
1313 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1314 config.navigation = Configuration.NAVIGATION_DPAD;
1315 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1316 }
1317
1318 // Determine whether a hard keyboard is available and enabled.
1319 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1320 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1321 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1322 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1323 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1324 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1325 }
1326
1327 // Let the policy update hidden states.
1328 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1329 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1330 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1331 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1332 }
1333
1334 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1335 int displayId) {
1336 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1337 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1338 final int unrotDw, unrotDh;
1339 if (rotated) {
1340 unrotDw = dh;
1341 unrotDh = dw;
1342 } else {
1343 unrotDw = dw;
1344 unrotDh = dh;
1345 }
1346 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1347 displayId);
1348 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1349 displayId);
1350 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1351 displayId);
1352 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1353 displayId);
1354 return sw;
1355 }
1356
1357 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1358 DisplayMetrics dm, int dw, int dh, int displayId) {
1359 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001360 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001361 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001362 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001363 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1364 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1365 if (curSize == 0 || size < curSize) {
1366 curSize = size;
1367 }
1368 return curSize;
1369 }
1370
1371 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1372 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1373
1374 // We need to determine the smallest width that will occur under normal
1375 // operation. To this, start with the base screen size and compute the
1376 // width under the different possible rotations. We need to un-rotate
1377 // the current screen dimensions before doing this.
1378 int unrotDw, unrotDh;
1379 if (rotated) {
1380 unrotDw = dh;
1381 unrotDh = dw;
1382 } else {
1383 unrotDw = dw;
1384 unrotDh = dh;
1385 }
1386 displayInfo.smallestNominalAppWidth = 1<<30;
1387 displayInfo.smallestNominalAppHeight = 1<<30;
1388 displayInfo.largestNominalAppWidth = 0;
1389 displayInfo.largestNominalAppHeight = 0;
1390 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1391 unrotDh);
1392 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1393 unrotDw);
1394 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1395 unrotDh);
1396 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1397 unrotDw);
1398 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1399 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1400 displayId);
1401 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1402 displayId);
1403 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1404 displayId);
1405 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1406 displayId);
1407 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1408 outConfig.screenLayout = sl;
1409 }
1410
1411 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1412 int uiMode, int displayId) {
1413 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001414 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1415 mDisplayInfo.displayCutout);
1416 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1417 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001418
1419 // Compute the screen layout size class for this rotation.
1420 int longSize = w;
1421 int shortSize = h;
1422 if (longSize < shortSize) {
1423 int tmp = longSize;
1424 longSize = shortSize;
1425 shortSize = tmp;
1426 }
1427 longSize = (int)(longSize/density);
1428 shortSize = (int)(shortSize/density);
1429 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1430 }
1431
1432 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1433 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001434 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1435 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001436 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001437 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001438 if (width < displayInfo.smallestNominalAppWidth) {
1439 displayInfo.smallestNominalAppWidth = width;
1440 }
1441 if (width > displayInfo.largestNominalAppWidth) {
1442 displayInfo.largestNominalAppWidth = width;
1443 }
1444 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001445 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001446 if (height < displayInfo.smallestNominalAppHeight) {
1447 displayInfo.smallestNominalAppHeight = height;
1448 }
1449 if (height > displayInfo.largestNominalAppHeight) {
1450 displayInfo.largestNominalAppHeight = height;
1451 }
1452 }
1453
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001454 DockedStackDividerController getDockedDividerController() {
1455 return mDividerControllerLocked;
1456 }
1457
Winson Chung655332c2016-10-31 13:14:28 -07001458 PinnedStackController getPinnedStackController() {
1459 return mPinnedStackControllerLocked;
1460 }
1461
Jeff Browna506a6e2013-06-04 00:02:38 -07001462 /**
1463 * Returns true if the specified UID has access to this display.
1464 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001465 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001466 return mDisplay.hasAccess(uid);
1467 }
1468
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001469 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001470 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001471 }
1472
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001473 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001474 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001475 }
1476
Wale Ogunwale61911492017-10-11 08:50:50 -07001477 /**
1478 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1479 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001480 TaskStack getSplitScreenPrimaryStack() {
1481 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001482 return (stack != null && stack.isVisible()) ? stack : null;
1483 }
1484
1485 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001486 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001487 * not visible.
1488 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001489 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1490 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001491 }
1492
1493 TaskStack getPinnedStack() {
1494 return mTaskStackContainers.getPinnedStack();
1495 }
1496
1497 private boolean hasPinnedStack() {
1498 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001499 }
1500
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001501 /**
1502 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1503 * Null is no compatible stack on the display.
1504 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001505 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001506 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1507 }
1508
1509 /**
1510 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1511 * activity type. Null is no compatible stack on the display.
1512 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001513 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001514 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001515 }
1516
Bryce Lee48f4b572017-04-10 10:54:15 -07001517 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001518 TaskStack getTopStack() {
1519 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001520 }
1521
Winson Chunge2d72172018-01-25 17:46:20 +00001522 ArrayList<Task> getVisibleTasks() {
1523 return mTaskStackContainers.getVisibleTasks();
1524 }
1525
Wale Ogunwale61911492017-10-11 08:50:50 -07001526 void onStackWindowingModeChanged(TaskStack stack) {
1527 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001528 }
1529
Andrii Kulian441e4492016-09-29 15:25:00 -07001530 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001531 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001532 super.onConfigurationChanged(newParentConfig);
1533
Andrii Kulian3a507b52016-09-19 18:14:12 -07001534 // The display size information is heavily dependent on the resources in the current
1535 // configuration, so we need to reconfigure it every time the configuration changes.
1536 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1537 mService.reconfigureDisplayLocked(this);
1538
Bryce Leef3c6a472017-11-14 14:53:06 -08001539 final DockedStackDividerController dividerController = getDockedDividerController();
1540
1541 if (dividerController != null) {
1542 getDockedDividerController().onConfigurationChanged();
1543 }
1544
1545 final PinnedStackController pinnedStackController = getPinnedStackController();
1546
1547 if (pinnedStackController != null) {
1548 getPinnedStackController().onConfigurationChanged();
1549 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001550 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001551
Andrii Kulian441e4492016-09-29 15:25:00 -07001552 /**
1553 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1554 * bounds were updated.
1555 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001556 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001557 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1558 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001559 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001560 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001561 }
1562 }
Winson Chung32c566f2017-04-11 18:31:21 -07001563
1564 // If there was no pinned stack, we still need to notify the controller of the display info
1565 // update as a result of the config change. We do this here to consolidate the flow between
1566 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001567 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001568 mPinnedStackControllerLocked.onDisplayInfoChanged();
1569 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001570 }
1571
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001572 @Override
1573 boolean fillsParent() {
1574 return true;
1575 }
1576
1577 @Override
1578 boolean isVisible() {
1579 return true;
1580 }
1581
1582 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001583 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001584 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001585 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001586 }
1587
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001588 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001589 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1590 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1591 // target, or here in order if there isn't an IME target.
1592 if (traverseTopToBottom) {
1593 for (int i = mChildren.size() - 1; i >= 0; --i) {
1594 final DisplayChildWindowContainer child = mChildren.get(i);
1595 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1596 // In this case the Ime windows will be processed above their target so we skip
1597 // here.
1598 continue;
1599 }
1600 if (child.forAllWindows(callback, traverseTopToBottom)) {
1601 return true;
1602 }
1603 }
1604 } else {
1605 final int count = mChildren.size();
1606 for (int i = 0; i < count; i++) {
1607 final DisplayChildWindowContainer child = mChildren.get(i);
1608 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1609 // In this case the Ime windows will be processed above their target so we skip
1610 // here.
1611 continue;
1612 }
1613 if (child.forAllWindows(callback, traverseTopToBottom)) {
1614 return true;
1615 }
1616 }
1617 }
1618 return false;
1619 }
1620
1621 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1622 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1623 }
1624
Wale Ogunwale399c8692017-05-08 14:22:42 -07001625 @Override
1626 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001627 final WindowManagerPolicy policy = mService.mPolicy;
1628
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001629 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001630 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001631 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001632 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001633 // If the display is frozen, some activities may be in the middle of restarting, and
1634 // thus have removed their old window. If the window has the flag to hide the lock
1635 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1636 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001637 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001638 } else if (policy.isKeyguardLocked()) {
1639 // Use the last orientation the while the display is frozen with the keyguard
1640 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1641 // window. We don't want to check the show when locked window directly though as
1642 // things aren't stable while the display is frozen, for example the window could be
1643 // momentarily unavailable due to activity relaunch.
1644 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001645 + "return " + mLastOrientation);
1646 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001647 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001648 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001649 final int orientation = mAboveAppWindowsContainers.getOrientation();
1650 if (orientation != SCREEN_ORIENTATION_UNSET) {
1651 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001652 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001653 }
1654
Wale Ogunwale399c8692017-05-08 14:22:42 -07001655 // Top system windows are not requesting an orientation. Start searching from apps.
1656 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001657 }
1658
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001659 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001660 // Check if display metrics changed and update base values if needed.
1661 updateBaseDisplayMetricsIfNeeded();
1662
Craig Mautner722285e2012-09-07 13:55:58 -07001663 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001664 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001665
Wale Ogunwale61911492017-10-11 08:50:50 -07001666 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1667 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001668 }
Craig Mautner722285e2012-09-07 13:55:58 -07001669 }
1670
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001671 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001672 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1673 if (displayManagerInternal != null) {
1674 // Bootstrap the default logical display from the display manager.
1675 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1676 if (newDisplayInfo != null) {
1677 mDisplayInfo.copyFrom(newDisplayInfo);
1678 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001679 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001680
Andrii Kuliancd097992017-03-23 18:31:59 -07001681 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1682 mDisplayInfo.logicalDensityDpi);
1683 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1684 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1685 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001686 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001687 }
1688
Andrii Kuliancd097992017-03-23 18:31:59 -07001689 /**
1690 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1691 * values.
1692 */
1693 private void updateBaseDisplayMetricsIfNeeded() {
1694 // Get real display metrics without overrides from WM.
1695 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1696 final int orientation = mDisplayInfo.rotation;
1697 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1698 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1699 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1700 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001701 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001702
1703 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1704 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001705 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1706 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001707
1708 if (displayMetricsChanged) {
1709 // Check if display size or density is forced.
1710 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1711 || mBaseDisplayHeight != mInitialDisplayHeight;
1712 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1713
1714 // If there is an override set for base values - use it, otherwise use new values.
1715 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1716 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1717 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1718
1719 // Real display metrics changed, so we should also update initial values.
1720 mInitialDisplayWidth = newWidth;
1721 mInitialDisplayHeight = newHeight;
1722 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001723 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001724 mService.reconfigureDisplayLocked(this);
1725 }
1726 }
1727
Bryce Lee27cec322017-03-21 09:41:37 -07001728 /** Sets the maximum width the screen resolution can be */
1729 void setMaxUiWidth(int width) {
1730 if (DEBUG_DISPLAY) {
1731 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1732 }
1733
1734 mMaxUiWidth = width;
1735
1736 // Update existing metrics.
1737 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1738 }
1739
1740 /** Update base (override) display metrics. */
1741 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1742 mBaseDisplayWidth = baseWidth;
1743 mBaseDisplayHeight = baseHeight;
1744 mBaseDisplayDensity = baseDensity;
1745
1746 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1747 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1748 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1749 mBaseDisplayWidth = mMaxUiWidth;
1750
1751 if (DEBUG_DISPLAY) {
1752 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1753 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1754 + " on display:" + getDisplayId());
1755 }
1756 }
1757
1758 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001759
1760 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001761 }
1762
Wale Ogunwaledb506192017-12-08 10:57:32 -08001763 void getStableRect(Rect out) {
1764 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001765 }
1766
Wale Ogunwale61911492017-10-11 08:50:50 -07001767 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001768 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1769 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001770
Wale Ogunwale61911492017-10-11 08:50:50 -07001771 final TaskStack stack = new TaskStack(mService, stackId, controller);
1772 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001773 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001774 }
1775
Andrii Kulian51c1b672017-04-07 18:39:32 -07001776 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001777 final DisplayContent prevDc = stack.getDisplayContent();
1778 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001779 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1780 + " which is not currently attached to any display");
1781 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001782 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001783 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1784 + " to its current displayId=" + mDisplayId);
1785 }
1786
Wale Ogunwale61911492017-10-11 08:50:50 -07001787 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001788 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001789 }
1790
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001791 @Override
1792 protected void addChild(DisplayChildWindowContainer child,
1793 Comparator<DisplayChildWindowContainer> comparator) {
1794 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1795 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001796
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001797 @Override
1798 protected void addChild(DisplayChildWindowContainer child, int index) {
1799 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1800 }
1801
1802 @Override
1803 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001804 // Only allow removal of direct children from this display if the display is in the process
1805 // of been removed.
1806 if (mRemovingDisplay) {
1807 super.removeChild(child);
1808 return;
1809 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001810 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001811 }
1812
Andrii Kuliand2765632016-12-12 22:26:34 -08001813 @Override
1814 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1815 // Children of the display are statically ordered, so the real intention here is to perform
1816 // the operation on the display and not the static direct children.
1817 getParent().positionChildAt(position, this, includingParents);
1818 }
1819
Winson Chung59a47ded2018-01-25 17:46:06 +00001820 void positionStackAt(int position, TaskStack child) {
1821 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1822 layoutAndAssignWindowLayersIfNeeded();
1823 }
1824
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001825 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001826 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1827 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001828 final int taskId = stack.taskIdFromPoint(x, y);
1829 if (taskId != -1) {
1830 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001831 }
1832 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001833 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001834 }
1835
Chong Zhang8e89b312015-09-09 15:09:30 -07001836 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001837 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001838 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001839 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001840 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001841 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001842 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001843 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1844 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001845 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001846 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001847 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001848
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001849 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1850 if (mTmpTaskForResizePointSearchResult.searchDone) {
1851 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001852 }
1853 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001854 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001855 }
1856
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001857 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001858 // The provided task is the task on this display with focus, so if WindowManagerService's
1859 // focused app is not on this display, focusedTask will be null.
1860 if (focusedTask == null) {
1861 mTouchExcludeRegion.setEmpty();
1862 } else {
1863 mTouchExcludeRegion.set(mBaseDisplayRect);
1864 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1865 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001866 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1867 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001868 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1869 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001870 }
1871 // If we removed the focused task above, add it back and only leave its
1872 // outside touch area in the exclusion. TapDectector is not interested in
1873 // any touch inside the focused task itself.
1874 if (!mTmpRect2.isEmpty()) {
1875 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1876 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001877 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001878 final WindowState inputMethod = mService.mInputMethodWindow;
1879 if (inputMethod != null && inputMethod.isVisibleLw()) {
1880 // If the input method is visible and the user is typing, we don't want these touch
1881 // events to be intercepted and used to change focus. This would likely cause a
1882 // disappearance of the input method.
1883 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001884 if (inputMethod.getDisplayId() == mDisplayId) {
1885 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1886 } else {
1887 // IME is on a different display, so we need to update its tap detector.
1888 // TODO(multidisplay): Remove when IME will always appear on same display.
1889 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1890 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001891 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001892 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001893 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001894 win.getTouchableRegion(mTmpRegion);
1895 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1896 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001897 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1898 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1899 win.amendTapExcludeRegion(mTouchExcludeRegion);
1900 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001901 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001902 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001903 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001904 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001905 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1906 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001907 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001908 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001909 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001910 }
1911
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001912 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001913 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001914 super.switchUser();
1915 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001916 }
1917
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001918 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001919 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1920 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001921 }
1922 }
1923
Wale Ogunwale10124582016-09-15 20:25:50 -07001924 @Override
1925 void removeIfPossible() {
1926 if (isAnimating()) {
1927 mDeferredRemoval = true;
1928 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001929 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001930 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001931 }
1932
Wale Ogunwale10124582016-09-15 20:25:50 -07001933 @Override
1934 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001935 mRemovingDisplay = true;
1936 try {
1937 super.removeImmediately();
1938 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001939 if (mService.canDispatchPointerEvents()) {
1940 if (mTapDetector != null) {
1941 mService.unregisterPointerEventListener(mTapDetector);
1942 }
1943 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1944 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1945 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001946 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001947 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001948 } finally {
1949 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001950 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001951
1952 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001953 }
1954
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001955 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001956 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001957 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001958 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1959
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001960 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001961 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001962 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001963 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001964 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001965 }
1966
Andrii Kulian0214ed92017-05-16 13:44:05 -07001967 /** @return 'true' if removal of this display content is deferred due to active animation. */
1968 boolean isRemovalDeferred() {
1969 return mDeferredRemoval;
1970 }
1971
Wale Ogunwale10124582016-09-15 20:25:50 -07001972 boolean animateForIme(float interpolatedValue, float animationTarget,
1973 float dividerAnimationTarget) {
1974 boolean updated = false;
1975
Wale Ogunwale61911492017-10-11 08:50:50 -07001976 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1977 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001978 if (stack == null || !stack.isAdjustedForIme()) {
1979 continue;
1980 }
1981
1982 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1983 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1984 updated = true;
1985 } else {
1986 mDividerControllerLocked.mLastAnimationProgress =
1987 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1988 mDividerControllerLocked.mLastDividerProgress =
1989 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1990 updated |= stack.updateAdjustForIme(
1991 mDividerControllerLocked.mLastAnimationProgress,
1992 mDividerControllerLocked.mLastDividerProgress,
1993 false /* force */);
1994 }
1995 if (interpolatedValue >= 1f) {
1996 stack.endImeAdjustAnimation();
1997 }
1998 }
1999
2000 return updated;
2001 }
2002
2003 boolean clearImeAdjustAnimation() {
2004 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002005 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2006 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002007 if (stack != null && stack.isAdjustedForIme()) {
2008 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2009 changed = true;
2010 }
2011 }
2012 return changed;
2013 }
2014
2015 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002016 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2017 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002018 if (stack.isVisible() && stack.isAdjustedForIme()) {
2019 stack.beginImeAdjustAnimation();
2020 }
2021 }
2022 }
2023
2024 void adjustForImeIfNeeded() {
2025 final WindowState imeWin = mService.mInputMethodWindow;
2026 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2027 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002028 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002029 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2030 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2031 imeTargetStack.getDockSide() : DOCKED_INVALID;
2032 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2033 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2034 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002035 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002036 final boolean imeHeightChanged = imeVisible &&
2037 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2038
2039 // The divider could be adjusted for IME position, or be thinner than usual,
2040 // or both. There are three possible cases:
2041 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2042 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2043 // - If IME is not visible, divider is not moved and is normal width.
2044
2045 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002046 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2047 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002048 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002049 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2050 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002051 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2052 } else {
2053 stack.resetAdjustedForIme(false);
2054 }
2055 }
2056 mDividerControllerLocked.setAdjustedForIme(
2057 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2058 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002059 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2060 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002061 stack.resetAdjustedForIme(!dockVisible);
2062 }
2063 mDividerControllerLocked.setAdjustedForIme(
2064 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2065 }
Winson Chung655332c2016-10-31 13:14:28 -07002066 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002067 }
2068
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002069 /**
2070 * If a window that has an animation specifying a colored background and the current wallpaper
2071 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2072 * suddenly disappear.
2073 */
2074 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002075 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2076 w -> w.mIsWallpaper && w.isVisibleNow());
2077
2078 if (visibleWallpaper != null) {
2079 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002080 }
2081 return winAnimator.mAnimLayer;
2082 }
2083
Wale Ogunwale10124582016-09-15 20:25:50 -07002084 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002085 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2086 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002087 stack.prepareFreezingTaskBounds();
2088 }
2089 }
2090
Wale Ogunwale94744212015-09-21 19:01:47 -07002091 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002092 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002093
2094 // Compute a transform matrix to undo the coordinate space transformation,
2095 // and present the window at the same physical position it previously occupied.
2096 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2097 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2098
2099 mTmpRectF.set(bounds);
2100 mTmpMatrix.mapRect(mTmpRectF);
2101 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002102 }
2103
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002104 static int deltaRotation(int oldRotation, int newRotation) {
2105 int delta = newRotation - oldRotation;
2106 if (delta < 0) delta += 4;
2107 return delta;
2108 }
2109
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002110 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002111 Matrix outMatrix) {
2112 // For rotations without Z-ordering we don't need the target rectangle's position.
2113 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2114 displayHeight, outMatrix);
2115 }
2116
2117 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2118 float displayWidth, float displayHeight, Matrix outMatrix) {
2119 switch (rotation) {
2120 case ROTATION_0:
2121 outMatrix.reset();
2122 break;
2123 case ROTATION_270:
2124 outMatrix.setRotate(270, 0, 0);
2125 outMatrix.postTranslate(0, displayHeight);
2126 outMatrix.postTranslate(rectTop, 0);
2127 break;
2128 case ROTATION_180:
2129 outMatrix.reset();
2130 break;
2131 case ROTATION_90:
2132 outMatrix.setRotate(90, 0, 0);
2133 outMatrix.postTranslate(displayWidth, 0);
2134 outMatrix.postTranslate(-rectTop, rectLeft);
2135 break;
2136 }
2137 }
2138
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002139 @CallSuper
2140 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002141 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002142 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002143 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002144 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002145 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2146 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002147 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002148 }
2149 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2150 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002151 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2152 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002153 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002154 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002155 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2156 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002157 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002158 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002159 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2160 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002161 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002162 }
2163 proto.write(DPI, mBaseDisplayDensity);
2164 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002165 proto.write(ROTATION, mRotation);
2166 final ScreenRotationAnimation screenRotationAnimation =
2167 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2168 if (screenRotationAnimation != null) {
2169 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2170 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002171 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002172 proto.end(token);
2173 }
2174
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002175 @Override
2176 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2177 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002178 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2179 final String subPrefix = " " + prefix;
2180 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2181 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2182 pw.print("dpi");
2183 if (mInitialDisplayWidth != mBaseDisplayWidth
2184 || mInitialDisplayHeight != mBaseDisplayHeight
2185 || mInitialDisplayDensity != mBaseDisplayDensity) {
2186 pw.print(" base=");
2187 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2188 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2189 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002190 if (mDisplayScalingDisabled) {
2191 pw.println(" noscale");
2192 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002193 pw.print(" cur=");
2194 pw.print(mDisplayInfo.logicalWidth);
2195 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2196 pw.print(" app=");
2197 pw.print(mDisplayInfo.appWidth);
2198 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2199 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2200 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2201 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2202 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002203 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002204 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002205 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002206
Craig Mautnerdc548482014-02-05 13:35:24 -08002207 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002208 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002209 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2210 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002211 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002212 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002213
Craig Mautnerdc548482014-02-05 13:35:24 -08002214 pw.println();
2215 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002216 pw.println();
2217 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002218 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002219 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002220 pw.print(" Exiting #"); pw.print(i);
2221 pw.print(' '); pw.print(token);
2222 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002223 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002224 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002225 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002226
Jorim Jaggi31f71702016-05-04 16:43:04 -07002227 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002228
2229 // Dump stack references
2230 final TaskStack homeStack = getHomeStack();
2231 if (homeStack != null) {
2232 pw.println(prefix + "homeStack=" + homeStack.getName());
2233 }
2234 final TaskStack pinnedStack = getPinnedStack();
2235 if (pinnedStack != null) {
2236 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2237 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002238 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002239 if (splitScreenPrimaryStack != null) {
2240 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2241 }
2242
2243 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002244 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002245 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002246 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002247
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002248 pw.println();
2249 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002250 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002251
2252 @Override
2253 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002254 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002255 }
2256
2257 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002258 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002259 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002260
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002261 /** Returns true if the stack in the windowing mode is visible. */
2262 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002263 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002264 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002265 }
2266
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002267 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002268 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002269 final int x = (int) xf;
2270 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002271 final WindowState touchedWin = getWindow(w -> {
2272 final int flags = w.mAttrs.flags;
2273 if (!w.isVisibleLw()) {
2274 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002275 }
2276 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002277 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002278 }
2279
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002280 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002281 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002282 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002283 }
2284
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002285 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002286
2287 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002288 return mTmpRegion.contains(x, y) || touchFlags == 0;
2289 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002290
2291 return touchedWin;
2292 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002293
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002294 boolean canAddToastWindowForUid(int uid) {
2295 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002296 // Also if the app is focused adding more than one toast at
2297 // a time for better backwards compatibility.
2298 final WindowState focusedWindowForUid = getWindow(w ->
2299 w.mOwnerUid == uid && w.isFocused());
2300 if (focusedWindowForUid != null) {
2301 return true;
2302 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002303 final WindowState win = getWindow(w ->
2304 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2305 && !w.mWindowRemovalAllowed);
2306 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002307 }
2308
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002309 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002310 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2311 return;
2312 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002313
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002314 // Used to communicate the old focus to the callback method.
2315 mTmpWindow = oldFocus;
2316
2317 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002318 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002319
2320 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002321 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002322
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002323 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002324
2325 if (mTmpWindow == null) {
2326 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2327 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002328 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002329 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002330 }
2331
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002332 /** Updates the layer assignment of windows on this display. */
2333 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002334 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002335 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002336 if (setLayoutNeeded) {
2337 setLayoutNeeded();
2338 }
Robert Carrb1579c82017-09-05 14:54:47 -07002339
Robert Carrf59b8dd2017-10-02 18:58:36 -07002340 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002341 // the application of this transaction until the animation pass triggers
2342 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2343 // the hiding and showing of surfaces.
2344 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002345 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002346 }
2347
Wale Ogunwale1666e312016-12-16 11:27:18 -08002348 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2349 // moving containers or resizing them. Need to investigate the best way to have it automatically
2350 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002351 void layoutAndAssignWindowLayersIfNeeded() {
2352 mService.mWindowsChanged = true;
2353 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002354
2355 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2356 false /*updateInputWindows*/)) {
2357 assignWindowLayers(false /* setLayoutNeeded */);
2358 }
2359
2360 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2361 mService.mWindowPlacerLocked.performSurfacePlacement();
2362 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2363 }
2364
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002365 /** Returns true if a leaked surface was destroyed */
2366 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002367 // Used to indicate that a surface was leaked.
2368 mTmpWindow = null;
2369 forAllWindows(w -> {
2370 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002371 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002372 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002373 }
2374 if (!mService.mSessions.contains(wsa.mSession)) {
2375 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002376 + w + " surface=" + wsa.mSurfaceController
2377 + " token=" + w.mToken
2378 + " pid=" + w.mSession.mPid
2379 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002380 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002381 mService.mForceRemoves.add(w);
2382 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002383 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002384 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002385 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002386 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002387 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002388 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002389 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002390 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002391 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002392
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002393 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002394 }
2395
2396 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002397 * Determine and return the window that should be the IME target.
2398 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2399 * @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 +00002400 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002401 WindowState computeImeTarget(boolean updateImeTarget) {
2402 if (mService.mInputMethodWindow == null) {
2403 // There isn't an IME so there shouldn't be a target...That was easy!
2404 if (updateImeTarget) {
2405 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2406 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002407 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002408 }
2409 return null;
2410 }
2411
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002412 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2413 // same display. Or even when the current IME/target are not on the same screen as the next
2414 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002415 mUpdateImeTarget = updateImeTarget;
2416 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002417
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002418
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002419 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2420 // to be on top of it, but it is not -really- where input will go. So look down below
2421 // for a real window to target...
2422 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2423 final AppWindowToken token = target.mAppToken;
2424 if (token != null) {
2425 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2426 if (betterTarget != null) {
2427 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002428 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002429 }
2430 }
2431
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002432 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2433 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002434
2435 // Now, a special case -- if the last target's window is in the process of exiting, and is
2436 // above the new target, keep on the last target to avoid flicker. Consider for example a
2437 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2438 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2439 // scrim.
2440 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002441 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2442 && (target == null
2443 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002444 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002445 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002446 }
2447
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002448 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2449 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002450
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002451 if (target == null) {
2452 if (updateImeTarget) {
2453 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2454 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2455 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002456 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002457 }
2458
2459 return null;
2460 }
2461
2462 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002463 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2464 if (token != null) {
2465
2466 // Now some fun for dealing with window animations that modify the Z order. We need
2467 // to look at all windows below the current target that are in this app, finding the
2468 // highest visible one in layering.
2469 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002470 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002471 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002472 }
2473
2474 if (highestTarget != null) {
2475 final AppTransition appTransition = mService.mAppTransition;
2476 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2477 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2478 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002479 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002480
2481 if (appTransition.isTransitionSet()) {
2482 // If we are currently setting up for an animation, hold everything until we
2483 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002484 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002485 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002486 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002487 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002488 // If the window we are currently targeting is involved with an animation,
2489 // and it is on top of the next target we will be over, then hold off on
2490 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002491 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002492 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002493 }
2494 }
2495 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002496
2497 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2498 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002499 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002500 }
2501
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002502 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002503 }
2504
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002505 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002506 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002507 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002508 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002509 }
2510
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002511 mService.mInputMethodTarget = target;
2512 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002513 assignWindowLayers(false /* setLayoutNeeded */);
2514 }
2515
2516 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2517 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2518 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2519 }
2520
2521 // Used to indicate we have reached the first window in the range we are interested in.
2522 mTmpWindow = null;
2523
2524 // TODO: Figure-out a more efficient way to do this.
2525 final WindowState candidate = getWindow(w -> {
2526 if (w == top) {
2527 // Reached the first window in the range we are interested in.
2528 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002529 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002530 if (mTmpWindow == null) {
2531 return false;
2532 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002533
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002534 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2535 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002536 }
2537 // If we reached the bottom of the range of windows we are considering,
2538 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002539 if (w == bottom) {
2540 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002541 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002542 return false;
2543 });
2544
2545 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002546 }
2547
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002548 void setLayoutNeeded() {
2549 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2550 mLayoutNeeded = true;
2551 }
2552
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002553 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002554 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2555 mLayoutNeeded = false;
2556 }
2557
2558 boolean isLayoutNeeded() {
2559 return mLayoutNeeded;
2560 }
2561
Wale Ogunwale02319a62016-09-26 15:21:22 -07002562 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2563 if (mTokenMap.isEmpty()) {
2564 return;
2565 }
2566 pw.println(" Display #" + mDisplayId);
2567 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2568 while (it.hasNext()) {
2569 final WindowToken token = it.next();
2570 pw.print(" ");
2571 pw.print(token);
2572 if (dumpAll) {
2573 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002574 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002575 } else {
2576 pw.println();
2577 }
2578 }
2579 }
2580
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002581 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002582 final int[] index = new int[1];
2583 forAllWindows(w -> {
2584 final WindowStateAnimator wAnim = w.mWinAnimator;
2585 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2586 index[0] = index[0] + 1;
2587 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002588 }
2589
Jorim Jaggife762342016-10-13 14:33:27 +02002590 /**
2591 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2592 */
2593 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2594 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002595 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002596 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2597 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002598 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002599 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002600 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002601 }
2602
Wale Ogunwale494009b82016-10-21 09:01:38 -07002603 boolean checkWaitingForWindows() {
2604
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002605 mHaveBootMsg = false;
2606 mHaveApp = false;
2607 mHaveWallpaper = false;
2608 mHaveKeyguard = true;
2609
2610 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002611 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2612 return true;
2613 }
2614 if (w.isDrawnLw()) {
2615 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002616 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002617 } else if (w.mAttrs.type == TYPE_APPLICATION
2618 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002619 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002620 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002621 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002622 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002623 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002624 }
2625 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002626 return false;
2627 });
2628
2629 if (visibleWindow != null) {
2630 // We have a visible window.
2631 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002632 }
2633
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002634 // if the wallpaper service is disabled on the device, we're never going to have
2635 // wallpaper, don't bother waiting for it
2636 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2637 com.android.internal.R.bool.config_enableWallpaperService)
2638 && !mService.mOnlyCore;
2639
Wale Ogunwale494009b82016-10-21 09:01:38 -07002640 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2641 "******** booted=" + mService.mSystemBooted
2642 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002643 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2644 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2645 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002646
2647 // If we are turning on the screen to show the boot message, don't do it until the boot
2648 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002649 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002650 return true;
2651 }
2652
2653 // If we are turning on the screen after the boot is completed normally, don't do so until
2654 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002655 if (mService.mSystemBooted
2656 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002657 return true;
2658 }
2659
2660 return false;
2661 }
2662
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002663 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002664 mTmpWindowAnimator = animator;
2665 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002666 }
2667
2668 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002669 resetAnimationBackgroundAnimator();
2670
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002671 // Used to indicate a detached wallpaper.
2672 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002673 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002674
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002675 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002676
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002677 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002678 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002679 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2680 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002681 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2682 }
2683 }
2684
Wale Ogunwale494009b82016-10-21 09:01:38 -07002685 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002686 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002687 if (imFocus == null) {
2688 return false;
2689 }
2690
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002691 if (DEBUG_INPUT_METHOD) {
2692 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2693 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2694 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002695 }
2696
Wale Ogunwale494009b82016-10-21 09:01:38 -07002697 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2698
2699 if (DEBUG_INPUT_METHOD) {
2700 Slog.i(TAG_WM, "IM target client: " + imeClient);
2701 if (imeClient != null) {
2702 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2703 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2704 }
2705 }
2706
2707 return imeClient != null && imeClient.asBinder() == client.asBinder();
2708 }
2709
2710 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002711 final WindowState win = getWindow(
2712 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2713 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002714 }
2715
2716 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002717 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002718 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002719 final int curValue = w.mSystemUiVisibility;
2720 final int diff = (curValue ^ visibility) & globalDiff;
2721 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002722 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002723 w.mSeq++;
2724 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002725 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002726 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2727 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002728 visibility, newValue, diff);
2729 }
2730 } catch (RemoteException e) {
2731 // so sorry
2732 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002733 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002734 }
2735
2736 void onWindowFreezeTimeout() {
2737 Slog.w(TAG_WM, "Window freeze timeout expired.");
2738 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002739
2740 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002741 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002742 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002743 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002744 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002745 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2746 - mService.mDisplayFreezeTime);
2747 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002748 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002749 mService.mWindowPlacerLocked.performSurfacePlacement();
2750 }
2751
2752 void waitForAllWindowsDrawn() {
2753 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002754 forAllWindows(w -> {
2755 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2756 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2757 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002758 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002759 w.mLastContentInsets.set(-1, -1, -1, -1);
2760 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002761 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002762 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002763 }
2764
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002765 // TODO: Super crazy long method that should be broken down...
2766 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2767
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002768 final int dw = mDisplayInfo.logicalWidth;
2769 final int dh = mDisplayInfo.logicalHeight;
2770 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2771
2772 mTmpUpdateAllDrawn.clear();
2773
2774 int repeats = 0;
2775 do {
2776 repeats++;
2777 if (repeats > 6) {
2778 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2779 clearLayoutNeeded();
2780 break;
2781 }
2782
2783 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2784 pendingLayoutChanges);
2785
Andrii Kulian839def92016-11-02 10:58:58 -07002786 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2787 // the wallpaper window jumping across displays.
2788 // Remove check for default display when there will be support for multiple wallpaper
2789 // targets (on different displays).
2790 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002791 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002792 }
2793
2794 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2795 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
Robert Carrae606b42018-02-15 15:36:23 -08002796 if (mService.updateOrientationFromAppTokensLocked(mDisplayId)) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002797 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002798 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002799 }
2800 }
2801
2802 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2803 setLayoutNeeded();
2804 }
2805
2806 // FIRST LOOP: Perform a layout, if needed.
2807 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2808 performLayout(repeats == 1, false /* updateInputWindows */);
2809 } else {
2810 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2811 }
2812
2813 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2814 pendingLayoutChanges = 0;
2815
2816 if (isDefaultDisplay) {
2817 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002818 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002819 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2820 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2821 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2822 }
2823 } while (pendingLayoutChanges != 0);
2824
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002825 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002826
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002827 mTmpRecoveringMemory = recoveringMemory;
2828 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002829 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002830
2831 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002832 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2833 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2834 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002835 true /* inTraversal, must call performTraversalInTrans... below */);
2836
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002837 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2838 if (wallpaperVisible != mLastWallpaperVisible) {
2839 mLastWallpaperVisible = wallpaperVisible;
2840 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2841 }
2842
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002843 while (!mTmpUpdateAllDrawn.isEmpty()) {
2844 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2845 // See if any windows have been drawn, so they (and others associated with them)
2846 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002847 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002848 }
2849
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002850 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002851 }
2852
Bryce Leef3c6a472017-11-14 14:53:06 -08002853 private void updateBounds() {
2854 calculateBounds(mTmpBounds);
2855 setBounds(mTmpBounds);
2856 }
2857
2858 // Determines the current display bounds based on the current state
2859 private void calculateBounds(Rect out) {
2860 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2861 final int orientation = mDisplayInfo.rotation;
2862 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2863 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2864 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2865 int width = mDisplayInfo.logicalWidth;
2866 int left = (physWidth - width) / 2;
2867 int height = mDisplayInfo.logicalHeight;
2868 int top = (physHeight - height) / 2;
2869 out.set(left, top, left + width, top + height);
2870 }
2871
2872 @Override
2873 public void getBounds(Rect out) {
2874 calculateBounds(out);
2875 }
2876
2877 private void getBounds(Rect out, int orientation) {
2878 getBounds(out);
2879
2880 // Rotate the Rect if needed.
2881 final int currentRotation = mDisplayInfo.rotation;
2882 final int rotationDelta = deltaRotation(currentRotation, orientation);
2883 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2884 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2885 mTmpRectF.set(out);
2886 mTmpMatrix.mapRect(mTmpRectF);
2887 mTmpRectF.round(out);
2888 }
2889 }
2890
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002891 void performLayout(boolean initial, boolean updateInputWindows) {
2892 if (!isLayoutNeeded()) {
2893 return;
2894 }
2895 clearLayoutNeeded();
2896
2897 final int dw = mDisplayInfo.logicalWidth;
2898 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002899 if (DEBUG_LAYOUT) {
2900 Slog.v(TAG, "-------------------------------------");
2901 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2902 }
2903
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01002904 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
2905 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002906 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2907 // display info above...
2908 mDisplayFrames.mRotation = mRotation;
2909 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002910 if (isDefaultDisplay) {
2911 // Not needed on non-default displays.
2912 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2913 mService.mScreenRect.set(0, 0, dw, dh);
2914 }
2915
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002916 int seq = mService.mLayoutSeq + 1;
2917 if (seq < 0) seq = 0;
2918 mService.mLayoutSeq = seq;
2919
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002920 // Used to indicate that we have processed the dream window and all additional windows are
2921 // behind it.
2922 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002923 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002924
2925 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002926 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002927
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002928 // Used to indicate that we have processed the dream window and all additional attached
2929 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002930 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002931 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002932
2933 // Now perform layout of attached windows, which usually depend on the position of the
2934 // window they are attached to. XXX does not deal with windows that are attached to windows
2935 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002936 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002937
2938 // Window frames may have changed. Tell the input dispatcher about it.
2939 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2940 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2941 if (updateInputWindows) {
2942 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2943 }
2944
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002945 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2946 }
2947
2948 /**
2949 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2950 * In portrait mode, it grabs the full screenshot.
2951 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002952 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002953 */
chaviw0315a1a2018-03-05 15:28:35 -08002954 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
2955 if (!mService.mPolicy.isScreenOn()) {
2956 if (DEBUG_SCREENSHOT) {
2957 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002958 }
chaviw0315a1a2018-03-05 15:28:35 -08002959 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002960 }
chaviwfbe47df2017-11-10 16:14:49 -08002961
chaviw0315a1a2018-03-05 15:28:35 -08002962 int dw = mDisplayInfo.logicalWidth;
2963 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08002964
chaviw0315a1a2018-03-05 15:28:35 -08002965 if (dw <= 0 || dh <= 0) {
2966 return null;
2967 }
chaviwfbe47df2017-11-10 16:14:49 -08002968
chaviw0315a1a2018-03-05 15:28:35 -08002969 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08002970
chaviw0315a1a2018-03-05 15:28:35 -08002971 // The screenshot API does not apply the current screen rotation.
2972 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08002973
chaviw0315a1a2018-03-05 15:28:35 -08002974 if (rot == ROTATION_90 || rot == ROTATION_270) {
2975 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2976 }
chaviwfbe47df2017-11-10 16:14:49 -08002977
chaviw0315a1a2018-03-05 15:28:35 -08002978 // SurfaceFlinger is not aware of orientation, so convert our logical
2979 // crop to SurfaceFlinger's portrait orientation.
2980 convertCropForSurfaceFlinger(frame, rot, dw, dh);
2981
2982 final ScreenRotationAnimation screenRotationAnimation =
2983 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2984 final boolean inRotation = screenRotationAnimation != null &&
2985 screenRotationAnimation.isAnimating();
2986 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
2987
2988 // TODO(b/68392460): We should screenshot Task controls directly
2989 // but it's difficult at the moment as the Task doesn't have the
2990 // correct size set.
2991 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
2992 if (bitmap == null) {
2993 Slog.w(TAG_WM, "Failed to take screenshot");
2994 return null;
2995 }
2996
2997 // Create a copy of the screenshot that is immutable and backed in ashmem.
2998 // This greatly reduces the overhead of passing the bitmap between processes.
2999 final Bitmap ret = bitmap.createAshmemBitmap(config);
3000 bitmap.recycle();
3001 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003002 }
3003
3004 // TODO: Can this use createRotationMatrix()?
3005 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3006 if (rot == Surface.ROTATION_90) {
3007 final int tmp = crop.top;
3008 crop.top = dw - crop.right;
3009 crop.right = crop.bottom;
3010 crop.bottom = dw - crop.left;
3011 crop.left = tmp;
3012 } else if (rot == Surface.ROTATION_180) {
3013 int tmp = crop.top;
3014 crop.top = dh - crop.bottom;
3015 crop.bottom = dh - tmp;
3016 tmp = crop.right;
3017 crop.right = dw - crop.left;
3018 crop.left = dw - tmp;
3019 } else if (rot == Surface.ROTATION_270) {
3020 final int tmp = crop.top;
3021 crop.top = crop.left;
3022 crop.left = dh - crop.bottom;
3023 crop.bottom = crop.right;
3024 crop.right = dh - tmp;
3025 }
3026 }
3027
3028 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003029 // Used to indicate the layout is needed.
3030 mTmpWindow = null;
3031
3032 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003033 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003034 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003035 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003036 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003037 w.setDisplayLayoutNeeded();
3038 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003039 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003040
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003041 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003042 mService.mWindowPlacerLocked.performSurfacePlacement();
3043 }
3044 }
3045
Wale Ogunwale1666e312016-12-16 11:27:18 -08003046 void setExitingTokensHasVisible(boolean hasVisible) {
3047 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3048 mExitingTokens.get(i).hasVisible = hasVisible;
3049 }
3050
3051 // Initialize state of exiting applications.
3052 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3053 }
3054
3055 void removeExistingTokensIfPossible() {
3056 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3057 final WindowToken token = mExitingTokens.get(i);
3058 if (!token.hasVisible) {
3059 mExitingTokens.remove(i);
3060 }
3061 }
3062
3063 // Time to remove any exiting applications?
3064 mTaskStackContainers.removeExistingAppTokensIfPossible();
3065 }
3066
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003067 @Override
3068 void onDescendantOverrideConfigurationChanged() {
3069 setLayoutNeeded();
3070 mService.requestTraversal();
3071 }
3072
David Stevens9440dc82017-03-16 19:00:20 -07003073 boolean okToDisplay() {
3074 if (mDisplayId == DEFAULT_DISPLAY) {
3075 return !mService.mDisplayFrozen
3076 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3077 }
3078 return mDisplayInfo.state == Display.STATE_ON;
3079 }
3080
3081 boolean okToAnimate() {
3082 return okToDisplay() &&
3083 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3084 }
3085
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003086 static final class TaskForResizePointSearchResult {
3087 boolean searchDone;
3088 Task taskForResize;
3089
3090 void reset() {
3091 searchDone = false;
3092 taskForResize = null;
3093 }
3094 }
Robert Carr3b716242016-08-16 16:02:21 -07003095
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003096 private static final class ApplySurfaceChangesTransactionState {
3097 boolean displayHasContent;
3098 boolean obscured;
3099 boolean syswin;
3100 boolean focusDisplayed;
3101 float preferredRefreshRate;
3102 int preferredModeId;
3103
3104 void reset() {
3105 displayHasContent = false;
3106 obscured = false;
3107 syswin = false;
3108 focusDisplayed = false;
3109 preferredRefreshRate = 0;
3110 preferredModeId = 0;
3111 }
3112 }
3113
3114 private static final class ScreenshotApplicationState {
3115 WindowState appWin;
3116 int maxLayer;
3117 int minLayer;
3118 boolean screenshotReady;
3119
3120 void reset(boolean screenshotReady) {
3121 appWin = null;
3122 maxLayer = 0;
3123 minLayer = 0;
3124 this.screenshotReady = screenshotReady;
3125 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3126 }
3127 }
3128
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003129 /**
3130 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3131 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3132 * homogeneous children type which is currently required by sub-classes of
3133 * {@link WindowContainer} class.
3134 */
3135 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3136
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003137 DisplayChildWindowContainer(WindowManagerService service) {
3138 super(service);
3139 }
3140
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003141 @Override
3142 boolean fillsParent() {
3143 return true;
3144 }
3145
3146 @Override
3147 boolean isVisible() {
3148 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003149 }
3150 }
3151
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003152 /**
3153 * Window container class that contains all containers on this display relating to Apps.
3154 * I.e Activities.
3155 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003156 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003157 /**
3158 * A control placed at the appropriate level for transitions to occur.
3159 */
chaviw23ee71c2017-12-18 11:29:41 -08003160 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003161
Robert Carrf7a7ca82017-12-06 13:17:07 -08003162 /**
3163 * Given that the split-screen divider does not have an AppWindowToken, it
3164 * will have to live inside of a "NonAppWindowContainer", in particular
3165 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3166 * it will need to be interleaved with some of our children, appearing on top of
3167 * both docked stacks but underneath any assistant stacks.
3168 *
3169 * To solve this problem we have this anchor control, which will always exist so
3170 * we can always assign it the correct value in our {@link #assignChildLayers}.
3171 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3172 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3173 * events between the two containers.
3174 */
3175 SurfaceControl mSplitScreenDividerAnchor = null;
3176
Wale Ogunwale61911492017-10-11 08:50:50 -07003177 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3178 // through the list to find them.
3179 private TaskStack mHomeStack = null;
3180 private TaskStack mPinnedStack = null;
3181 private TaskStack mSplitScreenPrimaryStack = null;
3182
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003183 TaskStackContainers(WindowManagerService service) {
3184 super(service);
3185 }
3186
Wale Ogunwale61911492017-10-11 08:50:50 -07003187 /**
3188 * Returns the topmost stack on the display that is compatible with the input windowing mode
3189 * and activity type. Null is no compatible stack on the display.
3190 */
3191 TaskStack getStack(int windowingMode, int activityType) {
3192 if (activityType == ACTIVITY_TYPE_HOME) {
3193 return mHomeStack;
3194 }
3195 if (windowingMode == WINDOWING_MODE_PINNED) {
3196 return mPinnedStack;
3197 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3198 return mSplitScreenPrimaryStack;
3199 }
3200 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3201 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003202 if (activityType == ACTIVITY_TYPE_UNDEFINED
3203 && windowingMode == stack.getWindowingMode()) {
3204 // Passing in undefined type means we want to match the topmost stack with the
3205 // windowing mode.
3206 return stack;
3207 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003208 if (stack.isCompatible(windowingMode, activityType)) {
3209 return stack;
3210 }
3211 }
3212 return null;
3213 }
3214
3215 @VisibleForTesting
3216 TaskStack getTopStack() {
3217 return mTaskStackContainers.getChildCount() > 0
3218 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3219 }
3220
3221 TaskStack getHomeStack() {
3222 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3223 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3224 }
3225 return mHomeStack;
3226 }
3227
3228 TaskStack getPinnedStack() {
3229 return mPinnedStack;
3230 }
3231
Matthew Ng64e77cf2017-10-31 14:01:31 -07003232 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003233 return mSplitScreenPrimaryStack;
3234 }
3235
Winson Chunge2d72172018-01-25 17:46:20 +00003236 ArrayList<Task> getVisibleTasks() {
3237 final ArrayList<Task> visibleTasks = new ArrayList<>();
3238 forAllTasks(task -> {
3239 if (task.isVisible()) {
3240 visibleTasks.add(task);
3241 }
3242 });
3243 return visibleTasks;
3244 }
3245
Andrii Kulian839def92016-11-02 10:58:58 -07003246 /**
3247 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003248 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003249 */
3250 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003251 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003252 addChild(stack, onTop);
3253 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003254 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003255
Wale Ogunwale61911492017-10-11 08:50:50 -07003256 void onStackWindowingModeChanged(TaskStack stack) {
3257 removeStackReferenceIfNeeded(stack);
3258 addStackReferenceIfNeeded(stack);
3259 if (stack == mPinnedStack && getTopStack() != stack) {
3260 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3261 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3262 }
3263 }
3264
3265 private void addStackReferenceIfNeeded(TaskStack stack) {
3266 if (stack.isActivityTypeHome()) {
3267 if (mHomeStack != null) {
3268 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3269 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3270 }
3271 mHomeStack = stack;
3272 }
3273 final int windowingMode = stack.getWindowingMode();
3274 if (windowingMode == WINDOWING_MODE_PINNED) {
3275 if (mPinnedStack != null) {
3276 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3277 + mPinnedStack + " already exist on display=" + this
3278 + " stack=" + stack);
3279 }
3280 mPinnedStack = stack;
3281 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3282 if (mSplitScreenPrimaryStack != null) {
3283 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3284 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3285 + " already exist on display=" + this + " stack=" + stack);
3286 }
3287 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003288 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003289 }
3290 }
3291
3292 private void removeStackReferenceIfNeeded(TaskStack stack) {
3293 if (stack == mHomeStack) {
3294 mHomeStack = null;
3295 } else if (stack == mPinnedStack) {
3296 mPinnedStack = null;
3297 } else if (stack == mSplitScreenPrimaryStack) {
3298 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003299 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3300 mService.setDockedStackCreateStateLocked(
3301 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3302 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003303 }
Andrii Kulian839def92016-11-02 10:58:58 -07003304 }
3305
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003306 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003307 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3308 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003309 addChild(stack, addIndex);
3310 setLayoutNeeded();
3311 }
3312
Wale Ogunwale61911492017-10-11 08:50:50 -07003313 @Override
3314 protected void removeChild(TaskStack stack) {
3315 super.removeChild(stack);
3316 removeStackReferenceIfNeeded(stack);
3317 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003318
3319 @Override
3320 boolean isOnTop() {
3321 // Considered always on top
3322 return true;
3323 }
3324
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003325 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003326 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003327 if (child.getWindowConfiguration().isAlwaysOnTop()
3328 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003329 // This stack is always-on-top, override the default behavior.
3330 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3331
3332 // Moving to its current position, as we must call super but we don't want to
3333 // perform any meaningful action.
3334 final int currentPosition = mChildren.indexOf(child);
3335 super.positionChildAt(currentPosition, child, false /* includingParents */);
3336 return;
3337 }
3338
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003339 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3340 super.positionChildAt(targetPosition, child, includingParents);
3341
3342 setLayoutNeeded();
3343 }
3344
3345 /**
3346 * When stack is added or repositioned, find a proper position for it.
3347 * This will make sure that pinned stack always stays on top.
3348 * @param requestedPosition Position requested by caller.
3349 * @param stack Stack to be added or positioned.
3350 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3351 * @return The proper position for the stack.
3352 */
3353 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3354 final int topChildPosition = mChildren.size() - 1;
3355 boolean toTop = requestedPosition == POSITION_TOP;
3356 toTop |= adding ? requestedPosition >= topChildPosition + 1
3357 : requestedPosition >= topChildPosition;
3358 int targetPosition = requestedPosition;
3359
Wale Ogunwale61911492017-10-11 08:50:50 -07003360 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003361 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003362 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003363 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003364 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3365 }
3366
3367 // So, stack is moved just below the pinned stack.
3368 // When we're adding a new stack the target is the current pinned stack position.
3369 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003370 // stack, because WindowContainer#positionAt() first removes element and then adds
3371 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003372 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3373 }
3374
3375 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003376 }
3377
3378 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003379 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3380 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003381 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003382 if (super.forAllWindows(callback, traverseTopToBottom)) {
3383 return true;
3384 }
3385 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3386 return true;
3387 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003388 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003389 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3390 return true;
3391 }
3392 if (super.forAllWindows(callback, traverseTopToBottom)) {
3393 return true;
3394 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003395 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003396 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003397 }
3398
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003399 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003400 boolean traverseTopToBottom) {
3401 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3402 // app tokens.
3403 // TODO: Investigate if we need to continue to do this or if we can just process them
3404 // in-order.
3405 if (traverseTopToBottom) {
3406 for (int i = mChildren.size() - 1; i >= 0; --i) {
3407 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3408 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003409 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3410 traverseTopToBottom)) {
3411 return true;
3412 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003413 }
3414 }
3415 } else {
3416 final int count = mChildren.size();
3417 for (int i = 0; i < count; ++i) {
3418 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3419 final int appTokensCount = appTokens.size();
3420 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003421 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3422 traverseTopToBottom)) {
3423 return true;
3424 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003425 }
3426 }
3427 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003428 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003429 }
3430
Wale Ogunwale1666e312016-12-16 11:27:18 -08003431 void setExitingTokensHasVisible(boolean hasVisible) {
3432 for (int i = mChildren.size() - 1; i >= 0; --i) {
3433 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3434 for (int j = appTokens.size() - 1; j >= 0; --j) {
3435 appTokens.get(j).hasVisible = hasVisible;
3436 }
3437 }
3438 }
3439
3440 void removeExistingAppTokensIfPossible() {
3441 for (int i = mChildren.size() - 1; i >= 0; --i) {
3442 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3443 for (int j = appTokens.size() - 1; j >= 0; --j) {
3444 final AppWindowToken token = appTokens.get(j);
3445 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3446 && (!token.mIsExiting || token.isEmpty())) {
3447 // Make sure there is no animation running on this token, so any windows
3448 // associated with it will be removed as soon as their animations are
3449 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003450 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003451 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3452 "performLayout: App token exiting now removed" + token);
3453 token.removeIfPossible();
3454 }
3455 }
3456 }
3457 }
3458
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003459 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003460 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003461 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3462 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003463 // Apps and their containers are not allowed to specify an orientation while the
3464 // docked or freeform stack is visible...except for the home stack/task if the
3465 // docked stack is minimized and it actually set something.
3466 if (mHomeStack != null && mHomeStack.isVisible()
3467 && mDividerControllerLocked.isMinimizedDock()) {
3468 final int orientation = mHomeStack.getOrientation();
3469 if (orientation != SCREEN_ORIENTATION_UNSET) {
3470 return orientation;
3471 }
3472 }
3473 return SCREEN_ORIENTATION_UNSPECIFIED;
3474 }
3475
3476 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003477 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3478 PackageManager.FEATURE_AUTOMOTIVE);
3479 if (isCar) {
3480 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3481 // allow anything but the default orientation.
3482 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3483 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3484 return SCREEN_ORIENTATION_UNSPECIFIED;
3485 }
3486
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003487 if (orientation != SCREEN_ORIENTATION_UNSET
3488 && orientation != SCREEN_ORIENTATION_BEHIND) {
3489 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3490 "App is requesting an orientation, return " + orientation);
3491 return orientation;
3492 }
3493
3494 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003495 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003496 // The next app has not been requested to be visible, so we keep the current orientation
3497 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003498 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003499 }
Robert Carrb1579c82017-09-05 14:54:47 -07003500
3501 @Override
3502 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003503 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003504
Robert Carr2f8aa392018-01-31 14:46:51 -08003505 for (int i = 0; i < mChildren.size(); i++) {
3506 final TaskStack s = mChildren.get(i);
3507 s.assignChildLayers(t);
3508 }
3509 }
3510
3511 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003512 final int HOME_STACK_STATE = 0;
3513 final int NORMAL_STACK_STATE = 1;
3514 final int ALWAYS_ON_TOP_STATE = 2;
3515
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003516 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003517 int layerForAnimationLayer = 0;
3518
Robert Carrf7a7ca82017-12-06 13:17:07 -08003519 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3520 for (int i = 0; i < mChildren.size(); i++) {
3521 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003522 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3523 continue;
3524 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3525 || s.isAlwaysOnTop())) {
3526 continue;
3527 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3528 continue;
3529 }
3530 s.assignLayer(t, layer++);
3531 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3532 t.setLayer(mSplitScreenDividerAnchor, layer++);
3533 }
Robert Carrb9506032018-02-13 13:54:00 -08003534 if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003535 // Ensure the animation layer ends up above the
3536 // highest animating stack and no higher.
3537 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003538 }
3539 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003540 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003541 if (mAppAnimationLayer != null) {
3542 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003543 }
Robert Carrb1579c82017-09-05 14:54:47 -07003544 }
3545
3546 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003547 SurfaceControl getAppAnimationLayer() {
3548 return mAppAnimationLayer;
3549 }
3550
Robert Carrf7a7ca82017-12-06 13:17:07 -08003551 SurfaceControl getSplitScreenDividerAnchor() {
3552 return mSplitScreenDividerAnchor;
3553 }
3554
chaviw23ee71c2017-12-18 11:29:41 -08003555 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003556 void onParentSet() {
3557 super.onParentSet();
3558 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003559 mAppAnimationLayer = makeChildSurface(null)
3560 .setName("animationLayer")
3561 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003562 mSplitScreenDividerAnchor = makeChildSurface(null)
3563 .setName("splitScreenDividerAnchor")
3564 .build();
3565 getPendingTransaction()
3566 .show(mAppAnimationLayer)
3567 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003568 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003569 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003570 mAppAnimationLayer.destroy();
3571 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003572 mSplitScreenDividerAnchor.destroy();
3573 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003574 }
3575 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003576 }
3577
Robert Carree4d4b92017-11-22 12:21:46 -08003578 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003579 AboveAppWindowContainers(String name, WindowManagerService service) {
3580 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003581 }
3582
Robert Carrb9506032018-02-13 13:54:00 -08003583 @Override
3584 void assignChildLayers(SurfaceControl.Transaction t) {
3585 assignChildLayers(t, null /* imeContainer */);
3586 }
3587
Robert Carree4d4b92017-11-22 12:21:46 -08003588 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3589 boolean needAssignIme = imeContainer != null
3590 && imeContainer.getSurfaceControl() != null;
3591 for (int j = 0; j < mChildren.size(); ++j) {
3592 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003593
3594 // See {@link mSplitScreenDividerAnchor}
3595 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3596 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3597 continue;
3598 }
Robert Carree4d4b92017-11-22 12:21:46 -08003599 wt.assignLayer(t, j);
3600 wt.assignChildLayers(t);
3601
3602 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3603 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003604
3605 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3606 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003607 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003608 needAssignIme = false;
3609 }
3610 }
3611 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003612 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003613 }
3614 }
3615 }
3616
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003617 /**
3618 * Window container class that contains all containers on this display that are not related to
3619 * Apps. E.g. status bar.
3620 */
Robert Carree4d4b92017-11-22 12:21:46 -08003621 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003622 /**
3623 * Compares two child window tokens returns -1 if the first is lesser than the second in
3624 * terms of z-order and 1 otherwise.
3625 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003626 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003627 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003628 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3629 token1.mOwnerCanManageAppTokens)
3630 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3631 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003632
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003633 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3634 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3635 return false;
3636 }
3637 final int req = w.mAttrs.screenOrientation;
3638 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3639 || req == SCREEN_ORIENTATION_UNSET) {
3640 return false;
3641 }
3642 return true;
3643 };
3644
Wale Ogunwale3a931692016-11-02 16:49:48 -07003645 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003646 private final Dimmer mDimmer = new Dimmer(this);
3647 private final Rect mTmpDimBoundsRect = new Rect();
3648
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003649 NonAppWindowContainers(String name, WindowManagerService service) {
3650 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003651 mName = name;
3652 }
3653
3654 void addChild(WindowToken token) {
3655 addChild(token, mWindowComparator);
3656 }
3657
3658 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003659 int getOrientation() {
3660 final WindowManagerPolicy policy = mService.mPolicy;
3661 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003662 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003663
3664 if (win != null) {
3665 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003666 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003667 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003668 if (mService.mKeyguardGoingAway) {
3669 // Keyguard can't affect the orientation if it is going away...
3670 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3671 return SCREEN_ORIENTATION_UNSET;
3672 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003673 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003674 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003675 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003676 }
3677
Andrii Kulian8ee72852017-03-10 10:36:45 -08003678 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003679
Jorim Jaggi75520d52017-08-24 17:23:19 +02003680 if (policy.isKeyguardShowingAndNotOccluded()
3681 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003682 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003683 }
3684
3685 return SCREEN_ORIENTATION_UNSET;
3686 }
3687
3688 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003689 String getName() {
3690 return mName;
3691 }
chaviwf29223e2018-01-31 13:23:51 -08003692
3693 @Override
3694 Dimmer getDimmer() {
3695 return mDimmer;
3696 }
3697
3698 @Override
3699 void prepareSurfaces() {
3700 mDimmer.resetDimStates();
3701 super.prepareSurfaces();
3702 getBounds(mTmpDimBoundsRect);
3703
3704 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3705 scheduleAnimation();
3706 }
3707 }
Robert Carr3b716242016-08-16 16:02:21 -07003708 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003709
Robert Carr9034d962018-01-04 18:27:42 -08003710 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3711 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3712 super(name, service);
3713 }
3714
3715 @Override
3716 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3717 }
3718 };
3719
Robert Carrb1579c82017-09-05 14:54:47 -07003720 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3721 return mService.makeSurfaceBuilder(s)
3722 .setParent(mWindowingLayer);
3723 }
3724
3725 @Override
3726 SurfaceSession getSession() {
3727 return mSession;
3728 }
3729
3730 @Override
3731 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003732 SurfaceSession s = child != null ? child.getSession() : getSession();
3733 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003734 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003735
3736 if (child == null) {
3737 return b;
3738 }
3739
Robert Carree4d4b92017-11-22 12:21:46 -08003740 return b.setName(child.getName())
3741 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003742 }
3743
3744 /**
3745 * The makeSurface variants are for use by the window-container
3746 * hierarchy. makeOverlay here is a function for various non windowing
3747 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3748 * and other potpourii.
3749 */
3750 SurfaceControl.Builder makeOverlay() {
3751 return mService.makeSurfaceBuilder(mSession)
3752 .setParent(mOverlayLayer);
3753 }
3754
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003755 /**
3756 * Reparents the given surface to mOverlayLayer.
3757 */
3758 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3759 transaction.reparent(surface, mOverlayLayer.getHandle());
3760 }
3761
Robert Carrb1579c82017-09-05 14:54:47 -07003762 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003763 applyMagnificationSpec(getPendingTransaction(), spec);
3764 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003765 }
3766
3767 @Override
3768 void onParentSet() {
3769 // Since we are the top of the SurfaceControl hierarchy here
3770 // we create the root surfaces explicitly rather than chaining
3771 // up as the default implementation in onParentSet does. So we
3772 // explicitly do NOT call super here.
3773 }
3774
3775 @Override
3776 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003777
3778 // These are layers as children of "mWindowingLayer"
3779 mBelowAppWindowsContainers.assignLayer(t, 0);
3780 mTaskStackContainers.assignLayer(t, 1);
3781 mAboveAppWindowsContainers.assignLayer(t, 2);
3782
3783 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003784 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003785
Robert Carree4d4b92017-11-22 12:21:46 -08003786 // In the case where we have an IME target that is not in split-screen
3787 // mode IME assignment is easy. We just need the IME to go directly above
3788 // the target. This way children of the target will naturally go above the IME
3789 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003790 //
Robert Carree4d4b92017-11-22 12:21:46 -08003791 // In the case of split-screen windowing mode, we need to elevate the IME above the
3792 // docked divider while keeping the app itself below the docked divider, so instead
3793 // we use relative layering of the IME targets child windows, and place the
3794 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003795 //
Robert Carree4d4b92017-11-22 12:21:46 -08003796 // In the case where we have no IME target we assign it where it's base layer would
3797 // place it in the AboveAppWindowContainers.
3798 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3799 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003800 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003801 // TODO: We need to use an extra level on the app surface to ensure
3802 // this is always above SurfaceView but always below attached window.
3803 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003804 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003805 }
3806
3807 // Above we have assigned layers to our children, now we ask them to assign
3808 // layers to their children.
3809 mBelowAppWindowsContainers.assignChildLayers(t);
3810 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003811 mAboveAppWindowsContainers.assignChildLayers(t,
3812 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003813 mImeWindowsContainers.assignChildLayers(t);
3814 }
3815
3816 /**
3817 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3818 * that the IME target is one of the docked applications. We'd like the docked divider to be
3819 * above both of the applications, and we'd like the IME to be above the docked divider.
3820 * However we need child windows of the applications to be above the IME (Text drag handles).
3821 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3822 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3823 * with {@link #WindowState#assignLayer}
3824 */
3825 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3826 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3827 }
3828
3829 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003830 void prepareSurfaces() {
3831 final ScreenRotationAnimation screenRotationAnimation =
3832 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3833 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3834 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3835 mPendingTransaction.setMatrix(mWindowingLayer,
3836 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3837 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3838 mPendingTransaction.setPosition(mWindowingLayer,
3839 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3840 mPendingTransaction.setAlpha(mWindowingLayer,
3841 screenRotationAnimation.getEnterTransformation().getAlpha());
3842 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003843
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003844 super.prepareSurfaces();
3845 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003846
3847 void assignStackOrdering(SurfaceControl.Transaction t) {
3848 mTaskStackContainers.assignStackOrdering(t);
3849 }
Craig Mautner59c00972012-07-30 12:10:24 -07003850}