blob: 2dce9133d094dbbe1f097b20d840811bc04a7ec6 [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 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700261 * @see #updateRotationUnchecked(boolean)
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 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700277 * @see #updateRotationUnchecked(boolean)
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 */
929 boolean updateRotationUnchecked(boolean inTransaction) {
930 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) {
Bryce Lee8f853582017-06-05 17:25:59 -07001033 mService.startFreezingDisplayLocked(inTransaction, 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
1044 // We have to reset this in case a window was removed before it
1045 // finished seamless rotation.
1046 mService.mSeamlessRotationCount = 0;
1047 }
1048
1049 // We need to update our screen size information to match the new rotation. If the rotation
1050 // has actually changed then this method will return true and, according to the comment at
1051 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1052 // By updating the Display info here it will be available to
1053 // #computeScreenConfiguration() later.
1054 updateDisplayAndOrientation(getConfiguration().uiMode);
1055
1056 if (!inTransaction) {
1057 if (SHOW_TRANSACTIONS) {
1058 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1059 }
1060 mService.openSurfaceTransaction();
1061 }
1062 try {
1063 // NOTE: We disable the rotation in the emulator because
1064 // it doesn't support hardware OpenGL emulation yet.
1065 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1066 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001067 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001068 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1069 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1070 mService.scheduleAnimationLocked();
1071 }
1072 }
1073
1074 if (rotateSeamlessly) {
1075 forAllWindows(w -> {
1076 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1077 }, true /* traverseTopToBottom */);
1078 }
1079
1080 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1081 } finally {
1082 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001083 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001084 if (SHOW_LIGHT_TRANSACTIONS) {
1085 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1086 }
1087 }
1088 }
1089
1090 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001091 if (w.mHasSurface && !rotateSeamlessly) {
1092 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001093 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001094 mService.mRoot.mOrientationChangeComplete = false;
1095 w.mLastFreezeDuration = 0;
1096 }
1097 w.mReportOrientationChanged = true;
1098 }, true /* traverseTopToBottom */);
1099
1100 if (rotateSeamlessly) {
1101 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1102 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1103 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1104 }
1105
1106 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1107 final WindowManagerService.RotationWatcher rotationWatcher
1108 = mService.mRotationWatchers.get(i);
1109 if (rotationWatcher.mDisplayId == mDisplayId) {
1110 try {
1111 rotationWatcher.mWatcher.onRotationChanged(rotation);
1112 } catch (RemoteException e) {
1113 // Ignore
1114 }
1115 }
1116 }
1117
1118 // TODO (multi-display): Magnification is supported only for the default display.
1119 // Announce rotation only if we will not animate as we already have the
1120 // windows in final state. Otherwise, we make this call at the rotation end.
1121 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1122 && isDefaultDisplay) {
1123 mService.mAccessibilityController.onRotationChangedLocked(this);
1124 }
1125
1126 return true;
1127 }
1128
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001129 void configureDisplayPolicy() {
1130 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1131 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1132
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001133 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
1134 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001135 }
1136
Andrii Kulian06d07d62017-03-14 11:11:47 -07001137 /**
1138 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1139 * changed.
1140 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1141 */
1142 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1143 // Use the effective "visual" dimensions based on current rotation
1144 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1145 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1146 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1147 int dw = realdw;
1148 int dh = realdh;
1149
1150 if (mAltOrientation) {
1151 if (realdw > realdh) {
1152 // Turn landscape into portrait.
1153 int maxw = (int)(realdh/1.3f);
1154 if (maxw < realdw) {
1155 dw = maxw;
1156 }
1157 } else {
1158 // Turn portrait into landscape.
1159 int maxh = (int)(realdw/1.3f);
1160 if (maxh < realdh) {
1161 dh = maxh;
1162 }
1163 }
1164 }
1165
1166 // Update application display metrics.
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001167 final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
1168 final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
1169
Andrii Kulian06d07d62017-03-14 11:11:47 -07001170 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001171 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001172 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001173 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001174 mDisplayInfo.rotation = mRotation;
1175 mDisplayInfo.logicalWidth = dw;
1176 mDisplayInfo.logicalHeight = dh;
1177 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1178 mDisplayInfo.appWidth = appWidth;
1179 mDisplayInfo.appHeight = appHeight;
1180 if (isDefaultDisplay) {
1181 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1182 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1183 }
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001184 mDisplayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001185 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1186 if (mDisplayScalingDisabled) {
1187 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1188 } else {
1189 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1190 }
1191
1192 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1193 mDisplayInfo);
1194
1195 mBaseDisplayRect.set(0, 0, dw, dh);
1196
1197 if (isDefaultDisplay) {
1198 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1199 mCompatDisplayMetrics);
1200 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001201
1202 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001203 return mDisplayInfo;
1204 }
1205
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001206 WmDisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001207 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1208 }
1209
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001210 private WmDisplayCutout calculateDisplayCutoutForRotationUncached(
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001211 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001212 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001213 return WmDisplayCutout.NO_CUTOUT;
Adrian Roos1cf585052018-01-03 18:43:27 +01001214 }
Adrian Roos11c25582018-02-19 18:06:36 +01001215 if (rotation == ROTATION_0) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001216 return WmDisplayCutout.computeSafeInsets(
1217 cutout, mInitialDisplayWidth, mInitialDisplayHeight);
Adrian Roos24264212018-02-19 16:26:15 +01001218 }
Adrian Roosbed538e2018-02-21 17:50:07 +01001219 final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001220 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001221 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1222 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001223 bounds.transform(mTmpMatrix);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001224 return WmDisplayCutout.computeSafeInsets(DisplayCutout.fromBounds(bounds),
Adrian Roos24264212018-02-19 16:26:15 +01001225 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1226 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001227 }
1228
Andrii Kulian06d07d62017-03-14 11:11:47 -07001229 /**
1230 * Compute display configuration based on display properties and policy settings.
1231 * Do not call if mDisplayReady == false.
1232 */
1233 void computeScreenConfiguration(Configuration config) {
1234 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1235
1236 final int dw = displayInfo.logicalWidth;
1237 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001238 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1239 // TODO: Probably best to set this based on some setting in the display content object,
1240 // so the display can be configured for things like fullscreen.
1241 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001242
Adrian Roos11c25582018-02-19 18:06:36 +01001243 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001244 config.screenWidthDp =
1245 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001246 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001247 config.screenHeightDp =
1248 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001249 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001250
Adrian Roos11c25582018-02-19 18:06:36 +01001251 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1252 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001253 final int leftInset = mTmpRect.left;
1254 final int topInset = mTmpRect.top;
1255 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001256 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1257 leftInset + displayInfo.appWidth /* right */,
1258 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001259 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1260 || displayInfo.rotation == Surface.ROTATION_270);
1261
1262 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001263 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001264
1265 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1266 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1267 ? Configuration.SCREENLAYOUT_ROUND_YES
1268 : Configuration.SCREENLAYOUT_ROUND_NO);
1269
1270 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1271 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1272 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1273 dh, mDisplayId);
1274 config.densityDpi = displayInfo.logicalDensityDpi;
1275
1276 config.colorMode =
1277 (displayInfo.isHdr()
1278 ? Configuration.COLOR_MODE_HDR_YES
1279 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001280 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001281 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1282 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1283
1284 // Update the configuration based on available input devices, lid switch,
1285 // and platform configuration.
1286 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1287 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1288 config.navigation = Configuration.NAVIGATION_NONAV;
1289
1290 int keyboardPresence = 0;
1291 int navigationPresence = 0;
1292 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1293 final int len = devices != null ? devices.length : 0;
1294 for (int i = 0; i < len; i++) {
1295 InputDevice device = devices[i];
1296 if (!device.isVirtual()) {
1297 final int sources = device.getSources();
1298 final int presenceFlag = device.isExternal() ?
1299 WindowManagerPolicy.PRESENCE_EXTERNAL :
1300 WindowManagerPolicy.PRESENCE_INTERNAL;
1301
1302 // TODO(multi-display): Configure on per-display basis.
1303 if (mService.mIsTouchDevice) {
1304 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1305 InputDevice.SOURCE_TOUCHSCREEN) {
1306 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1307 }
1308 } else {
1309 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1310 }
1311
1312 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1313 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1314 navigationPresence |= presenceFlag;
1315 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1316 && config.navigation == Configuration.NAVIGATION_NONAV) {
1317 config.navigation = Configuration.NAVIGATION_DPAD;
1318 navigationPresence |= presenceFlag;
1319 }
1320
1321 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1322 config.keyboard = Configuration.KEYBOARD_QWERTY;
1323 keyboardPresence |= presenceFlag;
1324 }
1325 }
1326 }
1327
1328 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1329 config.navigation = Configuration.NAVIGATION_DPAD;
1330 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1331 }
1332
1333 // Determine whether a hard keyboard is available and enabled.
1334 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1335 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1336 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1337 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1338 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1339 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1340 }
1341
1342 // Let the policy update hidden states.
1343 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1344 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1345 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1346 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1347 }
1348
1349 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1350 int displayId) {
1351 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1352 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1353 final int unrotDw, unrotDh;
1354 if (rotated) {
1355 unrotDw = dh;
1356 unrotDh = dw;
1357 } else {
1358 unrotDw = dw;
1359 unrotDh = dh;
1360 }
1361 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1362 displayId);
1363 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1364 displayId);
1365 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1366 displayId);
1367 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1368 displayId);
1369 return sw;
1370 }
1371
1372 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1373 DisplayMetrics dm, int dw, int dh, int displayId) {
1374 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001375 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001376 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001377 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001378 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1379 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1380 if (curSize == 0 || size < curSize) {
1381 curSize = size;
1382 }
1383 return curSize;
1384 }
1385
1386 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1387 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1388
1389 // We need to determine the smallest width that will occur under normal
1390 // operation. To this, start with the base screen size and compute the
1391 // width under the different possible rotations. We need to un-rotate
1392 // the current screen dimensions before doing this.
1393 int unrotDw, unrotDh;
1394 if (rotated) {
1395 unrotDw = dh;
1396 unrotDh = dw;
1397 } else {
1398 unrotDw = dw;
1399 unrotDh = dh;
1400 }
1401 displayInfo.smallestNominalAppWidth = 1<<30;
1402 displayInfo.smallestNominalAppHeight = 1<<30;
1403 displayInfo.largestNominalAppWidth = 0;
1404 displayInfo.largestNominalAppHeight = 0;
1405 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1406 unrotDh);
1407 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1408 unrotDw);
1409 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1410 unrotDh);
1411 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1412 unrotDw);
1413 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1414 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1415 displayId);
1416 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1417 displayId);
1418 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1419 displayId);
1420 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1421 displayId);
1422 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1423 outConfig.screenLayout = sl;
1424 }
1425
1426 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1427 int uiMode, int displayId) {
1428 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001429 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1430 mDisplayInfo.displayCutout);
1431 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1432 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001433
1434 // Compute the screen layout size class for this rotation.
1435 int longSize = w;
1436 int shortSize = h;
1437 if (longSize < shortSize) {
1438 int tmp = longSize;
1439 longSize = shortSize;
1440 shortSize = tmp;
1441 }
1442 longSize = (int)(longSize/density);
1443 shortSize = (int)(shortSize/density);
1444 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1445 }
1446
1447 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1448 int uiMode, int dw, int dh) {
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01001449 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1450 rotation).getDisplayCutout();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001451 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001452 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001453 if (width < displayInfo.smallestNominalAppWidth) {
1454 displayInfo.smallestNominalAppWidth = width;
1455 }
1456 if (width > displayInfo.largestNominalAppWidth) {
1457 displayInfo.largestNominalAppWidth = width;
1458 }
1459 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001460 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001461 if (height < displayInfo.smallestNominalAppHeight) {
1462 displayInfo.smallestNominalAppHeight = height;
1463 }
1464 if (height > displayInfo.largestNominalAppHeight) {
1465 displayInfo.largestNominalAppHeight = height;
1466 }
1467 }
1468
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001469 DockedStackDividerController getDockedDividerController() {
1470 return mDividerControllerLocked;
1471 }
1472
Winson Chung655332c2016-10-31 13:14:28 -07001473 PinnedStackController getPinnedStackController() {
1474 return mPinnedStackControllerLocked;
1475 }
1476
Jeff Browna506a6e2013-06-04 00:02:38 -07001477 /**
1478 * Returns true if the specified UID has access to this display.
1479 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001480 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001481 return mDisplay.hasAccess(uid);
1482 }
1483
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001484 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001485 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001486 }
1487
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001488 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001489 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001490 }
1491
Wale Ogunwale61911492017-10-11 08:50:50 -07001492 /**
1493 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1494 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001495 TaskStack getSplitScreenPrimaryStack() {
1496 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001497 return (stack != null && stack.isVisible()) ? stack : null;
1498 }
1499
1500 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001501 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001502 * not visible.
1503 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001504 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1505 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001506 }
1507
1508 TaskStack getPinnedStack() {
1509 return mTaskStackContainers.getPinnedStack();
1510 }
1511
1512 private boolean hasPinnedStack() {
1513 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001514 }
1515
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001516 /**
1517 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1518 * Null is no compatible stack on the display.
1519 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001520 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001521 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1522 }
1523
1524 /**
1525 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1526 * activity type. Null is no compatible stack on the display.
1527 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001528 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001529 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001530 }
1531
Bryce Lee48f4b572017-04-10 10:54:15 -07001532 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001533 TaskStack getTopStack() {
1534 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001535 }
1536
Winson Chunge2d72172018-01-25 17:46:20 +00001537 ArrayList<Task> getVisibleTasks() {
1538 return mTaskStackContainers.getVisibleTasks();
1539 }
1540
Wale Ogunwale61911492017-10-11 08:50:50 -07001541 void onStackWindowingModeChanged(TaskStack stack) {
1542 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001543 }
1544
Andrii Kulian441e4492016-09-29 15:25:00 -07001545 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001546 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001547 super.onConfigurationChanged(newParentConfig);
1548
Andrii Kulian3a507b52016-09-19 18:14:12 -07001549 // The display size information is heavily dependent on the resources in the current
1550 // configuration, so we need to reconfigure it every time the configuration changes.
1551 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1552 mService.reconfigureDisplayLocked(this);
1553
Bryce Leef3c6a472017-11-14 14:53:06 -08001554 final DockedStackDividerController dividerController = getDockedDividerController();
1555
1556 if (dividerController != null) {
1557 getDockedDividerController().onConfigurationChanged();
1558 }
1559
1560 final PinnedStackController pinnedStackController = getPinnedStackController();
1561
1562 if (pinnedStackController != null) {
1563 getPinnedStackController().onConfigurationChanged();
1564 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001565 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001566
Andrii Kulian441e4492016-09-29 15:25:00 -07001567 /**
1568 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1569 * bounds were updated.
1570 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001571 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001572 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1573 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001574 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001575 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001576 }
1577 }
Winson Chung32c566f2017-04-11 18:31:21 -07001578
1579 // If there was no pinned stack, we still need to notify the controller of the display info
1580 // update as a result of the config change. We do this here to consolidate the flow between
1581 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001582 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001583 mPinnedStackControllerLocked.onDisplayInfoChanged();
1584 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001585 }
1586
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001587 @Override
1588 boolean fillsParent() {
1589 return true;
1590 }
1591
1592 @Override
1593 boolean isVisible() {
1594 return true;
1595 }
1596
1597 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001598 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001599 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001600 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001601 }
1602
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001603 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001604 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1605 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1606 // target, or here in order if there isn't an IME target.
1607 if (traverseTopToBottom) {
1608 for (int i = mChildren.size() - 1; i >= 0; --i) {
1609 final DisplayChildWindowContainer child = mChildren.get(i);
1610 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1611 // In this case the Ime windows will be processed above their target so we skip
1612 // here.
1613 continue;
1614 }
1615 if (child.forAllWindows(callback, traverseTopToBottom)) {
1616 return true;
1617 }
1618 }
1619 } else {
1620 final int count = mChildren.size();
1621 for (int i = 0; i < count; i++) {
1622 final DisplayChildWindowContainer child = mChildren.get(i);
1623 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1624 // In this case the Ime windows will be processed above their target so we skip
1625 // here.
1626 continue;
1627 }
1628 if (child.forAllWindows(callback, traverseTopToBottom)) {
1629 return true;
1630 }
1631 }
1632 }
1633 return false;
1634 }
1635
1636 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1637 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1638 }
1639
Wale Ogunwale399c8692017-05-08 14:22:42 -07001640 @Override
1641 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001642 final WindowManagerPolicy policy = mService.mPolicy;
1643
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001644 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001645 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001646 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001647 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001648 // If the display is frozen, some activities may be in the middle of restarting, and
1649 // thus have removed their old window. If the window has the flag to hide the lock
1650 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1651 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001652 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001653 } else if (policy.isKeyguardLocked()) {
1654 // Use the last orientation the while the display is frozen with the keyguard
1655 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1656 // window. We don't want to check the show when locked window directly though as
1657 // things aren't stable while the display is frozen, for example the window could be
1658 // momentarily unavailable due to activity relaunch.
1659 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001660 + "return " + mLastOrientation);
1661 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001662 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001663 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001664 final int orientation = mAboveAppWindowsContainers.getOrientation();
1665 if (orientation != SCREEN_ORIENTATION_UNSET) {
1666 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001667 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001668 }
1669
Wale Ogunwale399c8692017-05-08 14:22:42 -07001670 // Top system windows are not requesting an orientation. Start searching from apps.
1671 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001672 }
1673
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001674 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001675 // Check if display metrics changed and update base values if needed.
1676 updateBaseDisplayMetricsIfNeeded();
1677
Craig Mautner722285e2012-09-07 13:55:58 -07001678 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001679 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001680
Wale Ogunwale61911492017-10-11 08:50:50 -07001681 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1682 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001683 }
Craig Mautner722285e2012-09-07 13:55:58 -07001684 }
1685
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001686 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001687 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1688 if (displayManagerInternal != null) {
1689 // Bootstrap the default logical display from the display manager.
1690 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1691 if (newDisplayInfo != null) {
1692 mDisplayInfo.copyFrom(newDisplayInfo);
1693 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001694 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001695
Andrii Kuliancd097992017-03-23 18:31:59 -07001696 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1697 mDisplayInfo.logicalDensityDpi);
1698 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1699 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1700 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001701 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001702 }
1703
Andrii Kuliancd097992017-03-23 18:31:59 -07001704 /**
1705 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1706 * values.
1707 */
1708 private void updateBaseDisplayMetricsIfNeeded() {
1709 // Get real display metrics without overrides from WM.
1710 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1711 final int orientation = mDisplayInfo.rotation;
1712 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1713 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1714 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1715 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001716 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001717
1718 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1719 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001720 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1721 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001722
1723 if (displayMetricsChanged) {
1724 // Check if display size or density is forced.
1725 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1726 || mBaseDisplayHeight != mInitialDisplayHeight;
1727 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1728
1729 // If there is an override set for base values - use it, otherwise use new values.
1730 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1731 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1732 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1733
1734 // Real display metrics changed, so we should also update initial values.
1735 mInitialDisplayWidth = newWidth;
1736 mInitialDisplayHeight = newHeight;
1737 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001738 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001739 mService.reconfigureDisplayLocked(this);
1740 }
1741 }
1742
Bryce Lee27cec322017-03-21 09:41:37 -07001743 /** Sets the maximum width the screen resolution can be */
1744 void setMaxUiWidth(int width) {
1745 if (DEBUG_DISPLAY) {
1746 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1747 }
1748
1749 mMaxUiWidth = width;
1750
1751 // Update existing metrics.
1752 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1753 }
1754
1755 /** Update base (override) display metrics. */
1756 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1757 mBaseDisplayWidth = baseWidth;
1758 mBaseDisplayHeight = baseHeight;
1759 mBaseDisplayDensity = baseDensity;
1760
1761 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1762 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1763 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1764 mBaseDisplayWidth = mMaxUiWidth;
1765
1766 if (DEBUG_DISPLAY) {
1767 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1768 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1769 + " on display:" + getDisplayId());
1770 }
1771 }
1772
1773 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001774
1775 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001776 }
1777
Wale Ogunwaledb506192017-12-08 10:57:32 -08001778 void getStableRect(Rect out) {
1779 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001780 }
1781
Wale Ogunwale61911492017-10-11 08:50:50 -07001782 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001783 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1784 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001785
Wale Ogunwale61911492017-10-11 08:50:50 -07001786 final TaskStack stack = new TaskStack(mService, stackId, controller);
1787 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001788 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001789 }
1790
Andrii Kulian51c1b672017-04-07 18:39:32 -07001791 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001792 final DisplayContent prevDc = stack.getDisplayContent();
1793 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001794 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1795 + " which is not currently attached to any display");
1796 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001797 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001798 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1799 + " to its current displayId=" + mDisplayId);
1800 }
1801
Wale Ogunwale61911492017-10-11 08:50:50 -07001802 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001803 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001804 }
1805
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001806 @Override
1807 protected void addChild(DisplayChildWindowContainer child,
1808 Comparator<DisplayChildWindowContainer> comparator) {
1809 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1810 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001811
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001812 @Override
1813 protected void addChild(DisplayChildWindowContainer child, int index) {
1814 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1815 }
1816
1817 @Override
1818 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001819 // Only allow removal of direct children from this display if the display is in the process
1820 // of been removed.
1821 if (mRemovingDisplay) {
1822 super.removeChild(child);
1823 return;
1824 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001825 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001826 }
1827
Andrii Kuliand2765632016-12-12 22:26:34 -08001828 @Override
1829 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1830 // Children of the display are statically ordered, so the real intention here is to perform
1831 // the operation on the display and not the static direct children.
1832 getParent().positionChildAt(position, this, includingParents);
1833 }
1834
Winson Chung59a47ded2018-01-25 17:46:06 +00001835 void positionStackAt(int position, TaskStack child) {
1836 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1837 layoutAndAssignWindowLayersIfNeeded();
1838 }
1839
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001840 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001841 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1842 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001843 final int taskId = stack.taskIdFromPoint(x, y);
1844 if (taskId != -1) {
1845 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001846 }
1847 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001848 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001849 }
1850
Chong Zhang8e89b312015-09-09 15:09:30 -07001851 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001852 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001853 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001854 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001855 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001856 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001857 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001858 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1859 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001860 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001861 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001862 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001863
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001864 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1865 if (mTmpTaskForResizePointSearchResult.searchDone) {
1866 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001867 }
1868 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001869 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001870 }
1871
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001872 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001873 // The provided task is the task on this display with focus, so if WindowManagerService's
1874 // focused app is not on this display, focusedTask will be null.
1875 if (focusedTask == null) {
1876 mTouchExcludeRegion.setEmpty();
1877 } else {
1878 mTouchExcludeRegion.set(mBaseDisplayRect);
1879 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1880 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001881 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1882 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001883 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1884 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001885 }
1886 // If we removed the focused task above, add it back and only leave its
1887 // outside touch area in the exclusion. TapDectector is not interested in
1888 // any touch inside the focused task itself.
1889 if (!mTmpRect2.isEmpty()) {
1890 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1891 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001892 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001893 final WindowState inputMethod = mService.mInputMethodWindow;
1894 if (inputMethod != null && inputMethod.isVisibleLw()) {
1895 // If the input method is visible and the user is typing, we don't want these touch
1896 // events to be intercepted and used to change focus. This would likely cause a
1897 // disappearance of the input method.
1898 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001899 if (inputMethod.getDisplayId() == mDisplayId) {
1900 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1901 } else {
1902 // IME is on a different display, so we need to update its tap detector.
1903 // TODO(multidisplay): Remove when IME will always appear on same display.
1904 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1905 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001906 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001907 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001908 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001909 win.getTouchableRegion(mTmpRegion);
1910 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1911 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001912 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1913 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1914 win.amendTapExcludeRegion(mTouchExcludeRegion);
1915 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001916 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001917 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001918 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001919 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001920 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1921 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001922 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001923 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001924 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001925 }
1926
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001927 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001928 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001929 super.switchUser();
1930 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001931 }
1932
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001933 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001934 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1935 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001936 }
1937 }
1938
Wale Ogunwale10124582016-09-15 20:25:50 -07001939 @Override
1940 void removeIfPossible() {
1941 if (isAnimating()) {
1942 mDeferredRemoval = true;
1943 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001944 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001945 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001946 }
1947
Wale Ogunwale10124582016-09-15 20:25:50 -07001948 @Override
1949 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001950 mRemovingDisplay = true;
1951 try {
1952 super.removeImmediately();
1953 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001954 if (mService.canDispatchPointerEvents()) {
1955 if (mTapDetector != null) {
1956 mService.unregisterPointerEventListener(mTapDetector);
1957 }
1958 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1959 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1960 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001961 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001962 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001963 } finally {
1964 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001965 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001966
1967 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001968 }
1969
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001970 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001971 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001972 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001973 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1974
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001975 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001976 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001977 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001978 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001979 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001980 }
1981
Andrii Kulian0214ed92017-05-16 13:44:05 -07001982 /** @return 'true' if removal of this display content is deferred due to active animation. */
1983 boolean isRemovalDeferred() {
1984 return mDeferredRemoval;
1985 }
1986
Wale Ogunwale10124582016-09-15 20:25:50 -07001987 boolean animateForIme(float interpolatedValue, float animationTarget,
1988 float dividerAnimationTarget) {
1989 boolean updated = false;
1990
Wale Ogunwale61911492017-10-11 08:50:50 -07001991 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1992 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001993 if (stack == null || !stack.isAdjustedForIme()) {
1994 continue;
1995 }
1996
1997 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1998 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1999 updated = true;
2000 } else {
2001 mDividerControllerLocked.mLastAnimationProgress =
2002 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2003 mDividerControllerLocked.mLastDividerProgress =
2004 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2005 updated |= stack.updateAdjustForIme(
2006 mDividerControllerLocked.mLastAnimationProgress,
2007 mDividerControllerLocked.mLastDividerProgress,
2008 false /* force */);
2009 }
2010 if (interpolatedValue >= 1f) {
2011 stack.endImeAdjustAnimation();
2012 }
2013 }
2014
2015 return updated;
2016 }
2017
2018 boolean clearImeAdjustAnimation() {
2019 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002020 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2021 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002022 if (stack != null && stack.isAdjustedForIme()) {
2023 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2024 changed = true;
2025 }
2026 }
2027 return changed;
2028 }
2029
2030 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002031 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2032 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002033 if (stack.isVisible() && stack.isAdjustedForIme()) {
2034 stack.beginImeAdjustAnimation();
2035 }
2036 }
2037 }
2038
2039 void adjustForImeIfNeeded() {
2040 final WindowState imeWin = mService.mInputMethodWindow;
2041 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2042 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002043 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002044 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2045 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2046 imeTargetStack.getDockSide() : DOCKED_INVALID;
2047 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2048 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2049 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002050 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002051 final boolean imeHeightChanged = imeVisible &&
2052 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2053
2054 // The divider could be adjusted for IME position, or be thinner than usual,
2055 // or both. There are three possible cases:
2056 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2057 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2058 // - If IME is not visible, divider is not moved and is normal width.
2059
2060 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002061 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2062 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002063 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002064 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2065 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002066 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2067 } else {
2068 stack.resetAdjustedForIme(false);
2069 }
2070 }
2071 mDividerControllerLocked.setAdjustedForIme(
2072 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2073 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002074 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2075 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002076 stack.resetAdjustedForIme(!dockVisible);
2077 }
2078 mDividerControllerLocked.setAdjustedForIme(
2079 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2080 }
Winson Chung655332c2016-10-31 13:14:28 -07002081 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002082 }
2083
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002084 /**
2085 * If a window that has an animation specifying a colored background and the current wallpaper
2086 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2087 * suddenly disappear.
2088 */
2089 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002090 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2091 w -> w.mIsWallpaper && w.isVisibleNow());
2092
2093 if (visibleWallpaper != null) {
2094 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002095 }
2096 return winAnimator.mAnimLayer;
2097 }
2098
Wale Ogunwale10124582016-09-15 20:25:50 -07002099 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002100 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2101 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002102 stack.prepareFreezingTaskBounds();
2103 }
2104 }
2105
Wale Ogunwale94744212015-09-21 19:01:47 -07002106 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002107 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002108
2109 // Compute a transform matrix to undo the coordinate space transformation,
2110 // and present the window at the same physical position it previously occupied.
2111 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2112 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2113
2114 mTmpRectF.set(bounds);
2115 mTmpMatrix.mapRect(mTmpRectF);
2116 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002117 }
2118
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002119 static int deltaRotation(int oldRotation, int newRotation) {
2120 int delta = newRotation - oldRotation;
2121 if (delta < 0) delta += 4;
2122 return delta;
2123 }
2124
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002125 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002126 Matrix outMatrix) {
2127 // For rotations without Z-ordering we don't need the target rectangle's position.
2128 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2129 displayHeight, outMatrix);
2130 }
2131
2132 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2133 float displayWidth, float displayHeight, Matrix outMatrix) {
2134 switch (rotation) {
2135 case ROTATION_0:
2136 outMatrix.reset();
2137 break;
2138 case ROTATION_270:
2139 outMatrix.setRotate(270, 0, 0);
2140 outMatrix.postTranslate(0, displayHeight);
2141 outMatrix.postTranslate(rectTop, 0);
2142 break;
2143 case ROTATION_180:
2144 outMatrix.reset();
2145 break;
2146 case ROTATION_90:
2147 outMatrix.setRotate(90, 0, 0);
2148 outMatrix.postTranslate(displayWidth, 0);
2149 outMatrix.postTranslate(-rectTop, rectLeft);
2150 break;
2151 }
2152 }
2153
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002154 @CallSuper
2155 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002156 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002157 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002158 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002159 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002160 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2161 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002162 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002163 }
2164 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2165 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002166 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2167 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002168 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002169 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002170 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2171 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002172 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002173 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002174 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2175 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002176 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002177 }
2178 proto.write(DPI, mBaseDisplayDensity);
2179 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002180 proto.write(ROTATION, mRotation);
2181 final ScreenRotationAnimation screenRotationAnimation =
2182 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2183 if (screenRotationAnimation != null) {
2184 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2185 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002186 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002187 proto.end(token);
2188 }
2189
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002190 @Override
2191 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2192 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002193 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2194 final String subPrefix = " " + prefix;
2195 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2196 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2197 pw.print("dpi");
2198 if (mInitialDisplayWidth != mBaseDisplayWidth
2199 || mInitialDisplayHeight != mBaseDisplayHeight
2200 || mInitialDisplayDensity != mBaseDisplayDensity) {
2201 pw.print(" base=");
2202 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2203 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2204 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002205 if (mDisplayScalingDisabled) {
2206 pw.println(" noscale");
2207 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002208 pw.print(" cur=");
2209 pw.print(mDisplayInfo.logicalWidth);
2210 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2211 pw.print(" app=");
2212 pw.print(mDisplayInfo.appWidth);
2213 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2214 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2215 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2216 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2217 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002218 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002219 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002220 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002221
Craig Mautnerdc548482014-02-05 13:35:24 -08002222 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002223 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002224 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2225 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002226 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002227 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002228
Craig Mautnerdc548482014-02-05 13:35:24 -08002229 pw.println();
2230 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002231 pw.println();
2232 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002233 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002234 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002235 pw.print(" Exiting #"); pw.print(i);
2236 pw.print(' '); pw.print(token);
2237 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002238 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002239 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002240 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002241
Jorim Jaggi31f71702016-05-04 16:43:04 -07002242 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002243
2244 // Dump stack references
2245 final TaskStack homeStack = getHomeStack();
2246 if (homeStack != null) {
2247 pw.println(prefix + "homeStack=" + homeStack.getName());
2248 }
2249 final TaskStack pinnedStack = getPinnedStack();
2250 if (pinnedStack != null) {
2251 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2252 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002253 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002254 if (splitScreenPrimaryStack != null) {
2255 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2256 }
2257
2258 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002259 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002260 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002261 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002262
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002263 pw.println();
2264 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002265 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002266
2267 @Override
2268 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002269 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002270 }
2271
2272 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002273 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002274 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002275
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002276 /** Returns true if the stack in the windowing mode is visible. */
2277 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002278 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002279 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002280 }
2281
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002282 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002283 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002284 final int x = (int) xf;
2285 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002286 final WindowState touchedWin = getWindow(w -> {
2287 final int flags = w.mAttrs.flags;
2288 if (!w.isVisibleLw()) {
2289 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002290 }
2291 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002292 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002293 }
2294
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002295 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002296 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002297 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002298 }
2299
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002300 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002301
2302 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002303 return mTmpRegion.contains(x, y) || touchFlags == 0;
2304 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002305
2306 return touchedWin;
2307 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002308
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002309 boolean canAddToastWindowForUid(int uid) {
2310 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002311 // Also if the app is focused adding more than one toast at
2312 // a time for better backwards compatibility.
2313 final WindowState focusedWindowForUid = getWindow(w ->
2314 w.mOwnerUid == uid && w.isFocused());
2315 if (focusedWindowForUid != null) {
2316 return true;
2317 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002318 final WindowState win = getWindow(w ->
2319 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2320 && !w.mWindowRemovalAllowed);
2321 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002322 }
2323
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002324 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002325 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2326 return;
2327 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002328
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002329 // Used to communicate the old focus to the callback method.
2330 mTmpWindow = oldFocus;
2331
2332 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002333 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002334
2335 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002336 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002337
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002338 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002339
2340 if (mTmpWindow == null) {
2341 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2342 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002343 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002344 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002345 }
2346
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002347 /** Updates the layer assignment of windows on this display. */
2348 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002349 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002350 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002351 if (setLayoutNeeded) {
2352 setLayoutNeeded();
2353 }
Robert Carrb1579c82017-09-05 14:54:47 -07002354
Robert Carrf59b8dd2017-10-02 18:58:36 -07002355 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002356 // the application of this transaction until the animation pass triggers
2357 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2358 // the hiding and showing of surfaces.
2359 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002360 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002361 }
2362
Wale Ogunwale1666e312016-12-16 11:27:18 -08002363 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2364 // moving containers or resizing them. Need to investigate the best way to have it automatically
2365 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002366 void layoutAndAssignWindowLayersIfNeeded() {
2367 mService.mWindowsChanged = true;
2368 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002369
2370 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2371 false /*updateInputWindows*/)) {
2372 assignWindowLayers(false /* setLayoutNeeded */);
2373 }
2374
2375 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2376 mService.mWindowPlacerLocked.performSurfacePlacement();
2377 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2378 }
2379
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002380 /** Returns true if a leaked surface was destroyed */
2381 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002382 // Used to indicate that a surface was leaked.
2383 mTmpWindow = null;
2384 forAllWindows(w -> {
2385 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002386 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002387 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002388 }
2389 if (!mService.mSessions.contains(wsa.mSession)) {
2390 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002391 + w + " surface=" + wsa.mSurfaceController
2392 + " token=" + w.mToken
2393 + " pid=" + w.mSession.mPid
2394 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002395 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002396 mService.mForceRemoves.add(w);
2397 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002398 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002399 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002400 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002401 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002402 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002403 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002404 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002405 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002406 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002407
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002408 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002409 }
2410
2411 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002412 * Determine and return the window that should be the IME target.
2413 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2414 * @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 +00002415 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002416 WindowState computeImeTarget(boolean updateImeTarget) {
2417 if (mService.mInputMethodWindow == null) {
2418 // There isn't an IME so there shouldn't be a target...That was easy!
2419 if (updateImeTarget) {
2420 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2421 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002422 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002423 }
2424 return null;
2425 }
2426
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002427 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2428 // same display. Or even when the current IME/target are not on the same screen as the next
2429 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002430 mUpdateImeTarget = updateImeTarget;
2431 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002432
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002433
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002434 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2435 // to be on top of it, but it is not -really- where input will go. So look down below
2436 // for a real window to target...
2437 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2438 final AppWindowToken token = target.mAppToken;
2439 if (token != null) {
2440 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2441 if (betterTarget != null) {
2442 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002443 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002444 }
2445 }
2446
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002447 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2448 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002449
2450 // Now, a special case -- if the last target's window is in the process of exiting, and is
2451 // above the new target, keep on the last target to avoid flicker. Consider for example a
2452 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2453 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2454 // scrim.
2455 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002456 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2457 && (target == null
2458 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002459 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002460 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002461 }
2462
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002463 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2464 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002465
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002466 if (target == null) {
2467 if (updateImeTarget) {
2468 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2469 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2470 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002471 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002472 }
2473
2474 return null;
2475 }
2476
2477 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002478 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2479 if (token != null) {
2480
2481 // Now some fun for dealing with window animations that modify the Z order. We need
2482 // to look at all windows below the current target that are in this app, finding the
2483 // highest visible one in layering.
2484 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002485 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002486 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002487 }
2488
2489 if (highestTarget != null) {
2490 final AppTransition appTransition = mService.mAppTransition;
2491 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2492 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2493 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002494 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002495
2496 if (appTransition.isTransitionSet()) {
2497 // If we are currently setting up for an animation, hold everything until we
2498 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002499 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002500 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002501 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002502 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002503 // If the window we are currently targeting is involved with an animation,
2504 // and it is on top of the next target we will be over, then hold off on
2505 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002506 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002507 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002508 }
2509 }
2510 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002511
2512 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2513 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002514 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002515 }
2516
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002517 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002518 }
2519
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002520 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002521 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002522 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002523 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002524 }
2525
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002526 mService.mInputMethodTarget = target;
2527 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002528 assignWindowLayers(false /* setLayoutNeeded */);
2529 }
2530
2531 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2532 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2533 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2534 }
2535
2536 // Used to indicate we have reached the first window in the range we are interested in.
2537 mTmpWindow = null;
2538
2539 // TODO: Figure-out a more efficient way to do this.
2540 final WindowState candidate = getWindow(w -> {
2541 if (w == top) {
2542 // Reached the first window in the range we are interested in.
2543 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002544 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002545 if (mTmpWindow == null) {
2546 return false;
2547 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002548
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002549 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2550 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002551 }
2552 // If we reached the bottom of the range of windows we are considering,
2553 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002554 if (w == bottom) {
2555 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002556 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002557 return false;
2558 });
2559
2560 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002561 }
2562
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002563 void setLayoutNeeded() {
2564 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2565 mLayoutNeeded = true;
2566 }
2567
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002568 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002569 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2570 mLayoutNeeded = false;
2571 }
2572
2573 boolean isLayoutNeeded() {
2574 return mLayoutNeeded;
2575 }
2576
Wale Ogunwale02319a62016-09-26 15:21:22 -07002577 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2578 if (mTokenMap.isEmpty()) {
2579 return;
2580 }
2581 pw.println(" Display #" + mDisplayId);
2582 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2583 while (it.hasNext()) {
2584 final WindowToken token = it.next();
2585 pw.print(" ");
2586 pw.print(token);
2587 if (dumpAll) {
2588 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002589 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002590 } else {
2591 pw.println();
2592 }
2593 }
2594 }
2595
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002596 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002597 final int[] index = new int[1];
2598 forAllWindows(w -> {
2599 final WindowStateAnimator wAnim = w.mWinAnimator;
2600 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2601 index[0] = index[0] + 1;
2602 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002603 }
2604
Jorim Jaggife762342016-10-13 14:33:27 +02002605 /**
2606 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2607 */
2608 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2609 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002610 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002611 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2612 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002613 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002614 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002615 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002616 }
2617
Wale Ogunwale494009b82016-10-21 09:01:38 -07002618 boolean checkWaitingForWindows() {
2619
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002620 mHaveBootMsg = false;
2621 mHaveApp = false;
2622 mHaveWallpaper = false;
2623 mHaveKeyguard = true;
2624
2625 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002626 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2627 return true;
2628 }
2629 if (w.isDrawnLw()) {
2630 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002631 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002632 } else if (w.mAttrs.type == TYPE_APPLICATION
2633 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002634 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002635 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002636 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002637 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002638 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002639 }
2640 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002641 return false;
2642 });
2643
2644 if (visibleWindow != null) {
2645 // We have a visible window.
2646 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002647 }
2648
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002649 // if the wallpaper service is disabled on the device, we're never going to have
2650 // wallpaper, don't bother waiting for it
2651 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2652 com.android.internal.R.bool.config_enableWallpaperService)
2653 && !mService.mOnlyCore;
2654
Wale Ogunwale494009b82016-10-21 09:01:38 -07002655 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2656 "******** booted=" + mService.mSystemBooted
2657 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002658 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2659 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2660 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002661
2662 // If we are turning on the screen to show the boot message, don't do it until the boot
2663 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002664 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002665 return true;
2666 }
2667
2668 // If we are turning on the screen after the boot is completed normally, don't do so until
2669 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002670 if (mService.mSystemBooted
2671 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002672 return true;
2673 }
2674
2675 return false;
2676 }
2677
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002678 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002679 mTmpWindowAnimator = animator;
2680 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002681 }
2682
2683 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002684 resetAnimationBackgroundAnimator();
2685
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002686 // Used to indicate a detached wallpaper.
2687 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002688 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002689
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002690 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002691
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002692 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002693 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002694 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2695 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002696 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2697 }
2698 }
2699
Wale Ogunwale494009b82016-10-21 09:01:38 -07002700 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002701 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002702 if (imFocus == null) {
2703 return false;
2704 }
2705
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002706 if (DEBUG_INPUT_METHOD) {
2707 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2708 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2709 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002710 }
2711
Wale Ogunwale494009b82016-10-21 09:01:38 -07002712 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2713
2714 if (DEBUG_INPUT_METHOD) {
2715 Slog.i(TAG_WM, "IM target client: " + imeClient);
2716 if (imeClient != null) {
2717 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2718 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2719 }
2720 }
2721
2722 return imeClient != null && imeClient.asBinder() == client.asBinder();
2723 }
2724
2725 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002726 final WindowState win = getWindow(
2727 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2728 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002729 }
2730
2731 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002732 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002733 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002734 final int curValue = w.mSystemUiVisibility;
2735 final int diff = (curValue ^ visibility) & globalDiff;
2736 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002737 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002738 w.mSeq++;
2739 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002740 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002741 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2742 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002743 visibility, newValue, diff);
2744 }
2745 } catch (RemoteException e) {
2746 // so sorry
2747 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002748 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002749 }
2750
2751 void onWindowFreezeTimeout() {
2752 Slog.w(TAG_WM, "Window freeze timeout expired.");
2753 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002754
2755 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002756 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002757 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002758 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002759 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002760 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2761 - mService.mDisplayFreezeTime);
2762 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002763 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002764 mService.mWindowPlacerLocked.performSurfacePlacement();
2765 }
2766
2767 void waitForAllWindowsDrawn() {
2768 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002769 forAllWindows(w -> {
2770 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2771 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2772 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002773 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002774 w.mLastContentInsets.set(-1, -1, -1, -1);
2775 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002776 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002777 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002778 }
2779
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002780 // TODO: Super crazy long method that should be broken down...
2781 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2782
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002783 final int dw = mDisplayInfo.logicalWidth;
2784 final int dh = mDisplayInfo.logicalHeight;
2785 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2786
2787 mTmpUpdateAllDrawn.clear();
2788
2789 int repeats = 0;
2790 do {
2791 repeats++;
2792 if (repeats > 6) {
2793 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2794 clearLayoutNeeded();
2795 break;
2796 }
2797
2798 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2799 pendingLayoutChanges);
2800
Andrii Kulian839def92016-11-02 10:58:58 -07002801 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2802 // the wallpaper window jumping across displays.
2803 // Remove check for default display when there will be support for multiple wallpaper
2804 // targets (on different displays).
2805 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002806 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002807 }
2808
2809 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2810 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2811 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2812 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002813 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002814 }
2815 }
2816
2817 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2818 setLayoutNeeded();
2819 }
2820
2821 // FIRST LOOP: Perform a layout, if needed.
2822 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2823 performLayout(repeats == 1, false /* updateInputWindows */);
2824 } else {
2825 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2826 }
2827
2828 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2829 pendingLayoutChanges = 0;
2830
2831 if (isDefaultDisplay) {
2832 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002833 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002834 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2835 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2836 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2837 }
2838 } while (pendingLayoutChanges != 0);
2839
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002840 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002841
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002842 mTmpRecoveringMemory = recoveringMemory;
2843 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002844 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002845
2846 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002847 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2848 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2849 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002850 true /* inTraversal, must call performTraversalInTrans... below */);
2851
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002852 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2853 if (wallpaperVisible != mLastWallpaperVisible) {
2854 mLastWallpaperVisible = wallpaperVisible;
2855 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2856 }
2857
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002858 while (!mTmpUpdateAllDrawn.isEmpty()) {
2859 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2860 // See if any windows have been drawn, so they (and others associated with them)
2861 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002862 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002863 }
2864
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002865 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002866 }
2867
Bryce Leef3c6a472017-11-14 14:53:06 -08002868 private void updateBounds() {
2869 calculateBounds(mTmpBounds);
2870 setBounds(mTmpBounds);
2871 }
2872
2873 // Determines the current display bounds based on the current state
2874 private void calculateBounds(Rect out) {
2875 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2876 final int orientation = mDisplayInfo.rotation;
2877 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2878 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2879 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2880 int width = mDisplayInfo.logicalWidth;
2881 int left = (physWidth - width) / 2;
2882 int height = mDisplayInfo.logicalHeight;
2883 int top = (physHeight - height) / 2;
2884 out.set(left, top, left + width, top + height);
2885 }
2886
2887 @Override
2888 public void getBounds(Rect out) {
2889 calculateBounds(out);
2890 }
2891
2892 private void getBounds(Rect out, int orientation) {
2893 getBounds(out);
2894
2895 // Rotate the Rect if needed.
2896 final int currentRotation = mDisplayInfo.rotation;
2897 final int rotationDelta = deltaRotation(currentRotation, orientation);
2898 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2899 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2900 mTmpRectF.set(out);
2901 mTmpMatrix.mapRect(mTmpRectF);
2902 mTmpRectF.round(out);
2903 }
2904 }
2905
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002906 void performLayout(boolean initial, boolean updateInputWindows) {
2907 if (!isLayoutNeeded()) {
2908 return;
2909 }
2910 clearLayoutNeeded();
2911
2912 final int dw = mDisplayInfo.logicalWidth;
2913 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002914 if (DEBUG_LAYOUT) {
2915 Slog.v(TAG, "-------------------------------------");
2916 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2917 }
2918
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01002919 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo,
2920 calculateDisplayCutoutForRotation(mDisplayInfo.rotation));
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002921 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2922 // display info above...
2923 mDisplayFrames.mRotation = mRotation;
2924 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002925 if (isDefaultDisplay) {
2926 // Not needed on non-default displays.
2927 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2928 mService.mScreenRect.set(0, 0, dw, dh);
2929 }
2930
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002931 int seq = mService.mLayoutSeq + 1;
2932 if (seq < 0) seq = 0;
2933 mService.mLayoutSeq = seq;
2934
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002935 // Used to indicate that we have processed the dream window and all additional windows are
2936 // behind it.
2937 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002938 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002939
2940 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002941 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002942
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002943 // Used to indicate that we have processed the dream window and all additional attached
2944 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002945 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002946 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002947
2948 // Now perform layout of attached windows, which usually depend on the position of the
2949 // window they are attached to. XXX does not deal with windows that are attached to windows
2950 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002951 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002952
2953 // Window frames may have changed. Tell the input dispatcher about it.
2954 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2955 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2956 if (updateInputWindows) {
2957 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2958 }
2959
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002960 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2961 }
2962
2963 /**
2964 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2965 * In portrait mode, it grabs the full screenshot.
2966 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002967 * @param config of the output bitmap
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002968 */
chaviw0315a1a2018-03-05 15:28:35 -08002969 Bitmap screenshotDisplayLocked(Bitmap.Config config) {
2970 if (!mService.mPolicy.isScreenOn()) {
2971 if (DEBUG_SCREENSHOT) {
2972 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002973 }
chaviw0315a1a2018-03-05 15:28:35 -08002974 return null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002975 }
chaviwfbe47df2017-11-10 16:14:49 -08002976
chaviw0315a1a2018-03-05 15:28:35 -08002977 int dw = mDisplayInfo.logicalWidth;
2978 int dh = mDisplayInfo.logicalHeight;
chaviwfbe47df2017-11-10 16:14:49 -08002979
chaviw0315a1a2018-03-05 15:28:35 -08002980 if (dw <= 0 || dh <= 0) {
2981 return null;
2982 }
chaviwfbe47df2017-11-10 16:14:49 -08002983
chaviw0315a1a2018-03-05 15:28:35 -08002984 final Rect frame = new Rect(0, 0, dw, dh);
chaviwfbe47df2017-11-10 16:14:49 -08002985
chaviw0315a1a2018-03-05 15:28:35 -08002986 // The screenshot API does not apply the current screen rotation.
2987 int rot = mDisplay.getRotation();
chaviwfbe47df2017-11-10 16:14:49 -08002988
chaviw0315a1a2018-03-05 15:28:35 -08002989 if (rot == ROTATION_90 || rot == ROTATION_270) {
2990 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2991 }
chaviwfbe47df2017-11-10 16:14:49 -08002992
chaviw0315a1a2018-03-05 15:28:35 -08002993 // SurfaceFlinger is not aware of orientation, so convert our logical
2994 // crop to SurfaceFlinger's portrait orientation.
2995 convertCropForSurfaceFlinger(frame, rot, dw, dh);
2996
2997 final ScreenRotationAnimation screenRotationAnimation =
2998 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
2999 final boolean inRotation = screenRotationAnimation != null &&
3000 screenRotationAnimation.isAnimating();
3001 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
3002
3003 // TODO(b/68392460): We should screenshot Task controls directly
3004 // but it's difficult at the moment as the Task doesn't have the
3005 // correct size set.
3006 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
3007 if (bitmap == null) {
3008 Slog.w(TAG_WM, "Failed to take screenshot");
3009 return null;
3010 }
3011
3012 // Create a copy of the screenshot that is immutable and backed in ashmem.
3013 // This greatly reduces the overhead of passing the bitmap between processes.
3014 final Bitmap ret = bitmap.createAshmemBitmap(config);
3015 bitmap.recycle();
3016 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003017 }
3018
3019 // TODO: Can this use createRotationMatrix()?
3020 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3021 if (rot == Surface.ROTATION_90) {
3022 final int tmp = crop.top;
3023 crop.top = dw - crop.right;
3024 crop.right = crop.bottom;
3025 crop.bottom = dw - crop.left;
3026 crop.left = tmp;
3027 } else if (rot == Surface.ROTATION_180) {
3028 int tmp = crop.top;
3029 crop.top = dh - crop.bottom;
3030 crop.bottom = dh - tmp;
3031 tmp = crop.right;
3032 crop.right = dw - crop.left;
3033 crop.left = dw - tmp;
3034 } else if (rot == Surface.ROTATION_270) {
3035 final int tmp = crop.top;
3036 crop.top = crop.left;
3037 crop.left = dh - crop.bottom;
3038 crop.bottom = crop.right;
3039 crop.right = dh - tmp;
3040 }
3041 }
3042
3043 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003044 // Used to indicate the layout is needed.
3045 mTmpWindow = null;
3046
3047 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003048 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003049 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003050 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003051 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003052 w.setDisplayLayoutNeeded();
3053 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003054 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003055
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003056 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003057 mService.mWindowPlacerLocked.performSurfacePlacement();
3058 }
3059 }
3060
Wale Ogunwale1666e312016-12-16 11:27:18 -08003061 void setExitingTokensHasVisible(boolean hasVisible) {
3062 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3063 mExitingTokens.get(i).hasVisible = hasVisible;
3064 }
3065
3066 // Initialize state of exiting applications.
3067 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3068 }
3069
3070 void removeExistingTokensIfPossible() {
3071 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3072 final WindowToken token = mExitingTokens.get(i);
3073 if (!token.hasVisible) {
3074 mExitingTokens.remove(i);
3075 }
3076 }
3077
3078 // Time to remove any exiting applications?
3079 mTaskStackContainers.removeExistingAppTokensIfPossible();
3080 }
3081
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003082 @Override
3083 void onDescendantOverrideConfigurationChanged() {
3084 setLayoutNeeded();
3085 mService.requestTraversal();
3086 }
3087
David Stevens9440dc82017-03-16 19:00:20 -07003088 boolean okToDisplay() {
3089 if (mDisplayId == DEFAULT_DISPLAY) {
3090 return !mService.mDisplayFrozen
3091 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3092 }
3093 return mDisplayInfo.state == Display.STATE_ON;
3094 }
3095
3096 boolean okToAnimate() {
3097 return okToDisplay() &&
3098 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3099 }
3100
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003101 static final class TaskForResizePointSearchResult {
3102 boolean searchDone;
3103 Task taskForResize;
3104
3105 void reset() {
3106 searchDone = false;
3107 taskForResize = null;
3108 }
3109 }
Robert Carr3b716242016-08-16 16:02:21 -07003110
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003111 private static final class ApplySurfaceChangesTransactionState {
3112 boolean displayHasContent;
3113 boolean obscured;
3114 boolean syswin;
3115 boolean focusDisplayed;
3116 float preferredRefreshRate;
3117 int preferredModeId;
3118
3119 void reset() {
3120 displayHasContent = false;
3121 obscured = false;
3122 syswin = false;
3123 focusDisplayed = false;
3124 preferredRefreshRate = 0;
3125 preferredModeId = 0;
3126 }
3127 }
3128
3129 private static final class ScreenshotApplicationState {
3130 WindowState appWin;
3131 int maxLayer;
3132 int minLayer;
3133 boolean screenshotReady;
3134
3135 void reset(boolean screenshotReady) {
3136 appWin = null;
3137 maxLayer = 0;
3138 minLayer = 0;
3139 this.screenshotReady = screenshotReady;
3140 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3141 }
3142 }
3143
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003144 /**
3145 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3146 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3147 * homogeneous children type which is currently required by sub-classes of
3148 * {@link WindowContainer} class.
3149 */
3150 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3151
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003152 DisplayChildWindowContainer(WindowManagerService service) {
3153 super(service);
3154 }
3155
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003156 @Override
3157 boolean fillsParent() {
3158 return true;
3159 }
3160
3161 @Override
3162 boolean isVisible() {
3163 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003164 }
3165 }
3166
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003167 /**
3168 * Window container class that contains all containers on this display relating to Apps.
3169 * I.e Activities.
3170 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003171 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003172 /**
3173 * A control placed at the appropriate level for transitions to occur.
3174 */
chaviw23ee71c2017-12-18 11:29:41 -08003175 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003176
Robert Carrf7a7ca82017-12-06 13:17:07 -08003177 /**
3178 * Given that the split-screen divider does not have an AppWindowToken, it
3179 * will have to live inside of a "NonAppWindowContainer", in particular
3180 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3181 * it will need to be interleaved with some of our children, appearing on top of
3182 * both docked stacks but underneath any assistant stacks.
3183 *
3184 * To solve this problem we have this anchor control, which will always exist so
3185 * we can always assign it the correct value in our {@link #assignChildLayers}.
3186 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3187 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3188 * events between the two containers.
3189 */
3190 SurfaceControl mSplitScreenDividerAnchor = null;
3191
Wale Ogunwale61911492017-10-11 08:50:50 -07003192 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3193 // through the list to find them.
3194 private TaskStack mHomeStack = null;
3195 private TaskStack mPinnedStack = null;
3196 private TaskStack mSplitScreenPrimaryStack = null;
3197
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003198 TaskStackContainers(WindowManagerService service) {
3199 super(service);
3200 }
3201
Wale Ogunwale61911492017-10-11 08:50:50 -07003202 /**
3203 * Returns the topmost stack on the display that is compatible with the input windowing mode
3204 * and activity type. Null is no compatible stack on the display.
3205 */
3206 TaskStack getStack(int windowingMode, int activityType) {
3207 if (activityType == ACTIVITY_TYPE_HOME) {
3208 return mHomeStack;
3209 }
3210 if (windowingMode == WINDOWING_MODE_PINNED) {
3211 return mPinnedStack;
3212 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3213 return mSplitScreenPrimaryStack;
3214 }
3215 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3216 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003217 if (activityType == ACTIVITY_TYPE_UNDEFINED
3218 && windowingMode == stack.getWindowingMode()) {
3219 // Passing in undefined type means we want to match the topmost stack with the
3220 // windowing mode.
3221 return stack;
3222 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003223 if (stack.isCompatible(windowingMode, activityType)) {
3224 return stack;
3225 }
3226 }
3227 return null;
3228 }
3229
3230 @VisibleForTesting
3231 TaskStack getTopStack() {
3232 return mTaskStackContainers.getChildCount() > 0
3233 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3234 }
3235
3236 TaskStack getHomeStack() {
3237 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3238 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3239 }
3240 return mHomeStack;
3241 }
3242
3243 TaskStack getPinnedStack() {
3244 return mPinnedStack;
3245 }
3246
Matthew Ng64e77cf2017-10-31 14:01:31 -07003247 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003248 return mSplitScreenPrimaryStack;
3249 }
3250
Winson Chunge2d72172018-01-25 17:46:20 +00003251 ArrayList<Task> getVisibleTasks() {
3252 final ArrayList<Task> visibleTasks = new ArrayList<>();
3253 forAllTasks(task -> {
3254 if (task.isVisible()) {
3255 visibleTasks.add(task);
3256 }
3257 });
3258 return visibleTasks;
3259 }
3260
Andrii Kulian839def92016-11-02 10:58:58 -07003261 /**
3262 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003263 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003264 */
3265 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003266 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003267 addChild(stack, onTop);
3268 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003269 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003270
Wale Ogunwale61911492017-10-11 08:50:50 -07003271 void onStackWindowingModeChanged(TaskStack stack) {
3272 removeStackReferenceIfNeeded(stack);
3273 addStackReferenceIfNeeded(stack);
3274 if (stack == mPinnedStack && getTopStack() != stack) {
3275 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3276 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3277 }
3278 }
3279
3280 private void addStackReferenceIfNeeded(TaskStack stack) {
3281 if (stack.isActivityTypeHome()) {
3282 if (mHomeStack != null) {
3283 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3284 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3285 }
3286 mHomeStack = stack;
3287 }
3288 final int windowingMode = stack.getWindowingMode();
3289 if (windowingMode == WINDOWING_MODE_PINNED) {
3290 if (mPinnedStack != null) {
3291 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3292 + mPinnedStack + " already exist on display=" + this
3293 + " stack=" + stack);
3294 }
3295 mPinnedStack = stack;
3296 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3297 if (mSplitScreenPrimaryStack != null) {
3298 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3299 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3300 + " already exist on display=" + this + " stack=" + stack);
3301 }
3302 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003303 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003304 }
3305 }
3306
3307 private void removeStackReferenceIfNeeded(TaskStack stack) {
3308 if (stack == mHomeStack) {
3309 mHomeStack = null;
3310 } else if (stack == mPinnedStack) {
3311 mPinnedStack = null;
3312 } else if (stack == mSplitScreenPrimaryStack) {
3313 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003314 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3315 mService.setDockedStackCreateStateLocked(
3316 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3317 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003318 }
Andrii Kulian839def92016-11-02 10:58:58 -07003319 }
3320
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003321 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003322 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3323 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003324 addChild(stack, addIndex);
3325 setLayoutNeeded();
3326 }
3327
Wale Ogunwale61911492017-10-11 08:50:50 -07003328 @Override
3329 protected void removeChild(TaskStack stack) {
3330 super.removeChild(stack);
3331 removeStackReferenceIfNeeded(stack);
3332 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003333
3334 @Override
3335 boolean isOnTop() {
3336 // Considered always on top
3337 return true;
3338 }
3339
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003340 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003341 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003342 if (child.getWindowConfiguration().isAlwaysOnTop()
3343 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003344 // This stack is always-on-top, override the default behavior.
3345 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3346
3347 // Moving to its current position, as we must call super but we don't want to
3348 // perform any meaningful action.
3349 final int currentPosition = mChildren.indexOf(child);
3350 super.positionChildAt(currentPosition, child, false /* includingParents */);
3351 return;
3352 }
3353
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003354 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3355 super.positionChildAt(targetPosition, child, includingParents);
3356
3357 setLayoutNeeded();
3358 }
3359
3360 /**
3361 * When stack is added or repositioned, find a proper position for it.
3362 * This will make sure that pinned stack always stays on top.
3363 * @param requestedPosition Position requested by caller.
3364 * @param stack Stack to be added or positioned.
3365 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3366 * @return The proper position for the stack.
3367 */
3368 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3369 final int topChildPosition = mChildren.size() - 1;
3370 boolean toTop = requestedPosition == POSITION_TOP;
3371 toTop |= adding ? requestedPosition >= topChildPosition + 1
3372 : requestedPosition >= topChildPosition;
3373 int targetPosition = requestedPosition;
3374
Wale Ogunwale61911492017-10-11 08:50:50 -07003375 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003376 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003377 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003378 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003379 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3380 }
3381
3382 // So, stack is moved just below the pinned stack.
3383 // When we're adding a new stack the target is the current pinned stack position.
3384 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003385 // stack, because WindowContainer#positionAt() first removes element and then adds
3386 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003387 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3388 }
3389
3390 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003391 }
3392
3393 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003394 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3395 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003396 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003397 if (super.forAllWindows(callback, traverseTopToBottom)) {
3398 return true;
3399 }
3400 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3401 return true;
3402 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003403 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003404 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3405 return true;
3406 }
3407 if (super.forAllWindows(callback, traverseTopToBottom)) {
3408 return true;
3409 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003410 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003411 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003412 }
3413
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003414 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003415 boolean traverseTopToBottom) {
3416 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3417 // app tokens.
3418 // TODO: Investigate if we need to continue to do this or if we can just process them
3419 // in-order.
3420 if (traverseTopToBottom) {
3421 for (int i = mChildren.size() - 1; i >= 0; --i) {
3422 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3423 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003424 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3425 traverseTopToBottom)) {
3426 return true;
3427 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003428 }
3429 }
3430 } else {
3431 final int count = mChildren.size();
3432 for (int i = 0; i < count; ++i) {
3433 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3434 final int appTokensCount = appTokens.size();
3435 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003436 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3437 traverseTopToBottom)) {
3438 return true;
3439 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003440 }
3441 }
3442 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003443 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003444 }
3445
Wale Ogunwale1666e312016-12-16 11:27:18 -08003446 void setExitingTokensHasVisible(boolean hasVisible) {
3447 for (int i = mChildren.size() - 1; i >= 0; --i) {
3448 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3449 for (int j = appTokens.size() - 1; j >= 0; --j) {
3450 appTokens.get(j).hasVisible = hasVisible;
3451 }
3452 }
3453 }
3454
3455 void removeExistingAppTokensIfPossible() {
3456 for (int i = mChildren.size() - 1; i >= 0; --i) {
3457 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3458 for (int j = appTokens.size() - 1; j >= 0; --j) {
3459 final AppWindowToken token = appTokens.get(j);
3460 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3461 && (!token.mIsExiting || token.isEmpty())) {
3462 // Make sure there is no animation running on this token, so any windows
3463 // associated with it will be removed as soon as their animations are
3464 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003465 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003466 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3467 "performLayout: App token exiting now removed" + token);
3468 token.removeIfPossible();
3469 }
3470 }
3471 }
3472 }
3473
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003474 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003475 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003476 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3477 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003478 // Apps and their containers are not allowed to specify an orientation while the
3479 // docked or freeform stack is visible...except for the home stack/task if the
3480 // docked stack is minimized and it actually set something.
3481 if (mHomeStack != null && mHomeStack.isVisible()
3482 && mDividerControllerLocked.isMinimizedDock()) {
3483 final int orientation = mHomeStack.getOrientation();
3484 if (orientation != SCREEN_ORIENTATION_UNSET) {
3485 return orientation;
3486 }
3487 }
3488 return SCREEN_ORIENTATION_UNSPECIFIED;
3489 }
3490
3491 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003492 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3493 PackageManager.FEATURE_AUTOMOTIVE);
3494 if (isCar) {
3495 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3496 // allow anything but the default orientation.
3497 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3498 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3499 return SCREEN_ORIENTATION_UNSPECIFIED;
3500 }
3501
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003502 if (orientation != SCREEN_ORIENTATION_UNSET
3503 && orientation != SCREEN_ORIENTATION_BEHIND) {
3504 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3505 "App is requesting an orientation, return " + orientation);
3506 return orientation;
3507 }
3508
3509 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003510 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003511 // The next app has not been requested to be visible, so we keep the current orientation
3512 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003513 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003514 }
Robert Carrb1579c82017-09-05 14:54:47 -07003515
3516 @Override
3517 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003518 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003519
Robert Carr2f8aa392018-01-31 14:46:51 -08003520 for (int i = 0; i < mChildren.size(); i++) {
3521 final TaskStack s = mChildren.get(i);
3522 s.assignChildLayers(t);
3523 }
3524 }
3525
3526 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003527 final int HOME_STACK_STATE = 0;
3528 final int NORMAL_STACK_STATE = 1;
3529 final int ALWAYS_ON_TOP_STATE = 2;
3530
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003531 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003532 int layerForAnimationLayer = 0;
3533
Robert Carrf7a7ca82017-12-06 13:17:07 -08003534 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3535 for (int i = 0; i < mChildren.size(); i++) {
3536 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003537 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3538 continue;
3539 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3540 || s.isAlwaysOnTop())) {
3541 continue;
3542 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3543 continue;
3544 }
3545 s.assignLayer(t, layer++);
3546 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3547 t.setLayer(mSplitScreenDividerAnchor, layer++);
3548 }
Robert Carrb9506032018-02-13 13:54:00 -08003549 if (s.isAppAnimating() && state != ALWAYS_ON_TOP_STATE) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003550 // Ensure the animation layer ends up above the
3551 // highest animating stack and no higher.
3552 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003553 }
3554 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003555 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003556 if (mAppAnimationLayer != null) {
3557 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003558 }
Robert Carrb1579c82017-09-05 14:54:47 -07003559 }
3560
3561 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003562 SurfaceControl getAppAnimationLayer() {
3563 return mAppAnimationLayer;
3564 }
3565
Robert Carrf7a7ca82017-12-06 13:17:07 -08003566 SurfaceControl getSplitScreenDividerAnchor() {
3567 return mSplitScreenDividerAnchor;
3568 }
3569
chaviw23ee71c2017-12-18 11:29:41 -08003570 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003571 void onParentSet() {
3572 super.onParentSet();
3573 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003574 mAppAnimationLayer = makeChildSurface(null)
3575 .setName("animationLayer")
3576 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003577 mSplitScreenDividerAnchor = makeChildSurface(null)
3578 .setName("splitScreenDividerAnchor")
3579 .build();
3580 getPendingTransaction()
3581 .show(mAppAnimationLayer)
3582 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003583 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003584 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003585 mAppAnimationLayer.destroy();
3586 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003587 mSplitScreenDividerAnchor.destroy();
3588 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003589 }
3590 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003591 }
3592
Robert Carree4d4b92017-11-22 12:21:46 -08003593 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003594 AboveAppWindowContainers(String name, WindowManagerService service) {
3595 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003596 }
3597
Robert Carrb9506032018-02-13 13:54:00 -08003598 @Override
3599 void assignChildLayers(SurfaceControl.Transaction t) {
3600 assignChildLayers(t, null /* imeContainer */);
3601 }
3602
Robert Carree4d4b92017-11-22 12:21:46 -08003603 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3604 boolean needAssignIme = imeContainer != null
3605 && imeContainer.getSurfaceControl() != null;
3606 for (int j = 0; j < mChildren.size(); ++j) {
3607 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003608
3609 // See {@link mSplitScreenDividerAnchor}
3610 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3611 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3612 continue;
3613 }
Robert Carree4d4b92017-11-22 12:21:46 -08003614 wt.assignLayer(t, j);
3615 wt.assignChildLayers(t);
3616
3617 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3618 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003619
3620 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3621 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003622 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003623 needAssignIme = false;
3624 }
3625 }
3626 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003627 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003628 }
3629 }
3630 }
3631
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003632 /**
3633 * Window container class that contains all containers on this display that are not related to
3634 * Apps. E.g. status bar.
3635 */
Robert Carree4d4b92017-11-22 12:21:46 -08003636 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003637 /**
3638 * Compares two child window tokens returns -1 if the first is lesser than the second in
3639 * terms of z-order and 1 otherwise.
3640 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003641 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003642 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003643 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3644 token1.mOwnerCanManageAppTokens)
3645 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3646 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003647
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003648 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3649 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3650 return false;
3651 }
3652 final int req = w.mAttrs.screenOrientation;
3653 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3654 || req == SCREEN_ORIENTATION_UNSET) {
3655 return false;
3656 }
3657 return true;
3658 };
3659
Wale Ogunwale3a931692016-11-02 16:49:48 -07003660 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003661 private final Dimmer mDimmer = new Dimmer(this);
3662 private final Rect mTmpDimBoundsRect = new Rect();
3663
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003664 NonAppWindowContainers(String name, WindowManagerService service) {
3665 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003666 mName = name;
3667 }
3668
3669 void addChild(WindowToken token) {
3670 addChild(token, mWindowComparator);
3671 }
3672
3673 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003674 int getOrientation() {
3675 final WindowManagerPolicy policy = mService.mPolicy;
3676 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003677 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003678
3679 if (win != null) {
3680 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003681 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003682 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003683 if (mService.mKeyguardGoingAway) {
3684 // Keyguard can't affect the orientation if it is going away...
3685 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3686 return SCREEN_ORIENTATION_UNSET;
3687 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003688 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003689 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003690 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003691 }
3692
Andrii Kulian8ee72852017-03-10 10:36:45 -08003693 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003694
Jorim Jaggi75520d52017-08-24 17:23:19 +02003695 if (policy.isKeyguardShowingAndNotOccluded()
3696 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003697 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003698 }
3699
3700 return SCREEN_ORIENTATION_UNSET;
3701 }
3702
3703 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003704 String getName() {
3705 return mName;
3706 }
chaviwf29223e2018-01-31 13:23:51 -08003707
3708 @Override
3709 Dimmer getDimmer() {
3710 return mDimmer;
3711 }
3712
3713 @Override
3714 void prepareSurfaces() {
3715 mDimmer.resetDimStates();
3716 super.prepareSurfaces();
3717 getBounds(mTmpDimBoundsRect);
3718
3719 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3720 scheduleAnimation();
3721 }
3722 }
Robert Carr3b716242016-08-16 16:02:21 -07003723 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003724
Robert Carr9034d962018-01-04 18:27:42 -08003725 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3726 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3727 super(name, service);
3728 }
3729
3730 @Override
3731 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3732 }
3733 };
3734
Robert Carrb1579c82017-09-05 14:54:47 -07003735 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3736 return mService.makeSurfaceBuilder(s)
3737 .setParent(mWindowingLayer);
3738 }
3739
3740 @Override
3741 SurfaceSession getSession() {
3742 return mSession;
3743 }
3744
3745 @Override
3746 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003747 SurfaceSession s = child != null ? child.getSession() : getSession();
3748 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003749 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003750
3751 if (child == null) {
3752 return b;
3753 }
3754
Robert Carree4d4b92017-11-22 12:21:46 -08003755 return b.setName(child.getName())
3756 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003757 }
3758
3759 /**
3760 * The makeSurface variants are for use by the window-container
3761 * hierarchy. makeOverlay here is a function for various non windowing
3762 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3763 * and other potpourii.
3764 */
3765 SurfaceControl.Builder makeOverlay() {
3766 return mService.makeSurfaceBuilder(mSession)
3767 .setParent(mOverlayLayer);
3768 }
3769
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003770 /**
3771 * Reparents the given surface to mOverlayLayer.
3772 */
3773 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3774 transaction.reparent(surface, mOverlayLayer.getHandle());
3775 }
3776
Robert Carrb1579c82017-09-05 14:54:47 -07003777 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003778 applyMagnificationSpec(getPendingTransaction(), spec);
3779 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003780 }
3781
3782 @Override
3783 void onParentSet() {
3784 // Since we are the top of the SurfaceControl hierarchy here
3785 // we create the root surfaces explicitly rather than chaining
3786 // up as the default implementation in onParentSet does. So we
3787 // explicitly do NOT call super here.
3788 }
3789
3790 @Override
3791 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003792
3793 // These are layers as children of "mWindowingLayer"
3794 mBelowAppWindowsContainers.assignLayer(t, 0);
3795 mTaskStackContainers.assignLayer(t, 1);
3796 mAboveAppWindowsContainers.assignLayer(t, 2);
3797
3798 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003799 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003800
Robert Carree4d4b92017-11-22 12:21:46 -08003801 // In the case where we have an IME target that is not in split-screen
3802 // mode IME assignment is easy. We just need the IME to go directly above
3803 // the target. This way children of the target will naturally go above the IME
3804 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003805 //
Robert Carree4d4b92017-11-22 12:21:46 -08003806 // In the case of split-screen windowing mode, we need to elevate the IME above the
3807 // docked divider while keeping the app itself below the docked divider, so instead
3808 // we use relative layering of the IME targets child windows, and place the
3809 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003810 //
Robert Carree4d4b92017-11-22 12:21:46 -08003811 // In the case where we have no IME target we assign it where it's base layer would
3812 // place it in the AboveAppWindowContainers.
3813 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3814 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003815 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003816 // TODO: We need to use an extra level on the app surface to ensure
3817 // this is always above SurfaceView but always below attached window.
3818 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003819 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003820 }
3821
3822 // Above we have assigned layers to our children, now we ask them to assign
3823 // layers to their children.
3824 mBelowAppWindowsContainers.assignChildLayers(t);
3825 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003826 mAboveAppWindowsContainers.assignChildLayers(t,
3827 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003828 mImeWindowsContainers.assignChildLayers(t);
3829 }
3830
3831 /**
3832 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3833 * that the IME target is one of the docked applications. We'd like the docked divider to be
3834 * above both of the applications, and we'd like the IME to be above the docked divider.
3835 * However we need child windows of the applications to be above the IME (Text drag handles).
3836 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3837 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3838 * with {@link #WindowState#assignLayer}
3839 */
3840 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3841 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3842 }
3843
3844 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003845 void prepareSurfaces() {
3846 final ScreenRotationAnimation screenRotationAnimation =
3847 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3848 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3849 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3850 mPendingTransaction.setMatrix(mWindowingLayer,
3851 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3852 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3853 mPendingTransaction.setPosition(mWindowingLayer,
3854 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3855 mPendingTransaction.setAlpha(mWindowingLayer,
3856 screenRotationAnimation.getEnterTransformation().getAlpha());
3857 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003858
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003859 super.prepareSurfaces();
3860 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003861
3862 void assignStackOrdering(SurfaceControl.Transaction t) {
3863 mTaskStackContainers.assignStackOrdering(t);
3864 }
Craig Mautner59c00972012-07-30 12:10:24 -07003865}