blob: 16228d74ea470996dc883b5a7d631a6c9b6c6452 [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;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800140import android.util.MutableBoolean;
Craig Mautnerde4ef022013-04-07 19:01:33 -0700141import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700142import android.util.proto.ProtoOutputStream;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700143import android.view.Display;
Adrian Roos1cf585052018-01-03 18:43:27 +0100144import android.view.DisplayCutout;
Craig Mautner59c00972012-07-30 12:10:24 -0700145import android.view.DisplayInfo;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700146import android.view.InputDevice;
Robert Carrb1579c82017-09-05 14:54:47 -0700147import android.view.MagnificationSpec;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700148import android.view.Surface;
149import android.view.SurfaceControl;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100150import android.view.SurfaceControl.Transaction;
Robert Carrb1579c82017-09-05 14:54:47 -0700151import android.view.SurfaceSession;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700152
Bryce Lee48f4b572017-04-10 10:54:15 -0700153import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800154import com.android.internal.util.ToBooleanFunction;
Wale Ogunwale494009b82016-10-21 09:01:38 -0700155import com.android.internal.view.IInputMethodClient;
Adrian Roose99bc052017-11-20 17:55:31 +0100156import com.android.server.policy.WindowManagerPolicy;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100157import com.android.server.wm.utils.RotationCache;
Craig Mautner59c00972012-07-30 12:10:24 -0700158
Robert Carr3b716242016-08-16 16:02:21 -0700159import java.io.FileDescriptor;
Craig Mautner59c00972012-07-30 12:10:24 -0700160import java.io.PrintWriter;
161import java.util.ArrayList;
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700162import java.util.Comparator;
Wale Ogunwale02319a62016-09-26 15:21:22 -0700163import java.util.HashMap;
164import java.util.Iterator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700165import java.util.LinkedList;
Andrii Kulian3a507b52016-09-19 18:14:12 -0700166import java.util.List;
Adrian Roos1cf585052018-01-03 18:43:27 +0100167import java.util.Objects;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800168import java.util.function.Consumer;
169import java.util.function.Predicate;
Craig Mautner59c00972012-07-30 12:10:24 -0700170
Craig Mautner59c00972012-07-30 12:10:24 -0700171/**
172 * Utility class for keeping track of the WindowStates and other pertinent contents of a
173 * particular Display.
174 *
175 * IMPORTANT: No method from this class should ever be used without holding
176 * WindowManagerService.mWindowMap.
177 */
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700178class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -0700179 private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
Craig Mautner59c00972012-07-30 12:10:24 -0700180
181 /** Unique identifier of this stack. */
182 private final int mDisplayId;
183
Wale Ogunwale3a931692016-11-02 16:49:48 -0700184 /** The containers below are the only child containers the display can have. */
185 // Contains all window containers that are related to apps (Activities)
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100186 private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700187 // Contains all non-app window containers that should be displayed above the app containers
188 // (e.g. Status bar)
Robert Carree4d4b92017-11-22 12:21:46 -0800189 private final AboveAppWindowContainers mAboveAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100190 new AboveAppWindowContainers("mAboveAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700191 // Contains all non-app window containers that should be displayed below the app containers
192 // (e.g. Wallpaper).
193 private final NonAppWindowContainers mBelowAppWindowsContainers =
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100194 new NonAppWindowContainers("mBelowAppWindowsContainers", mService);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700195 // Contains all IME window containers. Note that the z-ordering of the IME windows will depend
196 // 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 -0800197 // window containers together and move them in-sync if/when needed. We use a subclass of
198 // WindowContainer which is omitted from screen magnification, as the IME is never magnified.
199 private final NonMagnifiableWindowContainers mImeWindowsContainers =
200 new NonMagnifiableWindowContainers("mImeWindowsContainers", mService);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700201
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000202 private WindowState mTmpWindow;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800203 private WindowState mTmpWindow2;
204 private WindowAnimator mTmpWindowAnimator;
205 private boolean mTmpRecoveringMemory;
206 private boolean mUpdateImeTarget;
207 private boolean mTmpInitial;
Bryce Lee27cec322017-03-21 09:41:37 -0700208 private int mMaxUiWidth;
Craig Mautner59c00972012-07-30 12:10:24 -0700209
Wale Ogunwale02319a62016-09-26 15:21:22 -0700210 // Mapping from a token IBinder to a WindowToken object on this display.
211 private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
212
Andrii Kuliancd097992017-03-23 18:31:59 -0700213 // Initial display metrics.
Craig Mautner59c00972012-07-30 12:10:24 -0700214 int mInitialDisplayWidth = 0;
215 int mInitialDisplayHeight = 0;
Dianne Hackborndde331c2012-08-03 14:01:57 -0700216 int mInitialDisplayDensity = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700217
Adrian Roos1cf585052018-01-03 18:43:27 +0100218 DisplayCutout mInitialDisplayCutout;
Adrian Roos2aa0fcd2018-02-19 18:07:49 +0100219 private final RotationCache<DisplayCutout, DisplayCutout> mDisplayCutoutCache
220 = new RotationCache<>(this::calculateDisplayCutoutForRotationUncached);
Adrian Roos1cf585052018-01-03 18:43:27 +0100221
Andrii Kuliancd097992017-03-23 18:31:59 -0700222 /**
223 * Overridden display size. Initialized with {@link #mInitialDisplayWidth}
224 * and {@link #mInitialDisplayHeight}, but can be set via shell command "adb shell wm size".
225 * @see WindowManagerService#setForcedDisplaySize(int, int, int)
226 */
Craig Mautner59c00972012-07-30 12:10:24 -0700227 int mBaseDisplayWidth = 0;
228 int mBaseDisplayHeight = 0;
Andrii Kuliancd097992017-03-23 18:31:59 -0700229 /**
230 * Overridden display density for current user. Initialized with {@link #mInitialDisplayDensity}
231 * but can be set from Settings or via shell command "adb shell wm density".
232 * @see WindowManagerService#setForcedDisplayDensityForUser(int, int, int)
233 */
Dianne Hackborndde331c2012-08-03 14:01:57 -0700234 int mBaseDisplayDensity = 0;
Jeff Brownd46747a2015-04-15 19:02:36 -0700235 boolean mDisplayScalingDisabled;
Craig Mautner2d5618c2012-10-18 13:55:47 -0700236 private final DisplayInfo mDisplayInfo = new DisplayInfo();
237 private final Display mDisplay;
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700238 private final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000239 DisplayFrames mDisplayFrames;
240
Andrii Kulian06d07d62017-03-14 11:11:47 -0700241 /**
242 * For default display it contains real metrics, empty for others.
243 * @see WindowManagerService#createWatermarkInTransaction()
244 */
245 final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
246 /** @see #computeCompatSmallestWidth(boolean, int, int, int, int) */
247 private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700248
Andrii Kulian06d07d62017-03-14 11:11:47 -0700249 /**
250 * Compat metrics computed based on {@link #mDisplayMetrics}.
251 * @see #updateDisplayAndOrientation(int)
252 */
253 private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
254
255 /** The desired scaling factor for compatible apps. */
256 float mCompatibleScreenScale;
Craig Mautner59c00972012-07-30 12:10:24 -0700257
Andrii Kulian8ee72852017-03-10 10:36:45 -0800258 /**
259 * Current rotation of the display.
260 * Constants as per {@link android.view.Surface.Rotation}.
261 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700262 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800263 */
264 private int mRotation = 0;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700265
Andrii Kulian8ee72852017-03-10 10:36:45 -0800266 /**
267 * Last applied orientation of the display.
268 * Constants as per {@link android.content.pm.ActivityInfo.ScreenOrientation}.
269 *
270 * @see WindowManagerService#updateOrientationFromAppTokensLocked(boolean, int)
271 */
272 private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700273
Andrii Kulian8ee72852017-03-10 10:36:45 -0800274 /**
275 * Flag indicating that the application is receiving an orientation that has different metrics
276 * than it expected. E.g. Portrait instead of Landscape.
277 *
Andrii Kulian06d07d62017-03-14 11:11:47 -0700278 * @see #updateRotationUnchecked(boolean)
Andrii Kulian8ee72852017-03-10 10:36:45 -0800279 */
280 private boolean mAltOrientation = false;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700281
Andrii Kulian8ee72852017-03-10 10:36:45 -0800282 /**
283 * Orientation forced by some window. If there is no visible window that specifies orientation
284 * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
285 *
286 * @see NonAppWindowContainers#getOrientation()
287 */
288 private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700289
Andrii Kulian8ee72852017-03-10 10:36:45 -0800290 /**
291 * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
292 * occluded.
293 *
294 * @see NonAppWindowContainers#getOrientation()
295 */
296 private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
297
Lucas Dupin1ead7fc2017-05-24 14:14:44 -0700298 /**
299 * Keep track of wallpaper visibility to notify changes.
300 */
301 private boolean mLastWallpaperVisible = false;
302
Andrii Kulian06d07d62017-03-14 11:11:47 -0700303 private Rect mBaseDisplayRect = new Rect();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700304
Craig Mautner39834192012-09-02 07:47:24 -0700305 // Accessed directly by all users.
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -0700306 private boolean mLayoutNeeded;
Craig Mautner76a71652012-09-03 23:23:58 -0700307 int pendingLayoutChanges;
Andrii Kulian839def92016-11-02 10:58:58 -0700308 // TODO(multi-display): remove some of the usages.
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800309 boolean isDefaultDisplay;
Craig Mautner39834192012-09-02 07:47:24 -0700310
Craig Mautnerdc548482014-02-05 13:35:24 -0800311 /** Window tokens that are in the process of exiting, but still on screen for animations. */
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700312 final ArrayList<WindowToken> mExitingTokens = new ArrayList<>();
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800313
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700314 /** Detect user tapping outside of current focused task bounds .*/
315 TaskTapPointerEventListener mTapDetector;
Craig Mautnercf910b02013-04-23 11:23:27 -0700316
Craig Mautner6601b7b2013-04-29 10:29:11 -0700317 /** Detect user tapping outside of current focused stack bounds .*/
Wale Ogunwale9adfe572016-09-08 20:43:58 -0700318 private Region mTouchExcludeRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700319
Craig Mautner6601b7b2013-04-29 10:29:11 -0700320 /** Save allocating when calculating rects */
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800321 private final Rect mTmpRect = new Rect();
322 private final Rect mTmpRect2 = new Rect();
Andrii Kulian4dfb9c42016-10-11 20:06:27 -0700323 private final RectF mTmpRectF = new RectF();
324 private final Matrix mTmpMatrix = new Matrix();
Filip Gruszczynski912d9192015-12-01 16:14:04 -0800325 private final Region mTmpRegion = new Region();
Craig Mautner6601b7b2013-04-29 10:29:11 -0700326
Bryce Leef3c6a472017-11-14 14:53:06 -0800327 /** Used for handing back size of display */
328 private final Rect mTmpBounds = new Rect();
329
Craig Mautner95da1082014-02-24 17:54:35 -0800330 /** Remove this display when animation on it has completed. */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700331 private boolean mDeferredRemoval;
Craig Mautner1bf2b872014-02-05 15:37:40 -0800332
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700333 final DockedStackDividerController mDividerControllerLocked;
Winson Chung655332c2016-10-31 13:14:28 -0700334 final PinnedStackController mPinnedStackControllerLocked;
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700335
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800336 final ArrayList<WindowState> mTapExcludedWindows = new ArrayList<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800337 /** A collection of windows that provide tap exclude regions inside of them. */
338 final ArraySet<WindowState> mTapExcludeProvidingWindows = new ArraySet<>();
Filip Gruszczynskiecf67222015-12-11 15:16:36 -0800339
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000340 private boolean mHaveBootMsg = false;
341 private boolean mHaveApp = false;
342 private boolean mHaveWallpaper = false;
343 private boolean mHaveKeyguard = true;
Wale Ogunwalef7cab102016-10-25 15:25:14 -0700344
345 private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
346
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700347 private final TaskForResizePointSearchResult mTmpTaskForResizePointSearchResult =
348 new TaskForResizePointSearchResult();
Wale Ogunwale6213caa2016-12-02 16:47:15 +0000349 private final ApplySurfaceChangesTransactionState mTmpApplySurfaceChangesTransactionState =
350 new ApplySurfaceChangesTransactionState();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700351
Wale Ogunwale601a3f02016-10-17 08:39:39 -0700352 // True if this display is in the process of being removed. Used to determine if the removal of
353 // the display's direct children should be allowed.
354 private boolean mRemovingDisplay = false;
355
Bryce Leed1871262017-06-12 14:12:29 -0700356 // {@code false} if this display is in the processing of being created.
357 private boolean mDisplayReady = false;
358
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800359 WallpaperController mWallpaperController;
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700360
Robert Carrb1579c82017-09-05 14:54:47 -0700361 private final SurfaceSession mSession = new SurfaceSession();
362
363 /**
364 * We organize all top-level Surfaces in to the following layers.
365 * mOverlayLayer contains a few Surfaces which are always on top of others
Robert Carree4d4b92017-11-22 12:21:46 -0800366 * and omitted from Screen-Magnification, for example the strict mode flash or
367 * the magnification overlay itself.
Robert Carrb1579c82017-09-05 14:54:47 -0700368 * {@link #mWindowingLayer} contains everything else.
369 */
370 private SurfaceControl mOverlayLayer;
371
372 /**
373 * See {@link #mOverlayLayer}
374 */
375 private SurfaceControl mWindowingLayer;
376
377 /**
378 * Specifies the size of the surfaces in {@link #mOverlayLayer} and {@link #mWindowingLayer}.
379 * <p>
380 * For these surfaces currently we use a surface based on the larger of width or height so we
381 * don't have to resize when rotating the display.
382 */
383 private int mSurfaceSize;
384
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100385 /** Temporary float array to retrieve 3x3 matrix values. */
386 private final float[] mTmpFloats = new float[9];
387
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800388 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
389 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800390 final AppWindowToken atoken = w.mAppToken;
391 if (winAnimator.mDrawState == READY_TO_SHOW) {
392 if (atoken == null || atoken.allDrawn) {
393 if (w.performShowLocked()) {
394 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
395 if (DEBUG_LAYOUT_REPEATS) {
396 mService.mWindowPlacerLocked.debugLayoutRepeats(
397 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
398 }
399 }
400 }
401 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800402 };
403
404 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
405 final WindowStateAnimator winAnimator = w.mWinAnimator;
406 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
407 return;
408 }
409
410 final int flags = w.mAttrs.flags;
411
412 // If this window is animating, make a note that we have an animating window and take
413 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100414 if (winAnimator.isAnimationSet()) {
415 final AnimationAdapter anim = w.getAnimation();
416 if (anim != null) {
417 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800418 mTmpWindow = w;
419 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100420 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800421 if (color != 0) {
422 final TaskStack stack = w.getStack();
423 if (stack != null) {
424 stack.setAnimationBackground(winAnimator, color);
425 }
426 }
427 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800428 }
429
430 // If this window's app token is running a detached wallpaper animation, make a note so
431 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200432 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
433 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
434 if (animation != null) {
435 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800436 mTmpWindow = w;
437 }
438
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200439 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800440 if (color != 0) {
441 final TaskStack stack = w.getStack();
442 if (stack != null) {
443 stack.setAnimationBackground(winAnimator, color);
444 }
445 }
446 }
447 };
448
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800449 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
450 final int lostFocusUid = mTmpWindow.mOwnerUid;
451 final Handler handler = mService.mH;
452 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
453 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
454 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
455 w.mAttrs.hideTimeoutMilliseconds);
456 }
457 }
458 };
459
460 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
461 final AppWindowToken focusedApp = mService.mFocusedApp;
462 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
463 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
464
465 if (!w.canReceiveKeys()) {
466 return false;
467 }
468
469 final AppWindowToken wtoken = w.mAppToken;
470
471 // If this window's application has been removed, just skip it.
472 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
473 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
474 + (wtoken.removed ? "removed" : "sendingToBottom"));
475 return false;
476 }
477
478 if (focusedApp == null) {
479 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
480 + " using new focus @ " + w);
481 mTmpWindow = w;
482 return true;
483 }
484
485 if (!focusedApp.windowsAreFocusable()) {
486 // Current focused app windows aren't focusable...
487 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
488 + " focusable using new focus @ " + w);
489 mTmpWindow = w;
490 return true;
491 }
492
493 // Descend through all of the app tokens and find the first that either matches
494 // win.mAppToken (return win) or mFocusedApp (return null).
495 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
496 if (focusedApp.compareTo(wtoken) > 0) {
497 // App stack below focused app stack. No focus for you!!!
498 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
499 "findFocusedWindow: Reached focused app=" + focusedApp);
500 mTmpWindow = null;
501 return true;
502 }
503 }
504
505 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
506 mTmpWindow = w;
507 return true;
508 };
509
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800510 private final Consumer<WindowState> mPerformLayout = w -> {
511 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
512 // wasting time and funky changes while a window is animating away.
513 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
514 || w.isGoneForLayoutLw();
515
516 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
517 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
518 + " mLayoutAttached=" + w.mLayoutAttached
519 + " screen changed=" + w.isConfigChanged());
520 final AppWindowToken atoken = w.mAppToken;
521 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200522 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800523 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
524 + " parentHidden=" + w.isParentWindowHidden());
525 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200526 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800527 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
528 + " parentHidden=" + w.isParentWindowHidden());
529 }
530
531 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
532 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
533 // since that means "perform layout as normal, just don't display").
534 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
535 || ((w.isConfigChanged() || w.setReportResizeHints())
536 && !w.isGoneForLayoutLw() &&
537 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
538 (w.mHasSurface && w.mAppToken != null &&
539 w.mAppToken.layoutConfigChanges)))) {
540 if (!w.mLayoutAttached) {
541 if (mTmpInitial) {
542 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
543 w.mContentChanged = false;
544 }
545 if (w.mAttrs.type == TYPE_DREAM) {
546 // Don't layout windows behind a dream, so that if it does stuff like hide
547 // the status bar we won't get a bad transition when it goes away.
548 mTmpWindow = w;
549 }
550 w.mLayoutNeeded = false;
551 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200552 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000553 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800554 w.mLayoutSeq = mService.mLayoutSeq;
555
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200556 // If this is the first layout, we need to initialize the last inset values as
557 // otherwise we'd immediately cause an unnecessary resize.
558 if (firstLayout) {
559 w.updateLastInsetValues();
560 }
561
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800562 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
563 + " mContainingFrame=" + w.mContainingFrame
564 + " mDisplayFrame=" + w.mDisplayFrame);
565 }
566 }
567 };
568
569 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
570 if (w.mLayoutAttached) {
571 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
572 + " mViewVisibility=" + w.mViewVisibility
573 + " mRelayoutCalled=" + w.mRelayoutCalled);
574 // If this view is GONE, then skip it -- keep the current frame, and let the caller
575 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
576 // windows, since that means "perform layout as normal, just don't display").
577 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
578 return;
579 }
580 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
581 || w.mLayoutNeeded) {
582 if (mTmpInitial) {
583 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
584 w.mContentChanged = false;
585 }
586 w.mLayoutNeeded = false;
587 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000588 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800589 w.mLayoutSeq = mService.mLayoutSeq;
590 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
591 + " mContainingFrame=" + w.mContainingFrame
592 + " mDisplayFrame=" + w.mDisplayFrame);
593 }
594 } else if (w.mAttrs.type == TYPE_DREAM) {
595 // Don't layout windows behind a dream, so that if it does stuff like hide the
596 // status bar we won't get a bad transition when it goes away.
597 mTmpWindow = mTmpWindow2;
598 }
599 };
600
601 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
602 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
603 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
604 return w.canBeImeTarget();
605 };
606
607 private final Consumer<WindowState> mApplyPostLayoutPolicy =
608 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
609 mService.mInputMethodTarget);
610
611 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
612 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
613 final boolean obscuredChanged = w.mObscured !=
614 mTmpApplySurfaceChangesTransactionState.obscured;
615 final RootWindowContainer root = mService.mRoot;
616 // Only used if default window
617 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
618
619 // Update effect.
620 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
621 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
622 final boolean isDisplayed = w.isDisplayedLw();
623
624 if (isDisplayed && w.isObscuringDisplay()) {
625 // This window completely covers everything behind it, so we want to leave all
626 // of them as undimmed (for performance reasons).
627 root.mObscuringWindow = w;
628 mTmpApplySurfaceChangesTransactionState.obscured = true;
629 }
630
631 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
632 root.handleNotObscuredLocked(w,
633 mTmpApplySurfaceChangesTransactionState.obscured,
634 mTmpApplySurfaceChangesTransactionState.syswin);
635
636 if (w.mHasSurface && isDisplayed) {
637 final int type = w.mAttrs.type;
638 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
639 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
640 mTmpApplySurfaceChangesTransactionState.syswin = true;
641 }
642 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
643 && w.mAttrs.preferredRefreshRate != 0) {
644 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
645 = w.mAttrs.preferredRefreshRate;
646 }
647 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
648 && w.mAttrs.preferredDisplayModeId != 0) {
649 mTmpApplySurfaceChangesTransactionState.preferredModeId
650 = w.mAttrs.preferredDisplayModeId;
651 }
652 }
653 }
654
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800655 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
656 && mWallpaperController.isWallpaperTarget(w)) {
657 // This is the wallpaper target and its obscured state changed... make sure the
658 // current wallpaper's visibility has been updated accordingly.
659 mWallpaperController.updateWallpaperVisibility();
660 }
661
chaviw161ea3e2018-01-31 12:01:12 -0800662 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800663
664 final WindowStateAnimator winAnimator = w.mWinAnimator;
665
666 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
667 w.mContentChanged = false;
668
669 // Moved from updateWindowsAndWallpaperLocked().
670 if (w.mHasSurface) {
671 // Take care of the window being ready to display.
672 final boolean committed = winAnimator.commitFinishDrawingLocked();
673 if (isDefaultDisplay && committed) {
674 if (w.mAttrs.type == TYPE_DREAM) {
675 // HACK: When a dream is shown, it may at that point hide the lock screen.
676 // So we need to redo the layout to let the phone window manager make this
677 // happen.
678 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
679 if (DEBUG_LAYOUT_REPEATS) {
680 surfacePlacer.debugLayoutRepeats(
681 "dream and commitFinishDrawingLocked true",
682 pendingLayoutChanges);
683 }
684 }
685 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
686 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
687 "First draw done in potential wallpaper target " + w);
688 root.mWallpaperMayChange = true;
689 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
690 if (DEBUG_LAYOUT_REPEATS) {
691 surfacePlacer.debugLayoutRepeats(
692 "wallpaper and commitFinishDrawingLocked true",
693 pendingLayoutChanges);
694 }
695 }
696 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800697 }
698
699 final AppWindowToken atoken = w.mAppToken;
700 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100701 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800702 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
703 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
704 mTmpUpdateAllDrawn.add(atoken);
705 }
706 }
707
708 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
709 && w.isDisplayedLw()) {
710 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
711 }
712
713 w.updateResizingWindowIfNeeded();
714 };
715
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800716 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800717 * Create new {@link DisplayContent} instance, add itself to the root window container and
718 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700719 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800720 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700721 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
722 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700723 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700724 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800725 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100726 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800727 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800728 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
729 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
730 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
731 + " new=" + display);
732 }
733
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700734 mDisplay = display;
735 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700736 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700737 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700738 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700739 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000740 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo);
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 Carrb1579c82017-09-05 14:54:47 -0700745 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth);
746
747 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
748 .setSize(mSurfaceSize, mSurfaceSize)
749 .setOpaque(true);
750 mWindowingLayer = b.setName("Display Root").build();
751 mOverlayLayer = b.setName("Display Overlays").build();
752
Robert Carrf59b8dd2017-10-02 18:58:36 -0700753 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700754 .setLayerStack(mWindowingLayer, mDisplayId)
755 .show(mWindowingLayer)
756 .setLayer(mOverlayLayer, 1)
757 .setLayerStack(mOverlayLayer, mDisplayId)
758 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700759 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700760
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700761 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700762 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700763 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700764 super.addChild(mAboveAppWindowsContainers, null);
765 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800766
767 // Add itself as a child to the root container.
768 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700769
770 // TODO(b/62541591): evaluate whether this is the best spot to declare the
771 // {@link DisplayContent} ready for use.
772 mDisplayReady = true;
773 }
774
775 boolean isReady() {
776 // The display is ready when the system and the individual display are both ready.
777 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700778 }
779
780 int getDisplayId() {
781 return mDisplayId;
782 }
783
Wale Ogunwale02319a62016-09-26 15:21:22 -0700784 WindowToken getWindowToken(IBinder binder) {
785 return mTokenMap.get(binder);
786 }
787
788 AppWindowToken getAppWindowToken(IBinder binder) {
789 final WindowToken token = getWindowToken(binder);
790 if (token == null) {
791 return null;
792 }
793 return token.asAppWindowToken();
794 }
795
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700796 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700797 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
798 if (dc != null) {
799 // We currently don't support adding a window token to the display if the display
800 // already has the binder mapped to another token. If there is a use case for supporting
801 // this moving forward we will either need to merge the WindowTokens some how or have
802 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700803 throw new IllegalArgumentException("Can't map token=" + token + " to display="
804 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700805 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700806 if (binder == null) {
807 throw new IllegalArgumentException("Can't map token=" + token + " to display="
808 + getName() + " binder is null");
809 }
810 if (token == null) {
811 throw new IllegalArgumentException("Can't map null token to display="
812 + getName() + " binder=" + binder);
813 }
814
Wale Ogunwale02319a62016-09-26 15:21:22 -0700815 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700816
817 if (token.asAppWindowToken() == null) {
818 // Add non-app token to container hierarchy on the display. App tokens are added through
819 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700820 switch (token.windowType) {
821 case TYPE_WALLPAPER:
822 mBelowAppWindowsContainers.addChild(token);
823 break;
824 case TYPE_INPUT_METHOD:
825 case TYPE_INPUT_METHOD_DIALOG:
826 mImeWindowsContainers.addChild(token);
827 break;
828 default:
829 mAboveAppWindowsContainers.addChild(token);
830 break;
831 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700832 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700833 }
834
835 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700836 final WindowToken token = mTokenMap.remove(binder);
837 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800838 token.setExiting();
839 }
840 return token;
841 }
842
843 /** Changes the display the input window token is housed on to this one. */
844 void reParentWindowToken(WindowToken token) {
845 final DisplayContent prevDc = token.getDisplayContent();
846 if (prevDc == this) {
847 return;
848 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800849 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
850 && token.asAppWindowToken() == null) {
851 // Removed the token from the map, but made sure it's not an app token before removing
852 // from parent.
853 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700854 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800855
856 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700857 }
858
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700859 void removeAppToken(IBinder binder) {
860 final WindowToken token = removeWindowToken(binder);
861 if (token == null) {
862 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
863 return;
864 }
865
866 final AppWindowToken appToken = token.asAppWindowToken();
867
868 if (appToken == null) {
869 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
870 return;
871 }
872
873 appToken.onRemovedFromDisplay();
874 }
875
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700876 Display getDisplay() {
877 return mDisplay;
878 }
879
Craig Mautner59c00972012-07-30 12:10:24 -0700880 DisplayInfo getDisplayInfo() {
881 return mDisplayInfo;
882 }
883
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700884 DisplayMetrics getDisplayMetrics() {
885 return mDisplayMetrics;
886 }
887
Andrii Kulian8ee72852017-03-10 10:36:45 -0800888 int getRotation() {
889 return mRotation;
890 }
891
892 void setRotation(int newRotation) {
893 mRotation = newRotation;
894 }
895
896 int getLastOrientation() {
897 return mLastOrientation;
898 }
899
900 void setLastOrientation(int orientation) {
901 mLastOrientation = orientation;
902 }
903
904 boolean getAltOrientation() {
905 return mAltOrientation;
906 }
907
908 void setAltOrientation(boolean altOrientation) {
909 mAltOrientation = altOrientation;
910 }
911
912 int getLastWindowForcedOrientation() {
913 return mLastWindowForcedOrientation;
914 }
915
Andrii Kulian06d07d62017-03-14 11:11:47 -0700916 /**
917 * Update rotation of the display.
918 *
919 * Returns true if the rotation has been changed. In this case YOU MUST CALL
920 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
921 */
922 boolean updateRotationUnchecked(boolean inTransaction) {
923 if (mService.mDeferredRotationPauseCount > 0) {
924 // Rotation updates have been paused temporarily. Defer the update until
925 // updates have been resumed.
926 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
927 return false;
928 }
929
930 ScreenRotationAnimation screenRotationAnimation =
931 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
932 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
933 // Rotation updates cannot be performed while the previous rotation change
934 // animation is still in progress. Skip this update. We will try updating
935 // again after the animation is finished and the display is unfrozen.
936 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
937 return false;
938 }
939 if (mService.mDisplayFrozen) {
940 // Even if the screen rotation animation has finished (e.g. isAnimating
941 // returns false), there is still some time where we haven't yet unfrozen
942 // the display. We also need to abort rotation here.
943 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
944 "Deferring rotation, still finishing previous rotation");
945 return false;
946 }
947
948 if (!mService.mDisplayEnabled) {
949 // No point choosing a rotation if the display is not enabled.
950 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
951 return false;
952 }
953
954 final int oldRotation = mRotation;
955 final int lastOrientation = mLastOrientation;
956 final boolean oldAltOrientation = mAltOrientation;
957 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700958 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700959 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700960
Robert Carr0e007272017-10-02 13:00:55 -0700961 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700962 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
963 if (seamlessRotated != null) {
964 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
965 // to complete (that is, waiting for windows to redraw). It's tempting to check
966 // w.mSeamlessRotationCount but that could be incorrect in the case of
967 // window-removal.
968 return false;
969 }
Robert Carr0e007272017-10-02 13:00:55 -0700970
971 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700972 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700973 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700974 mayRotateSeamlessly = false;
975 }
976 for (int i = 0; i < mService.mSessions.size(); i++) {
977 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
978 mayRotateSeamlessly = false;
979 break;
980 }
981 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700982 }
Robert Carr0e007272017-10-02 13:00:55 -0700983 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700984
985 // TODO: Implement forced rotation changes.
986 // Set mAltOrientation to indicate that the application is receiving
987 // an orientation that has different metrics than it expected.
988 // eg. Portrait instead of Landscape.
989
990 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
991 lastOrientation, rotation);
992
993 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
994 + ", got rotation " + rotation + " which has "
995 + (altOrientation ? "incompatible" : "compatible") + " metrics");
996
997 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
998 // No change.
999 return false;
1000 }
1001
1002 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1003 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1004 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1005
1006 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1007 mService.mWaitingForConfig = true;
1008 }
1009
1010 mRotation = rotation;
1011 mAltOrientation = altOrientation;
1012 if (isDefaultDisplay) {
1013 mService.mPolicy.setRotationLw(rotation);
1014 }
1015
1016 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1017 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1018 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1019 WINDOW_FREEZE_TIMEOUT_DURATION);
1020
1021 setLayoutNeeded();
1022 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001023 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001024
1025 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001026 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001027 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1028 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1029 mDisplayId);
1030 } else {
1031 // The screen rotation animation uses a screenshot to freeze the screen
1032 // while windows resize underneath.
1033 // When we are rotating seamlessly, we allow the elements to transition
1034 // to their rotated state independently and without a freeze required.
1035 screenRotationAnimation = null;
1036
1037 // We have to reset this in case a window was removed before it
1038 // finished seamless rotation.
1039 mService.mSeamlessRotationCount = 0;
1040 }
1041
1042 // We need to update our screen size information to match the new rotation. If the rotation
1043 // has actually changed then this method will return true and, according to the comment at
1044 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1045 // By updating the Display info here it will be available to
1046 // #computeScreenConfiguration() later.
1047 updateDisplayAndOrientation(getConfiguration().uiMode);
1048
1049 if (!inTransaction) {
1050 if (SHOW_TRANSACTIONS) {
1051 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1052 }
1053 mService.openSurfaceTransaction();
1054 }
1055 try {
1056 // NOTE: We disable the rotation in the emulator because
1057 // it doesn't support hardware OpenGL emulation yet.
1058 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1059 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001060 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001061 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1062 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1063 mService.scheduleAnimationLocked();
1064 }
1065 }
1066
1067 if (rotateSeamlessly) {
1068 forAllWindows(w -> {
1069 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1070 }, true /* traverseTopToBottom */);
1071 }
1072
1073 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1074 } finally {
1075 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001076 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001077 if (SHOW_LIGHT_TRANSACTIONS) {
1078 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1079 }
1080 }
1081 }
1082
1083 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001084 if (w.mHasSurface && !rotateSeamlessly) {
1085 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001086 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001087 mService.mRoot.mOrientationChangeComplete = false;
1088 w.mLastFreezeDuration = 0;
1089 }
1090 w.mReportOrientationChanged = true;
1091 }, true /* traverseTopToBottom */);
1092
1093 if (rotateSeamlessly) {
1094 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1095 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1096 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1097 }
1098
1099 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1100 final WindowManagerService.RotationWatcher rotationWatcher
1101 = mService.mRotationWatchers.get(i);
1102 if (rotationWatcher.mDisplayId == mDisplayId) {
1103 try {
1104 rotationWatcher.mWatcher.onRotationChanged(rotation);
1105 } catch (RemoteException e) {
1106 // Ignore
1107 }
1108 }
1109 }
1110
1111 // TODO (multi-display): Magnification is supported only for the default display.
1112 // Announce rotation only if we will not animate as we already have the
1113 // windows in final state. Otherwise, we make this call at the rotation end.
1114 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1115 && isDefaultDisplay) {
1116 mService.mAccessibilityController.onRotationChangedLocked(this);
1117 }
1118
1119 return true;
1120 }
1121
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001122 void configureDisplayPolicy() {
1123 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1124 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1125
1126 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
1127 }
1128
Andrii Kulian06d07d62017-03-14 11:11:47 -07001129 /**
1130 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1131 * changed.
1132 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1133 */
1134 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1135 // Use the effective "visual" dimensions based on current rotation
1136 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1137 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1138 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1139 int dw = realdw;
1140 int dh = realdh;
1141
1142 if (mAltOrientation) {
1143 if (realdw > realdh) {
1144 // Turn landscape into portrait.
1145 int maxw = (int)(realdh/1.3f);
1146 if (maxw < realdw) {
1147 dw = maxw;
1148 }
1149 } else {
1150 // Turn portrait into landscape.
1151 int maxh = (int)(realdw/1.3f);
1152 if (maxh < realdh) {
1153 dh = maxh;
1154 }
1155 }
1156 }
1157
1158 // Update application display metrics.
Adrian Roos11c25582018-02-19 18:06:36 +01001159 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1160 mRotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001161 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001162 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001163 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001164 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001165 mDisplayInfo.rotation = mRotation;
1166 mDisplayInfo.logicalWidth = dw;
1167 mDisplayInfo.logicalHeight = dh;
1168 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1169 mDisplayInfo.appWidth = appWidth;
1170 mDisplayInfo.appHeight = appHeight;
1171 if (isDefaultDisplay) {
1172 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1173 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1174 }
Adrian Roos11c25582018-02-19 18:06:36 +01001175 mDisplayInfo.displayCutout = displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001176 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1177 if (mDisplayScalingDisabled) {
1178 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1179 } else {
1180 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1181 }
1182
1183 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1184 mDisplayInfo);
1185
1186 mBaseDisplayRect.set(0, 0, dw, dh);
1187
1188 if (isDefaultDisplay) {
1189 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1190 mCompatDisplayMetrics);
1191 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001192
1193 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001194 return mDisplayInfo;
1195 }
1196
Adrian Roos11c25582018-02-19 18:06:36 +01001197 DisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001198 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1199 }
1200
1201 private DisplayCutout calculateDisplayCutoutForRotationUncached(
1202 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001203 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos1cf585052018-01-03 18:43:27 +01001204 return cutout;
1205 }
Adrian Roos11c25582018-02-19 18:06:36 +01001206 if (rotation == ROTATION_0) {
Adrian Roos24264212018-02-19 16:26:15 +01001207 return cutout.computeSafeInsets(mInitialDisplayWidth, mInitialDisplayHeight);
1208 }
Adrian Roos11c25582018-02-19 18:06:36 +01001209 final boolean rotated = (rotation == ROTATION_90 || mRotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001210 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001211 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1212 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001213 bounds.transform(mTmpMatrix);
Adrian Roos24264212018-02-19 16:26:15 +01001214 return DisplayCutout.fromBounds(bounds).computeSafeInsets(
1215 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1216 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001217 }
1218
Andrii Kulian06d07d62017-03-14 11:11:47 -07001219 /**
1220 * Compute display configuration based on display properties and policy settings.
1221 * Do not call if mDisplayReady == false.
1222 */
1223 void computeScreenConfiguration(Configuration config) {
1224 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1225
1226 final int dw = displayInfo.logicalWidth;
1227 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001228 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1229 // TODO: Probably best to set this based on some setting in the display content object,
1230 // so the display can be configured for things like fullscreen.
1231 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001232
Adrian Roos11c25582018-02-19 18:06:36 +01001233 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001234 config.screenWidthDp =
1235 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001236 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001237 config.screenHeightDp =
1238 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001239 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001240
Adrian Roos11c25582018-02-19 18:06:36 +01001241 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1242 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001243 final int leftInset = mTmpRect.left;
1244 final int topInset = mTmpRect.top;
1245 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001246 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1247 leftInset + displayInfo.appWidth /* right */,
1248 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001249 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1250 || displayInfo.rotation == Surface.ROTATION_270);
1251
1252 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001253 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001254
1255 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1256 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1257 ? Configuration.SCREENLAYOUT_ROUND_YES
1258 : Configuration.SCREENLAYOUT_ROUND_NO);
1259
1260 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1261 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1262 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1263 dh, mDisplayId);
1264 config.densityDpi = displayInfo.logicalDensityDpi;
1265
1266 config.colorMode =
1267 (displayInfo.isHdr()
1268 ? Configuration.COLOR_MODE_HDR_YES
1269 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001270 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001271 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1272 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1273
1274 // Update the configuration based on available input devices, lid switch,
1275 // and platform configuration.
1276 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1277 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1278 config.navigation = Configuration.NAVIGATION_NONAV;
1279
1280 int keyboardPresence = 0;
1281 int navigationPresence = 0;
1282 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1283 final int len = devices != null ? devices.length : 0;
1284 for (int i = 0; i < len; i++) {
1285 InputDevice device = devices[i];
1286 if (!device.isVirtual()) {
1287 final int sources = device.getSources();
1288 final int presenceFlag = device.isExternal() ?
1289 WindowManagerPolicy.PRESENCE_EXTERNAL :
1290 WindowManagerPolicy.PRESENCE_INTERNAL;
1291
1292 // TODO(multi-display): Configure on per-display basis.
1293 if (mService.mIsTouchDevice) {
1294 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1295 InputDevice.SOURCE_TOUCHSCREEN) {
1296 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1297 }
1298 } else {
1299 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1300 }
1301
1302 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1303 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1304 navigationPresence |= presenceFlag;
1305 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1306 && config.navigation == Configuration.NAVIGATION_NONAV) {
1307 config.navigation = Configuration.NAVIGATION_DPAD;
1308 navigationPresence |= presenceFlag;
1309 }
1310
1311 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1312 config.keyboard = Configuration.KEYBOARD_QWERTY;
1313 keyboardPresence |= presenceFlag;
1314 }
1315 }
1316 }
1317
1318 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1319 config.navigation = Configuration.NAVIGATION_DPAD;
1320 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1321 }
1322
1323 // Determine whether a hard keyboard is available and enabled.
1324 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1325 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1326 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1327 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1328 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1329 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1330 }
1331
1332 // Let the policy update hidden states.
1333 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1334 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1335 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1336 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1337 }
1338
1339 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1340 int displayId) {
1341 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1342 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1343 final int unrotDw, unrotDh;
1344 if (rotated) {
1345 unrotDw = dh;
1346 unrotDh = dw;
1347 } else {
1348 unrotDw = dw;
1349 unrotDh = dh;
1350 }
1351 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1352 displayId);
1353 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1354 displayId);
1355 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1356 displayId);
1357 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1358 displayId);
1359 return sw;
1360 }
1361
1362 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1363 DisplayMetrics dm, int dw, int dh, int displayId) {
1364 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001365 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001366 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001367 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001368 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1369 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1370 if (curSize == 0 || size < curSize) {
1371 curSize = size;
1372 }
1373 return curSize;
1374 }
1375
1376 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1377 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1378
1379 // We need to determine the smallest width that will occur under normal
1380 // operation. To this, start with the base screen size and compute the
1381 // width under the different possible rotations. We need to un-rotate
1382 // the current screen dimensions before doing this.
1383 int unrotDw, unrotDh;
1384 if (rotated) {
1385 unrotDw = dh;
1386 unrotDh = dw;
1387 } else {
1388 unrotDw = dw;
1389 unrotDh = dh;
1390 }
1391 displayInfo.smallestNominalAppWidth = 1<<30;
1392 displayInfo.smallestNominalAppHeight = 1<<30;
1393 displayInfo.largestNominalAppWidth = 0;
1394 displayInfo.largestNominalAppHeight = 0;
1395 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1396 unrotDh);
1397 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1398 unrotDw);
1399 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1400 unrotDh);
1401 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1402 unrotDw);
1403 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1404 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1405 displayId);
1406 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1407 displayId);
1408 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1409 displayId);
1410 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1411 displayId);
1412 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1413 outConfig.screenLayout = sl;
1414 }
1415
1416 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1417 int uiMode, int displayId) {
1418 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001419 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1420 mDisplayInfo.displayCutout);
1421 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1422 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001423
1424 // Compute the screen layout size class for this rotation.
1425 int longSize = w;
1426 int shortSize = h;
1427 if (longSize < shortSize) {
1428 int tmp = longSize;
1429 longSize = shortSize;
1430 shortSize = tmp;
1431 }
1432 longSize = (int)(longSize/density);
1433 shortSize = (int)(shortSize/density);
1434 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1435 }
1436
1437 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1438 int uiMode, int dw, int dh) {
Adrian Roos11c25582018-02-19 18:06:36 +01001439 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001440 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001441 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001442 if (width < displayInfo.smallestNominalAppWidth) {
1443 displayInfo.smallestNominalAppWidth = width;
1444 }
1445 if (width > displayInfo.largestNominalAppWidth) {
1446 displayInfo.largestNominalAppWidth = width;
1447 }
1448 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001449 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001450 if (height < displayInfo.smallestNominalAppHeight) {
1451 displayInfo.smallestNominalAppHeight = height;
1452 }
1453 if (height > displayInfo.largestNominalAppHeight) {
1454 displayInfo.largestNominalAppHeight = height;
1455 }
1456 }
1457
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001458 DockedStackDividerController getDockedDividerController() {
1459 return mDividerControllerLocked;
1460 }
1461
Winson Chung655332c2016-10-31 13:14:28 -07001462 PinnedStackController getPinnedStackController() {
1463 return mPinnedStackControllerLocked;
1464 }
1465
Jeff Browna506a6e2013-06-04 00:02:38 -07001466 /**
1467 * Returns true if the specified UID has access to this display.
1468 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001469 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001470 return mDisplay.hasAccess(uid);
1471 }
1472
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001473 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001474 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001475 }
1476
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001477 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001478 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001479 }
1480
Wale Ogunwale61911492017-10-11 08:50:50 -07001481 /**
1482 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1483 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001484 TaskStack getSplitScreenPrimaryStack() {
1485 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001486 return (stack != null && stack.isVisible()) ? stack : null;
1487 }
1488
1489 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001490 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001491 * not visible.
1492 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001493 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1494 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001495 }
1496
1497 TaskStack getPinnedStack() {
1498 return mTaskStackContainers.getPinnedStack();
1499 }
1500
1501 private boolean hasPinnedStack() {
1502 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001503 }
1504
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001505 /**
1506 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1507 * Null is no compatible stack on the display.
1508 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001509 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001510 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1511 }
1512
1513 /**
1514 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1515 * activity type. Null is no compatible stack on the display.
1516 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001517 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001518 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001519 }
1520
Bryce Lee48f4b572017-04-10 10:54:15 -07001521 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001522 TaskStack getTopStack() {
1523 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001524 }
1525
Winson Chunge2d72172018-01-25 17:46:20 +00001526 ArrayList<Task> getVisibleTasks() {
1527 return mTaskStackContainers.getVisibleTasks();
1528 }
1529
Wale Ogunwale61911492017-10-11 08:50:50 -07001530 void onStackWindowingModeChanged(TaskStack stack) {
1531 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001532 }
1533
Andrii Kulian441e4492016-09-29 15:25:00 -07001534 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001535 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001536 super.onConfigurationChanged(newParentConfig);
1537
Andrii Kulian3a507b52016-09-19 18:14:12 -07001538 // The display size information is heavily dependent on the resources in the current
1539 // configuration, so we need to reconfigure it every time the configuration changes.
1540 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1541 mService.reconfigureDisplayLocked(this);
1542
Bryce Leef3c6a472017-11-14 14:53:06 -08001543 final DockedStackDividerController dividerController = getDockedDividerController();
1544
1545 if (dividerController != null) {
1546 getDockedDividerController().onConfigurationChanged();
1547 }
1548
1549 final PinnedStackController pinnedStackController = getPinnedStackController();
1550
1551 if (pinnedStackController != null) {
1552 getPinnedStackController().onConfigurationChanged();
1553 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001554 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001555
Andrii Kulian441e4492016-09-29 15:25:00 -07001556 /**
1557 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1558 * bounds were updated.
1559 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001560 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001561 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1562 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001563 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001564 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001565 }
1566 }
Winson Chung32c566f2017-04-11 18:31:21 -07001567
1568 // If there was no pinned stack, we still need to notify the controller of the display info
1569 // update as a result of the config change. We do this here to consolidate the flow between
1570 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001571 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001572 mPinnedStackControllerLocked.onDisplayInfoChanged();
1573 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001574 }
1575
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001576 @Override
1577 boolean fillsParent() {
1578 return true;
1579 }
1580
1581 @Override
1582 boolean isVisible() {
1583 return true;
1584 }
1585
1586 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001587 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001588 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001589 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001590 }
1591
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001592 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001593 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1594 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1595 // target, or here in order if there isn't an IME target.
1596 if (traverseTopToBottom) {
1597 for (int i = mChildren.size() - 1; i >= 0; --i) {
1598 final DisplayChildWindowContainer child = mChildren.get(i);
1599 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1600 // In this case the Ime windows will be processed above their target so we skip
1601 // here.
1602 continue;
1603 }
1604 if (child.forAllWindows(callback, traverseTopToBottom)) {
1605 return true;
1606 }
1607 }
1608 } else {
1609 final int count = mChildren.size();
1610 for (int i = 0; i < count; i++) {
1611 final DisplayChildWindowContainer child = mChildren.get(i);
1612 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1613 // In this case the Ime windows will be processed above their target so we skip
1614 // here.
1615 continue;
1616 }
1617 if (child.forAllWindows(callback, traverseTopToBottom)) {
1618 return true;
1619 }
1620 }
1621 }
1622 return false;
1623 }
1624
1625 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1626 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1627 }
1628
Wale Ogunwale399c8692017-05-08 14:22:42 -07001629 @Override
1630 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001631 final WindowManagerPolicy policy = mService.mPolicy;
1632
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001633 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001634 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001635 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001636 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001637 // If the display is frozen, some activities may be in the middle of restarting, and
1638 // thus have removed their old window. If the window has the flag to hide the lock
1639 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1640 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001641 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001642 } else if (policy.isKeyguardLocked()) {
1643 // Use the last orientation the while the display is frozen with the keyguard
1644 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1645 // window. We don't want to check the show when locked window directly though as
1646 // things aren't stable while the display is frozen, for example the window could be
1647 // momentarily unavailable due to activity relaunch.
1648 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001649 + "return " + mLastOrientation);
1650 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001651 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001652 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001653 final int orientation = mAboveAppWindowsContainers.getOrientation();
1654 if (orientation != SCREEN_ORIENTATION_UNSET) {
1655 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001656 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001657 }
1658
Wale Ogunwale399c8692017-05-08 14:22:42 -07001659 // Top system windows are not requesting an orientation. Start searching from apps.
1660 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001661 }
1662
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001663 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001664 // Check if display metrics changed and update base values if needed.
1665 updateBaseDisplayMetricsIfNeeded();
1666
Craig Mautner722285e2012-09-07 13:55:58 -07001667 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001668 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001669
Wale Ogunwale61911492017-10-11 08:50:50 -07001670 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1671 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001672 }
Craig Mautner722285e2012-09-07 13:55:58 -07001673 }
1674
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001675 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001676 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1677 if (displayManagerInternal != null) {
1678 // Bootstrap the default logical display from the display manager.
1679 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1680 if (newDisplayInfo != null) {
1681 mDisplayInfo.copyFrom(newDisplayInfo);
1682 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001683 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001684
Andrii Kuliancd097992017-03-23 18:31:59 -07001685 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1686 mDisplayInfo.logicalDensityDpi);
1687 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1688 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1689 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001690 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001691 }
1692
Andrii Kuliancd097992017-03-23 18:31:59 -07001693 /**
1694 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1695 * values.
1696 */
1697 private void updateBaseDisplayMetricsIfNeeded() {
1698 // Get real display metrics without overrides from WM.
1699 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1700 final int orientation = mDisplayInfo.rotation;
1701 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1702 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1703 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1704 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001705 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001706
1707 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1708 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001709 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1710 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001711
1712 if (displayMetricsChanged) {
1713 // Check if display size or density is forced.
1714 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1715 || mBaseDisplayHeight != mInitialDisplayHeight;
1716 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1717
1718 // If there is an override set for base values - use it, otherwise use new values.
1719 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1720 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1721 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1722
1723 // Real display metrics changed, so we should also update initial values.
1724 mInitialDisplayWidth = newWidth;
1725 mInitialDisplayHeight = newHeight;
1726 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001727 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001728 mService.reconfigureDisplayLocked(this);
1729 }
1730 }
1731
Bryce Lee27cec322017-03-21 09:41:37 -07001732 /** Sets the maximum width the screen resolution can be */
1733 void setMaxUiWidth(int width) {
1734 if (DEBUG_DISPLAY) {
1735 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1736 }
1737
1738 mMaxUiWidth = width;
1739
1740 // Update existing metrics.
1741 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1742 }
1743
1744 /** Update base (override) display metrics. */
1745 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1746 mBaseDisplayWidth = baseWidth;
1747 mBaseDisplayHeight = baseHeight;
1748 mBaseDisplayDensity = baseDensity;
1749
1750 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1751 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1752 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1753 mBaseDisplayWidth = mMaxUiWidth;
1754
1755 if (DEBUG_DISPLAY) {
1756 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1757 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1758 + " on display:" + getDisplayId());
1759 }
1760 }
1761
1762 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001763
1764 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001765 }
1766
Wale Ogunwaledb506192017-12-08 10:57:32 -08001767 void getStableRect(Rect out) {
1768 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001769 }
1770
Wale Ogunwale61911492017-10-11 08:50:50 -07001771 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001772 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1773 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001774
Wale Ogunwale61911492017-10-11 08:50:50 -07001775 final TaskStack stack = new TaskStack(mService, stackId, controller);
1776 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001777 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001778 }
1779
Andrii Kulian51c1b672017-04-07 18:39:32 -07001780 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001781 final DisplayContent prevDc = stack.getDisplayContent();
1782 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001783 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1784 + " which is not currently attached to any display");
1785 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001786 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001787 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1788 + " to its current displayId=" + mDisplayId);
1789 }
1790
Wale Ogunwale61911492017-10-11 08:50:50 -07001791 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001792 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001793 }
1794
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001795 @Override
1796 protected void addChild(DisplayChildWindowContainer child,
1797 Comparator<DisplayChildWindowContainer> comparator) {
1798 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1799 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001800
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001801 @Override
1802 protected void addChild(DisplayChildWindowContainer child, int index) {
1803 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1804 }
1805
1806 @Override
1807 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001808 // Only allow removal of direct children from this display if the display is in the process
1809 // of been removed.
1810 if (mRemovingDisplay) {
1811 super.removeChild(child);
1812 return;
1813 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001814 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001815 }
1816
Andrii Kuliand2765632016-12-12 22:26:34 -08001817 @Override
1818 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1819 // Children of the display are statically ordered, so the real intention here is to perform
1820 // the operation on the display and not the static direct children.
1821 getParent().positionChildAt(position, this, includingParents);
1822 }
1823
Winson Chung59a47ded2018-01-25 17:46:06 +00001824 void positionStackAt(int position, TaskStack child) {
1825 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1826 layoutAndAssignWindowLayersIfNeeded();
1827 }
1828
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001829 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001830 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1831 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001832 final int taskId = stack.taskIdFromPoint(x, y);
1833 if (taskId != -1) {
1834 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001835 }
1836 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001837 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001838 }
1839
Chong Zhang8e89b312015-09-09 15:09:30 -07001840 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001841 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001842 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001843 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001844 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001845 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001846 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001847 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1848 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001849 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001850 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001851 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001852
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001853 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1854 if (mTmpTaskForResizePointSearchResult.searchDone) {
1855 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001856 }
1857 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001858 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001859 }
1860
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001861 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001862 // The provided task is the task on this display with focus, so if WindowManagerService's
1863 // focused app is not on this display, focusedTask will be null.
1864 if (focusedTask == null) {
1865 mTouchExcludeRegion.setEmpty();
1866 } else {
1867 mTouchExcludeRegion.set(mBaseDisplayRect);
1868 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1869 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001870 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1871 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001872 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1873 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001874 }
1875 // If we removed the focused task above, add it back and only leave its
1876 // outside touch area in the exclusion. TapDectector is not interested in
1877 // any touch inside the focused task itself.
1878 if (!mTmpRect2.isEmpty()) {
1879 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1880 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001881 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001882 final WindowState inputMethod = mService.mInputMethodWindow;
1883 if (inputMethod != null && inputMethod.isVisibleLw()) {
1884 // If the input method is visible and the user is typing, we don't want these touch
1885 // events to be intercepted and used to change focus. This would likely cause a
1886 // disappearance of the input method.
1887 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001888 if (inputMethod.getDisplayId() == mDisplayId) {
1889 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1890 } else {
1891 // IME is on a different display, so we need to update its tap detector.
1892 // TODO(multidisplay): Remove when IME will always appear on same display.
1893 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1894 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001895 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001896 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001897 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001898 win.getTouchableRegion(mTmpRegion);
1899 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1900 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001901 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1902 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1903 win.amendTapExcludeRegion(mTouchExcludeRegion);
1904 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001905 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001906 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001907 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001908 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001909 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1910 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001911 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001912 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001913 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001914 }
1915
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001916 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001917 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001918 super.switchUser();
1919 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001920 }
1921
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001922 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001923 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1924 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001925 }
1926 }
1927
Wale Ogunwale10124582016-09-15 20:25:50 -07001928 @Override
1929 void removeIfPossible() {
1930 if (isAnimating()) {
1931 mDeferredRemoval = true;
1932 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001933 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001934 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001935 }
1936
Wale Ogunwale10124582016-09-15 20:25:50 -07001937 @Override
1938 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001939 mRemovingDisplay = true;
1940 try {
1941 super.removeImmediately();
1942 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001943 if (mService.canDispatchPointerEvents()) {
1944 if (mTapDetector != null) {
1945 mService.unregisterPointerEventListener(mTapDetector);
1946 }
1947 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1948 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1949 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001950 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001951 mService.mAnimator.removeDisplayLocked(mDisplayId);
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001952 } finally {
1953 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001954 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001955
1956 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001957 }
1958
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001959 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001960 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001961 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001962 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1963
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001964 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001965 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001966 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001967 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001968 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001969 }
1970
Andrii Kulian0214ed92017-05-16 13:44:05 -07001971 /** @return 'true' if removal of this display content is deferred due to active animation. */
1972 boolean isRemovalDeferred() {
1973 return mDeferredRemoval;
1974 }
1975
Wale Ogunwale10124582016-09-15 20:25:50 -07001976 boolean animateForIme(float interpolatedValue, float animationTarget,
1977 float dividerAnimationTarget) {
1978 boolean updated = false;
1979
Wale Ogunwale61911492017-10-11 08:50:50 -07001980 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1981 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001982 if (stack == null || !stack.isAdjustedForIme()) {
1983 continue;
1984 }
1985
1986 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1987 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1988 updated = true;
1989 } else {
1990 mDividerControllerLocked.mLastAnimationProgress =
1991 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
1992 mDividerControllerLocked.mLastDividerProgress =
1993 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
1994 updated |= stack.updateAdjustForIme(
1995 mDividerControllerLocked.mLastAnimationProgress,
1996 mDividerControllerLocked.mLastDividerProgress,
1997 false /* force */);
1998 }
1999 if (interpolatedValue >= 1f) {
2000 stack.endImeAdjustAnimation();
2001 }
2002 }
2003
2004 return updated;
2005 }
2006
2007 boolean clearImeAdjustAnimation() {
2008 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002009 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2010 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002011 if (stack != null && stack.isAdjustedForIme()) {
2012 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2013 changed = true;
2014 }
2015 }
2016 return changed;
2017 }
2018
2019 void beginImeAdjustAnimation() {
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.isVisible() && stack.isAdjustedForIme()) {
2023 stack.beginImeAdjustAnimation();
2024 }
2025 }
2026 }
2027
2028 void adjustForImeIfNeeded() {
2029 final WindowState imeWin = mService.mInputMethodWindow;
2030 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2031 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002032 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002033 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2034 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2035 imeTargetStack.getDockSide() : DOCKED_INVALID;
2036 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2037 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2038 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002039 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002040 final boolean imeHeightChanged = imeVisible &&
2041 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2042
2043 // The divider could be adjusted for IME position, or be thinner than usual,
2044 // or both. There are three possible cases:
2045 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2046 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2047 // - If IME is not visible, divider is not moved and is normal width.
2048
2049 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002050 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2051 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002052 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002053 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2054 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002055 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2056 } else {
2057 stack.resetAdjustedForIme(false);
2058 }
2059 }
2060 mDividerControllerLocked.setAdjustedForIme(
2061 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2062 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002063 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2064 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002065 stack.resetAdjustedForIme(!dockVisible);
2066 }
2067 mDividerControllerLocked.setAdjustedForIme(
2068 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2069 }
Winson Chung655332c2016-10-31 13:14:28 -07002070 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002071 }
2072
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002073 /**
2074 * If a window that has an animation specifying a colored background and the current wallpaper
2075 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2076 * suddenly disappear.
2077 */
2078 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002079 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2080 w -> w.mIsWallpaper && w.isVisibleNow());
2081
2082 if (visibleWallpaper != null) {
2083 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002084 }
2085 return winAnimator.mAnimLayer;
2086 }
2087
Wale Ogunwale10124582016-09-15 20:25:50 -07002088 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002089 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2090 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002091 stack.prepareFreezingTaskBounds();
2092 }
2093 }
2094
Wale Ogunwale94744212015-09-21 19:01:47 -07002095 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002096 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002097
2098 // Compute a transform matrix to undo the coordinate space transformation,
2099 // and present the window at the same physical position it previously occupied.
2100 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2101 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2102
2103 mTmpRectF.set(bounds);
2104 mTmpMatrix.mapRect(mTmpRectF);
2105 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002106 }
2107
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002108 static int deltaRotation(int oldRotation, int newRotation) {
2109 int delta = newRotation - oldRotation;
2110 if (delta < 0) delta += 4;
2111 return delta;
2112 }
2113
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002114 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002115 Matrix outMatrix) {
2116 // For rotations without Z-ordering we don't need the target rectangle's position.
2117 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2118 displayHeight, outMatrix);
2119 }
2120
2121 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2122 float displayWidth, float displayHeight, Matrix outMatrix) {
2123 switch (rotation) {
2124 case ROTATION_0:
2125 outMatrix.reset();
2126 break;
2127 case ROTATION_270:
2128 outMatrix.setRotate(270, 0, 0);
2129 outMatrix.postTranslate(0, displayHeight);
2130 outMatrix.postTranslate(rectTop, 0);
2131 break;
2132 case ROTATION_180:
2133 outMatrix.reset();
2134 break;
2135 case ROTATION_90:
2136 outMatrix.setRotate(90, 0, 0);
2137 outMatrix.postTranslate(displayWidth, 0);
2138 outMatrix.postTranslate(-rectTop, rectLeft);
2139 break;
2140 }
2141 }
2142
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002143 @CallSuper
2144 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002145 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002146 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002147 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002148 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002149 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2150 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002151 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002152 }
2153 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2154 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002155 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2156 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002157 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002158 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002159 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2160 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002161 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002162 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002163 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2164 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002165 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002166 }
2167 proto.write(DPI, mBaseDisplayDensity);
2168 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002169 proto.write(ROTATION, mRotation);
2170 final ScreenRotationAnimation screenRotationAnimation =
2171 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2172 if (screenRotationAnimation != null) {
2173 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2174 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002175 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002176 proto.end(token);
2177 }
2178
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002179 @Override
2180 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2181 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002182 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2183 final String subPrefix = " " + prefix;
2184 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2185 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2186 pw.print("dpi");
2187 if (mInitialDisplayWidth != mBaseDisplayWidth
2188 || mInitialDisplayHeight != mBaseDisplayHeight
2189 || mInitialDisplayDensity != mBaseDisplayDensity) {
2190 pw.print(" base=");
2191 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2192 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2193 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002194 if (mDisplayScalingDisabled) {
2195 pw.println(" noscale");
2196 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002197 pw.print(" cur=");
2198 pw.print(mDisplayInfo.logicalWidth);
2199 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2200 pw.print(" app=");
2201 pw.print(mDisplayInfo.appWidth);
2202 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2203 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2204 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2205 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2206 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002207 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002208 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002209 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002210
Craig Mautnerdc548482014-02-05 13:35:24 -08002211 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002212 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002213 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2214 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002215 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002216 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002217
Craig Mautnerdc548482014-02-05 13:35:24 -08002218 pw.println();
2219 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002220 pw.println();
2221 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002222 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002223 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002224 pw.print(" Exiting #"); pw.print(i);
2225 pw.print(' '); pw.print(token);
2226 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002227 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002228 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002229 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002230
Jorim Jaggi31f71702016-05-04 16:43:04 -07002231 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002232
2233 // Dump stack references
2234 final TaskStack homeStack = getHomeStack();
2235 if (homeStack != null) {
2236 pw.println(prefix + "homeStack=" + homeStack.getName());
2237 }
2238 final TaskStack pinnedStack = getPinnedStack();
2239 if (pinnedStack != null) {
2240 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2241 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002242 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002243 if (splitScreenPrimaryStack != null) {
2244 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2245 }
2246
2247 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002248 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002249 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002250 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002251
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002252 pw.println();
2253 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002254 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002255
2256 @Override
2257 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002258 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002259 }
2260
2261 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002262 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002263 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002264
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002265 /** Returns true if the stack in the windowing mode is visible. */
2266 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002267 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002268 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002269 }
2270
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002271 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002272 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002273 final int x = (int) xf;
2274 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002275 final WindowState touchedWin = getWindow(w -> {
2276 final int flags = w.mAttrs.flags;
2277 if (!w.isVisibleLw()) {
2278 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002279 }
2280 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002281 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002282 }
2283
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002284 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002285 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002286 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002287 }
2288
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002289 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002290
2291 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002292 return mTmpRegion.contains(x, y) || touchFlags == 0;
2293 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002294
2295 return touchedWin;
2296 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002297
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002298 boolean canAddToastWindowForUid(int uid) {
2299 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002300 // Also if the app is focused adding more than one toast at
2301 // a time for better backwards compatibility.
2302 final WindowState focusedWindowForUid = getWindow(w ->
2303 w.mOwnerUid == uid && w.isFocused());
2304 if (focusedWindowForUid != null) {
2305 return true;
2306 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002307 final WindowState win = getWindow(w ->
2308 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2309 && !w.mWindowRemovalAllowed);
2310 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002311 }
2312
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002313 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002314 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2315 return;
2316 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002317
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002318 // Used to communicate the old focus to the callback method.
2319 mTmpWindow = oldFocus;
2320
2321 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002322 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002323
2324 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002325 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002326
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002327 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002328
2329 if (mTmpWindow == null) {
2330 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2331 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002332 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002333 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002334 }
2335
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002336 /** Updates the layer assignment of windows on this display. */
2337 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002338 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002339 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002340 if (setLayoutNeeded) {
2341 setLayoutNeeded();
2342 }
Robert Carrb1579c82017-09-05 14:54:47 -07002343
Robert Carrf59b8dd2017-10-02 18:58:36 -07002344 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002345 // the application of this transaction until the animation pass triggers
2346 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2347 // the hiding and showing of surfaces.
2348 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002349 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002350 }
2351
Wale Ogunwale1666e312016-12-16 11:27:18 -08002352 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2353 // moving containers or resizing them. Need to investigate the best way to have it automatically
2354 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002355 void layoutAndAssignWindowLayersIfNeeded() {
2356 mService.mWindowsChanged = true;
2357 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002358
2359 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2360 false /*updateInputWindows*/)) {
2361 assignWindowLayers(false /* setLayoutNeeded */);
2362 }
2363
2364 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2365 mService.mWindowPlacerLocked.performSurfacePlacement();
2366 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2367 }
2368
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002369 /** Returns true if a leaked surface was destroyed */
2370 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002371 // Used to indicate that a surface was leaked.
2372 mTmpWindow = null;
2373 forAllWindows(w -> {
2374 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002375 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002376 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002377 }
2378 if (!mService.mSessions.contains(wsa.mSession)) {
2379 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002380 + w + " surface=" + wsa.mSurfaceController
2381 + " token=" + w.mToken
2382 + " pid=" + w.mSession.mPid
2383 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002384 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002385 mService.mForceRemoves.add(w);
2386 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002387 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002388 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002389 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002390 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002391 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002392 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002393 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002394 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002395 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002396
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002397 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002398 }
2399
2400 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002401 * Determine and return the window that should be the IME target.
2402 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2403 * @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 +00002404 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002405 WindowState computeImeTarget(boolean updateImeTarget) {
2406 if (mService.mInputMethodWindow == null) {
2407 // There isn't an IME so there shouldn't be a target...That was easy!
2408 if (updateImeTarget) {
2409 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2410 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002411 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002412 }
2413 return null;
2414 }
2415
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002416 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2417 // same display. Or even when the current IME/target are not on the same screen as the next
2418 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002419 mUpdateImeTarget = updateImeTarget;
2420 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002421
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002422
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002423 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2424 // to be on top of it, but it is not -really- where input will go. So look down below
2425 // for a real window to target...
2426 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2427 final AppWindowToken token = target.mAppToken;
2428 if (token != null) {
2429 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2430 if (betterTarget != null) {
2431 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002432 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002433 }
2434 }
2435
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002436 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2437 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002438
2439 // Now, a special case -- if the last target's window is in the process of exiting, and is
2440 // above the new target, keep on the last target to avoid flicker. Consider for example a
2441 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2442 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2443 // scrim.
2444 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002445 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2446 && (target == null
2447 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002448 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002449 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002450 }
2451
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002452 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2453 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002454
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002455 if (target == null) {
2456 if (updateImeTarget) {
2457 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2458 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2459 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002460 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002461 }
2462
2463 return null;
2464 }
2465
2466 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002467 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2468 if (token != null) {
2469
2470 // Now some fun for dealing with window animations that modify the Z order. We need
2471 // to look at all windows below the current target that are in this app, finding the
2472 // highest visible one in layering.
2473 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002474 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002475 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002476 }
2477
2478 if (highestTarget != null) {
2479 final AppTransition appTransition = mService.mAppTransition;
2480 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2481 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2482 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002483 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002484
2485 if (appTransition.isTransitionSet()) {
2486 // If we are currently setting up for an animation, hold everything until we
2487 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002488 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002489 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002490 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002491 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002492 // If the window we are currently targeting is involved with an animation,
2493 // and it is on top of the next target we will be over, then hold off on
2494 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002495 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002496 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002497 }
2498 }
2499 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002500
2501 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2502 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002503 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002504 }
2505
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002506 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002507 }
2508
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002509 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002510 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002511 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002512 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002513 }
2514
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002515 mService.mInputMethodTarget = target;
2516 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002517 assignWindowLayers(false /* setLayoutNeeded */);
2518 }
2519
2520 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2521 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2522 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2523 }
2524
2525 // Used to indicate we have reached the first window in the range we are interested in.
2526 mTmpWindow = null;
2527
2528 // TODO: Figure-out a more efficient way to do this.
2529 final WindowState candidate = getWindow(w -> {
2530 if (w == top) {
2531 // Reached the first window in the range we are interested in.
2532 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002533 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002534 if (mTmpWindow == null) {
2535 return false;
2536 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002537
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002538 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2539 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002540 }
2541 // If we reached the bottom of the range of windows we are considering,
2542 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002543 if (w == bottom) {
2544 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002545 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002546 return false;
2547 });
2548
2549 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002550 }
2551
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002552 void setLayoutNeeded() {
2553 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2554 mLayoutNeeded = true;
2555 }
2556
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002557 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002558 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2559 mLayoutNeeded = false;
2560 }
2561
2562 boolean isLayoutNeeded() {
2563 return mLayoutNeeded;
2564 }
2565
Wale Ogunwale02319a62016-09-26 15:21:22 -07002566 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2567 if (mTokenMap.isEmpty()) {
2568 return;
2569 }
2570 pw.println(" Display #" + mDisplayId);
2571 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2572 while (it.hasNext()) {
2573 final WindowToken token = it.next();
2574 pw.print(" ");
2575 pw.print(token);
2576 if (dumpAll) {
2577 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002578 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002579 } else {
2580 pw.println();
2581 }
2582 }
2583 }
2584
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002585 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002586 final int[] index = new int[1];
2587 forAllWindows(w -> {
2588 final WindowStateAnimator wAnim = w.mWinAnimator;
2589 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2590 index[0] = index[0] + 1;
2591 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002592 }
2593
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002594 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002595 forAllWindows(w -> {
2596 w.mWinAnimator.enableSurfaceTrace(fd);
2597 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002598 }
2599
2600 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002601 forAllWindows(w -> {
2602 w.mWinAnimator.disableSurfaceTrace();
2603 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002604 }
2605
Jorim Jaggife762342016-10-13 14:33:27 +02002606 /**
2607 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2608 */
2609 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2610 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002611 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002612 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2613 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002614 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002615 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002616 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002617 }
2618
Wale Ogunwale494009b82016-10-21 09:01:38 -07002619 boolean checkWaitingForWindows() {
2620
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002621 mHaveBootMsg = false;
2622 mHaveApp = false;
2623 mHaveWallpaper = false;
2624 mHaveKeyguard = true;
2625
2626 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002627 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2628 return true;
2629 }
2630 if (w.isDrawnLw()) {
2631 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002632 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002633 } else if (w.mAttrs.type == TYPE_APPLICATION
2634 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002635 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002636 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002637 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002638 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002639 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002640 }
2641 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002642 return false;
2643 });
2644
2645 if (visibleWindow != null) {
2646 // We have a visible window.
2647 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002648 }
2649
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002650 // if the wallpaper service is disabled on the device, we're never going to have
2651 // wallpaper, don't bother waiting for it
2652 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2653 com.android.internal.R.bool.config_enableWallpaperService)
2654 && !mService.mOnlyCore;
2655
Wale Ogunwale494009b82016-10-21 09:01:38 -07002656 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2657 "******** booted=" + mService.mSystemBooted
2658 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002659 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2660 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2661 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002662
2663 // If we are turning on the screen to show the boot message, don't do it until the boot
2664 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002665 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002666 return true;
2667 }
2668
2669 // If we are turning on the screen after the boot is completed normally, don't do so until
2670 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002671 if (mService.mSystemBooted
2672 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002673 return true;
2674 }
2675
2676 return false;
2677 }
2678
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002679 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002680 mTmpWindowAnimator = animator;
2681 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002682 }
2683
2684 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002685 resetAnimationBackgroundAnimator();
2686
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002687 // Used to indicate a detached wallpaper.
2688 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002689 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002690
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002691 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002692
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002693 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002694 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002695 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2696 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002697 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2698 }
2699 }
2700
Wale Ogunwale494009b82016-10-21 09:01:38 -07002701 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002702 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002703 if (imFocus == null) {
2704 return false;
2705 }
2706
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002707 if (DEBUG_INPUT_METHOD) {
2708 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2709 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2710 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002711 }
2712
Wale Ogunwale494009b82016-10-21 09:01:38 -07002713 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2714
2715 if (DEBUG_INPUT_METHOD) {
2716 Slog.i(TAG_WM, "IM target client: " + imeClient);
2717 if (imeClient != null) {
2718 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2719 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2720 }
2721 }
2722
2723 return imeClient != null && imeClient.asBinder() == client.asBinder();
2724 }
2725
2726 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002727 final WindowState win = getWindow(
2728 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2729 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002730 }
2731
2732 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002733 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002734 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002735 final int curValue = w.mSystemUiVisibility;
2736 final int diff = (curValue ^ visibility) & globalDiff;
2737 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002738 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002739 w.mSeq++;
2740 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002741 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002742 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2743 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002744 visibility, newValue, diff);
2745 }
2746 } catch (RemoteException e) {
2747 // so sorry
2748 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002749 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002750 }
2751
2752 void onWindowFreezeTimeout() {
2753 Slog.w(TAG_WM, "Window freeze timeout expired.");
2754 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002755
2756 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002757 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002758 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002759 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002760 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002761 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2762 - mService.mDisplayFreezeTime);
2763 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002764 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002765 mService.mWindowPlacerLocked.performSurfacePlacement();
2766 }
2767
2768 void waitForAllWindowsDrawn() {
2769 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002770 forAllWindows(w -> {
2771 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2772 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2773 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002774 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002775 w.mLastContentInsets.set(-1, -1, -1, -1);
2776 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002777 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002778 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002779 }
2780
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002781 // TODO: Super crazy long method that should be broken down...
2782 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2783
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002784 final int dw = mDisplayInfo.logicalWidth;
2785 final int dh = mDisplayInfo.logicalHeight;
2786 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2787
2788 mTmpUpdateAllDrawn.clear();
2789
2790 int repeats = 0;
2791 do {
2792 repeats++;
2793 if (repeats > 6) {
2794 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2795 clearLayoutNeeded();
2796 break;
2797 }
2798
2799 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2800 pendingLayoutChanges);
2801
Andrii Kulian839def92016-11-02 10:58:58 -07002802 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2803 // the wallpaper window jumping across displays.
2804 // Remove check for default display when there will be support for multiple wallpaper
2805 // targets (on different displays).
2806 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002807 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002808 }
2809
2810 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2811 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2812 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2813 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002814 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002815 }
2816 }
2817
2818 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2819 setLayoutNeeded();
2820 }
2821
2822 // FIRST LOOP: Perform a layout, if needed.
2823 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2824 performLayout(repeats == 1, false /* updateInputWindows */);
2825 } else {
2826 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2827 }
2828
2829 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2830 pendingLayoutChanges = 0;
2831
2832 if (isDefaultDisplay) {
2833 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002834 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002835 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2836 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2837 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2838 }
2839 } while (pendingLayoutChanges != 0);
2840
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002841 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002842
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002843 mTmpRecoveringMemory = recoveringMemory;
2844 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002845 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002846
2847 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002848 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2849 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2850 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002851 true /* inTraversal, must call performTraversalInTrans... below */);
2852
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002853 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2854 if (wallpaperVisible != mLastWallpaperVisible) {
2855 mLastWallpaperVisible = wallpaperVisible;
2856 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2857 }
2858
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002859 while (!mTmpUpdateAllDrawn.isEmpty()) {
2860 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2861 // See if any windows have been drawn, so they (and others associated with them)
2862 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002863 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002864 }
2865
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002866 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002867 }
2868
Bryce Leef3c6a472017-11-14 14:53:06 -08002869 private void updateBounds() {
2870 calculateBounds(mTmpBounds);
2871 setBounds(mTmpBounds);
2872 }
2873
2874 // Determines the current display bounds based on the current state
2875 private void calculateBounds(Rect out) {
2876 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2877 final int orientation = mDisplayInfo.rotation;
2878 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2879 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2880 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2881 int width = mDisplayInfo.logicalWidth;
2882 int left = (physWidth - width) / 2;
2883 int height = mDisplayInfo.logicalHeight;
2884 int top = (physHeight - height) / 2;
2885 out.set(left, top, left + width, top + height);
2886 }
2887
2888 @Override
2889 public void getBounds(Rect out) {
2890 calculateBounds(out);
2891 }
2892
2893 private void getBounds(Rect out, int orientation) {
2894 getBounds(out);
2895
2896 // Rotate the Rect if needed.
2897 final int currentRotation = mDisplayInfo.rotation;
2898 final int rotationDelta = deltaRotation(currentRotation, orientation);
2899 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2900 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2901 mTmpRectF.set(out);
2902 mTmpMatrix.mapRect(mTmpRectF);
2903 mTmpRectF.round(out);
2904 }
2905 }
2906
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002907 void performLayout(boolean initial, boolean updateInputWindows) {
2908 if (!isLayoutNeeded()) {
2909 return;
2910 }
2911 clearLayoutNeeded();
2912
2913 final int dw = mDisplayInfo.logicalWidth;
2914 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002915 if (DEBUG_LAYOUT) {
2916 Slog.v(TAG, "-------------------------------------");
2917 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2918 }
2919
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002920 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
2921 // 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
2968 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2969 */
chaviwfbe47df2017-11-10 16:14:49 -08002970 Bitmap screenshotDisplay(Bitmap.Config config, boolean wallpaperOnly) {
2971 synchronized (mService.mWindowMap) {
Jorim Jaggi51304d72017-05-17 17:25:32 +02002972 if (!mService.mPolicy.isScreenOn()) {
chaviwfbe47df2017-11-10 16:14:49 -08002973 if (DEBUG_SCREENSHOT) {
2974 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002975 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002976 return null;
2977 }
2978
chaviwfbe47df2017-11-10 16:14:49 -08002979 if (wallpaperOnly && !shouldScreenshotWallpaper()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002980 return null;
2981 }
2982
chaviwfbe47df2017-11-10 16:14:49 -08002983 int dw = mDisplayInfo.logicalWidth;
2984 int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002985
chaviwfbe47df2017-11-10 16:14:49 -08002986 if (dw <= 0 || dh <= 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002987 return null;
2988 }
2989
chaviwfbe47df2017-11-10 16:14:49 -08002990 final Rect frame = new Rect(0, 0, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002991
2992 // The screenshot API does not apply the current screen rotation.
2993 int rot = mDisplay.getRotation();
2994
2995 if (rot == ROTATION_90 || rot == ROTATION_270) {
2996 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
2997 }
2998
chaviwfbe47df2017-11-10 16:14:49 -08002999 // SurfaceFlinger is not aware of orientation, so convert our logical
3000 // crop to SurfaceFlinger's portrait orientation.
3001 convertCropForSurfaceFlinger(frame, rot, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003002
3003 final ScreenRotationAnimation screenRotationAnimation =
3004 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3005 final boolean inRotation = screenRotationAnimation != null &&
3006 screenRotationAnimation.isAnimating();
chaviwfbe47df2017-11-10 16:14:49 -08003007 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003008
Robert Carrb1579c82017-09-05 14:54:47 -07003009 // TODO(b/68392460): We should screenshot Task controls directly
3010 // but it's difficult at the moment as the Task doesn't have the
3011 // correct size set.
chaviwfbe47df2017-11-10 16:14:49 -08003012 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003013 if (bitmap == null) {
Robert Carrb1579c82017-09-05 14:54:47 -07003014 Slog.w(TAG_WM, "Failed to take screenshot");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003015 return null;
3016 }
chaviwfbe47df2017-11-10 16:14:49 -08003017
3018 // Create a copy of the screenshot that is immutable and backed in ashmem.
3019 // This greatly reduces the overhead of passing the bitmap between processes.
3020 final Bitmap ret = bitmap.createAshmemBitmap(config);
3021 bitmap.recycle();
3022 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003023 }
chaviwfbe47df2017-11-10 16:14:49 -08003024 }
3025
3026 private boolean shouldScreenshotWallpaper() {
3027 MutableBoolean screenshotReady = new MutableBoolean(false);
3028
3029 forAllWindows(w -> {
3030 if (!w.mIsWallpaper) {
3031 return false;
3032 }
3033
3034 // Found the wallpaper window
3035 final WindowStateAnimator winAnim = w.mWinAnimator;
3036
3037 if (winAnim.getShown() && winAnim.mLastAlpha > 0f) {
3038 screenshotReady.value = true;
3039 }
3040
3041 return true;
3042 }, true /* traverseTopToBottom */);
3043
3044 return screenshotReady.value;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003045 }
3046
3047 // TODO: Can this use createRotationMatrix()?
3048 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3049 if (rot == Surface.ROTATION_90) {
3050 final int tmp = crop.top;
3051 crop.top = dw - crop.right;
3052 crop.right = crop.bottom;
3053 crop.bottom = dw - crop.left;
3054 crop.left = tmp;
3055 } else if (rot == Surface.ROTATION_180) {
3056 int tmp = crop.top;
3057 crop.top = dh - crop.bottom;
3058 crop.bottom = dh - tmp;
3059 tmp = crop.right;
3060 crop.right = dw - crop.left;
3061 crop.left = dw - tmp;
3062 } else if (rot == Surface.ROTATION_270) {
3063 final int tmp = crop.top;
3064 crop.top = crop.left;
3065 crop.left = dh - crop.bottom;
3066 crop.bottom = crop.right;
3067 crop.right = dh - tmp;
3068 }
3069 }
3070
3071 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003072 // Used to indicate the layout is needed.
3073 mTmpWindow = null;
3074
3075 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003076 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003077 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003078 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003079 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003080 w.setDisplayLayoutNeeded();
3081 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003082 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003083
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003084 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003085 mService.mWindowPlacerLocked.performSurfacePlacement();
3086 }
3087 }
3088
Wale Ogunwale1666e312016-12-16 11:27:18 -08003089 void setExitingTokensHasVisible(boolean hasVisible) {
3090 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3091 mExitingTokens.get(i).hasVisible = hasVisible;
3092 }
3093
3094 // Initialize state of exiting applications.
3095 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3096 }
3097
3098 void removeExistingTokensIfPossible() {
3099 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3100 final WindowToken token = mExitingTokens.get(i);
3101 if (!token.hasVisible) {
3102 mExitingTokens.remove(i);
3103 }
3104 }
3105
3106 // Time to remove any exiting applications?
3107 mTaskStackContainers.removeExistingAppTokensIfPossible();
3108 }
3109
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003110 @Override
3111 void onDescendantOverrideConfigurationChanged() {
3112 setLayoutNeeded();
3113 mService.requestTraversal();
3114 }
3115
David Stevens9440dc82017-03-16 19:00:20 -07003116 boolean okToDisplay() {
3117 if (mDisplayId == DEFAULT_DISPLAY) {
3118 return !mService.mDisplayFrozen
3119 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3120 }
3121 return mDisplayInfo.state == Display.STATE_ON;
3122 }
3123
3124 boolean okToAnimate() {
3125 return okToDisplay() &&
3126 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3127 }
3128
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003129 static final class TaskForResizePointSearchResult {
3130 boolean searchDone;
3131 Task taskForResize;
3132
3133 void reset() {
3134 searchDone = false;
3135 taskForResize = null;
3136 }
3137 }
Robert Carr3b716242016-08-16 16:02:21 -07003138
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003139 private static final class ApplySurfaceChangesTransactionState {
3140 boolean displayHasContent;
3141 boolean obscured;
3142 boolean syswin;
3143 boolean focusDisplayed;
3144 float preferredRefreshRate;
3145 int preferredModeId;
3146
3147 void reset() {
3148 displayHasContent = false;
3149 obscured = false;
3150 syswin = false;
3151 focusDisplayed = false;
3152 preferredRefreshRate = 0;
3153 preferredModeId = 0;
3154 }
3155 }
3156
3157 private static final class ScreenshotApplicationState {
3158 WindowState appWin;
3159 int maxLayer;
3160 int minLayer;
3161 boolean screenshotReady;
3162
3163 void reset(boolean screenshotReady) {
3164 appWin = null;
3165 maxLayer = 0;
3166 minLayer = 0;
3167 this.screenshotReady = screenshotReady;
3168 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3169 }
3170 }
3171
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003172 /**
3173 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3174 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3175 * homogeneous children type which is currently required by sub-classes of
3176 * {@link WindowContainer} class.
3177 */
3178 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3179
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003180 DisplayChildWindowContainer(WindowManagerService service) {
3181 super(service);
3182 }
3183
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003184 @Override
3185 boolean fillsParent() {
3186 return true;
3187 }
3188
3189 @Override
3190 boolean isVisible() {
3191 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003192 }
3193 }
3194
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003195 /**
3196 * Window container class that contains all containers on this display relating to Apps.
3197 * I.e Activities.
3198 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003199 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003200 /**
3201 * A control placed at the appropriate level for transitions to occur.
3202 */
chaviw23ee71c2017-12-18 11:29:41 -08003203 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003204
Robert Carrf7a7ca82017-12-06 13:17:07 -08003205 /**
3206 * Given that the split-screen divider does not have an AppWindowToken, it
3207 * will have to live inside of a "NonAppWindowContainer", in particular
3208 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3209 * it will need to be interleaved with some of our children, appearing on top of
3210 * both docked stacks but underneath any assistant stacks.
3211 *
3212 * To solve this problem we have this anchor control, which will always exist so
3213 * we can always assign it the correct value in our {@link #assignChildLayers}.
3214 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3215 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3216 * events between the two containers.
3217 */
3218 SurfaceControl mSplitScreenDividerAnchor = null;
3219
Wale Ogunwale61911492017-10-11 08:50:50 -07003220 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3221 // through the list to find them.
3222 private TaskStack mHomeStack = null;
3223 private TaskStack mPinnedStack = null;
3224 private TaskStack mSplitScreenPrimaryStack = null;
3225
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003226 TaskStackContainers(WindowManagerService service) {
3227 super(service);
3228 }
3229
Wale Ogunwale61911492017-10-11 08:50:50 -07003230 /**
3231 * Returns the topmost stack on the display that is compatible with the input windowing mode
3232 * and activity type. Null is no compatible stack on the display.
3233 */
3234 TaskStack getStack(int windowingMode, int activityType) {
3235 if (activityType == ACTIVITY_TYPE_HOME) {
3236 return mHomeStack;
3237 }
3238 if (windowingMode == WINDOWING_MODE_PINNED) {
3239 return mPinnedStack;
3240 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3241 return mSplitScreenPrimaryStack;
3242 }
3243 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3244 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003245 if (activityType == ACTIVITY_TYPE_UNDEFINED
3246 && windowingMode == stack.getWindowingMode()) {
3247 // Passing in undefined type means we want to match the topmost stack with the
3248 // windowing mode.
3249 return stack;
3250 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003251 if (stack.isCompatible(windowingMode, activityType)) {
3252 return stack;
3253 }
3254 }
3255 return null;
3256 }
3257
3258 @VisibleForTesting
3259 TaskStack getTopStack() {
3260 return mTaskStackContainers.getChildCount() > 0
3261 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3262 }
3263
3264 TaskStack getHomeStack() {
3265 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3266 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3267 }
3268 return mHomeStack;
3269 }
3270
3271 TaskStack getPinnedStack() {
3272 return mPinnedStack;
3273 }
3274
Matthew Ng64e77cf2017-10-31 14:01:31 -07003275 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003276 return mSplitScreenPrimaryStack;
3277 }
3278
Winson Chunge2d72172018-01-25 17:46:20 +00003279 ArrayList<Task> getVisibleTasks() {
3280 final ArrayList<Task> visibleTasks = new ArrayList<>();
3281 forAllTasks(task -> {
3282 if (task.isVisible()) {
3283 visibleTasks.add(task);
3284 }
3285 });
3286 return visibleTasks;
3287 }
3288
Andrii Kulian839def92016-11-02 10:58:58 -07003289 /**
3290 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003291 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003292 */
3293 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003294 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003295 addChild(stack, onTop);
3296 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003297 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003298
Wale Ogunwale61911492017-10-11 08:50:50 -07003299 void onStackWindowingModeChanged(TaskStack stack) {
3300 removeStackReferenceIfNeeded(stack);
3301 addStackReferenceIfNeeded(stack);
3302 if (stack == mPinnedStack && getTopStack() != stack) {
3303 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3304 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3305 }
3306 }
3307
3308 private void addStackReferenceIfNeeded(TaskStack stack) {
3309 if (stack.isActivityTypeHome()) {
3310 if (mHomeStack != null) {
3311 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3312 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3313 }
3314 mHomeStack = stack;
3315 }
3316 final int windowingMode = stack.getWindowingMode();
3317 if (windowingMode == WINDOWING_MODE_PINNED) {
3318 if (mPinnedStack != null) {
3319 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3320 + mPinnedStack + " already exist on display=" + this
3321 + " stack=" + stack);
3322 }
3323 mPinnedStack = stack;
3324 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3325 if (mSplitScreenPrimaryStack != null) {
3326 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3327 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3328 + " already exist on display=" + this + " stack=" + stack);
3329 }
3330 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003331 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003332 }
3333 }
3334
3335 private void removeStackReferenceIfNeeded(TaskStack stack) {
3336 if (stack == mHomeStack) {
3337 mHomeStack = null;
3338 } else if (stack == mPinnedStack) {
3339 mPinnedStack = null;
3340 } else if (stack == mSplitScreenPrimaryStack) {
3341 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003342 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3343 mService.setDockedStackCreateStateLocked(
3344 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3345 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003346 }
Andrii Kulian839def92016-11-02 10:58:58 -07003347 }
3348
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003349 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003350 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3351 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003352 addChild(stack, addIndex);
3353 setLayoutNeeded();
3354 }
3355
Wale Ogunwale61911492017-10-11 08:50:50 -07003356 @Override
3357 protected void removeChild(TaskStack stack) {
3358 super.removeChild(stack);
3359 removeStackReferenceIfNeeded(stack);
3360 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003361
3362 @Override
3363 boolean isOnTop() {
3364 // Considered always on top
3365 return true;
3366 }
3367
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003368 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003369 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003370 if (child.getWindowConfiguration().isAlwaysOnTop()
3371 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003372 // This stack is always-on-top, override the default behavior.
3373 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3374
3375 // Moving to its current position, as we must call super but we don't want to
3376 // perform any meaningful action.
3377 final int currentPosition = mChildren.indexOf(child);
3378 super.positionChildAt(currentPosition, child, false /* includingParents */);
3379 return;
3380 }
3381
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003382 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3383 super.positionChildAt(targetPosition, child, includingParents);
3384
3385 setLayoutNeeded();
3386 }
3387
3388 /**
3389 * When stack is added or repositioned, find a proper position for it.
3390 * This will make sure that pinned stack always stays on top.
3391 * @param requestedPosition Position requested by caller.
3392 * @param stack Stack to be added or positioned.
3393 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3394 * @return The proper position for the stack.
3395 */
3396 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3397 final int topChildPosition = mChildren.size() - 1;
3398 boolean toTop = requestedPosition == POSITION_TOP;
3399 toTop |= adding ? requestedPosition >= topChildPosition + 1
3400 : requestedPosition >= topChildPosition;
3401 int targetPosition = requestedPosition;
3402
Wale Ogunwale61911492017-10-11 08:50:50 -07003403 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003404 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003405 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003406 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003407 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3408 }
3409
3410 // So, stack is moved just below the pinned stack.
3411 // When we're adding a new stack the target is the current pinned stack position.
3412 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003413 // stack, because WindowContainer#positionAt() first removes element and then adds
3414 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003415 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3416 }
3417
3418 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003419 }
3420
3421 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003422 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3423 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003424 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003425 if (super.forAllWindows(callback, traverseTopToBottom)) {
3426 return true;
3427 }
3428 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3429 return true;
3430 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003431 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003432 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3433 return true;
3434 }
3435 if (super.forAllWindows(callback, traverseTopToBottom)) {
3436 return true;
3437 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003438 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003439 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003440 }
3441
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003442 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003443 boolean traverseTopToBottom) {
3444 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3445 // app tokens.
3446 // TODO: Investigate if we need to continue to do this or if we can just process them
3447 // in-order.
3448 if (traverseTopToBottom) {
3449 for (int i = mChildren.size() - 1; i >= 0; --i) {
3450 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3451 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003452 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3453 traverseTopToBottom)) {
3454 return true;
3455 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003456 }
3457 }
3458 } else {
3459 final int count = mChildren.size();
3460 for (int i = 0; i < count; ++i) {
3461 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3462 final int appTokensCount = appTokens.size();
3463 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003464 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3465 traverseTopToBottom)) {
3466 return true;
3467 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003468 }
3469 }
3470 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003471 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003472 }
3473
Wale Ogunwale1666e312016-12-16 11:27:18 -08003474 void setExitingTokensHasVisible(boolean hasVisible) {
3475 for (int i = mChildren.size() - 1; i >= 0; --i) {
3476 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3477 for (int j = appTokens.size() - 1; j >= 0; --j) {
3478 appTokens.get(j).hasVisible = hasVisible;
3479 }
3480 }
3481 }
3482
3483 void removeExistingAppTokensIfPossible() {
3484 for (int i = mChildren.size() - 1; i >= 0; --i) {
3485 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3486 for (int j = appTokens.size() - 1; j >= 0; --j) {
3487 final AppWindowToken token = appTokens.get(j);
3488 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3489 && (!token.mIsExiting || token.isEmpty())) {
3490 // Make sure there is no animation running on this token, so any windows
3491 // associated with it will be removed as soon as their animations are
3492 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003493 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003494 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3495 "performLayout: App token exiting now removed" + token);
3496 token.removeIfPossible();
3497 }
3498 }
3499 }
3500 }
3501
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003502 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003503 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003504 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3505 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003506 // Apps and their containers are not allowed to specify an orientation while the
3507 // docked or freeform stack is visible...except for the home stack/task if the
3508 // docked stack is minimized and it actually set something.
3509 if (mHomeStack != null && mHomeStack.isVisible()
3510 && mDividerControllerLocked.isMinimizedDock()) {
3511 final int orientation = mHomeStack.getOrientation();
3512 if (orientation != SCREEN_ORIENTATION_UNSET) {
3513 return orientation;
3514 }
3515 }
3516 return SCREEN_ORIENTATION_UNSPECIFIED;
3517 }
3518
3519 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003520 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3521 PackageManager.FEATURE_AUTOMOTIVE);
3522 if (isCar) {
3523 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3524 // allow anything but the default orientation.
3525 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3526 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3527 return SCREEN_ORIENTATION_UNSPECIFIED;
3528 }
3529
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003530 if (orientation != SCREEN_ORIENTATION_UNSET
3531 && orientation != SCREEN_ORIENTATION_BEHIND) {
3532 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3533 "App is requesting an orientation, return " + orientation);
3534 return orientation;
3535 }
3536
3537 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003538 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003539 // The next app has not been requested to be visible, so we keep the current orientation
3540 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003541 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003542 }
Robert Carrb1579c82017-09-05 14:54:47 -07003543
3544 @Override
3545 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003546 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003547
Robert Carr2f8aa392018-01-31 14:46:51 -08003548 for (int i = 0; i < mChildren.size(); i++) {
3549 final TaskStack s = mChildren.get(i);
3550 s.assignChildLayers(t);
3551 }
3552 }
3553
3554 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003555 final int HOME_STACK_STATE = 0;
3556 final int NORMAL_STACK_STATE = 1;
3557 final int ALWAYS_ON_TOP_STATE = 2;
3558
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003559 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003560 int layerForAnimationLayer = 0;
3561
Robert Carrf7a7ca82017-12-06 13:17:07 -08003562 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3563 for (int i = 0; i < mChildren.size(); i++) {
3564 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003565 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3566 continue;
3567 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3568 || s.isAlwaysOnTop())) {
3569 continue;
3570 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3571 continue;
3572 }
3573 s.assignLayer(t, layer++);
3574 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3575 t.setLayer(mSplitScreenDividerAnchor, layer++);
3576 }
3577 if (s.isSelfOrChildAnimating()) {
3578 // Ensure the animation layer ends up above the
3579 // highest animating stack and no higher.
3580 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003581 }
3582 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003583 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003584 if (mAppAnimationLayer != null) {
3585 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003586 }
Robert Carrb1579c82017-09-05 14:54:47 -07003587 }
3588
3589 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003590 SurfaceControl getAppAnimationLayer() {
3591 return mAppAnimationLayer;
3592 }
3593
Robert Carrf7a7ca82017-12-06 13:17:07 -08003594 SurfaceControl getSplitScreenDividerAnchor() {
3595 return mSplitScreenDividerAnchor;
3596 }
3597
chaviw23ee71c2017-12-18 11:29:41 -08003598 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003599 void onParentSet() {
3600 super.onParentSet();
3601 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003602 mAppAnimationLayer = makeChildSurface(null)
3603 .setName("animationLayer")
3604 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003605 mSplitScreenDividerAnchor = makeChildSurface(null)
3606 .setName("splitScreenDividerAnchor")
3607 .build();
3608 getPendingTransaction()
3609 .show(mAppAnimationLayer)
3610 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003611 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003612 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003613 mAppAnimationLayer.destroy();
3614 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003615 mSplitScreenDividerAnchor.destroy();
3616 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003617 }
3618 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003619 }
3620
Robert Carree4d4b92017-11-22 12:21:46 -08003621 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003622 AboveAppWindowContainers(String name, WindowManagerService service) {
3623 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003624 }
3625
3626 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3627 boolean needAssignIme = imeContainer != null
3628 && imeContainer.getSurfaceControl() != null;
3629 for (int j = 0; j < mChildren.size(); ++j) {
3630 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003631
3632 // See {@link mSplitScreenDividerAnchor}
3633 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3634 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3635 continue;
3636 }
Robert Carree4d4b92017-11-22 12:21:46 -08003637 wt.assignLayer(t, j);
3638 wt.assignChildLayers(t);
3639
3640 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3641 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003642
3643 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3644 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003645 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003646 needAssignIme = false;
3647 }
3648 }
3649 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003650 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003651 }
3652 }
3653 }
3654
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003655 /**
3656 * Window container class that contains all containers on this display that are not related to
3657 * Apps. E.g. status bar.
3658 */
Robert Carree4d4b92017-11-22 12:21:46 -08003659 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003660 /**
3661 * Compares two child window tokens returns -1 if the first is lesser than the second in
3662 * terms of z-order and 1 otherwise.
3663 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003664 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003665 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003666 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3667 token1.mOwnerCanManageAppTokens)
3668 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3669 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003670
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003671 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3672 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3673 return false;
3674 }
3675 final int req = w.mAttrs.screenOrientation;
3676 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3677 || req == SCREEN_ORIENTATION_UNSET) {
3678 return false;
3679 }
3680 return true;
3681 };
3682
Wale Ogunwale3a931692016-11-02 16:49:48 -07003683 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003684 private final Dimmer mDimmer = new Dimmer(this);
3685 private final Rect mTmpDimBoundsRect = new Rect();
3686
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003687 NonAppWindowContainers(String name, WindowManagerService service) {
3688 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003689 mName = name;
3690 }
3691
3692 void addChild(WindowToken token) {
3693 addChild(token, mWindowComparator);
3694 }
3695
3696 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003697 int getOrientation() {
3698 final WindowManagerPolicy policy = mService.mPolicy;
3699 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003700 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003701
3702 if (win != null) {
3703 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003704 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003705 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003706 if (mService.mKeyguardGoingAway) {
3707 // Keyguard can't affect the orientation if it is going away...
3708 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3709 return SCREEN_ORIENTATION_UNSET;
3710 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003711 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003712 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003713 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003714 }
3715
Andrii Kulian8ee72852017-03-10 10:36:45 -08003716 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003717
Jorim Jaggi75520d52017-08-24 17:23:19 +02003718 if (policy.isKeyguardShowingAndNotOccluded()
3719 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003720 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003721 }
3722
3723 return SCREEN_ORIENTATION_UNSET;
3724 }
3725
3726 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003727 String getName() {
3728 return mName;
3729 }
chaviwf29223e2018-01-31 13:23:51 -08003730
3731 @Override
3732 Dimmer getDimmer() {
3733 return mDimmer;
3734 }
3735
3736 @Override
3737 void prepareSurfaces() {
3738 mDimmer.resetDimStates();
3739 super.prepareSurfaces();
3740 getBounds(mTmpDimBoundsRect);
3741
3742 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3743 scheduleAnimation();
3744 }
3745 }
Robert Carr3b716242016-08-16 16:02:21 -07003746 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003747
Robert Carr9034d962018-01-04 18:27:42 -08003748 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3749 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3750 super(name, service);
3751 }
3752
3753 @Override
3754 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3755 }
3756 };
3757
Robert Carrb1579c82017-09-05 14:54:47 -07003758 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3759 return mService.makeSurfaceBuilder(s)
3760 .setParent(mWindowingLayer);
3761 }
3762
3763 @Override
3764 SurfaceSession getSession() {
3765 return mSession;
3766 }
3767
3768 @Override
3769 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003770 SurfaceSession s = child != null ? child.getSession() : getSession();
3771 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003772 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003773
3774 if (child == null) {
3775 return b;
3776 }
3777
Robert Carree4d4b92017-11-22 12:21:46 -08003778 return b.setName(child.getName())
3779 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003780 }
3781
3782 /**
3783 * The makeSurface variants are for use by the window-container
3784 * hierarchy. makeOverlay here is a function for various non windowing
3785 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3786 * and other potpourii.
3787 */
3788 SurfaceControl.Builder makeOverlay() {
3789 return mService.makeSurfaceBuilder(mSession)
3790 .setParent(mOverlayLayer);
3791 }
3792
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003793 /**
3794 * Reparents the given surface to mOverlayLayer.
3795 */
3796 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3797 transaction.reparent(surface, mOverlayLayer.getHandle());
3798 }
3799
Robert Carrb1579c82017-09-05 14:54:47 -07003800 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003801 applyMagnificationSpec(getPendingTransaction(), spec);
3802 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003803 }
3804
3805 @Override
3806 void onParentSet() {
3807 // Since we are the top of the SurfaceControl hierarchy here
3808 // we create the root surfaces explicitly rather than chaining
3809 // up as the default implementation in onParentSet does. So we
3810 // explicitly do NOT call super here.
3811 }
3812
3813 @Override
3814 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003815
3816 // These are layers as children of "mWindowingLayer"
3817 mBelowAppWindowsContainers.assignLayer(t, 0);
3818 mTaskStackContainers.assignLayer(t, 1);
3819 mAboveAppWindowsContainers.assignLayer(t, 2);
3820
3821 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003822 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003823
Robert Carree4d4b92017-11-22 12:21:46 -08003824 // In the case where we have an IME target that is not in split-screen
3825 // mode IME assignment is easy. We just need the IME to go directly above
3826 // the target. This way children of the target will naturally go above the IME
3827 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003828 //
Robert Carree4d4b92017-11-22 12:21:46 -08003829 // In the case of split-screen windowing mode, we need to elevate the IME above the
3830 // docked divider while keeping the app itself below the docked divider, so instead
3831 // we use relative layering of the IME targets child windows, and place the
3832 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003833 //
Robert Carree4d4b92017-11-22 12:21:46 -08003834 // In the case where we have no IME target we assign it where it's base layer would
3835 // place it in the AboveAppWindowContainers.
3836 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3837 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003838 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003839 // TODO: We need to use an extra level on the app surface to ensure
3840 // this is always above SurfaceView but always below attached window.
3841 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003842 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003843 }
3844
3845 // Above we have assigned layers to our children, now we ask them to assign
3846 // layers to their children.
3847 mBelowAppWindowsContainers.assignChildLayers(t);
3848 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003849 mAboveAppWindowsContainers.assignChildLayers(t,
3850 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003851 mImeWindowsContainers.assignChildLayers(t);
3852 }
3853
3854 /**
3855 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3856 * that the IME target is one of the docked applications. We'd like the docked divider to be
3857 * above both of the applications, and we'd like the IME to be above the docked divider.
3858 * However we need child windows of the applications to be above the IME (Text drag handles).
3859 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3860 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3861 * with {@link #WindowState#assignLayer}
3862 */
3863 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3864 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3865 }
3866
3867 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003868 void prepareSurfaces() {
3869 final ScreenRotationAnimation screenRotationAnimation =
3870 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3871 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3872 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3873 mPendingTransaction.setMatrix(mWindowingLayer,
3874 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3875 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3876 mPendingTransaction.setPosition(mWindowingLayer,
3877 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3878 mPendingTransaction.setAlpha(mWindowingLayer,
3879 screenRotationAnimation.getEnterTransformation().getAlpha());
3880 }
Chavi Weingartenb736e322018-02-23 00:27:54 +00003881
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003882 super.prepareSurfaces();
3883 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003884
3885 void assignStackOrdering(SurfaceControl.Transaction t) {
3886 mTaskStackContainers.assignStackOrdering(t);
3887 }
Craig Mautner59c00972012-07-30 12:10:24 -07003888}