blob: 13357b89972987f7f87dddf34361d1b81c1c028a [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
Chavi Weingarten38804382018-02-15 21:00:15 +0000385 /**
386 * A list of surfaces to be destroyed after {@link #mPendingTransaction} is applied.
387 */
388 private final ArrayList<SurfaceControl> mPendingDestroyingSurfaces = new ArrayList<>();
389
Jorim Jaggi9af095b2017-12-12 17:18:57 +0100390 /** Temporary float array to retrieve 3x3 matrix values. */
391 private final float[] mTmpFloats = new float[9];
392
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800393 private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
394 WindowStateAnimator winAnimator = w.mWinAnimator;
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800395 final AppWindowToken atoken = w.mAppToken;
396 if (winAnimator.mDrawState == READY_TO_SHOW) {
397 if (atoken == null || atoken.allDrawn) {
398 if (w.performShowLocked()) {
399 pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
400 if (DEBUG_LAYOUT_REPEATS) {
401 mService.mWindowPlacerLocked.debugLayoutRepeats(
402 "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
403 }
404 }
405 }
406 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800407 };
408
409 private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
410 final WindowStateAnimator winAnimator = w.mWinAnimator;
411 if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
412 return;
413 }
414
415 final int flags = w.mAttrs.flags;
416
417 // If this window is animating, make a note that we have an animating window and take
418 // care of a request to run a detached wallpaper animation.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100419 if (winAnimator.isAnimationSet()) {
420 final AnimationAdapter anim = w.getAnimation();
421 if (anim != null) {
422 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && anim.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800423 mTmpWindow = w;
424 }
Jorim Jaggia5e10572017-11-15 14:36:26 +0100425 final int color = anim.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800426 if (color != 0) {
427 final TaskStack stack = w.getStack();
428 if (stack != null) {
429 stack.setAnimationBackground(winAnimator, color);
430 }
431 }
432 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800433 }
434
435 // If this window's app token is running a detached wallpaper animation, make a note so
436 // we can ensure the wallpaper is displayed behind it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200437 final AppWindowToken atoken = winAnimator.mWin.mAppToken;
438 final AnimationAdapter animation = atoken != null ? atoken.getAnimation() : null;
439 if (animation != null) {
440 if ((flags & FLAG_SHOW_WALLPAPER) != 0 && animation.getDetachWallpaper()) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800441 mTmpWindow = w;
442 }
443
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200444 final int color = animation.getBackgroundColor();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800445 if (color != 0) {
446 final TaskStack stack = w.getStack();
447 if (stack != null) {
448 stack.setAnimationBackground(winAnimator, color);
449 }
450 }
451 }
452 };
453
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800454 private final Consumer<WindowState> mScheduleToastTimeout = w -> {
455 final int lostFocusUid = mTmpWindow.mOwnerUid;
456 final Handler handler = mService.mH;
457 if (w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == lostFocusUid) {
458 if (!handler.hasMessages(WINDOW_HIDE_TIMEOUT, w)) {
459 handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w),
460 w.mAttrs.hideTimeoutMilliseconds);
461 }
462 }
463 };
464
465 private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
466 final AppWindowToken focusedApp = mService.mFocusedApp;
467 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Looking for focus: " + w
468 + ", flags=" + w.mAttrs.flags + ", canReceive=" + w.canReceiveKeys());
469
470 if (!w.canReceiveKeys()) {
471 return false;
472 }
473
474 final AppWindowToken wtoken = w.mAppToken;
475
476 // If this window's application has been removed, just skip it.
477 if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
478 if (DEBUG_FOCUS) Slog.v(TAG_WM, "Skipping " + wtoken + " because "
479 + (wtoken.removed ? "removed" : "sendingToBottom"));
480 return false;
481 }
482
483 if (focusedApp == null) {
484 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp=null"
485 + " using new focus @ " + w);
486 mTmpWindow = w;
487 return true;
488 }
489
490 if (!focusedApp.windowsAreFocusable()) {
491 // Current focused app windows aren't focusable...
492 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: focusedApp windows not"
493 + " focusable using new focus @ " + w);
494 mTmpWindow = w;
495 return true;
496 }
497
498 // Descend through all of the app tokens and find the first that either matches
499 // win.mAppToken (return win) or mFocusedApp (return null).
500 if (wtoken != null && w.mAttrs.type != TYPE_APPLICATION_STARTING) {
501 if (focusedApp.compareTo(wtoken) > 0) {
502 // App stack below focused app stack. No focus for you!!!
503 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM,
504 "findFocusedWindow: Reached focused app=" + focusedApp);
505 mTmpWindow = null;
506 return true;
507 }
508 }
509
510 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: Found new focus @ " + w);
511 mTmpWindow = w;
512 return true;
513 };
514
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800515 private final Consumer<WindowState> mPerformLayout = w -> {
516 // Don't do layout of a window if it is not visible, or soon won't be visible, to avoid
517 // wasting time and funky changes while a window is animating away.
518 final boolean gone = (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w))
519 || w.isGoneForLayoutLw();
520
521 if (DEBUG_LAYOUT && !w.mLayoutAttached) {
522 Slog.v(TAG, "1ST PASS " + w + ": gone=" + gone + " mHaveFrame=" + w.mHaveFrame
523 + " mLayoutAttached=" + w.mLayoutAttached
524 + " screen changed=" + w.isConfigChanged());
525 final AppWindowToken atoken = w.mAppToken;
526 if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200527 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800528 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
529 + " parentHidden=" + w.isParentWindowHidden());
530 else Slog.v(TAG, " VIS: mViewVisibility=" + w.mViewVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200531 + " mRelayoutCalled=" + w.mRelayoutCalled + " hidden=" + w.mToken.isHidden()
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800532 + " hiddenRequested=" + (atoken != null && atoken.hiddenRequested)
533 + " parentHidden=" + w.isParentWindowHidden());
534 }
535
536 // If this view is GONE, then skip it -- keep the current frame, and let the caller know
537 // so they can ignore it if they want. (We do the normal layout for INVISIBLE windows,
538 // since that means "perform layout as normal, just don't display").
539 if (!gone || !w.mHaveFrame || w.mLayoutNeeded
540 || ((w.isConfigChanged() || w.setReportResizeHints())
541 && !w.isGoneForLayoutLw() &&
542 ((w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
543 (w.mHasSurface && w.mAppToken != null &&
544 w.mAppToken.layoutConfigChanges)))) {
545 if (!w.mLayoutAttached) {
546 if (mTmpInitial) {
547 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
548 w.mContentChanged = false;
549 }
550 if (w.mAttrs.type == TYPE_DREAM) {
551 // Don't layout windows behind a dream, so that if it does stuff like hide
552 // the status bar we won't get a bad transition when it goes away.
553 mTmpWindow = w;
554 }
555 w.mLayoutNeeded = false;
556 w.prelayout();
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200557 final boolean firstLayout = !w.isLaidOut();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000558 mService.mPolicy.layoutWindowLw(w, null, mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800559 w.mLayoutSeq = mService.mLayoutSeq;
560
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200561 // If this is the first layout, we need to initialize the last inset values as
562 // otherwise we'd immediately cause an unnecessary resize.
563 if (firstLayout) {
564 w.updateLastInsetValues();
565 }
566
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800567 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
568 + " mContainingFrame=" + w.mContainingFrame
569 + " mDisplayFrame=" + w.mDisplayFrame);
570 }
571 }
572 };
573
574 private final Consumer<WindowState> mPerformLayoutAttached = w -> {
575 if (w.mLayoutAttached) {
576 if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + w + " mHaveFrame=" + w.mHaveFrame
577 + " mViewVisibility=" + w.mViewVisibility
578 + " mRelayoutCalled=" + w.mRelayoutCalled);
579 // If this view is GONE, then skip it -- keep the current frame, and let the caller
580 // know so they can ignore it if they want. (We do the normal layout for INVISIBLE
581 // windows, since that means "perform layout as normal, just don't display").
582 if (mTmpWindow != null && mService.mPolicy.canBeHiddenByKeyguardLw(w)) {
583 return;
584 }
585 if ((w.mViewVisibility != GONE && w.mRelayoutCalled) || !w.mHaveFrame
586 || w.mLayoutNeeded) {
587 if (mTmpInitial) {
588 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
589 w.mContentChanged = false;
590 }
591 w.mLayoutNeeded = false;
592 w.prelayout();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000593 mService.mPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800594 w.mLayoutSeq = mService.mLayoutSeq;
595 if (DEBUG_LAYOUT) Slog.v(TAG, " LAYOUT: mFrame=" + w.mFrame
596 + " mContainingFrame=" + w.mContainingFrame
597 + " mDisplayFrame=" + w.mDisplayFrame);
598 }
599 } else if (w.mAttrs.type == TYPE_DREAM) {
600 // Don't layout windows behind a dream, so that if it does stuff like hide the
601 // status bar we won't get a bad transition when it goes away.
602 mTmpWindow = mTmpWindow2;
603 }
604 };
605
606 private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
607 if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
608 + " fl=0x" + Integer.toHexString(w.mAttrs.flags));
609 return w.canBeImeTarget();
610 };
611
612 private final Consumer<WindowState> mApplyPostLayoutPolicy =
613 w -> mService.mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(),
614 mService.mInputMethodTarget);
615
616 private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
617 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
618 final boolean obscuredChanged = w.mObscured !=
619 mTmpApplySurfaceChangesTransactionState.obscured;
620 final RootWindowContainer root = mService.mRoot;
621 // Only used if default window
622 final boolean someoneLosingFocus = !mService.mLosingFocus.isEmpty();
623
624 // Update effect.
625 w.mObscured = mTmpApplySurfaceChangesTransactionState.obscured;
626 if (!mTmpApplySurfaceChangesTransactionState.obscured) {
627 final boolean isDisplayed = w.isDisplayedLw();
628
629 if (isDisplayed && w.isObscuringDisplay()) {
630 // This window completely covers everything behind it, so we want to leave all
631 // of them as undimmed (for performance reasons).
632 root.mObscuringWindow = w;
633 mTmpApplySurfaceChangesTransactionState.obscured = true;
634 }
635
636 mTmpApplySurfaceChangesTransactionState.displayHasContent |=
637 root.handleNotObscuredLocked(w,
638 mTmpApplySurfaceChangesTransactionState.obscured,
639 mTmpApplySurfaceChangesTransactionState.syswin);
640
641 if (w.mHasSurface && isDisplayed) {
642 final int type = w.mAttrs.type;
643 if (type == TYPE_SYSTEM_DIALOG || type == TYPE_SYSTEM_ERROR
644 || (w.mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
645 mTmpApplySurfaceChangesTransactionState.syswin = true;
646 }
647 if (mTmpApplySurfaceChangesTransactionState.preferredRefreshRate == 0
648 && w.mAttrs.preferredRefreshRate != 0) {
649 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate
650 = w.mAttrs.preferredRefreshRate;
651 }
652 if (mTmpApplySurfaceChangesTransactionState.preferredModeId == 0
653 && w.mAttrs.preferredDisplayModeId != 0) {
654 mTmpApplySurfaceChangesTransactionState.preferredModeId
655 = w.mAttrs.preferredDisplayModeId;
656 }
657 }
658 }
659
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800660 if (isDefaultDisplay && obscuredChanged && w.isVisibleLw()
661 && mWallpaperController.isWallpaperTarget(w)) {
662 // This is the wallpaper target and its obscured state changed... make sure the
663 // current wallpaper's visibility has been updated accordingly.
664 mWallpaperController.updateWallpaperVisibility();
665 }
666
chaviw161ea3e2018-01-31 12:01:12 -0800667 w.handleWindowMovedIfNeeded();
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800668
669 final WindowStateAnimator winAnimator = w.mWinAnimator;
670
671 //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
672 w.mContentChanged = false;
673
674 // Moved from updateWindowsAndWallpaperLocked().
675 if (w.mHasSurface) {
676 // Take care of the window being ready to display.
677 final boolean committed = winAnimator.commitFinishDrawingLocked();
678 if (isDefaultDisplay && committed) {
679 if (w.mAttrs.type == TYPE_DREAM) {
680 // HACK: When a dream is shown, it may at that point hide the lock screen.
681 // So we need to redo the layout to let the phone window manager make this
682 // happen.
683 pendingLayoutChanges |= FINISH_LAYOUT_REDO_LAYOUT;
684 if (DEBUG_LAYOUT_REPEATS) {
685 surfacePlacer.debugLayoutRepeats(
686 "dream and commitFinishDrawingLocked true",
687 pendingLayoutChanges);
688 }
689 }
690 if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
691 if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
692 "First draw done in potential wallpaper target " + w);
693 root.mWallpaperMayChange = true;
694 pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
695 if (DEBUG_LAYOUT_REPEATS) {
696 surfacePlacer.debugLayoutRepeats(
697 "wallpaper and commitFinishDrawingLocked true",
698 pendingLayoutChanges);
699 }
700 }
701 }
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800702 }
703
704 final AppWindowToken atoken = w.mAppToken;
705 if (atoken != null) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100706 atoken.updateLetterbox(w);
Wale Ogunwale1e129a42016-11-21 13:03:47 -0800707 final boolean updateAllDrawn = atoken.updateDrawnWindowStates(w);
708 if (updateAllDrawn && !mTmpUpdateAllDrawn.contains(atoken)) {
709 mTmpUpdateAllDrawn.add(atoken);
710 }
711 }
712
713 if (isDefaultDisplay && someoneLosingFocus && w == mService.mCurrentFocus
714 && w.isDisplayedLw()) {
715 mTmpApplySurfaceChangesTransactionState.focusDisplayed = true;
716 }
717
718 w.updateResizingWindowIfNeeded();
719 };
720
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800721 /**
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800722 * Create new {@link DisplayContent} instance, add itself to the root window container and
723 * initialize direct children.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700724 * @param display May not be null.
Craig Mautnerdf88d732014-01-27 09:21:32 -0800725 * @param service You know.
Wale Ogunwale0303c572016-10-20 10:16:29 -0700726 * @param wallpaperController wallpaper windows controller used to adjust the positioning of the
727 * wallpaper windows in the window list.
Craig Mautner2d5618c2012-10-18 13:55:47 -0700728 */
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700729 DisplayContent(Display display, WindowManagerService service,
Bryce Leef19cbe22018-02-02 15:09:21 -0800730 WallpaperController wallpaperController, DisplayWindowController controller) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100731 super(service);
Bryce Leef19cbe22018-02-02 15:09:21 -0800732 setController(controller);
Wale Ogunwale1666e312016-12-16 11:27:18 -0800733 if (service.mRoot.getDisplayContent(display.getDisplayId()) != null) {
734 throw new IllegalArgumentException("Display with ID=" + display.getDisplayId()
735 + " already exists=" + service.mRoot.getDisplayContent(display.getDisplayId())
736 + " new=" + display);
737 }
738
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700739 mDisplay = display;
740 mDisplayId = display.getDisplayId();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700741 mWallpaperController = wallpaperController;
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700742 display.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700743 display.getMetrics(mDisplayMetrics);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700744 isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
Wale Ogunwale828ff7e2017-11-14 01:01:29 +0000745 mDisplayFrames = new DisplayFrames(mDisplayId, mDisplayInfo);
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -0700746 initializeDisplayBaseInfo();
Jorim Jaggi42625d1b2016-02-11 20:11:07 -0800747 mDividerControllerLocked = new DockedStackDividerController(service, this);
Winson Chung655332c2016-10-31 13:14:28 -0700748 mPinnedStackControllerLocked = new PinnedStackController(service, this);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700749
Robert Carrb1579c82017-09-05 14:54:47 -0700750 mSurfaceSize = Math.max(mBaseDisplayHeight, mBaseDisplayWidth);
751
752 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(mSession)
753 .setSize(mSurfaceSize, mSurfaceSize)
754 .setOpaque(true);
755 mWindowingLayer = b.setName("Display Root").build();
756 mOverlayLayer = b.setName("Display Overlays").build();
757
Robert Carrf59b8dd2017-10-02 18:58:36 -0700758 getPendingTransaction().setLayer(mWindowingLayer, 0)
Robert Carrb1579c82017-09-05 14:54:47 -0700759 .setLayerStack(mWindowingLayer, mDisplayId)
760 .show(mWindowingLayer)
761 .setLayer(mOverlayLayer, 1)
762 .setLayerStack(mOverlayLayer, mDisplayId)
763 .show(mOverlayLayer);
Robert Carrf59b8dd2017-10-02 18:58:36 -0700764 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -0700765
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700766 // These are the only direct children we should ever have and they are permanent.
Wale Ogunwale3a931692016-11-02 16:49:48 -0700767 super.addChild(mBelowAppWindowsContainers, null);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700768 super.addChild(mTaskStackContainers, null);
Wale Ogunwale3a931692016-11-02 16:49:48 -0700769 super.addChild(mAboveAppWindowsContainers, null);
770 super.addChild(mImeWindowsContainers, null);
Andrii Kulian367ff7f2017-01-25 19:45:34 -0800771
772 // Add itself as a child to the root container.
773 mService.mRoot.addChild(this, null);
Bryce Leed1871262017-06-12 14:12:29 -0700774
775 // TODO(b/62541591): evaluate whether this is the best spot to declare the
776 // {@link DisplayContent} ready for use.
777 mDisplayReady = true;
778 }
779
780 boolean isReady() {
781 // The display is ready when the system and the individual display are both ready.
782 return mService.mDisplayReady && mDisplayReady;
Craig Mautner59c00972012-07-30 12:10:24 -0700783 }
784
785 int getDisplayId() {
786 return mDisplayId;
787 }
788
Wale Ogunwale02319a62016-09-26 15:21:22 -0700789 WindowToken getWindowToken(IBinder binder) {
790 return mTokenMap.get(binder);
791 }
792
793 AppWindowToken getAppWindowToken(IBinder binder) {
794 final WindowToken token = getWindowToken(binder);
795 if (token == null) {
796 return null;
797 }
798 return token.asAppWindowToken();
799 }
800
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700801 private void addWindowToken(IBinder binder, WindowToken token) {
Wale Ogunwale02319a62016-09-26 15:21:22 -0700802 final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
803 if (dc != null) {
804 // We currently don't support adding a window token to the display if the display
805 // already has the binder mapped to another token. If there is a use case for supporting
806 // this moving forward we will either need to merge the WindowTokens some how or have
807 // the binder map to a list of window tokens.
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700808 throw new IllegalArgumentException("Can't map token=" + token + " to display="
809 + getName() + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700810 }
Wale Ogunwale2f569ed2017-05-08 09:15:49 -0700811 if (binder == null) {
812 throw new IllegalArgumentException("Can't map token=" + token + " to display="
813 + getName() + " binder is null");
814 }
815 if (token == null) {
816 throw new IllegalArgumentException("Can't map null token to display="
817 + getName() + " binder=" + binder);
818 }
819
Wale Ogunwale02319a62016-09-26 15:21:22 -0700820 mTokenMap.put(binder, token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700821
822 if (token.asAppWindowToken() == null) {
823 // Add non-app token to container hierarchy on the display. App tokens are added through
824 // the parent container managing them (e.g. Tasks).
Wale Ogunwale3a931692016-11-02 16:49:48 -0700825 switch (token.windowType) {
826 case TYPE_WALLPAPER:
827 mBelowAppWindowsContainers.addChild(token);
828 break;
829 case TYPE_INPUT_METHOD:
830 case TYPE_INPUT_METHOD_DIALOG:
831 mImeWindowsContainers.addChild(token);
832 break;
833 default:
834 mAboveAppWindowsContainers.addChild(token);
835 break;
836 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700837 }
Wale Ogunwale02319a62016-09-26 15:21:22 -0700838 }
839
840 WindowToken removeWindowToken(IBinder binder) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700841 final WindowToken token = mTokenMap.remove(binder);
842 if (token != null && token.asAppWindowToken() == null) {
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800843 token.setExiting();
844 }
845 return token;
846 }
847
848 /** Changes the display the input window token is housed on to this one. */
849 void reParentWindowToken(WindowToken token) {
850 final DisplayContent prevDc = token.getDisplayContent();
851 if (prevDc == this) {
852 return;
853 }
Andrii Kulian6cc1a1d2016-12-27 23:52:59 -0800854 if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
855 && token.asAppWindowToken() == null) {
856 // Removed the token from the map, but made sure it's not an app token before removing
857 // from parent.
858 token.getParent().removeChild(token);
Wale Ogunwale19e452e2016-10-12 12:36:29 -0700859 }
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800860
861 addWindowToken(token.token, token);
Wale Ogunwale02319a62016-09-26 15:21:22 -0700862 }
863
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700864 void removeAppToken(IBinder binder) {
865 final WindowToken token = removeWindowToken(binder);
866 if (token == null) {
867 Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
868 return;
869 }
870
871 final AppWindowToken appToken = token.asAppWindowToken();
872
873 if (appToken == null) {
874 Slog.w(TAG_WM, "Attempted to remove non-App token: " + binder + " token=" + token);
875 return;
876 }
877
878 appToken.onRemovedFromDisplay();
879 }
880
Craig Mautnerb47bbc32012-08-22 17:41:48 -0700881 Display getDisplay() {
882 return mDisplay;
883 }
884
Craig Mautner59c00972012-07-30 12:10:24 -0700885 DisplayInfo getDisplayInfo() {
886 return mDisplayInfo;
887 }
888
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700889 DisplayMetrics getDisplayMetrics() {
890 return mDisplayMetrics;
891 }
892
Andrii Kulian8ee72852017-03-10 10:36:45 -0800893 int getRotation() {
894 return mRotation;
895 }
896
897 void setRotation(int newRotation) {
898 mRotation = newRotation;
899 }
900
901 int getLastOrientation() {
902 return mLastOrientation;
903 }
904
905 void setLastOrientation(int orientation) {
906 mLastOrientation = orientation;
907 }
908
909 boolean getAltOrientation() {
910 return mAltOrientation;
911 }
912
913 void setAltOrientation(boolean altOrientation) {
914 mAltOrientation = altOrientation;
915 }
916
917 int getLastWindowForcedOrientation() {
918 return mLastWindowForcedOrientation;
919 }
920
Andrii Kulian06d07d62017-03-14 11:11:47 -0700921 /**
922 * Update rotation of the display.
923 *
924 * Returns true if the rotation has been changed. In this case YOU MUST CALL
925 * {@link WindowManagerService#sendNewConfiguration(int)} TO UNFREEZE THE SCREEN.
926 */
927 boolean updateRotationUnchecked(boolean inTransaction) {
928 if (mService.mDeferredRotationPauseCount > 0) {
929 // Rotation updates have been paused temporarily. Defer the update until
930 // updates have been resumed.
931 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, rotation is paused.");
932 return false;
933 }
934
935 ScreenRotationAnimation screenRotationAnimation =
936 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
937 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
938 // Rotation updates cannot be performed while the previous rotation change
939 // animation is still in progress. Skip this update. We will try updating
940 // again after the animation is finished and the display is unfrozen.
941 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, animation in progress.");
942 return false;
943 }
944 if (mService.mDisplayFrozen) {
945 // Even if the screen rotation animation has finished (e.g. isAnimating
946 // returns false), there is still some time where we haven't yet unfrozen
947 // the display. We also need to abort rotation here.
948 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
949 "Deferring rotation, still finishing previous rotation");
950 return false;
951 }
952
953 if (!mService.mDisplayEnabled) {
954 // No point choosing a rotation if the display is not enabled.
955 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Deferring rotation, display is not enabled.");
956 return false;
957 }
958
959 final int oldRotation = mRotation;
960 final int lastOrientation = mLastOrientation;
961 final boolean oldAltOrientation = mAltOrientation;
962 int rotation = mService.mPolicy.rotationForOrientationLw(lastOrientation, oldRotation);
Robert Carr0e007272017-10-02 13:00:55 -0700963 boolean mayRotateSeamlessly = mService.mPolicy.shouldRotateSeamlessly(oldRotation,
Robert Carr897215d2017-03-29 12:25:50 -0700964 rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -0700965
Robert Carr0e007272017-10-02 13:00:55 -0700966 if (mayRotateSeamlessly) {
Andrii Kulian06d07d62017-03-14 11:11:47 -0700967 final WindowState seamlessRotated = getWindow((w) -> w.mSeamlesslyRotated);
968 if (seamlessRotated != null) {
969 // We can't rotate (seamlessly or not) while waiting for the last seamless rotation
970 // to complete (that is, waiting for windows to redraw). It's tempting to check
971 // w.mSeamlessRotationCount but that could be incorrect in the case of
972 // window-removal.
973 return false;
974 }
Robert Carr0e007272017-10-02 13:00:55 -0700975
976 // In the presence of the PINNED stack or System Alert
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700977 // windows we unfortunately can not seamlessly rotate.
Wale Ogunwale61911492017-10-11 08:50:50 -0700978 if (hasPinnedStack()) {
Robert Carr0e007272017-10-02 13:00:55 -0700979 mayRotateSeamlessly = false;
980 }
981 for (int i = 0; i < mService.mSessions.size(); i++) {
982 if (mService.mSessions.valueAt(i).hasAlertWindowSurfaces()) {
983 mayRotateSeamlessly = false;
984 break;
985 }
986 }
Andrii Kulian06d07d62017-03-14 11:11:47 -0700987 }
Robert Carr0e007272017-10-02 13:00:55 -0700988 final boolean rotateSeamlessly = mayRotateSeamlessly;
Andrii Kulian06d07d62017-03-14 11:11:47 -0700989
990 // TODO: Implement forced rotation changes.
991 // Set mAltOrientation to indicate that the application is receiving
992 // an orientation that has different metrics than it expected.
993 // eg. Portrait instead of Landscape.
994
995 final boolean altOrientation = !mService.mPolicy.rotationHasCompatibleMetricsLw(
996 lastOrientation, rotation);
997
998 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Selected orientation " + lastOrientation
999 + ", got rotation " + rotation + " which has "
1000 + (altOrientation ? "incompatible" : "compatible") + " metrics");
1001
1002 if (oldRotation == rotation && oldAltOrientation == altOrientation) {
1003 // No change.
1004 return false;
1005 }
1006
1007 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Rotation changed to " + rotation
1008 + (altOrientation ? " (alt)" : "") + " from " + oldRotation
1009 + (oldAltOrientation ? " (alt)" : "") + ", lastOrientation=" + lastOrientation);
1010
1011 if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
1012 mService.mWaitingForConfig = true;
1013 }
1014
1015 mRotation = rotation;
1016 mAltOrientation = altOrientation;
1017 if (isDefaultDisplay) {
1018 mService.mPolicy.setRotationLw(rotation);
1019 }
1020
1021 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
1022 mService.mH.removeMessages(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT);
1023 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
1024 WINDOW_FREEZE_TIMEOUT_DURATION);
1025
1026 setLayoutNeeded();
1027 final int[] anim = new int[2];
Robert Carrf59b8dd2017-10-02 18:58:36 -07001028 mService.mPolicy.selectRotationAnimationLw(anim);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001029
1030 if (!rotateSeamlessly) {
Bryce Lee8f853582017-06-05 17:25:59 -07001031 mService.startFreezingDisplayLocked(inTransaction, anim[0], anim[1], this);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001032 // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
1033 screenRotationAnimation = mService.mAnimator.getScreenRotationAnimationLocked(
1034 mDisplayId);
1035 } else {
1036 // The screen rotation animation uses a screenshot to freeze the screen
1037 // while windows resize underneath.
1038 // When we are rotating seamlessly, we allow the elements to transition
1039 // to their rotated state independently and without a freeze required.
1040 screenRotationAnimation = null;
1041
1042 // We have to reset this in case a window was removed before it
1043 // finished seamless rotation.
1044 mService.mSeamlessRotationCount = 0;
1045 }
1046
1047 // We need to update our screen size information to match the new rotation. If the rotation
1048 // has actually changed then this method will return true and, according to the comment at
1049 // the top of the method, the caller is obligated to call computeNewConfigurationLocked().
1050 // By updating the Display info here it will be available to
1051 // #computeScreenConfiguration() later.
1052 updateDisplayAndOrientation(getConfiguration().uiMode);
1053
1054 if (!inTransaction) {
1055 if (SHOW_TRANSACTIONS) {
1056 Slog.i(TAG_WM, ">>> OPEN TRANSACTION setRotationUnchecked");
1057 }
1058 mService.openSurfaceTransaction();
1059 }
1060 try {
1061 // NOTE: We disable the rotation in the emulator because
1062 // it doesn't support hardware OpenGL emulation yet.
1063 if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
1064 && screenRotationAnimation.hasScreenshot()) {
Robert Carrb1579c82017-09-05 14:54:47 -07001065 if (screenRotationAnimation.setRotationInTransaction(rotation,
Andrii Kulian06d07d62017-03-14 11:11:47 -07001066 MAX_ANIMATION_DURATION, mService.getTransitionAnimationScaleLocked(),
1067 mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight)) {
1068 mService.scheduleAnimationLocked();
1069 }
1070 }
1071
1072 if (rotateSeamlessly) {
1073 forAllWindows(w -> {
1074 w.mWinAnimator.seamlesslyRotateWindow(oldRotation, rotation);
1075 }, true /* traverseTopToBottom */);
1076 }
1077
1078 mService.mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
1079 } finally {
1080 if (!inTransaction) {
Adrian Roos111aff92017-09-27 18:11:46 +02001081 mService.closeSurfaceTransaction("setRotationUnchecked");
Andrii Kulian06d07d62017-03-14 11:11:47 -07001082 if (SHOW_LIGHT_TRANSACTIONS) {
1083 Slog.i(TAG_WM, "<<< CLOSE TRANSACTION setRotationUnchecked");
1084 }
1085 }
1086 }
1087
1088 forAllWindows(w -> {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001089 if (w.mHasSurface && !rotateSeamlessly) {
1090 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Set mOrientationChanging of " + w);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001091 w.setOrientationChanging(true);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001092 mService.mRoot.mOrientationChangeComplete = false;
1093 w.mLastFreezeDuration = 0;
1094 }
1095 w.mReportOrientationChanged = true;
1096 }, true /* traverseTopToBottom */);
1097
1098 if (rotateSeamlessly) {
1099 mService.mH.removeMessages(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT);
1100 mService.mH.sendEmptyMessageDelayed(WindowManagerService.H.SEAMLESS_ROTATION_TIMEOUT,
1101 SEAMLESS_ROTATION_TIMEOUT_DURATION);
1102 }
1103
1104 for (int i = mService.mRotationWatchers.size() - 1; i >= 0; i--) {
1105 final WindowManagerService.RotationWatcher rotationWatcher
1106 = mService.mRotationWatchers.get(i);
1107 if (rotationWatcher.mDisplayId == mDisplayId) {
1108 try {
1109 rotationWatcher.mWatcher.onRotationChanged(rotation);
1110 } catch (RemoteException e) {
1111 // Ignore
1112 }
1113 }
1114 }
1115
1116 // TODO (multi-display): Magnification is supported only for the default display.
1117 // Announce rotation only if we will not animate as we already have the
1118 // windows in final state. Otherwise, we make this call at the rotation end.
1119 if (screenRotationAnimation == null && mService.mAccessibilityController != null
1120 && isDefaultDisplay) {
1121 mService.mAccessibilityController.onRotationChangedLocked(this);
1122 }
1123
1124 return true;
1125 }
1126
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001127 void configureDisplayPolicy() {
1128 mService.mPolicy.setInitialDisplaySize(getDisplay(),
1129 mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1130
1131 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
1132 }
1133
Andrii Kulian06d07d62017-03-14 11:11:47 -07001134 /**
1135 * Update {@link #mDisplayInfo} and other internal variables when display is rotated or config
1136 * changed.
1137 * Do not call if {@link WindowManagerService#mDisplayReady} == false.
1138 */
1139 private DisplayInfo updateDisplayAndOrientation(int uiMode) {
1140 // Use the effective "visual" dimensions based on current rotation
1141 final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
1142 final int realdw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
1143 final int realdh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
1144 int dw = realdw;
1145 int dh = realdh;
1146
1147 if (mAltOrientation) {
1148 if (realdw > realdh) {
1149 // Turn landscape into portrait.
1150 int maxw = (int)(realdh/1.3f);
1151 if (maxw < realdw) {
1152 dw = maxw;
1153 }
1154 } else {
1155 // Turn portrait into landscape.
1156 int maxh = (int)(realdw/1.3f);
1157 if (maxh < realdh) {
1158 dh = maxh;
1159 }
1160 }
1161 }
1162
1163 // Update application display metrics.
Adrian Roos11c25582018-02-19 18:06:36 +01001164 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(
1165 mRotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001166 final int appWidth = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001167 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001168 final int appHeight = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001169 mDisplayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001170 mDisplayInfo.rotation = mRotation;
1171 mDisplayInfo.logicalWidth = dw;
1172 mDisplayInfo.logicalHeight = dh;
1173 mDisplayInfo.logicalDensityDpi = mBaseDisplayDensity;
1174 mDisplayInfo.appWidth = appWidth;
1175 mDisplayInfo.appHeight = appHeight;
1176 if (isDefaultDisplay) {
1177 mDisplayInfo.getLogicalMetrics(mRealDisplayMetrics,
1178 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
1179 }
Adrian Roos11c25582018-02-19 18:06:36 +01001180 mDisplayInfo.displayCutout = displayCutout;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001181 mDisplayInfo.getAppMetrics(mDisplayMetrics);
1182 if (mDisplayScalingDisabled) {
1183 mDisplayInfo.flags |= Display.FLAG_SCALING_DISABLED;
1184 } else {
1185 mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
1186 }
1187
1188 mService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
1189 mDisplayInfo);
1190
1191 mBaseDisplayRect.set(0, 0, dw, dh);
1192
1193 if (isDefaultDisplay) {
1194 mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(mDisplayMetrics,
1195 mCompatDisplayMetrics);
1196 }
Bryce Leef3c6a472017-11-14 14:53:06 -08001197
1198 updateBounds();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001199 return mDisplayInfo;
1200 }
1201
Adrian Roos11c25582018-02-19 18:06:36 +01001202 DisplayCutout calculateDisplayCutoutForRotation(int rotation) {
Adrian Roos2aa0fcd2018-02-19 18:07:49 +01001203 return mDisplayCutoutCache.getOrCompute(mInitialDisplayCutout, rotation);
1204 }
1205
1206 private DisplayCutout calculateDisplayCutoutForRotationUncached(
1207 DisplayCutout cutout, int rotation) {
Adrian Roos24264212018-02-19 16:26:15 +01001208 if (cutout == null || cutout == DisplayCutout.NO_CUTOUT) {
Adrian Roos1cf585052018-01-03 18:43:27 +01001209 return cutout;
1210 }
Adrian Roos11c25582018-02-19 18:06:36 +01001211 if (rotation == ROTATION_0) {
Adrian Roos24264212018-02-19 16:26:15 +01001212 return cutout.computeSafeInsets(mInitialDisplayWidth, mInitialDisplayHeight);
1213 }
Adrian Roos11c25582018-02-19 18:06:36 +01001214 final boolean rotated = (rotation == ROTATION_90 || mRotation == ROTATION_270);
Adrian Roos1cf585052018-01-03 18:43:27 +01001215 final Path bounds = cutout.getBounds().getBoundaryPath();
Adrian Roos11c25582018-02-19 18:06:36 +01001216 transformPhysicalToLogicalCoordinates(rotation, mInitialDisplayWidth, mInitialDisplayHeight,
1217 mTmpMatrix);
Adrian Roos1cf585052018-01-03 18:43:27 +01001218 bounds.transform(mTmpMatrix);
Adrian Roos24264212018-02-19 16:26:15 +01001219 return DisplayCutout.fromBounds(bounds).computeSafeInsets(
1220 rotated ? mInitialDisplayHeight : mInitialDisplayWidth,
1221 rotated ? mInitialDisplayWidth : mInitialDisplayHeight);
Adrian Roos1cf585052018-01-03 18:43:27 +01001222 }
1223
Andrii Kulian06d07d62017-03-14 11:11:47 -07001224 /**
1225 * Compute display configuration based on display properties and policy settings.
1226 * Do not call if mDisplayReady == false.
1227 */
1228 void computeScreenConfiguration(Configuration config) {
1229 final DisplayInfo displayInfo = updateDisplayAndOrientation(config.uiMode);
1230
1231 final int dw = displayInfo.logicalWidth;
1232 final int dh = displayInfo.logicalHeight;
Wale Ogunwale687b4272017-07-27 02:56:23 -07001233 config.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
1234 // TODO: Probably best to set this based on some setting in the display content object,
1235 // so the display can be configured for things like fullscreen.
1236 config.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
Bryce Leec1f2f2a2017-06-22 15:29:42 -07001237
Adrian Roos11c25582018-02-19 18:06:36 +01001238 final float density = mDisplayMetrics.density;
Andrii Kulian06d07d62017-03-14 11:11:47 -07001239 config.screenWidthDp =
1240 (int)(mService.mPolicy.getConfigDisplayWidth(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001241 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001242 config.screenHeightDp =
1243 (int)(mService.mPolicy.getConfigDisplayHeight(dw, dh, displayInfo.rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001244 config.uiMode, mDisplayId, displayInfo.displayCutout) / density);
Bryce Lee7566d762017-03-30 09:34:15 -07001245
Adrian Roos11c25582018-02-19 18:06:36 +01001246 mService.mPolicy.getNonDecorInsetsLw(displayInfo.rotation, dw, dh,
1247 displayInfo.displayCutout, mTmpRect);
Bryce Lee7566d762017-03-30 09:34:15 -07001248 final int leftInset = mTmpRect.left;
1249 final int topInset = mTmpRect.top;
1250 // appBounds at the root level should mirror the app screen size.
Wale Ogunwale822e5122017-07-26 06:02:24 -07001251 config.windowConfiguration.setAppBounds(leftInset /* left */, topInset /* top */,
1252 leftInset + displayInfo.appWidth /* right */,
1253 topInset + displayInfo.appHeight /* bottom */);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001254 final boolean rotated = (displayInfo.rotation == Surface.ROTATION_90
1255 || displayInfo.rotation == Surface.ROTATION_270);
1256
1257 computeSizeRangesAndScreenLayout(displayInfo, mDisplayId, rotated, config.uiMode, dw, dh,
Adrian Roos11c25582018-02-19 18:06:36 +01001258 density, config);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001259
1260 config.screenLayout = (config.screenLayout & ~Configuration.SCREENLAYOUT_ROUND_MASK)
1261 | ((displayInfo.flags & Display.FLAG_ROUND) != 0
1262 ? Configuration.SCREENLAYOUT_ROUND_YES
1263 : Configuration.SCREENLAYOUT_ROUND_NO);
1264
1265 config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
1266 config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
1267 config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, config.uiMode, dw,
1268 dh, mDisplayId);
1269 config.densityDpi = displayInfo.logicalDensityDpi;
1270
1271 config.colorMode =
1272 (displayInfo.isHdr()
1273 ? Configuration.COLOR_MODE_HDR_YES
1274 : Configuration.COLOR_MODE_HDR_NO)
Romain Guye89d0bb2017-06-20 12:23:42 -07001275 | (displayInfo.isWideColorGamut() && mService.hasWideColorGamutSupport()
Andrii Kulian06d07d62017-03-14 11:11:47 -07001276 ? Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_YES
1277 : Configuration.COLOR_MODE_WIDE_COLOR_GAMUT_NO);
1278
1279 // Update the configuration based on available input devices, lid switch,
1280 // and platform configuration.
1281 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1282 config.keyboard = Configuration.KEYBOARD_NOKEYS;
1283 config.navigation = Configuration.NAVIGATION_NONAV;
1284
1285 int keyboardPresence = 0;
1286 int navigationPresence = 0;
1287 final InputDevice[] devices = mService.mInputManager.getInputDevices();
1288 final int len = devices != null ? devices.length : 0;
1289 for (int i = 0; i < len; i++) {
1290 InputDevice device = devices[i];
1291 if (!device.isVirtual()) {
1292 final int sources = device.getSources();
1293 final int presenceFlag = device.isExternal() ?
1294 WindowManagerPolicy.PRESENCE_EXTERNAL :
1295 WindowManagerPolicy.PRESENCE_INTERNAL;
1296
1297 // TODO(multi-display): Configure on per-display basis.
1298 if (mService.mIsTouchDevice) {
1299 if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
1300 InputDevice.SOURCE_TOUCHSCREEN) {
1301 config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
1302 }
1303 } else {
1304 config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
1305 }
1306
1307 if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
1308 config.navigation = Configuration.NAVIGATION_TRACKBALL;
1309 navigationPresence |= presenceFlag;
1310 } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
1311 && config.navigation == Configuration.NAVIGATION_NONAV) {
1312 config.navigation = Configuration.NAVIGATION_DPAD;
1313 navigationPresence |= presenceFlag;
1314 }
1315
1316 if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
1317 config.keyboard = Configuration.KEYBOARD_QWERTY;
1318 keyboardPresence |= presenceFlag;
1319 }
1320 }
1321 }
1322
1323 if (config.navigation == Configuration.NAVIGATION_NONAV && mService.mHasPermanentDpad) {
1324 config.navigation = Configuration.NAVIGATION_DPAD;
1325 navigationPresence |= WindowManagerPolicy.PRESENCE_INTERNAL;
1326 }
1327
1328 // Determine whether a hard keyboard is available and enabled.
1329 // TODO(multi-display): Should the hardware keyboard be tied to a display or to a device?
1330 boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
1331 if (hardKeyboardAvailable != mService.mHardKeyboardAvailable) {
1332 mService.mHardKeyboardAvailable = hardKeyboardAvailable;
1333 mService.mH.removeMessages(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1334 mService.mH.sendEmptyMessage(WindowManagerService.H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
1335 }
1336
1337 // Let the policy update hidden states.
1338 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
1339 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
1340 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
1341 mService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
1342 }
1343
1344 private int computeCompatSmallestWidth(boolean rotated, int uiMode, int dw, int dh,
1345 int displayId) {
1346 mTmpDisplayMetrics.setTo(mDisplayMetrics);
1347 final DisplayMetrics tmpDm = mTmpDisplayMetrics;
1348 final int unrotDw, unrotDh;
1349 if (rotated) {
1350 unrotDw = dh;
1351 unrotDh = dw;
1352 } else {
1353 unrotDw = dw;
1354 unrotDh = dh;
1355 }
1356 int sw = reduceCompatConfigWidthSize(0, Surface.ROTATION_0, uiMode, tmpDm, unrotDw, unrotDh,
1357 displayId);
1358 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_90, uiMode, tmpDm, unrotDh, unrotDw,
1359 displayId);
1360 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_180, uiMode, tmpDm, unrotDw, unrotDh,
1361 displayId);
1362 sw = reduceCompatConfigWidthSize(sw, Surface.ROTATION_270, uiMode, tmpDm, unrotDh, unrotDw,
1363 displayId);
1364 return sw;
1365 }
1366
1367 private int reduceCompatConfigWidthSize(int curSize, int rotation, int uiMode,
1368 DisplayMetrics dm, int dw, int dh, int displayId) {
1369 dm.noncompatWidthPixels = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001370 displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001371 dm.noncompatHeightPixels = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation,
Adrian Roos11c25582018-02-19 18:06:36 +01001372 uiMode, displayId, mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001373 float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
1374 int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
1375 if (curSize == 0 || size < curSize) {
1376 curSize = size;
1377 }
1378 return curSize;
1379 }
1380
1381 private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, int displayId,
1382 boolean rotated, int uiMode, int dw, int dh, float density, Configuration outConfig) {
1383
1384 // We need to determine the smallest width that will occur under normal
1385 // operation. To this, start with the base screen size and compute the
1386 // width under the different possible rotations. We need to un-rotate
1387 // the current screen dimensions before doing this.
1388 int unrotDw, unrotDh;
1389 if (rotated) {
1390 unrotDw = dh;
1391 unrotDh = dw;
1392 } else {
1393 unrotDw = dw;
1394 unrotDh = dh;
1395 }
1396 displayInfo.smallestNominalAppWidth = 1<<30;
1397 displayInfo.smallestNominalAppHeight = 1<<30;
1398 displayInfo.largestNominalAppWidth = 0;
1399 displayInfo.largestNominalAppHeight = 0;
1400 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_0, uiMode, unrotDw,
1401 unrotDh);
1402 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_90, uiMode, unrotDh,
1403 unrotDw);
1404 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_180, uiMode, unrotDw,
1405 unrotDh);
1406 adjustDisplaySizeRanges(displayInfo, displayId, Surface.ROTATION_270, uiMode, unrotDh,
1407 unrotDw);
1408 int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
1409 sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh, uiMode,
1410 displayId);
1411 sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw, uiMode,
1412 displayId);
1413 sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh, uiMode,
1414 displayId);
1415 sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw, uiMode,
1416 displayId);
1417 outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
1418 outConfig.screenLayout = sl;
1419 }
1420
1421 private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh,
1422 int uiMode, int displayId) {
1423 // Get the app screen size at this rotation.
Adrian Roos11c25582018-02-19 18:06:36 +01001424 int w = mService.mPolicy.getNonDecorDisplayWidth(dw, dh, rotation, uiMode, displayId,
1425 mDisplayInfo.displayCutout);
1426 int h = mService.mPolicy.getNonDecorDisplayHeight(dw, dh, rotation, uiMode, displayId,
1427 mDisplayInfo.displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001428
1429 // Compute the screen layout size class for this rotation.
1430 int longSize = w;
1431 int shortSize = h;
1432 if (longSize < shortSize) {
1433 int tmp = longSize;
1434 longSize = shortSize;
1435 shortSize = tmp;
1436 }
1437 longSize = (int)(longSize/density);
1438 shortSize = (int)(shortSize/density);
1439 return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
1440 }
1441
1442 private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int displayId, int rotation,
1443 int uiMode, int dw, int dh) {
Adrian Roos11c25582018-02-19 18:06:36 +01001444 final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(rotation);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001445 final int width = mService.mPolicy.getConfigDisplayWidth(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001446 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001447 if (width < displayInfo.smallestNominalAppWidth) {
1448 displayInfo.smallestNominalAppWidth = width;
1449 }
1450 if (width > displayInfo.largestNominalAppWidth) {
1451 displayInfo.largestNominalAppWidth = width;
1452 }
1453 final int height = mService.mPolicy.getConfigDisplayHeight(dw, dh, rotation, uiMode,
Adrian Roos11c25582018-02-19 18:06:36 +01001454 displayId, displayCutout);
Andrii Kulian06d07d62017-03-14 11:11:47 -07001455 if (height < displayInfo.smallestNominalAppHeight) {
1456 displayInfo.smallestNominalAppHeight = height;
1457 }
1458 if (height > displayInfo.largestNominalAppHeight) {
1459 displayInfo.largestNominalAppHeight = height;
1460 }
1461 }
1462
Jorim Jaggi61f39a72015-10-29 16:54:18 +01001463 DockedStackDividerController getDockedDividerController() {
1464 return mDividerControllerLocked;
1465 }
1466
Winson Chung655332c2016-10-31 13:14:28 -07001467 PinnedStackController getPinnedStackController() {
1468 return mPinnedStackControllerLocked;
1469 }
1470
Jeff Browna506a6e2013-06-04 00:02:38 -07001471 /**
1472 * Returns true if the specified UID has access to this display.
1473 */
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001474 boolean hasAccess(int uid) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001475 return mDisplay.hasAccess(uid);
1476 }
1477
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001478 boolean isPrivate() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001479 return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
keunyounga446bf02013-06-21 19:07:57 -07001480 }
1481
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001482 TaskStack getHomeStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001483 return mTaskStackContainers.getHomeStack();
Craig Mautnerd5d5d0f2013-04-03 15:08:21 -07001484 }
1485
Wale Ogunwale61911492017-10-11 08:50:50 -07001486 /**
1487 * @return The primary split-screen stack, but only if it is visible, and {@code null} otherwise.
1488 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001489 TaskStack getSplitScreenPrimaryStack() {
1490 TaskStack stack = mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001491 return (stack != null && stack.isVisible()) ? stack : null;
1492 }
1493
1494 /**
Matthew Ng64e77cf2017-10-31 14:01:31 -07001495 * Like {@link #getSplitScreenPrimaryStack}, but also returns the stack if it's currently
Wale Ogunwale61911492017-10-11 08:50:50 -07001496 * not visible.
1497 */
Matthew Ng64e77cf2017-10-31 14:01:31 -07001498 TaskStack getSplitScreenPrimaryStackIgnoringVisibility() {
1499 return mTaskStackContainers.getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07001500 }
1501
1502 TaskStack getPinnedStack() {
1503 return mTaskStackContainers.getPinnedStack();
1504 }
1505
1506 private boolean hasPinnedStack() {
1507 return mTaskStackContainers.getPinnedStack() != null;
Chong Zhangd9d35bd2016-08-04 17:55:21 -07001508 }
1509
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001510 /**
1511 * Returns the topmost stack on the display that is compatible with the input windowing mode.
1512 * Null is no compatible stack on the display.
1513 */
Wale Ogunwale30e441d2017-11-09 08:28:45 -08001514 TaskStack getTopStackInWindowingMode(int windowingMode) {
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001515 return getStack(windowingMode, ACTIVITY_TYPE_UNDEFINED);
1516 }
1517
1518 /**
1519 * Returns the topmost stack on the display that is compatible with the input windowing mode and
1520 * activity type. Null is no compatible stack on the display.
1521 */
Wale Ogunwale68278562017-09-23 17:13:55 -07001522 TaskStack getStack(int windowingMode, int activityType) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001523 return mTaskStackContainers.getStack(windowingMode, activityType);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001524 }
1525
Bryce Lee48f4b572017-04-10 10:54:15 -07001526 @VisibleForTesting
Wale Ogunwale61911492017-10-11 08:50:50 -07001527 TaskStack getTopStack() {
1528 return mTaskStackContainers.getTopStack();
Bryce Lee48f4b572017-04-10 10:54:15 -07001529 }
1530
Winson Chunge2d72172018-01-25 17:46:20 +00001531 ArrayList<Task> getVisibleTasks() {
1532 return mTaskStackContainers.getVisibleTasks();
1533 }
1534
Wale Ogunwale61911492017-10-11 08:50:50 -07001535 void onStackWindowingModeChanged(TaskStack stack) {
1536 mTaskStackContainers.onStackWindowingModeChanged(stack);
Bryce Lee48f4b572017-04-10 10:54:15 -07001537 }
1538
Andrii Kulian441e4492016-09-29 15:25:00 -07001539 @Override
Wale Ogunwale98d62312017-07-12 09:24:56 -07001540 public void onConfigurationChanged(Configuration newParentConfig) {
Andrii Kulian441e4492016-09-29 15:25:00 -07001541 super.onConfigurationChanged(newParentConfig);
1542
Andrii Kulian3a507b52016-09-19 18:14:12 -07001543 // The display size information is heavily dependent on the resources in the current
1544 // configuration, so we need to reconfigure it every time the configuration changes.
1545 // See {@link PhoneWindowManager#setInitialDisplaySize}...sigh...
1546 mService.reconfigureDisplayLocked(this);
1547
Bryce Leef3c6a472017-11-14 14:53:06 -08001548 final DockedStackDividerController dividerController = getDockedDividerController();
1549
1550 if (dividerController != null) {
1551 getDockedDividerController().onConfigurationChanged();
1552 }
1553
1554 final PinnedStackController pinnedStackController = getPinnedStackController();
1555
1556 if (pinnedStackController != null) {
1557 getPinnedStackController().onConfigurationChanged();
1558 }
Andrii Kulian441e4492016-09-29 15:25:00 -07001559 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001560
Andrii Kulian441e4492016-09-29 15:25:00 -07001561 /**
1562 * Callback used to trigger bounds update after configuration change and get ids of stacks whose
1563 * bounds were updated.
1564 */
Bryce Leeaea60d22018-01-31 14:42:15 -08001565 void updateStackBoundsAfterConfigChange(@NonNull List<TaskStack> changedStackList) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001566 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1567 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Andrii Kulian441e4492016-09-29 15:25:00 -07001568 if (stack.updateBoundsAfterConfigChange()) {
Bryce Leeaea60d22018-01-31 14:42:15 -08001569 changedStackList.add(stack);
Andrii Kulian3a507b52016-09-19 18:14:12 -07001570 }
1571 }
Winson Chung32c566f2017-04-11 18:31:21 -07001572
1573 // If there was no pinned stack, we still need to notify the controller of the display info
1574 // update as a result of the config change. We do this here to consolidate the flow between
1575 // changes when there is and is not a stack.
Wale Ogunwale61911492017-10-11 08:50:50 -07001576 if (!hasPinnedStack()) {
Winson Chung32c566f2017-04-11 18:31:21 -07001577 mPinnedStackControllerLocked.onDisplayInfoChanged();
1578 }
Andrii Kulian3a507b52016-09-19 18:14:12 -07001579 }
1580
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001581 @Override
1582 boolean fillsParent() {
1583 return true;
1584 }
1585
1586 @Override
1587 boolean isVisible() {
1588 return true;
1589 }
1590
1591 @Override
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001592 void onAppTransitionDone() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001593 super.onAppTransitionDone();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001594 mService.mWindowsChanged = true;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001595 }
1596
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001597 @Override
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08001598 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1599 // Special handling so we can process IME windows with #forAllImeWindows above their IME
1600 // target, or here in order if there isn't an IME target.
1601 if (traverseTopToBottom) {
1602 for (int i = mChildren.size() - 1; i >= 0; --i) {
1603 final DisplayChildWindowContainer child = mChildren.get(i);
1604 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1605 // In this case the Ime windows will be processed above their target so we skip
1606 // here.
1607 continue;
1608 }
1609 if (child.forAllWindows(callback, traverseTopToBottom)) {
1610 return true;
1611 }
1612 }
1613 } else {
1614 final int count = mChildren.size();
1615 for (int i = 0; i < count; i++) {
1616 final DisplayChildWindowContainer child = mChildren.get(i);
1617 if (child == mImeWindowsContainers && mService.mInputMethodTarget != null) {
1618 // In this case the Ime windows will be processed above their target so we skip
1619 // here.
1620 continue;
1621 }
1622 if (child.forAllWindows(callback, traverseTopToBottom)) {
1623 return true;
1624 }
1625 }
1626 }
1627 return false;
1628 }
1629
1630 boolean forAllImeWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
1631 return mImeWindowsContainers.forAllWindows(callback, traverseTopToBottom);
1632 }
1633
Wale Ogunwale399c8692017-05-08 14:22:42 -07001634 @Override
1635 int getOrientation() {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001636 final WindowManagerPolicy policy = mService.mPolicy;
1637
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001638 if (mService.mDisplayFrozen) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08001639 if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001640 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08001641 "Display is frozen, return " + mLastWindowForcedOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001642 // If the display is frozen, some activities may be in the middle of restarting, and
1643 // thus have removed their old window. If the window has the flag to hide the lock
1644 // screen, then the lock screen can re-appear and inflict its own orientation on us.
1645 // Keep the orientation stable until this all settles down.
Andrii Kulian8ee72852017-03-10 10:36:45 -08001646 return mLastWindowForcedOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001647 } else if (policy.isKeyguardLocked()) {
1648 // Use the last orientation the while the display is frozen with the keyguard
1649 // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
1650 // window. We don't want to check the show when locked window directly though as
1651 // things aren't stable while the display is frozen, for example the window could be
1652 // momentarily unavailable due to activity relaunch.
1653 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display is frozen while keyguard locked, "
Andrii Kulian8ee72852017-03-10 10:36:45 -08001654 + "return " + mLastOrientation);
1655 return mLastOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001656 }
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001657 } else {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001658 final int orientation = mAboveAppWindowsContainers.getOrientation();
1659 if (orientation != SCREEN_ORIENTATION_UNSET) {
1660 return orientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07001661 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001662 }
1663
Wale Ogunwale399c8692017-05-08 14:22:42 -07001664 // Top system windows are not requesting an orientation. Start searching from apps.
1665 return mTaskStackContainers.getOrientation();
Wale Ogunwale51362492016-09-08 17:49:17 -07001666 }
1667
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001668 void updateDisplayInfo() {
Andrii Kuliancd097992017-03-23 18:31:59 -07001669 // Check if display metrics changed and update base values if needed.
1670 updateBaseDisplayMetricsIfNeeded();
1671
Craig Mautner722285e2012-09-07 13:55:58 -07001672 mDisplay.getDisplayInfo(mDisplayInfo);
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001673 mDisplay.getMetrics(mDisplayMetrics);
Andrii Kuliancd097992017-03-23 18:31:59 -07001674
Wale Ogunwale61911492017-10-11 08:50:50 -07001675 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1676 mTaskStackContainers.getChildAt(i).updateDisplayInfo(null);
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001677 }
Craig Mautner722285e2012-09-07 13:55:58 -07001678 }
1679
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001680 void initializeDisplayBaseInfo() {
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001681 final DisplayManagerInternal displayManagerInternal = mService.mDisplayManagerInternal;
1682 if (displayManagerInternal != null) {
1683 // Bootstrap the default logical display from the display manager.
1684 final DisplayInfo newDisplayInfo = displayManagerInternal.getDisplayInfo(mDisplayId);
1685 if (newDisplayInfo != null) {
1686 mDisplayInfo.copyFrom(newDisplayInfo);
1687 }
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001688 }
Wale Ogunwaleb699ce02016-07-18 12:05:30 -07001689
Andrii Kuliancd097992017-03-23 18:31:59 -07001690 updateBaseDisplayMetrics(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight,
1691 mDisplayInfo.logicalDensityDpi);
1692 mInitialDisplayWidth = mDisplayInfo.logicalWidth;
1693 mInitialDisplayHeight = mDisplayInfo.logicalHeight;
1694 mInitialDisplayDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001695 mInitialDisplayCutout = mDisplayInfo.displayCutout;
Wale Ogunwalefd04d8c2015-09-30 10:09:39 -07001696 }
1697
Andrii Kuliancd097992017-03-23 18:31:59 -07001698 /**
1699 * If display metrics changed, overrides are not set and it's not just a rotation - update base
1700 * values.
1701 */
1702 private void updateBaseDisplayMetricsIfNeeded() {
1703 // Get real display metrics without overrides from WM.
1704 mService.mDisplayManagerInternal.getNonOverrideDisplayInfo(mDisplayId, mDisplayInfo);
1705 final int orientation = mDisplayInfo.rotation;
1706 final boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
1707 final int newWidth = rotated ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
1708 final int newHeight = rotated ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
1709 final int newDensity = mDisplayInfo.logicalDensityDpi;
Adrian Roos1cf585052018-01-03 18:43:27 +01001710 final DisplayCutout newCutout = mDisplayInfo.displayCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001711
1712 final boolean displayMetricsChanged = mInitialDisplayWidth != newWidth
1713 || mInitialDisplayHeight != newHeight
Adrian Roos1cf585052018-01-03 18:43:27 +01001714 || mInitialDisplayDensity != mDisplayInfo.logicalDensityDpi
1715 || !Objects.equals(mInitialDisplayCutout, newCutout);
Andrii Kuliancd097992017-03-23 18:31:59 -07001716
1717 if (displayMetricsChanged) {
1718 // Check if display size or density is forced.
1719 final boolean isDisplaySizeForced = mBaseDisplayWidth != mInitialDisplayWidth
1720 || mBaseDisplayHeight != mInitialDisplayHeight;
1721 final boolean isDisplayDensityForced = mBaseDisplayDensity != mInitialDisplayDensity;
1722
1723 // If there is an override set for base values - use it, otherwise use new values.
1724 updateBaseDisplayMetrics(isDisplaySizeForced ? mBaseDisplayWidth : newWidth,
1725 isDisplaySizeForced ? mBaseDisplayHeight : newHeight,
1726 isDisplayDensityForced ? mBaseDisplayDensity : newDensity);
1727
1728 // Real display metrics changed, so we should also update initial values.
1729 mInitialDisplayWidth = newWidth;
1730 mInitialDisplayHeight = newHeight;
1731 mInitialDisplayDensity = newDensity;
Adrian Roos1cf585052018-01-03 18:43:27 +01001732 mInitialDisplayCutout = newCutout;
Andrii Kuliancd097992017-03-23 18:31:59 -07001733 mService.reconfigureDisplayLocked(this);
1734 }
1735 }
1736
Bryce Lee27cec322017-03-21 09:41:37 -07001737 /** Sets the maximum width the screen resolution can be */
1738 void setMaxUiWidth(int width) {
1739 if (DEBUG_DISPLAY) {
1740 Slog.v(TAG_WM, "Setting max ui width:" + width + " on display:" + getDisplayId());
1741 }
1742
1743 mMaxUiWidth = width;
1744
1745 // Update existing metrics.
1746 updateBaseDisplayMetrics(mBaseDisplayWidth, mBaseDisplayHeight, mBaseDisplayDensity);
1747 }
1748
1749 /** Update base (override) display metrics. */
1750 void updateBaseDisplayMetrics(int baseWidth, int baseHeight, int baseDensity) {
1751 mBaseDisplayWidth = baseWidth;
1752 mBaseDisplayHeight = baseHeight;
1753 mBaseDisplayDensity = baseDensity;
1754
1755 if (mMaxUiWidth > 0 && mBaseDisplayWidth > mMaxUiWidth) {
1756 mBaseDisplayHeight = (mMaxUiWidth * mBaseDisplayHeight) / mBaseDisplayWidth;
1757 mBaseDisplayDensity = (mMaxUiWidth * mBaseDisplayDensity) / mBaseDisplayWidth;
1758 mBaseDisplayWidth = mMaxUiWidth;
1759
1760 if (DEBUG_DISPLAY) {
1761 Slog.v(TAG_WM, "Applying config restraints:" + mBaseDisplayWidth + "x"
1762 + mBaseDisplayHeight + " at density:" + mBaseDisplayDensity
1763 + " on display:" + getDisplayId());
1764 }
1765 }
1766
1767 mBaseDisplayRect.set(0, 0, mBaseDisplayWidth, mBaseDisplayHeight);
Bryce Leef3c6a472017-11-14 14:53:06 -08001768
1769 updateBounds();
Bryce Lee27cec322017-03-21 09:41:37 -07001770 }
1771
Wale Ogunwaledb506192017-12-08 10:57:32 -08001772 void getStableRect(Rect out) {
1773 out.set(mDisplayFrames.mStable);
Chong Zhangf66db432016-01-13 10:39:51 -08001774 }
1775
Wale Ogunwale61911492017-10-11 08:50:50 -07001776 TaskStack createStack(int stackId, boolean onTop, StackWindowController controller) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001777 if (DEBUG_STACK) Slog.d(TAG_WM, "Create new stackId=" + stackId + " on displayId="
1778 + mDisplayId);
Andrii Kulian839def92016-11-02 10:58:58 -07001779
Wale Ogunwale61911492017-10-11 08:50:50 -07001780 final TaskStack stack = new TaskStack(mService, stackId, controller);
1781 mTaskStackContainers.addStackToDisplay(stack, onTop);
Wale Ogunwale1666e312016-12-16 11:27:18 -08001782 return stack;
Andrii Kulian839def92016-11-02 10:58:58 -07001783 }
1784
Andrii Kulian51c1b672017-04-07 18:39:32 -07001785 void moveStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08001786 final DisplayContent prevDc = stack.getDisplayContent();
1787 if (prevDc == null) {
Andrii Kulian839def92016-11-02 10:58:58 -07001788 throw new IllegalStateException("Trying to move stackId=" + stack.mStackId
1789 + " which is not currently attached to any display");
1790 }
Wale Ogunwale1666e312016-12-16 11:27:18 -08001791 if (prevDc.getDisplayId() == mDisplayId) {
Andrii Kulian839def92016-11-02 10:58:58 -07001792 throw new IllegalArgumentException("Trying to move stackId=" + stack.mStackId
1793 + " to its current displayId=" + mDisplayId);
1794 }
1795
Wale Ogunwale61911492017-10-11 08:50:50 -07001796 prevDc.mTaskStackContainers.removeChild(stack);
Andrii Kulian51c1b672017-04-07 18:39:32 -07001797 mTaskStackContainers.addStackToDisplay(stack, onTop);
Craig Mautnerc00204b2013-03-05 15:02:14 -08001798 }
1799
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001800 @Override
1801 protected void addChild(DisplayChildWindowContainer child,
1802 Comparator<DisplayChildWindowContainer> comparator) {
1803 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1804 }
Wale Ogunwale1e60e0c2015-10-28 13:36:10 -07001805
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001806 @Override
1807 protected void addChild(DisplayChildWindowContainer child, int index) {
1808 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
1809 }
1810
1811 @Override
1812 protected void removeChild(DisplayChildWindowContainer child) {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001813 // Only allow removal of direct children from this display if the display is in the process
1814 // of been removed.
1815 if (mRemovingDisplay) {
1816 super.removeChild(child);
1817 return;
1818 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001819 throw new UnsupportedOperationException("See DisplayChildWindowContainer");
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001820 }
1821
Andrii Kuliand2765632016-12-12 22:26:34 -08001822 @Override
1823 void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
1824 // Children of the display are statically ordered, so the real intention here is to perform
1825 // the operation on the display and not the static direct children.
1826 getParent().positionChildAt(position, this, includingParents);
1827 }
1828
Winson Chung59a47ded2018-01-25 17:46:06 +00001829 void positionStackAt(int position, TaskStack child) {
1830 mTaskStackContainers.positionChildAt(position, child, false /* includingParents */);
1831 layoutAndAssignWindowLayersIfNeeded();
1832 }
1833
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001834 int taskIdFromPoint(int x, int y) {
Wale Ogunwale61911492017-10-11 08:50:50 -07001835 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1836 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001837 final int taskId = stack.taskIdFromPoint(x, y);
1838 if (taskId != -1) {
1839 return taskId;
Craig Mautner967212c2013-04-13 21:10:58 -07001840 }
1841 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001842 return -1;
Craig Mautnercf910b02013-04-23 11:23:27 -07001843 }
1844
Chong Zhang8e89b312015-09-09 15:09:30 -07001845 /**
Chong Zhangd8ceb852015-11-11 14:53:41 -08001846 * Find the task whose outside touch area (for resizing) (x, y) falls within.
Chong Zhang9184ec62015-09-24 12:32:21 -07001847 * Returns null if the touch doesn't fall into a resizing area.
Chong Zhang8e89b312015-09-09 15:09:30 -07001848 */
Wale Ogunwale15ead902016-09-02 14:30:11 -07001849 Task findTaskForResizePoint(int x, int y) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07001850 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001851 mTmpTaskForResizePointSearchResult.reset();
Wale Ogunwale61911492017-10-11 08:50:50 -07001852 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1853 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001854 if (!stack.getWindowConfiguration().canResizeTask()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001855 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001856 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001857
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001858 stack.findTaskForResizePoint(x, y, delta, mTmpTaskForResizePointSearchResult);
1859 if (mTmpTaskForResizePointSearchResult.searchDone) {
1860 return mTmpTaskForResizePointSearchResult.taskForResize;
Chong Zhang8e89b312015-09-09 15:09:30 -07001861 }
1862 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001863 return null;
Chong Zhang8e89b312015-09-09 15:09:30 -07001864 }
1865
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001866 void setTouchExcludeRegion(Task focusedTask) {
David Stevensee9e2772017-02-09 16:30:27 -08001867 // The provided task is the task on this display with focus, so if WindowManagerService's
1868 // focused app is not on this display, focusedTask will be null.
1869 if (focusedTask == null) {
1870 mTouchExcludeRegion.setEmpty();
1871 } else {
1872 mTouchExcludeRegion.set(mBaseDisplayRect);
1873 final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
1874 mTmpRect2.setEmpty();
Wale Ogunwale61911492017-10-11 08:50:50 -07001875 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1876 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00001877 stack.setTouchExcludeRegion(focusedTask, delta, mTouchExcludeRegion,
1878 mDisplayFrames.mContent, mTmpRect2);
David Stevensee9e2772017-02-09 16:30:27 -08001879 }
1880 // If we removed the focused task above, add it back and only leave its
1881 // outside touch area in the exclusion. TapDectector is not interested in
1882 // any touch inside the focused task itself.
1883 if (!mTmpRect2.isEmpty()) {
1884 mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
1885 }
Chong Zhangd8ceb852015-11-11 14:53:41 -08001886 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001887 final WindowState inputMethod = mService.mInputMethodWindow;
1888 if (inputMethod != null && inputMethod.isVisibleLw()) {
1889 // If the input method is visible and the user is typing, we don't want these touch
1890 // events to be intercepted and used to change focus. This would likely cause a
1891 // disappearance of the input method.
1892 inputMethod.getTouchableRegion(mTmpRegion);
Andrii Kulian7a31b772017-05-02 13:22:42 -07001893 if (inputMethod.getDisplayId() == mDisplayId) {
1894 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1895 } else {
1896 // IME is on a different display, so we need to update its tap detector.
1897 // TODO(multidisplay): Remove when IME will always appear on same display.
1898 inputMethod.getDisplayContent().setTouchExcludeRegion(null /* focusedTask */);
1899 }
Filip Gruszczynski912d9192015-12-01 16:14:04 -08001900 }
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001901 for (int i = mTapExcludedWindows.size() - 1; i >= 0; i--) {
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001902 final WindowState win = mTapExcludedWindows.get(i);
Filip Gruszczynskiecf67222015-12-11 15:16:36 -08001903 win.getTouchableRegion(mTmpRegion);
1904 mTouchExcludeRegion.op(mTmpRegion, Region.Op.UNION);
1905 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001906 for (int i = mTapExcludeProvidingWindows.size() - 1; i >= 0; i--) {
1907 final WindowState win = mTapExcludeProvidingWindows.valueAt(i);
1908 win.amendTapExcludeRegion(mTouchExcludeRegion);
1909 }
Andrii Kulian03c403d2016-11-11 11:14:12 -08001910 // TODO(multi-display): Support docked stacks on secondary displays.
Matthew Ng64e77cf2017-10-31 14:01:31 -07001911 if (mDisplayId == DEFAULT_DISPLAY && getSplitScreenPrimaryStack() != null) {
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001912 mDividerControllerLocked.getTouchRegion(mTmpRect);
Jorim Jaggi7f19cb82016-03-25 19:37:44 -07001913 mTmpRegion.set(mTmpRect);
Jorim Jaggid47e7e12016-03-01 09:57:38 +01001914 mTouchExcludeRegion.op(mTmpRegion, Op.UNION);
1915 }
Craig Mautner1bef3892015-02-17 15:09:47 -08001916 if (mTapDetector != null) {
Chong Zhang2e2c81a2016-07-15 11:28:17 -07001917 mTapDetector.setTouchExcludeRegion(mTouchExcludeRegion);
Craig Mautner1bef3892015-02-17 15:09:47 -08001918 }
Craig Mautner6601b7b2013-04-29 10:29:11 -07001919 }
1920
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001921 @Override
Wale Ogunwalee05f5012016-09-16 16:27:29 -07001922 void switchUser() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001923 super.switchUser();
1924 mService.mWindowsChanged = true;
Craig Mautner858d8a62013-04-23 17:08:34 -07001925 }
1926
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001927 private void resetAnimationBackgroundAnimator() {
Wale Ogunwale61911492017-10-11 08:50:50 -07001928 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
1929 mTaskStackContainers.getChildAt(stackNdx).resetAnimationBackgroundAnimator();
Craig Mautner05d29032013-05-03 13:40:13 -07001930 }
1931 }
1932
Wale Ogunwale10124582016-09-15 20:25:50 -07001933 @Override
1934 void removeIfPossible() {
1935 if (isAnimating()) {
1936 mDeferredRemoval = true;
1937 return;
Craig Mautner2eb15342013-08-07 13:13:35 -07001938 }
Wale Ogunwale10124582016-09-15 20:25:50 -07001939 removeImmediately();
Craig Mautner2eb15342013-08-07 13:13:35 -07001940 }
1941
Wale Ogunwale10124582016-09-15 20:25:50 -07001942 @Override
1943 void removeImmediately() {
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001944 mRemovingDisplay = true;
1945 try {
1946 super.removeImmediately();
1947 if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
Tarandeep Singh7ac8d3a2017-09-05 11:09:39 -07001948 if (mService.canDispatchPointerEvents()) {
1949 if (mTapDetector != null) {
1950 mService.unregisterPointerEventListener(mTapDetector);
1951 }
1952 if (mDisplayId == DEFAULT_DISPLAY && mService.mMousePositionTracker != null) {
1953 mService.unregisterPointerEventListener(mService.mMousePositionTracker);
1954 }
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001955 }
Jorim Jaggia3844032018-01-03 15:54:43 +01001956 mService.mAnimator.removeDisplayLocked(mDisplayId);
Chavi Weingarten38804382018-02-15 21:00:15 +00001957
1958 // The pending transaction won't be applied so we should
1959 // just clean up any surfaces pending destruction.
1960 onPendingTransactionApplied();
Wale Ogunwale601a3f02016-10-17 08:39:39 -07001961 } finally {
1962 mRemovingDisplay = false;
Craig Mautner95da1082014-02-24 17:54:35 -08001963 }
Bryce Leef19cbe22018-02-02 15:09:21 -08001964
1965 mService.onDisplayRemoved(mDisplayId);
Craig Mautner95da1082014-02-24 17:54:35 -08001966 }
1967
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001968 /** Returns true if a removal action is still being deferred. */
Wale Ogunwale10124582016-09-15 20:25:50 -07001969 @Override
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001970 boolean checkCompleteDeferredRemoval() {
Wale Ogunwale10124582016-09-15 20:25:50 -07001971 final boolean stillDeferringRemoval = super.checkCompleteDeferredRemoval();
1972
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001973 if (!stillDeferringRemoval && mDeferredRemoval) {
Wale Ogunwale10124582016-09-15 20:25:50 -07001974 removeImmediately();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001975 return false;
Craig Mautner95da1082014-02-24 17:54:35 -08001976 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001977 return true;
Craig Mautner95da1082014-02-24 17:54:35 -08001978 }
1979
Andrii Kulian0214ed92017-05-16 13:44:05 -07001980 /** @return 'true' if removal of this display content is deferred due to active animation. */
1981 boolean isRemovalDeferred() {
1982 return mDeferredRemoval;
1983 }
1984
Wale Ogunwale10124582016-09-15 20:25:50 -07001985 boolean animateForIme(float interpolatedValue, float animationTarget,
1986 float dividerAnimationTarget) {
1987 boolean updated = false;
1988
Wale Ogunwale61911492017-10-11 08:50:50 -07001989 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
1990 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07001991 if (stack == null || !stack.isAdjustedForIme()) {
1992 continue;
1993 }
1994
1995 if (interpolatedValue >= 1f && animationTarget == 0f && dividerAnimationTarget == 0f) {
1996 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
1997 updated = true;
1998 } else {
1999 mDividerControllerLocked.mLastAnimationProgress =
2000 mDividerControllerLocked.getInterpolatedAnimationValue(interpolatedValue);
2001 mDividerControllerLocked.mLastDividerProgress =
2002 mDividerControllerLocked.getInterpolatedDividerValue(interpolatedValue);
2003 updated |= stack.updateAdjustForIme(
2004 mDividerControllerLocked.mLastAnimationProgress,
2005 mDividerControllerLocked.mLastDividerProgress,
2006 false /* force */);
2007 }
2008 if (interpolatedValue >= 1f) {
2009 stack.endImeAdjustAnimation();
2010 }
2011 }
2012
2013 return updated;
2014 }
2015
2016 boolean clearImeAdjustAnimation() {
2017 boolean changed = false;
Wale Ogunwale61911492017-10-11 08:50:50 -07002018 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2019 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002020 if (stack != null && stack.isAdjustedForIme()) {
2021 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
2022 changed = true;
2023 }
2024 }
2025 return changed;
2026 }
2027
2028 void beginImeAdjustAnimation() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002029 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2030 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002031 if (stack.isVisible() && stack.isAdjustedForIme()) {
2032 stack.beginImeAdjustAnimation();
2033 }
2034 }
2035 }
2036
2037 void adjustForImeIfNeeded() {
2038 final WindowState imeWin = mService.mInputMethodWindow;
2039 final boolean imeVisible = imeWin != null && imeWin.isVisibleLw() && imeWin.isDisplayedLw()
2040 && !mDividerControllerLocked.isImeHideRequested();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002041 final boolean dockVisible = isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
Wale Ogunwale10124582016-09-15 20:25:50 -07002042 final TaskStack imeTargetStack = mService.getImeFocusStackLocked();
2043 final int imeDockSide = (dockVisible && imeTargetStack != null) ?
2044 imeTargetStack.getDockSide() : DOCKED_INVALID;
2045 final boolean imeOnTop = (imeDockSide == DOCKED_TOP);
2046 final boolean imeOnBottom = (imeDockSide == DOCKED_BOTTOM);
2047 final boolean dockMinimized = mDividerControllerLocked.isMinimizedDock();
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002048 final int imeHeight = mDisplayFrames.getInputMethodWindowVisibleHeight();
Wale Ogunwale10124582016-09-15 20:25:50 -07002049 final boolean imeHeightChanged = imeVisible &&
2050 imeHeight != mDividerControllerLocked.getImeHeightAdjustedFor();
2051
2052 // The divider could be adjusted for IME position, or be thinner than usual,
2053 // or both. There are three possible cases:
2054 // - If IME is visible, and focus is on top, divider is not moved for IME but thinner.
2055 // - If IME is visible, and focus is on bottom, divider is moved for IME and thinner.
2056 // - If IME is not visible, divider is not moved and is normal width.
2057
2058 if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
Wale Ogunwale61911492017-10-11 08:50:50 -07002059 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2060 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002061 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
Wale Ogunwale68278562017-09-23 17:13:55 -07002062 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)
2063 && stack.inSplitScreenWindowingMode()) {
Wale Ogunwale10124582016-09-15 20:25:50 -07002064 stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
2065 } else {
2066 stack.resetAdjustedForIme(false);
2067 }
2068 }
2069 mDividerControllerLocked.setAdjustedForIme(
2070 imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
2071 } else {
Wale Ogunwale61911492017-10-11 08:50:50 -07002072 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
2073 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale10124582016-09-15 20:25:50 -07002074 stack.resetAdjustedForIme(!dockVisible);
2075 }
2076 mDividerControllerLocked.setAdjustedForIme(
2077 false /*ime*/, false /*divider*/, dockVisible /*animate*/, imeWin, imeHeight);
2078 }
Winson Chung655332c2016-10-31 13:14:28 -07002079 mPinnedStackControllerLocked.setAdjustedForIme(imeVisible, imeHeight);
Wale Ogunwale10124582016-09-15 20:25:50 -07002080 }
2081
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002082 /**
2083 * If a window that has an animation specifying a colored background and the current wallpaper
2084 * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
2085 * suddenly disappear.
2086 */
2087 int getLayerForAnimationBackground(WindowStateAnimator winAnimator) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002088 final WindowState visibleWallpaper = mBelowAppWindowsContainers.getWindow(
2089 w -> w.mIsWallpaper && w.isVisibleNow());
2090
2091 if (visibleWallpaper != null) {
2092 return visibleWallpaper.mWinAnimator.mAnimLayer;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002093 }
2094 return winAnimator.mAnimLayer;
2095 }
2096
Wale Ogunwale10124582016-09-15 20:25:50 -07002097 void prepareFreezingTaskBounds() {
Wale Ogunwale61911492017-10-11 08:50:50 -07002098 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2099 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Wale Ogunwale10124582016-09-15 20:25:50 -07002100 stack.prepareFreezingTaskBounds();
2101 }
2102 }
2103
Wale Ogunwale94744212015-09-21 19:01:47 -07002104 void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
Bryce Leef3c6a472017-11-14 14:53:06 -08002105 getBounds(mTmpRect, newRotation);
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002106
2107 // Compute a transform matrix to undo the coordinate space transformation,
2108 // and present the window at the same physical position it previously occupied.
2109 final int deltaRotation = deltaRotation(newRotation, oldRotation);
2110 createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
2111
2112 mTmpRectF.set(bounds);
2113 mTmpMatrix.mapRect(mTmpRectF);
2114 mTmpRectF.round(bounds);
Wale Ogunwale94744212015-09-21 19:01:47 -07002115 }
2116
Wale Ogunwale4a02d812015-02-12 23:01:38 -08002117 static int deltaRotation(int oldRotation, int newRotation) {
2118 int delta = newRotation - oldRotation;
2119 if (delta < 0) delta += 4;
2120 return delta;
2121 }
2122
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002123 private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
Andrii Kulian4dfb9c42016-10-11 20:06:27 -07002124 Matrix outMatrix) {
2125 // For rotations without Z-ordering we don't need the target rectangle's position.
2126 createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
2127 displayHeight, outMatrix);
2128 }
2129
2130 static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
2131 float displayWidth, float displayHeight, Matrix outMatrix) {
2132 switch (rotation) {
2133 case ROTATION_0:
2134 outMatrix.reset();
2135 break;
2136 case ROTATION_270:
2137 outMatrix.setRotate(270, 0, 0);
2138 outMatrix.postTranslate(0, displayHeight);
2139 outMatrix.postTranslate(rectTop, 0);
2140 break;
2141 case ROTATION_180:
2142 outMatrix.reset();
2143 break;
2144 case ROTATION_90:
2145 outMatrix.setRotate(90, 0, 0);
2146 outMatrix.postTranslate(displayWidth, 0);
2147 outMatrix.postTranslate(-rectTop, rectLeft);
2148 break;
2149 }
2150 }
2151
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002152 @CallSuper
2153 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002154 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002155 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002156 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002157 proto.write(ID, mDisplayId);
Wale Ogunwale61911492017-10-11 08:50:50 -07002158 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2159 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002160 stack.writeToProto(proto, STACKS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002161 }
2162 mDividerControllerLocked.writeToProto(proto, DOCKED_STACK_DIVIDER_CONTROLLER);
2163 mPinnedStackControllerLocked.writeToProto(proto, PINNED_STACK_CONTROLLER);
Wale Ogunwale61911492017-10-11 08:50:50 -07002164 for (int i = mAboveAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2165 final WindowToken windowToken = mAboveAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002166 windowToken.writeToProto(proto, ABOVE_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002167 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002168 for (int i = mBelowAppWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2169 final WindowToken windowToken = mBelowAppWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002170 windowToken.writeToProto(proto, BELOW_APP_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002171 }
Wale Ogunwale61911492017-10-11 08:50:50 -07002172 for (int i = mImeWindowsContainers.getChildCount() - 1; i >= 0; --i) {
2173 final WindowToken windowToken = mImeWindowsContainers.getChildAt(i);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002174 windowToken.writeToProto(proto, IME_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002175 }
2176 proto.write(DPI, mBaseDisplayDensity);
2177 mDisplayInfo.writeToProto(proto, DISPLAY_INFO);
Steven Timotiusf2d68892017-08-28 17:00:01 -07002178 proto.write(ROTATION, mRotation);
2179 final ScreenRotationAnimation screenRotationAnimation =
2180 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
2181 if (screenRotationAnimation != null) {
2182 screenRotationAnimation.writeToProto(proto, SCREEN_ROTATION_ANIMATION);
2183 }
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002184 mDisplayFrames.writeToProto(proto, DISPLAY_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07002185 proto.end(token);
2186 }
2187
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002188 @Override
2189 public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2190 super.dump(pw, prefix, dumpAll);
Craig Mautnera91f9e22012-09-14 16:22:08 -07002191 pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
2192 final String subPrefix = " " + prefix;
2193 pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
2194 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
2195 pw.print("dpi");
2196 if (mInitialDisplayWidth != mBaseDisplayWidth
2197 || mInitialDisplayHeight != mBaseDisplayHeight
2198 || mInitialDisplayDensity != mBaseDisplayDensity) {
2199 pw.print(" base=");
2200 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
2201 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
2202 }
Jeff Brownd46747a2015-04-15 19:02:36 -07002203 if (mDisplayScalingDisabled) {
2204 pw.println(" noscale");
2205 }
Craig Mautnera91f9e22012-09-14 16:22:08 -07002206 pw.print(" cur=");
2207 pw.print(mDisplayInfo.logicalWidth);
2208 pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
2209 pw.print(" app=");
2210 pw.print(mDisplayInfo.appWidth);
2211 pw.print("x"); pw.print(mDisplayInfo.appHeight);
2212 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
2213 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
2214 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
2215 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
David Stevensf833ba92017-03-16 19:00:20 -07002216 pw.print(subPrefix + "deferred=" + mDeferredRemoval
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002217 + " mLayoutNeeded=" + mLayoutNeeded);
David Stevensf833ba92017-03-16 19:00:20 -07002218 pw.println(" mTouchExcludeRegion=" + mTouchExcludeRegion);
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002219
Craig Mautnerdc548482014-02-05 13:35:24 -08002220 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002221 pw.println(prefix + "Application tokens in top down Z order:");
Wale Ogunwale61911492017-10-11 08:50:50 -07002222 for (int stackNdx = mTaskStackContainers.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
2223 final TaskStack stack = mTaskStackContainers.getChildAt(stackNdx);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002224 stack.dump(pw, prefix + " ", dumpAll);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002225 }
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002226
Craig Mautnerdc548482014-02-05 13:35:24 -08002227 pw.println();
2228 if (!mExitingTokens.isEmpty()) {
Craig Mautnerde4ef022013-04-07 19:01:33 -07002229 pw.println();
2230 pw.println(" Exiting tokens:");
Wale Ogunwaleb429e682016-01-06 12:36:34 -08002231 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002232 final WindowToken token = mExitingTokens.get(i);
Craig Mautnerde4ef022013-04-07 19:01:33 -07002233 pw.print(" Exiting #"); pw.print(i);
2234 pw.print(' '); pw.print(token);
2235 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002236 token.dump(pw, " ", dumpAll);
Craig Mautnerb1fd65c02013-02-05 13:34:57 -08002237 }
Craig Mautnerde4ef022013-04-07 19:01:33 -07002238 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07002239
Jorim Jaggi31f71702016-05-04 16:43:04 -07002240 pw.println();
Wale Ogunwale61911492017-10-11 08:50:50 -07002241
2242 // Dump stack references
2243 final TaskStack homeStack = getHomeStack();
2244 if (homeStack != null) {
2245 pw.println(prefix + "homeStack=" + homeStack.getName());
2246 }
2247 final TaskStack pinnedStack = getPinnedStack();
2248 if (pinnedStack != null) {
2249 pw.println(prefix + "pinnedStack=" + pinnedStack.getName());
2250 }
Matthew Ng64e77cf2017-10-31 14:01:31 -07002251 final TaskStack splitScreenPrimaryStack = getSplitScreenPrimaryStack();
Wale Ogunwale61911492017-10-11 08:50:50 -07002252 if (splitScreenPrimaryStack != null) {
2253 pw.println(prefix + "splitScreenPrimaryStack=" + splitScreenPrimaryStack.getName());
2254 }
2255
2256 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002257 mDividerControllerLocked.dump(prefix, pw);
Winson Chung655332c2016-10-31 13:14:28 -07002258 pw.println();
Jorim Jaggiad5d2842016-11-01 18:22:53 -07002259 mPinnedStackControllerLocked.dump(prefix, pw);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002260
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002261 pw.println();
2262 mDisplayFrames.dump(prefix, pw);
Craig Mautner59c00972012-07-30 12:10:24 -07002263 }
Craig Mautnere0a38842013-12-16 16:14:02 -08002264
2265 @Override
2266 public String toString() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002267 return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002268 }
2269
2270 String getName() {
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002271 return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
Craig Mautnere0a38842013-12-16 16:14:02 -08002272 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002273
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002274 /** Returns true if the stack in the windowing mode is visible. */
2275 boolean isStackVisible(int windowingMode) {
Wale Ogunwale30e441d2017-11-09 08:28:45 -08002276 final TaskStack stack = getTopStackInWindowingMode(windowingMode);
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002277 return stack != null && stack.isVisible();
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08002278 }
2279
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002280 /** Find the visible, touch-deliverable window under the given point */
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002281 WindowState getTouchableWinAtPointLocked(float xf, float yf) {
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002282 final int x = (int) xf;
2283 final int y = (int) yf;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002284 final WindowState touchedWin = getWindow(w -> {
2285 final int flags = w.mAttrs.flags;
2286 if (!w.isVisibleLw()) {
2287 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002288 }
2289 if ((flags & FLAG_NOT_TOUCHABLE) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002290 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002291 }
2292
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002293 w.getVisibleBounds(mTmpRect);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002294 if (!mTmpRect.contains(x, y)) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002295 return false;
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002296 }
2297
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002298 w.getTouchableRegion(mTmpRegion);
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002299
2300 final int touchFlags = flags & (FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002301 return mTmpRegion.contains(x, y) || touchFlags == 0;
2302 });
Vladislav Kaznacheev5d6bdeb2016-02-12 17:07:20 -08002303
2304 return touchedWin;
2305 }
Jorim Jaggi6626f542016-08-22 13:08:44 -07002306
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002307 boolean canAddToastWindowForUid(int uid) {
2308 // We allow one toast window per UID being shown at a time.
Svet Ganovdaca8ee2017-01-21 17:40:40 -08002309 // Also if the app is focused adding more than one toast at
2310 // a time for better backwards compatibility.
2311 final WindowState focusedWindowForUid = getWindow(w ->
2312 w.mOwnerUid == uid && w.isFocused());
2313 if (focusedWindowForUid != null) {
2314 return true;
2315 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002316 final WindowState win = getWindow(w ->
2317 w.mAttrs.type == TYPE_TOAST && w.mOwnerUid == uid && !w.mPermanentlyHidden
2318 && !w.mWindowRemovalAllowed);
2319 return win == null;
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002320 }
2321
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002322 void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002323 if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
2324 return;
2325 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002326
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002327 // Used to communicate the old focus to the callback method.
2328 mTmpWindow = oldFocus;
2329
2330 forAllWindows(mScheduleToastTimeout, false /* traverseTopToBottom */);
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002331 }
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002332
2333 WindowState findFocusedWindow() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002334 mTmpWindow = null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002335
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002336 forAllWindows(mFindFocusedWindow, true /* traverseTopToBottom */);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002337
2338 if (mTmpWindow == null) {
2339 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "findFocusedWindow: No focusable windows.");
2340 return null;
Wale Ogunwale63d4ecc2016-09-08 18:48:26 -07002341 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002342 return mTmpWindow;
Wale Ogunwaleec731152016-09-08 20:18:57 -07002343 }
2344
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002345 /** Updates the layer assignment of windows on this display. */
2346 void assignWindowLayers(boolean setLayoutNeeded) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002347 Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "assignWindowLayers");
Robert Carrf59b8dd2017-10-02 18:58:36 -07002348 assignChildLayers(getPendingTransaction());
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002349 if (setLayoutNeeded) {
2350 setLayoutNeeded();
2351 }
Robert Carrb1579c82017-09-05 14:54:47 -07002352
Robert Carrf59b8dd2017-10-02 18:58:36 -07002353 // We accumlate the layer changes in-to "getPendingTransaction()" but we defer
Robert Carrb1579c82017-09-05 14:54:47 -07002354 // the application of this transaction until the animation pass triggers
2355 // prepareSurfaces. This allows us to synchronize Z-ordering changes with
2356 // the hiding and showing of surfaces.
2357 scheduleAnimation();
Jorim Jaggiffe128d2017-11-30 13:54:36 +01002358 Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002359 }
2360
Wale Ogunwale1666e312016-12-16 11:27:18 -08002361 // TODO: This should probably be called any time a visual change is made to the hierarchy like
2362 // moving containers or resizing them. Need to investigate the best way to have it automatically
2363 // happen so we don't run into issues with programmers forgetting to do it.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002364 void layoutAndAssignWindowLayersIfNeeded() {
2365 mService.mWindowsChanged = true;
2366 setLayoutNeeded();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002367
2368 if (!mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
2369 false /*updateInputWindows*/)) {
2370 assignWindowLayers(false /* setLayoutNeeded */);
2371 }
2372
2373 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2374 mService.mWindowPlacerLocked.performSurfacePlacement();
2375 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2376 }
2377
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002378 /** Returns true if a leaked surface was destroyed */
2379 boolean destroyLeakedSurfaces() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002380 // Used to indicate that a surface was leaked.
2381 mTmpWindow = null;
2382 forAllWindows(w -> {
2383 final WindowStateAnimator wsa = w.mWinAnimator;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002384 if (wsa.mSurfaceController == null) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002385 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002386 }
2387 if (!mService.mSessions.contains(wsa.mSession)) {
2388 Slog.w(TAG_WM, "LEAKED SURFACE (session doesn't exist): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002389 + w + " surface=" + wsa.mSurfaceController
2390 + " token=" + w.mToken
2391 + " pid=" + w.mSession.mPid
2392 + " uid=" + w.mSession.mUid);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002393 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002394 mService.mForceRemoves.add(w);
2395 mTmpWindow = w;
Wale Ogunwale89973222017-04-23 18:39:45 -07002396 } else if (w.mAppToken != null && w.mAppToken.isClientHidden()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002397 Slog.w(TAG_WM, "LEAKED SURFACE (app token hidden): "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002398 + w + " surface=" + wsa.mSurfaceController
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002399 + " token=" + w.mAppToken);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002400 if (SHOW_TRANSACTIONS) logSurface(w, "LEAK DESTROY", false);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002401 wsa.destroySurface();
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002402 mTmpWindow = w;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002403 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002404 }, false /* traverseTopToBottom */);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002405
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002406 return mTmpWindow != null;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002407 }
2408
2409 /**
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002410 * Determine and return the window that should be the IME target.
2411 * @param updateImeTarget If true the system IME target will be updated to match what we found.
2412 * @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 +00002413 */
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002414 WindowState computeImeTarget(boolean updateImeTarget) {
2415 if (mService.mInputMethodWindow == null) {
2416 // There isn't an IME so there shouldn't be a target...That was easy!
2417 if (updateImeTarget) {
2418 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from "
2419 + mService.mInputMethodTarget + " to null since mInputMethodWindow is null");
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002420 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002421 }
2422 return null;
2423 }
2424
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002425 // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
2426 // same display. Or even when the current IME/target are not on the same screen as the next
2427 // IME/target. For now only look for input windows on the main screen.
Wale Ogunwale8e44f6c2017-03-09 15:25:10 -08002428 mUpdateImeTarget = updateImeTarget;
2429 WindowState target = getWindow(mComputeImeTargetPredicate);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002430
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002431
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002432 // Yet more tricksyness! If this window is a "starting" window, we do actually want
2433 // to be on top of it, but it is not -really- where input will go. So look down below
2434 // for a real window to target...
2435 if (target != null && target.mAttrs.type == TYPE_APPLICATION_STARTING) {
2436 final AppWindowToken token = target.mAppToken;
2437 if (token != null) {
2438 final WindowState betterTarget = token.getImeTargetBelowWindow(target);
2439 if (betterTarget != null) {
2440 target = betterTarget;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002441 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002442 }
2443 }
2444
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002445 if (DEBUG_INPUT_METHOD && updateImeTarget) Slog.v(TAG_WM,
2446 "Proposed new IME target: " + target);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002447
2448 // Now, a special case -- if the last target's window is in the process of exiting, and is
2449 // above the new target, keep on the last target to avoid flicker. Consider for example a
2450 // Dialog with the IME shown: when the Dialog is dismissed, we want to keep the IME above it
2451 // until it is completely gone so it doesn't drop behind the dialog or its full-screen
2452 // scrim.
2453 final WindowState curTarget = mService.mInputMethodTarget;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002454 if (curTarget != null && curTarget.isDisplayedLw() && curTarget.isClosing()
2455 && (target == null
2456 || curTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002457 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Current target higher, not changing");
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002458 return curTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002459 }
2460
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002461 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Desired input method target=" + target
2462 + " updateImeTarget=" + updateImeTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002463
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002464 if (target == null) {
2465 if (updateImeTarget) {
2466 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget
2467 + " to null." + (SHOW_STACK_CRAWLS ? " Callers="
2468 + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002469 setInputMethodTarget(null, mService.mInputMethodTargetWaitingAnim);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002470 }
2471
2472 return null;
2473 }
2474
2475 if (updateImeTarget) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002476 AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
2477 if (token != null) {
2478
2479 // Now some fun for dealing with window animations that modify the Z order. We need
2480 // to look at all windows below the current target that are in this app, finding the
2481 // highest visible one in layering.
2482 WindowState highestTarget = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002483 if (token.isSelfAnimating()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002484 highestTarget = token.getHighestAnimLayerWindow(curTarget);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002485 }
2486
2487 if (highestTarget != null) {
2488 final AppTransition appTransition = mService.mAppTransition;
2489 if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, appTransition + " " + highestTarget
2490 + " animating=" + highestTarget.mWinAnimator.isAnimationSet()
2491 + " layer=" + highestTarget.mWinAnimator.mAnimLayer
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002492 + " new layer=" + target.mWinAnimator.mAnimLayer);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002493
2494 if (appTransition.isTransitionSet()) {
2495 // If we are currently setting up for an animation, hold everything until we
2496 // can find out what will happen.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002497 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002498 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002499 } else if (highestTarget.mWinAnimator.isAnimationSet() &&
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002500 highestTarget.mWinAnimator.mAnimLayer > target.mWinAnimator.mAnimLayer) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002501 // If the window we are currently targeting is involved with an animation,
2502 // and it is on top of the next target we will be over, then hold off on
2503 // moving until that is done.
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002504 setInputMethodTarget(highestTarget, true);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002505 return highestTarget;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002506 }
2507 }
2508 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002509
2510 if (DEBUG_INPUT_METHOD) Slog.w(TAG_WM, "Moving IM target from " + curTarget + " to "
2511 + target + (SHOW_STACK_CRAWLS ? " Callers=" + Debug.getCallers(4) : ""));
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002512 setInputMethodTarget(target, false);
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002513 }
2514
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002515 return target;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002516 }
2517
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002518 private void setInputMethodTarget(WindowState target, boolean targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002519 if (target == mService.mInputMethodTarget
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002520 && mService.mInputMethodTargetWaitingAnim == targetWaitingAnim) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002521 return;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002522 }
2523
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002524 mService.mInputMethodTarget = target;
2525 mService.mInputMethodTargetWaitingAnim = targetWaitingAnim;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002526 assignWindowLayers(false /* setLayoutNeeded */);
2527 }
2528
2529 boolean getNeedsMenu(WindowState top, WindowManagerPolicy.WindowState bottom) {
2530 if (top.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2531 return top.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
2532 }
2533
2534 // Used to indicate we have reached the first window in the range we are interested in.
2535 mTmpWindow = null;
2536
2537 // TODO: Figure-out a more efficient way to do this.
2538 final WindowState candidate = getWindow(w -> {
2539 if (w == top) {
2540 // Reached the first window in the range we are interested in.
2541 mTmpWindow = w;
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002542 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002543 if (mTmpWindow == null) {
2544 return false;
2545 }
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002546
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002547 if (w.mAttrs.needsMenuKey != NEEDS_MENU_UNSET) {
2548 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002549 }
2550 // If we reached the bottom of the range of windows we are considering,
2551 // assume no menu is needed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002552 if (w == bottom) {
2553 return true;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002554 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002555 return false;
2556 });
2557
2558 return candidate != null && candidate.mAttrs.needsMenuKey == NEEDS_MENU_SET_TRUE;
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002559 }
2560
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002561 void setLayoutNeeded() {
2562 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "setLayoutNeeded: callers=" + Debug.getCallers(3));
2563 mLayoutNeeded = true;
2564 }
2565
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002566 private void clearLayoutNeeded() {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002567 if (DEBUG_LAYOUT) Slog.w(TAG_WM, "clearLayoutNeeded: callers=" + Debug.getCallers(3));
2568 mLayoutNeeded = false;
2569 }
2570
2571 boolean isLayoutNeeded() {
2572 return mLayoutNeeded;
2573 }
2574
Wale Ogunwale02319a62016-09-26 15:21:22 -07002575 void dumpTokens(PrintWriter pw, boolean dumpAll) {
2576 if (mTokenMap.isEmpty()) {
2577 return;
2578 }
2579 pw.println(" Display #" + mDisplayId);
2580 final Iterator<WindowToken> it = mTokenMap.values().iterator();
2581 while (it.hasNext()) {
2582 final WindowToken token = it.next();
2583 pw.print(" ");
2584 pw.print(token);
2585 if (dumpAll) {
2586 pw.println(':');
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002587 token.dump(pw, " ", dumpAll);
Wale Ogunwale02319a62016-09-26 15:21:22 -07002588 } else {
2589 pw.println();
2590 }
2591 }
2592 }
2593
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002594 void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002595 final int[] index = new int[1];
2596 forAllWindows(w -> {
2597 final WindowStateAnimator wAnim = w.mWinAnimator;
2598 pw.println(subPrefix + "Window #" + index[0] + ": " + wAnim);
2599 index[0] = index[0] + 1;
2600 }, false /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002601 }
2602
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002603 void enableSurfaceTrace(FileDescriptor fd) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002604 forAllWindows(w -> {
2605 w.mWinAnimator.enableSurfaceTrace(fd);
2606 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002607 }
2608
2609 void disableSurfaceTrace() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002610 forAllWindows(w -> {
2611 w.mWinAnimator.disableSurfaceTrace();
2612 }, true /* traverseTopToBottom */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002613 }
2614
Jorim Jaggife762342016-10-13 14:33:27 +02002615 /**
2616 * Starts the Keyguard exit animation on all windows that don't belong to an app token.
2617 */
2618 void startKeyguardExitOnNonAppWindows(boolean onWallpaper, boolean goingToShade) {
2619 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002620 forAllWindows(w -> {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002621 if (w.mAppToken == null && policy.canBeHiddenByKeyguardLw(w)
2622 && w.wouldBeVisibleIfPolicyIgnored() && !w.isVisible()) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01002623 w.startAnimation(policy.createHiddenByKeyguardExit(onWallpaper, goingToShade));
Jorim Jaggife762342016-10-13 14:33:27 +02002624 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002625 }, true /* traverseTopToBottom */);
Jorim Jaggife762342016-10-13 14:33:27 +02002626 }
2627
Wale Ogunwale494009b82016-10-21 09:01:38 -07002628 boolean checkWaitingForWindows() {
2629
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002630 mHaveBootMsg = false;
2631 mHaveApp = false;
2632 mHaveWallpaper = false;
2633 mHaveKeyguard = true;
2634
2635 final WindowState visibleWindow = getWindow(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002636 if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
2637 return true;
2638 }
2639 if (w.isDrawnLw()) {
2640 if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002641 mHaveBootMsg = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002642 } else if (w.mAttrs.type == TYPE_APPLICATION
2643 || w.mAttrs.type == TYPE_DRAWN_APPLICATION) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002644 mHaveApp = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002645 } else if (w.mAttrs.type == TYPE_WALLPAPER) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002646 mHaveWallpaper = true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002647 } else if (w.mAttrs.type == TYPE_STATUS_BAR) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002648 mHaveKeyguard = mService.mPolicy.isKeyguardDrawnLw();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002649 }
2650 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002651 return false;
2652 });
2653
2654 if (visibleWindow != null) {
2655 // We have a visible window.
2656 return true;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002657 }
2658
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002659 // if the wallpaper service is disabled on the device, we're never going to have
2660 // wallpaper, don't bother waiting for it
2661 boolean wallpaperEnabled = mService.mContext.getResources().getBoolean(
2662 com.android.internal.R.bool.config_enableWallpaperService)
2663 && !mService.mOnlyCore;
2664
Wale Ogunwale494009b82016-10-21 09:01:38 -07002665 if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG_WM,
2666 "******** booted=" + mService.mSystemBooted
2667 + " msg=" + mService.mShowingBootMessages
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002668 + " haveBoot=" + mHaveBootMsg + " haveApp=" + mHaveApp
2669 + " haveWall=" + mHaveWallpaper + " wallEnabled=" + wallpaperEnabled
2670 + " haveKeyguard=" + mHaveKeyguard);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002671
2672 // If we are turning on the screen to show the boot message, don't do it until the boot
2673 // message is actually displayed.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002674 if (!mService.mSystemBooted && !mHaveBootMsg) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002675 return true;
2676 }
2677
2678 // If we are turning on the screen after the boot is completed normally, don't do so until
2679 // we have the application and wallpaper.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002680 if (mService.mSystemBooted
2681 && ((!mHaveApp && !mHaveKeyguard) || (wallpaperEnabled && !mHaveWallpaper))) {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002682 return true;
2683 }
2684
2685 return false;
2686 }
2687
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002688 void updateWindowsForAnimator(WindowAnimator animator) {
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002689 mTmpWindowAnimator = animator;
2690 forAllWindows(mUpdateWindowsForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002691 }
2692
2693 void updateWallpaperForAnimator(WindowAnimator animator) {
Jorim Jaggi7156b652016-10-25 08:31:58 -07002694 resetAnimationBackgroundAnimator();
2695
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002696 // Used to indicate a detached wallpaper.
2697 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002698 mTmpWindowAnimator = animator;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002699
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002700 forAllWindows(mUpdateWallpaperForAnimator, true /* traverseTopToBottom */);
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002701
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002702 if (animator.mWindowDetachedWallpaper != mTmpWindow) {
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002703 if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002704 + animator.mWindowDetachedWallpaper + " to " + mTmpWindow);
2705 animator.mWindowDetachedWallpaper = mTmpWindow;
Wale Ogunwale824ab5c2016-10-20 09:31:56 -07002706 animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
2707 }
2708 }
2709
Wale Ogunwale494009b82016-10-21 09:01:38 -07002710 boolean inputMethodClientHasFocus(IInputMethodClient client) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002711 final WindowState imFocus = computeImeTarget(false /* updateImeTarget */);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002712 if (imFocus == null) {
2713 return false;
2714 }
2715
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002716 if (DEBUG_INPUT_METHOD) {
2717 Slog.i(TAG_WM, "Desired input method target: " + imFocus);
2718 Slog.i(TAG_WM, "Current focus: " + mService.mCurrentFocus);
2719 Slog.i(TAG_WM, "Last focus: " + mService.mLastFocus);
Jorim Jaggiffa5a9d2016-11-23 16:59:19 +00002720 }
2721
Wale Ogunwale494009b82016-10-21 09:01:38 -07002722 final IInputMethodClient imeClient = imFocus.mSession.mClient;
2723
2724 if (DEBUG_INPUT_METHOD) {
2725 Slog.i(TAG_WM, "IM target client: " + imeClient);
2726 if (imeClient != null) {
2727 Slog.i(TAG_WM, "IM target client binder: " + imeClient.asBinder());
2728 Slog.i(TAG_WM, "Requesting client binder: " + client.asBinder());
2729 }
2730 }
2731
2732 return imeClient != null && imeClient.asBinder() == client.asBinder();
2733 }
2734
2735 boolean hasSecureWindowOnScreen() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002736 final WindowState win = getWindow(
2737 w -> w.isOnScreen() && (w.mAttrs.flags & FLAG_SECURE) != 0);
2738 return win != null;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002739 }
2740
2741 void updateSystemUiVisibility(int visibility, int globalDiff) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002742 forAllWindows(w -> {
Wale Ogunwale494009b82016-10-21 09:01:38 -07002743 try {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002744 final int curValue = w.mSystemUiVisibility;
2745 final int diff = (curValue ^ visibility) & globalDiff;
2746 final int newValue = (curValue & ~diff) | (visibility & diff);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002747 if (newValue != curValue) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002748 w.mSeq++;
2749 w.mSystemUiVisibility = newValue;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002750 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002751 if (newValue != curValue || w.mAttrs.hasSystemUiListeners) {
2752 w.mClient.dispatchSystemUiVisibilityChanged(w.mSeq,
Wale Ogunwale494009b82016-10-21 09:01:38 -07002753 visibility, newValue, diff);
2754 }
2755 } catch (RemoteException e) {
2756 // so sorry
2757 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002758 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002759 }
2760
2761 void onWindowFreezeTimeout() {
2762 Slog.w(TAG_WM, "Window freeze timeout expired.");
2763 mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002764
2765 forAllWindows(w -> {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002766 if (!w.getOrientationChanging()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002767 return;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002768 }
Robert Carr9c1c3a02017-08-08 12:59:01 -07002769 w.orientationChangeTimedOut();
Wale Ogunwale494009b82016-10-21 09:01:38 -07002770 w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2771 - mService.mDisplayFreezeTime);
2772 Slog.w(TAG_WM, "Force clearing orientation change: " + w);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002773 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002774 mService.mWindowPlacerLocked.performSurfacePlacement();
2775 }
2776
2777 void waitForAllWindowsDrawn() {
2778 final WindowManagerPolicy policy = mService.mPolicy;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002779 forAllWindows(w -> {
2780 final boolean keyguard = policy.isKeyguardHostWindow(w.mAttrs);
2781 if (w.isVisibleLw() && (w.mAppToken != null || keyguard)) {
2782 w.mWinAnimator.mDrawState = DRAW_PENDING;
Wale Ogunwale494009b82016-10-21 09:01:38 -07002783 // Force add to mResizingWindows.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002784 w.mLastContentInsets.set(-1, -1, -1, -1);
2785 mService.mWaitingForDrawn.add(w);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002786 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002787 }, true /* traverseTopToBottom */);
Wale Ogunwale494009b82016-10-21 09:01:38 -07002788 }
2789
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002790 // TODO: Super crazy long method that should be broken down...
2791 boolean applySurfaceChangesTransaction(boolean recoveringMemory) {
2792
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002793 final int dw = mDisplayInfo.logicalWidth;
2794 final int dh = mDisplayInfo.logicalHeight;
2795 final WindowSurfacePlacer surfacePlacer = mService.mWindowPlacerLocked;
2796
2797 mTmpUpdateAllDrawn.clear();
2798
2799 int repeats = 0;
2800 do {
2801 repeats++;
2802 if (repeats > 6) {
2803 Slog.w(TAG, "Animation repeat aborted after too many iterations");
2804 clearLayoutNeeded();
2805 break;
2806 }
2807
2808 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats("On entry to LockedInner",
2809 pendingLayoutChanges);
2810
Andrii Kulian839def92016-11-02 10:58:58 -07002811 // TODO(multi-display): For now adjusting wallpaper only on primary display to avoid
2812 // the wallpaper window jumping across displays.
2813 // Remove check for default display when there will be support for multiple wallpaper
2814 // targets (on different displays).
2815 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002816 mWallpaperController.adjustWallpaperWindows(this);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002817 }
2818
2819 if (isDefaultDisplay && (pendingLayoutChanges & FINISH_LAYOUT_REDO_CONFIG) != 0) {
2820 if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
2821 if (mService.updateOrientationFromAppTokensLocked(true, mDisplayId)) {
2822 setLayoutNeeded();
Andrii Kulianb17e8692016-11-01 10:37:22 -07002823 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, mDisplayId).sendToTarget();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002824 }
2825 }
2826
2827 if ((pendingLayoutChanges & FINISH_LAYOUT_REDO_LAYOUT) != 0) {
2828 setLayoutNeeded();
2829 }
2830
2831 // FIRST LOOP: Perform a layout, if needed.
2832 if (repeats < LAYOUT_REPEAT_THRESHOLD) {
2833 performLayout(repeats == 1, false /* updateInputWindows */);
2834 } else {
2835 Slog.w(TAG, "Layout repeat skipped after too many iterations");
2836 }
2837
2838 // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think it is animating.
2839 pendingLayoutChanges = 0;
2840
2841 if (isDefaultDisplay) {
2842 mService.mPolicy.beginPostLayoutPolicyLw(dw, dh);
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002843 forAllWindows(mApplyPostLayoutPolicy, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002844 pendingLayoutChanges |= mService.mPolicy.finishPostLayoutPolicyLw();
2845 if (DEBUG_LAYOUT_REPEATS) surfacePlacer.debugLayoutRepeats(
2846 "after finishPostLayoutPolicyLw", pendingLayoutChanges);
2847 }
2848 } while (pendingLayoutChanges != 0);
2849
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002850 mTmpApplySurfaceChangesTransactionState.reset();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002851
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002852 mTmpRecoveringMemory = recoveringMemory;
2853 forAllWindows(mApplySurfaceChangesTransaction, true /* traverseTopToBottom */);
Jorim Jaggi6b0f8462018-01-05 17:23:47 +01002854 prepareSurfaces();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002855
2856 mService.mDisplayManagerInternal.setDisplayProperties(mDisplayId,
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002857 mTmpApplySurfaceChangesTransactionState.displayHasContent,
2858 mTmpApplySurfaceChangesTransactionState.preferredRefreshRate,
2859 mTmpApplySurfaceChangesTransactionState.preferredModeId,
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002860 true /* inTraversal, must call performTraversalInTrans... below */);
2861
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07002862 final boolean wallpaperVisible = mWallpaperController.isWallpaperVisible();
2863 if (wallpaperVisible != mLastWallpaperVisible) {
2864 mLastWallpaperVisible = wallpaperVisible;
2865 mService.mWallpaperVisibilityListeners.notifyWallpaperVisibilityChanged(this);
2866 }
2867
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002868 while (!mTmpUpdateAllDrawn.isEmpty()) {
2869 final AppWindowToken atoken = mTmpUpdateAllDrawn.removeLast();
2870 // See if any windows have been drawn, so they (and others associated with them)
2871 // can now be shown.
Matthew Ng498c71d2017-04-18 13:55:45 -07002872 atoken.updateAllDrawn();
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002873 }
2874
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002875 return mTmpApplySurfaceChangesTransactionState.focusDisplayed;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002876 }
2877
Bryce Leef3c6a472017-11-14 14:53:06 -08002878 private void updateBounds() {
2879 calculateBounds(mTmpBounds);
2880 setBounds(mTmpBounds);
2881 }
2882
2883 // Determines the current display bounds based on the current state
2884 private void calculateBounds(Rect out) {
2885 // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
2886 final int orientation = mDisplayInfo.rotation;
2887 boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
2888 final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
2889 final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
2890 int width = mDisplayInfo.logicalWidth;
2891 int left = (physWidth - width) / 2;
2892 int height = mDisplayInfo.logicalHeight;
2893 int top = (physHeight - height) / 2;
2894 out.set(left, top, left + width, top + height);
2895 }
2896
2897 @Override
2898 public void getBounds(Rect out) {
2899 calculateBounds(out);
2900 }
2901
2902 private void getBounds(Rect out, int orientation) {
2903 getBounds(out);
2904
2905 // Rotate the Rect if needed.
2906 final int currentRotation = mDisplayInfo.rotation;
2907 final int rotationDelta = deltaRotation(currentRotation, orientation);
2908 if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
2909 createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
2910 mTmpRectF.set(out);
2911 mTmpMatrix.mapRect(mTmpRectF);
2912 mTmpRectF.round(out);
2913 }
2914 }
2915
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002916 void performLayout(boolean initial, boolean updateInputWindows) {
2917 if (!isLayoutNeeded()) {
2918 return;
2919 }
2920 clearLayoutNeeded();
2921
2922 final int dw = mDisplayInfo.logicalWidth;
2923 final int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002924 if (DEBUG_LAYOUT) {
2925 Slog.v(TAG, "-------------------------------------");
2926 Slog.v(TAG, "performLayout: needed=" + isLayoutNeeded() + " dw=" + dw + " dh=" + dh);
2927 }
2928
Wale Ogunwale828ff7e2017-11-14 01:01:29 +00002929 mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo);
2930 // TODO: Not sure if we really need to set the rotation here since we are updating from the
2931 // display info above...
2932 mDisplayFrames.mRotation = mRotation;
2933 mService.mPolicy.beginLayoutLw(mDisplayFrames, getConfiguration().uiMode);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002934 if (isDefaultDisplay) {
2935 // Not needed on non-default displays.
2936 mService.mSystemDecorLayer = mService.mPolicy.getSystemDecorLayerLw();
2937 mService.mScreenRect.set(0, 0, dw, dh);
2938 }
2939
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002940 int seq = mService.mLayoutSeq + 1;
2941 if (seq < 0) seq = 0;
2942 mService.mLayoutSeq = seq;
2943
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002944 // Used to indicate that we have processed the dream window and all additional windows are
2945 // behind it.
2946 mTmpWindow = null;
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002947 mTmpInitial = initial;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002948
2949 // First perform layout of any root windows (not attached to another window).
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002950 forAllWindows(mPerformLayout, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002951
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002952 // Used to indicate that we have processed the dream window and all additional attached
2953 // windows are behind it.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002954 mTmpWindow2 = mTmpWindow;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002955 mTmpWindow = null;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002956
2957 // Now perform layout of attached windows, which usually depend on the position of the
2958 // window they are attached to. XXX does not deal with windows that are attached to windows
2959 // that are themselves attached.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08002960 forAllWindows(mPerformLayoutAttached, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002961
2962 // Window frames may have changed. Tell the input dispatcher about it.
2963 mService.mInputMonitor.layoutInputConsumers(dw, dh);
2964 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
2965 if (updateInputWindows) {
2966 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2967 }
2968
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002969 mService.mH.sendEmptyMessage(UPDATE_DOCKED_STACK_DIVIDER);
2970 }
2971
2972 /**
2973 * Takes a snapshot of the display. In landscape mode this grabs the whole screen.
2974 * In portrait mode, it grabs the full screenshot.
2975 *
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002976 * @param config of the output bitmap
2977 * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
2978 */
chaviwfbe47df2017-11-10 16:14:49 -08002979 Bitmap screenshotDisplay(Bitmap.Config config, boolean wallpaperOnly) {
2980 synchronized (mService.mWindowMap) {
Jorim Jaggi51304d72017-05-17 17:25:32 +02002981 if (!mService.mPolicy.isScreenOn()) {
chaviwfbe47df2017-11-10 16:14:49 -08002982 if (DEBUG_SCREENSHOT) {
2983 Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002984 }
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002985 return null;
2986 }
2987
chaviwfbe47df2017-11-10 16:14:49 -08002988 if (wallpaperOnly && !shouldScreenshotWallpaper()) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002989 return null;
2990 }
2991
chaviwfbe47df2017-11-10 16:14:49 -08002992 int dw = mDisplayInfo.logicalWidth;
2993 int dh = mDisplayInfo.logicalHeight;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002994
chaviwfbe47df2017-11-10 16:14:49 -08002995 if (dw <= 0 || dh <= 0) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07002996 return null;
2997 }
2998
chaviwfbe47df2017-11-10 16:14:49 -08002999 final Rect frame = new Rect(0, 0, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003000
3001 // The screenshot API does not apply the current screen rotation.
3002 int rot = mDisplay.getRotation();
3003
3004 if (rot == ROTATION_90 || rot == ROTATION_270) {
3005 rot = (rot == ROTATION_90) ? ROTATION_270 : ROTATION_90;
3006 }
3007
chaviwfbe47df2017-11-10 16:14:49 -08003008 // SurfaceFlinger is not aware of orientation, so convert our logical
3009 // crop to SurfaceFlinger's portrait orientation.
3010 convertCropForSurfaceFlinger(frame, rot, dw, dh);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003011
3012 final ScreenRotationAnimation screenRotationAnimation =
3013 mService.mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
3014 final boolean inRotation = screenRotationAnimation != null &&
3015 screenRotationAnimation.isAnimating();
chaviwfbe47df2017-11-10 16:14:49 -08003016 if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM, "Taking screenshot while rotating");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003017
Robert Carrb1579c82017-09-05 14:54:47 -07003018 // TODO(b/68392460): We should screenshot Task controls directly
3019 // but it's difficult at the moment as the Task doesn't have the
3020 // correct size set.
chaviwfbe47df2017-11-10 16:14:49 -08003021 final Bitmap bitmap = SurfaceControl.screenshot(frame, dw, dh, 0, 1, inRotation, rot);
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003022 if (bitmap == null) {
Robert Carrb1579c82017-09-05 14:54:47 -07003023 Slog.w(TAG_WM, "Failed to take screenshot");
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003024 return null;
3025 }
chaviwfbe47df2017-11-10 16:14:49 -08003026
3027 // Create a copy of the screenshot that is immutable and backed in ashmem.
3028 // This greatly reduces the overhead of passing the bitmap between processes.
3029 final Bitmap ret = bitmap.createAshmemBitmap(config);
3030 bitmap.recycle();
3031 return ret;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003032 }
chaviwfbe47df2017-11-10 16:14:49 -08003033 }
3034
3035 private boolean shouldScreenshotWallpaper() {
3036 MutableBoolean screenshotReady = new MutableBoolean(false);
3037
3038 forAllWindows(w -> {
3039 if (!w.mIsWallpaper) {
3040 return false;
3041 }
3042
3043 // Found the wallpaper window
3044 final WindowStateAnimator winAnim = w.mWinAnimator;
3045
3046 if (winAnim.getShown() && winAnim.mLastAlpha > 0f) {
3047 screenshotReady.value = true;
3048 }
3049
3050 return true;
3051 }, true /* traverseTopToBottom */);
3052
3053 return screenshotReady.value;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003054 }
3055
3056 // TODO: Can this use createRotationMatrix()?
3057 private static void convertCropForSurfaceFlinger(Rect crop, int rot, int dw, int dh) {
3058 if (rot == Surface.ROTATION_90) {
3059 final int tmp = crop.top;
3060 crop.top = dw - crop.right;
3061 crop.right = crop.bottom;
3062 crop.bottom = dw - crop.left;
3063 crop.left = tmp;
3064 } else if (rot == Surface.ROTATION_180) {
3065 int tmp = crop.top;
3066 crop.top = dh - crop.bottom;
3067 crop.bottom = dh - tmp;
3068 tmp = crop.right;
3069 crop.right = dw - crop.left;
3070 crop.left = dw - tmp;
3071 } else if (rot == Surface.ROTATION_270) {
3072 final int tmp = crop.top;
3073 crop.top = crop.left;
3074 crop.left = dh - crop.bottom;
3075 crop.bottom = crop.right;
3076 crop.right = dh - tmp;
3077 }
3078 }
3079
3080 void onSeamlessRotationTimeout() {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003081 // Used to indicate the layout is needed.
3082 mTmpWindow = null;
3083
3084 forAllWindows(w -> {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003085 if (!w.mSeamlesslyRotated) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003086 return;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003087 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003088 mTmpWindow = w;
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003089 w.setDisplayLayoutNeeded();
3090 mService.markForSeamlessRotation(w, false);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003091 }, true /* traverseTopToBottom */);
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003092
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003093 if (mTmpWindow != null) {
Wale Ogunwalef7cab102016-10-25 15:25:14 -07003094 mService.mWindowPlacerLocked.performSurfacePlacement();
3095 }
3096 }
3097
Wale Ogunwale1666e312016-12-16 11:27:18 -08003098 void setExitingTokensHasVisible(boolean hasVisible) {
3099 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3100 mExitingTokens.get(i).hasVisible = hasVisible;
3101 }
3102
3103 // Initialize state of exiting applications.
3104 mTaskStackContainers.setExitingTokensHasVisible(hasVisible);
3105 }
3106
3107 void removeExistingTokensIfPossible() {
3108 for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
3109 final WindowToken token = mExitingTokens.get(i);
3110 if (!token.hasVisible) {
3111 mExitingTokens.remove(i);
3112 }
3113 }
3114
3115 // Time to remove any exiting applications?
3116 mTaskStackContainers.removeExistingAppTokensIfPossible();
3117 }
3118
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003119 @Override
3120 void onDescendantOverrideConfigurationChanged() {
3121 setLayoutNeeded();
3122 mService.requestTraversal();
3123 }
3124
David Stevens9440dc82017-03-16 19:00:20 -07003125 boolean okToDisplay() {
3126 if (mDisplayId == DEFAULT_DISPLAY) {
3127 return !mService.mDisplayFrozen
3128 && mService.mDisplayEnabled && mService.mPolicy.isScreenOn();
3129 }
3130 return mDisplayInfo.state == Display.STATE_ON;
3131 }
3132
3133 boolean okToAnimate() {
3134 return okToDisplay() &&
3135 (mDisplayId != DEFAULT_DISPLAY || mService.mPolicy.okToAnimate());
3136 }
3137
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07003138 static final class TaskForResizePointSearchResult {
3139 boolean searchDone;
3140 Task taskForResize;
3141
3142 void reset() {
3143 searchDone = false;
3144 taskForResize = null;
3145 }
3146 }
Robert Carr3b716242016-08-16 16:02:21 -07003147
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003148 private static final class ApplySurfaceChangesTransactionState {
3149 boolean displayHasContent;
3150 boolean obscured;
3151 boolean syswin;
3152 boolean focusDisplayed;
3153 float preferredRefreshRate;
3154 int preferredModeId;
3155
3156 void reset() {
3157 displayHasContent = false;
3158 obscured = false;
3159 syswin = false;
3160 focusDisplayed = false;
3161 preferredRefreshRate = 0;
3162 preferredModeId = 0;
3163 }
3164 }
3165
3166 private static final class ScreenshotApplicationState {
3167 WindowState appWin;
3168 int maxLayer;
3169 int minLayer;
3170 boolean screenshotReady;
3171
3172 void reset(boolean screenshotReady) {
3173 appWin = null;
3174 maxLayer = 0;
3175 minLayer = 0;
3176 this.screenshotReady = screenshotReady;
3177 minLayer = (screenshotReady) ? 0 : Integer.MAX_VALUE;
3178 }
3179 }
3180
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003181 /**
3182 * Base class for any direct child window container of {@link #DisplayContent} need to inherit
3183 * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
3184 * homogeneous children type which is currently required by sub-classes of
3185 * {@link WindowContainer} class.
3186 */
3187 static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
3188
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003189 DisplayChildWindowContainer(WindowManagerService service) {
3190 super(service);
3191 }
3192
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003193 @Override
3194 boolean fillsParent() {
3195 return true;
3196 }
3197
3198 @Override
3199 boolean isVisible() {
3200 return true;
Robert Carr3b716242016-08-16 16:02:21 -07003201 }
3202 }
3203
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003204 /**
3205 * Window container class that contains all containers on this display relating to Apps.
3206 * I.e Activities.
3207 */
Wale Ogunwale3a931692016-11-02 16:49:48 -07003208 private final class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
Robert Carrb1579c82017-09-05 14:54:47 -07003209 /**
3210 * A control placed at the appropriate level for transitions to occur.
3211 */
chaviw23ee71c2017-12-18 11:29:41 -08003212 SurfaceControl mAppAnimationLayer = null;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003213
Robert Carrf7a7ca82017-12-06 13:17:07 -08003214 /**
3215 * Given that the split-screen divider does not have an AppWindowToken, it
3216 * will have to live inside of a "NonAppWindowContainer", in particular
3217 * {@link DisplayContent#mAboveAppWindowsContainers}. However, in visual Z order
3218 * it will need to be interleaved with some of our children, appearing on top of
3219 * both docked stacks but underneath any assistant stacks.
3220 *
3221 * To solve this problem we have this anchor control, which will always exist so
3222 * we can always assign it the correct value in our {@link #assignChildLayers}.
3223 * Likewise since it always exists, {@link AboveAppWindowContainers} can always
3224 * assign the divider a layer relative to it. This way we prevent linking lifecycle
3225 * events between the two containers.
3226 */
3227 SurfaceControl mSplitScreenDividerAnchor = null;
3228
Wale Ogunwale61911492017-10-11 08:50:50 -07003229 // Cached reference to some special stacks we tend to get a lot so we don't need to loop
3230 // through the list to find them.
3231 private TaskStack mHomeStack = null;
3232 private TaskStack mPinnedStack = null;
3233 private TaskStack mSplitScreenPrimaryStack = null;
3234
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003235 TaskStackContainers(WindowManagerService service) {
3236 super(service);
3237 }
3238
Wale Ogunwale61911492017-10-11 08:50:50 -07003239 /**
3240 * Returns the topmost stack on the display that is compatible with the input windowing mode
3241 * and activity type. Null is no compatible stack on the display.
3242 */
3243 TaskStack getStack(int windowingMode, int activityType) {
3244 if (activityType == ACTIVITY_TYPE_HOME) {
3245 return mHomeStack;
3246 }
3247 if (windowingMode == WINDOWING_MODE_PINNED) {
3248 return mPinnedStack;
3249 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3250 return mSplitScreenPrimaryStack;
3251 }
3252 for (int i = mTaskStackContainers.getChildCount() - 1; i >= 0; --i) {
3253 final TaskStack stack = mTaskStackContainers.getChildAt(i);
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003254 if (activityType == ACTIVITY_TYPE_UNDEFINED
3255 && windowingMode == stack.getWindowingMode()) {
3256 // Passing in undefined type means we want to match the topmost stack with the
3257 // windowing mode.
3258 return stack;
3259 }
Wale Ogunwale61911492017-10-11 08:50:50 -07003260 if (stack.isCompatible(windowingMode, activityType)) {
3261 return stack;
3262 }
3263 }
3264 return null;
3265 }
3266
3267 @VisibleForTesting
3268 TaskStack getTopStack() {
3269 return mTaskStackContainers.getChildCount() > 0
3270 ? mTaskStackContainers.getChildAt(mTaskStackContainers.getChildCount() - 1) : null;
3271 }
3272
3273 TaskStack getHomeStack() {
3274 if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
3275 Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
3276 }
3277 return mHomeStack;
3278 }
3279
3280 TaskStack getPinnedStack() {
3281 return mPinnedStack;
3282 }
3283
Matthew Ng64e77cf2017-10-31 14:01:31 -07003284 TaskStack getSplitScreenPrimaryStack() {
Wale Ogunwale61911492017-10-11 08:50:50 -07003285 return mSplitScreenPrimaryStack;
3286 }
3287
Winson Chunge2d72172018-01-25 17:46:20 +00003288 ArrayList<Task> getVisibleTasks() {
3289 final ArrayList<Task> visibleTasks = new ArrayList<>();
3290 forAllTasks(task -> {
3291 if (task.isVisible()) {
3292 visibleTasks.add(task);
3293 }
3294 });
3295 return visibleTasks;
3296 }
3297
Andrii Kulian839def92016-11-02 10:58:58 -07003298 /**
3299 * Adds the stack to this container.
Wale Ogunwale61911492017-10-11 08:50:50 -07003300 * @see DisplayContent#createStack(int, boolean, StackWindowController)
Andrii Kulian839def92016-11-02 10:58:58 -07003301 */
3302 void addStackToDisplay(TaskStack stack, boolean onTop) {
Wale Ogunwale61911492017-10-11 08:50:50 -07003303 addStackReferenceIfNeeded(stack);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003304 addChild(stack, onTop);
3305 stack.onDisplayChanged(DisplayContent.this);
Robert Carr3b716242016-08-16 16:02:21 -07003306 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003307
Wale Ogunwale61911492017-10-11 08:50:50 -07003308 void onStackWindowingModeChanged(TaskStack stack) {
3309 removeStackReferenceIfNeeded(stack);
3310 addStackReferenceIfNeeded(stack);
3311 if (stack == mPinnedStack && getTopStack() != stack) {
3312 // Looks like this stack changed windowing mode to pinned. Move it to the top.
3313 positionChildAt(POSITION_TOP, stack, false /* includingParents */);
3314 }
3315 }
3316
3317 private void addStackReferenceIfNeeded(TaskStack stack) {
3318 if (stack.isActivityTypeHome()) {
3319 if (mHomeStack != null) {
3320 throw new IllegalArgumentException("addStackReferenceIfNeeded: home stack="
3321 + mHomeStack + " already exist on display=" + this + " stack=" + stack);
3322 }
3323 mHomeStack = stack;
3324 }
3325 final int windowingMode = stack.getWindowingMode();
3326 if (windowingMode == WINDOWING_MODE_PINNED) {
3327 if (mPinnedStack != null) {
3328 throw new IllegalArgumentException("addStackReferenceIfNeeded: pinned stack="
3329 + mPinnedStack + " already exist on display=" + this
3330 + " stack=" + stack);
3331 }
3332 mPinnedStack = stack;
3333 } else if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) {
3334 if (mSplitScreenPrimaryStack != null) {
3335 throw new IllegalArgumentException("addStackReferenceIfNeeded:"
3336 + " split-screen-primary" + " stack=" + mSplitScreenPrimaryStack
3337 + " already exist on display=" + this + " stack=" + stack);
3338 }
3339 mSplitScreenPrimaryStack = stack;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003340 mDividerControllerLocked.notifyDockedStackExistsChanged(true);
Wale Ogunwale61911492017-10-11 08:50:50 -07003341 }
3342 }
3343
3344 private void removeStackReferenceIfNeeded(TaskStack stack) {
3345 if (stack == mHomeStack) {
3346 mHomeStack = null;
3347 } else if (stack == mPinnedStack) {
3348 mPinnedStack = null;
3349 } else if (stack == mSplitScreenPrimaryStack) {
3350 mSplitScreenPrimaryStack = null;
Wale Ogunwale30e441d2017-11-09 08:28:45 -08003351 // Re-set the split-screen create mode whenever the split-screen stack is removed.
3352 mService.setDockedStackCreateStateLocked(
3353 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT, null /* initialBounds */);
3354 mDividerControllerLocked.notifyDockedStackExistsChanged(false);
Wale Ogunwale61911492017-10-11 08:50:50 -07003355 }
Andrii Kulian839def92016-11-02 10:58:58 -07003356 }
3357
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003358 private void addChild(TaskStack stack, boolean toTop) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003359 final int addIndex = findPositionForStack(toTop ? mChildren.size() : 0, stack,
3360 true /* adding */);
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003361 addChild(stack, addIndex);
3362 setLayoutNeeded();
3363 }
3364
Wale Ogunwale61911492017-10-11 08:50:50 -07003365 @Override
3366 protected void removeChild(TaskStack stack) {
3367 super.removeChild(stack);
3368 removeStackReferenceIfNeeded(stack);
3369 }
Bryce Lee00d586d2017-07-28 20:48:43 -07003370
3371 @Override
3372 boolean isOnTop() {
3373 // Considered always on top
3374 return true;
3375 }
3376
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003377 @Override
Andrii Kuliand2765632016-12-12 22:26:34 -08003378 void positionChildAt(int position, TaskStack child, boolean includingParents) {
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003379 if (child.getWindowConfiguration().isAlwaysOnTop()
3380 && position != POSITION_TOP) {
Andrii Kuliand2765632016-12-12 22:26:34 -08003381 // This stack is always-on-top, override the default behavior.
3382 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
3383
3384 // Moving to its current position, as we must call super but we don't want to
3385 // perform any meaningful action.
3386 final int currentPosition = mChildren.indexOf(child);
3387 super.positionChildAt(currentPosition, child, false /* includingParents */);
3388 return;
3389 }
3390
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003391 final int targetPosition = findPositionForStack(position, child, false /* adding */);
3392 super.positionChildAt(targetPosition, child, includingParents);
3393
3394 setLayoutNeeded();
3395 }
3396
3397 /**
3398 * When stack is added or repositioned, find a proper position for it.
3399 * This will make sure that pinned stack always stays on top.
3400 * @param requestedPosition Position requested by caller.
3401 * @param stack Stack to be added or positioned.
3402 * @param adding Flag indicates whether we're adding a new stack or positioning an existing.
3403 * @return The proper position for the stack.
3404 */
3405 private int findPositionForStack(int requestedPosition, TaskStack stack, boolean adding) {
3406 final int topChildPosition = mChildren.size() - 1;
3407 boolean toTop = requestedPosition == POSITION_TOP;
3408 toTop |= adding ? requestedPosition >= topChildPosition + 1
3409 : requestedPosition >= topChildPosition;
3410 int targetPosition = requestedPosition;
3411
Wale Ogunwale61911492017-10-11 08:50:50 -07003412 if (toTop && stack.getWindowingMode() != WINDOWING_MODE_PINNED && hasPinnedStack()) {
Bryce Lee48f4b572017-04-10 10:54:15 -07003413 // The pinned stack is always the top most stack (always-on-top) when it is present.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003414 TaskStack topStack = mChildren.get(topChildPosition);
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07003415 if (topStack.getWindowingMode() != WINDOWING_MODE_PINNED) {
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003416 throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
3417 }
3418
3419 // So, stack is moved just below the pinned stack.
3420 // When we're adding a new stack the target is the current pinned stack position.
3421 // When we're positioning an existing stack the target is the position below pinned
Andrii Kulian7cd7c2d2017-01-18 12:14:37 -08003422 // stack, because WindowContainer#positionAt() first removes element and then adds
3423 // it to specified place.
Andrii Kuliancd5dcb8b2017-01-03 17:09:45 -08003424 targetPosition = adding ? topChildPosition : topChildPosition - 1;
3425 }
3426
3427 return targetPosition;
Andrii Kuliand2765632016-12-12 22:26:34 -08003428 }
3429
3430 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003431 boolean forAllWindows(ToBooleanFunction<WindowState> callback,
3432 boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003433 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003434 if (super.forAllWindows(callback, traverseTopToBottom)) {
3435 return true;
3436 }
3437 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3438 return true;
3439 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003440 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003441 if (forAllExitingAppTokenWindows(callback, traverseTopToBottom)) {
3442 return true;
3443 }
3444 if (super.forAllWindows(callback, traverseTopToBottom)) {
3445 return true;
3446 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003447 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003448 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003449 }
3450
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003451 private boolean forAllExitingAppTokenWindows(ToBooleanFunction<WindowState> callback,
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003452 boolean traverseTopToBottom) {
3453 // For legacy reasons we process the TaskStack.mExitingAppTokens first here before the
3454 // app tokens.
3455 // TODO: Investigate if we need to continue to do this or if we can just process them
3456 // in-order.
3457 if (traverseTopToBottom) {
3458 for (int i = mChildren.size() - 1; i >= 0; --i) {
3459 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3460 for (int j = appTokens.size() - 1; j >= 0; --j) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003461 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3462 traverseTopToBottom)) {
3463 return true;
3464 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003465 }
3466 }
3467 } else {
3468 final int count = mChildren.size();
3469 for (int i = 0; i < count; ++i) {
3470 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3471 final int appTokensCount = appTokens.size();
3472 for (int j = 0; j < appTokensCount; j++) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003473 if (appTokens.get(j).forAllWindowsUnchecked(callback,
3474 traverseTopToBottom)) {
3475 return true;
3476 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003477 }
3478 }
3479 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003480 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003481 }
3482
Wale Ogunwale1666e312016-12-16 11:27:18 -08003483 void setExitingTokensHasVisible(boolean hasVisible) {
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 appTokens.get(j).hasVisible = hasVisible;
3488 }
3489 }
3490 }
3491
3492 void removeExistingAppTokensIfPossible() {
3493 for (int i = mChildren.size() - 1; i >= 0; --i) {
3494 final AppTokenList appTokens = mChildren.get(i).mExitingAppTokens;
3495 for (int j = appTokens.size() - 1; j >= 0; --j) {
3496 final AppWindowToken token = appTokens.get(j);
3497 if (!token.hasVisible && !mService.mClosingApps.contains(token)
3498 && (!token.mIsExiting || token.isEmpty())) {
3499 // Make sure there is no animation running on this token, so any windows
3500 // associated with it will be removed as soon as their animations are
3501 // complete.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003502 cancelAnimation();
Wale Ogunwale1666e312016-12-16 11:27:18 -08003503 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
3504 "performLayout: App token exiting now removed" + token);
3505 token.removeIfPossible();
3506 }
3507 }
3508 }
3509 }
3510
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003511 @Override
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003512 int getOrientation() {
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003513 if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)
3514 || isStackVisible(WINDOWING_MODE_FREEFORM)) {
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003515 // Apps and their containers are not allowed to specify an orientation while the
3516 // docked or freeform stack is visible...except for the home stack/task if the
3517 // docked stack is minimized and it actually set something.
3518 if (mHomeStack != null && mHomeStack.isVisible()
3519 && mDividerControllerLocked.isMinimizedDock()) {
3520 final int orientation = mHomeStack.getOrientation();
3521 if (orientation != SCREEN_ORIENTATION_UNSET) {
3522 return orientation;
3523 }
3524 }
3525 return SCREEN_ORIENTATION_UNSPECIFIED;
3526 }
3527
3528 final int orientation = super.getOrientation();
Dean Harding3e5a1522017-10-06 09:19:01 -07003529 boolean isCar = mService.mContext.getPackageManager().hasSystemFeature(
3530 PackageManager.FEATURE_AUTOMOTIVE);
3531 if (isCar) {
3532 // In a car, you cannot physically rotate the screen, so it doesn't make sense to
3533 // allow anything but the default orientation.
3534 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3535 "Forcing UNSPECIFIED orientation in car. Ignoring " + orientation);
3536 return SCREEN_ORIENTATION_UNSPECIFIED;
3537 }
3538
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003539 if (orientation != SCREEN_ORIENTATION_UNSET
3540 && orientation != SCREEN_ORIENTATION_BEHIND) {
3541 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
3542 "App is requesting an orientation, return " + orientation);
3543 return orientation;
3544 }
3545
3546 if (DEBUG_ORIENTATION) Slog.v(TAG_WM,
Andrii Kulian8ee72852017-03-10 10:36:45 -08003547 "No app is requesting an orientation, return " + mLastOrientation);
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003548 // The next app has not been requested to be visible, so we keep the current orientation
3549 // to prevent freezing/unfreezing the display too early.
Andrii Kulian8ee72852017-03-10 10:36:45 -08003550 return mLastOrientation;
Wale Ogunwalee6f806e2016-10-20 15:29:42 -07003551 }
Robert Carrb1579c82017-09-05 14:54:47 -07003552
3553 @Override
3554 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carr2f8aa392018-01-31 14:46:51 -08003555 assignStackOrdering(t);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003556
Robert Carr2f8aa392018-01-31 14:46:51 -08003557 for (int i = 0; i < mChildren.size(); i++) {
3558 final TaskStack s = mChildren.get(i);
3559 s.assignChildLayers(t);
3560 }
3561 }
3562
3563 void assignStackOrdering(SurfaceControl.Transaction t) {
Robert Carrf7a7ca82017-12-06 13:17:07 -08003564 final int HOME_STACK_STATE = 0;
3565 final int NORMAL_STACK_STATE = 1;
3566 final int ALWAYS_ON_TOP_STATE = 2;
3567
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003568 int layer = 0;
Robert Carr2f8aa392018-01-31 14:46:51 -08003569 int layerForAnimationLayer = 0;
3570
Robert Carrf7a7ca82017-12-06 13:17:07 -08003571 for (int state = 0; state <= ALWAYS_ON_TOP_STATE; state++) {
3572 for (int i = 0; i < mChildren.size(); i++) {
3573 final TaskStack s = mChildren.get(i);
Robert Carr2f8aa392018-01-31 14:46:51 -08003574 if (state == HOME_STACK_STATE && !s.isActivityTypeHome()) {
3575 continue;
3576 } else if (state == NORMAL_STACK_STATE && (s.isActivityTypeHome()
3577 || s.isAlwaysOnTop())) {
3578 continue;
3579 } else if (state == ALWAYS_ON_TOP_STATE && !s.isAlwaysOnTop()) {
3580 continue;
3581 }
3582 s.assignLayer(t, layer++);
3583 if (s.inSplitScreenWindowingMode() && mSplitScreenDividerAnchor != null) {
3584 t.setLayer(mSplitScreenDividerAnchor, layer++);
3585 }
3586 if (s.isSelfOrChildAnimating()) {
3587 // Ensure the animation layer ends up above the
3588 // highest animating stack and no higher.
3589 layerForAnimationLayer = layer++;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003590 }
3591 }
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003592 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003593 if (mAppAnimationLayer != null) {
3594 t.setLayer(mAppAnimationLayer, layerForAnimationLayer);
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003595 }
Robert Carrb1579c82017-09-05 14:54:47 -07003596 }
3597
3598 @Override
chaviw23ee71c2017-12-18 11:29:41 -08003599 SurfaceControl getAppAnimationLayer() {
3600 return mAppAnimationLayer;
3601 }
3602
Robert Carrf7a7ca82017-12-06 13:17:07 -08003603 SurfaceControl getSplitScreenDividerAnchor() {
3604 return mSplitScreenDividerAnchor;
3605 }
3606
chaviw23ee71c2017-12-18 11:29:41 -08003607 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07003608 void onParentSet() {
3609 super.onParentSet();
3610 if (getParent() != null) {
chaviw23ee71c2017-12-18 11:29:41 -08003611 mAppAnimationLayer = makeChildSurface(null)
3612 .setName("animationLayer")
3613 .build();
Robert Carrf7a7ca82017-12-06 13:17:07 -08003614 mSplitScreenDividerAnchor = makeChildSurface(null)
3615 .setName("splitScreenDividerAnchor")
3616 .build();
3617 getPendingTransaction()
3618 .show(mAppAnimationLayer)
3619 .show(mSplitScreenDividerAnchor);
chaviw23ee71c2017-12-18 11:29:41 -08003620 scheduleAnimation();
Robert Carrb1579c82017-09-05 14:54:47 -07003621 } else {
chaviw23ee71c2017-12-18 11:29:41 -08003622 mAppAnimationLayer.destroy();
3623 mAppAnimationLayer = null;
Robert Carrf7a7ca82017-12-06 13:17:07 -08003624 mSplitScreenDividerAnchor.destroy();
3625 mSplitScreenDividerAnchor = null;
Robert Carrb1579c82017-09-05 14:54:47 -07003626 }
3627 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003628 }
3629
Robert Carree4d4b92017-11-22 12:21:46 -08003630 private final class AboveAppWindowContainers extends NonAppWindowContainers {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003631 AboveAppWindowContainers(String name, WindowManagerService service) {
3632 super(name, service);
Robert Carree4d4b92017-11-22 12:21:46 -08003633 }
3634
3635 void assignChildLayers(SurfaceControl.Transaction t, WindowContainer imeContainer) {
3636 boolean needAssignIme = imeContainer != null
3637 && imeContainer.getSurfaceControl() != null;
3638 for (int j = 0; j < mChildren.size(); ++j) {
3639 final WindowToken wt = mChildren.get(j);
Robert Carrf7a7ca82017-12-06 13:17:07 -08003640
3641 // See {@link mSplitScreenDividerAnchor}
3642 if (wt.windowType == TYPE_DOCK_DIVIDER) {
3643 wt.assignRelativeLayer(t, mTaskStackContainers.getSplitScreenDividerAnchor(), 1);
3644 continue;
3645 }
Robert Carree4d4b92017-11-22 12:21:46 -08003646 wt.assignLayer(t, j);
3647 wt.assignChildLayers(t);
3648
3649 int layer = mService.mPolicy.getWindowLayerFromTypeLw(
3650 wt.windowType, wt.mOwnerCanManageAppTokens);
Robert Carrb8e78fa2017-11-28 13:07:58 -08003651
3652 if (needAssignIme && layer >= mService.mPolicy.getWindowLayerFromTypeLw(
3653 TYPE_INPUT_METHOD_DIALOG, true)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003654 imeContainer.assignRelativeLayer(t, wt.getSurfaceControl(), -1);
Robert Carree4d4b92017-11-22 12:21:46 -08003655 needAssignIme = false;
3656 }
3657 }
3658 if (needAssignIme) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003659 imeContainer.assignRelativeLayer(t, getSurfaceControl(), Integer.MAX_VALUE);
Robert Carree4d4b92017-11-22 12:21:46 -08003660 }
3661 }
3662 }
3663
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003664 /**
3665 * Window container class that contains all containers on this display that are not related to
3666 * Apps. E.g. status bar.
3667 */
Robert Carree4d4b92017-11-22 12:21:46 -08003668 private class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
Wale Ogunwale3a931692016-11-02 16:49:48 -07003669 /**
3670 * Compares two child window tokens returns -1 if the first is lesser than the second in
3671 * terms of z-order and 1 otherwise.
3672 */
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003673 private final Comparator<WindowToken> mWindowComparator = (token1, token2) ->
Wale Ogunwale3a931692016-11-02 16:49:48 -07003674 // Tokens with higher base layer are z-ordered on-top.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -08003675 mService.mPolicy.getWindowLayerFromTypeLw(token1.windowType,
3676 token1.mOwnerCanManageAppTokens)
3677 < mService.mPolicy.getWindowLayerFromTypeLw(token2.windowType,
3678 token2.mOwnerCanManageAppTokens) ? -1 : 1;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003679
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003680 private final Predicate<WindowState> mGetOrientingWindow = w -> {
3681 if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
3682 return false;
3683 }
3684 final int req = w.mAttrs.screenOrientation;
3685 if(req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
3686 || req == SCREEN_ORIENTATION_UNSET) {
3687 return false;
3688 }
3689 return true;
3690 };
3691
Wale Ogunwale3a931692016-11-02 16:49:48 -07003692 private final String mName;
chaviwf29223e2018-01-31 13:23:51 -08003693 private final Dimmer mDimmer = new Dimmer(this);
3694 private final Rect mTmpDimBoundsRect = new Rect();
3695
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003696 NonAppWindowContainers(String name, WindowManagerService service) {
3697 super(service);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003698 mName = name;
3699 }
3700
3701 void addChild(WindowToken token) {
3702 addChild(token, mWindowComparator);
3703 }
3704
3705 @Override
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003706 int getOrientation() {
3707 final WindowManagerPolicy policy = mService.mPolicy;
3708 // Find a window requesting orientation.
Wale Ogunwale1e129a42016-11-21 13:03:47 -08003709 final WindowState win = getWindow(mGetOrientingWindow);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003710
3711 if (win != null) {
3712 final int req = win.mAttrs.screenOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003713 if (policy.isKeyguardHostWindow(win.mAttrs)) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003714 mLastKeyguardForcedOrientation = req;
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003715 if (mService.mKeyguardGoingAway) {
3716 // Keyguard can't affect the orientation if it is going away...
3717 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
3718 return SCREEN_ORIENTATION_UNSET;
3719 }
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003720 }
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003721 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, win + " forcing orientation to " + req);
Andrii Kulian8ee72852017-03-10 10:36:45 -08003722 return (mLastWindowForcedOrientation = req);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003723 }
3724
Andrii Kulian8ee72852017-03-10 10:36:45 -08003725 mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003726
Jorim Jaggi75520d52017-08-24 17:23:19 +02003727 if (policy.isKeyguardShowingAndNotOccluded()
3728 || mService.mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE) {
Andrii Kulian8ee72852017-03-10 10:36:45 -08003729 return mLastKeyguardForcedOrientation;
Wale Ogunwale6213caa2016-12-02 16:47:15 +00003730 }
3731
3732 return SCREEN_ORIENTATION_UNSET;
3733 }
3734
3735 @Override
Wale Ogunwale3a931692016-11-02 16:49:48 -07003736 String getName() {
3737 return mName;
3738 }
chaviwf29223e2018-01-31 13:23:51 -08003739
3740 @Override
3741 Dimmer getDimmer() {
3742 return mDimmer;
3743 }
3744
3745 @Override
3746 void prepareSurfaces() {
3747 mDimmer.resetDimStates();
3748 super.prepareSurfaces();
3749 getBounds(mTmpDimBoundsRect);
3750
3751 if (mDimmer.updateDims(getPendingTransaction(), mTmpDimBoundsRect)) {
3752 scheduleAnimation();
3753 }
3754 }
Robert Carr3b716242016-08-16 16:02:21 -07003755 }
Jorim Jaggi6a7a8592017-01-12 00:44:33 +01003756
Robert Carr9034d962018-01-04 18:27:42 -08003757 private class NonMagnifiableWindowContainers extends NonAppWindowContainers {
3758 NonMagnifiableWindowContainers(String name, WindowManagerService service) {
3759 super(name, service);
3760 }
3761
3762 @Override
3763 void applyMagnificationSpec(Transaction t, MagnificationSpec spec) {
3764 }
3765 };
3766
Robert Carrb1579c82017-09-05 14:54:47 -07003767 SurfaceControl.Builder makeSurface(SurfaceSession s) {
3768 return mService.makeSurfaceBuilder(s)
3769 .setParent(mWindowingLayer);
3770 }
3771
3772 @Override
3773 SurfaceSession getSession() {
3774 return mSession;
3775 }
3776
3777 @Override
3778 SurfaceControl.Builder makeChildSurface(WindowContainer child) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003779 SurfaceSession s = child != null ? child.getSession() : getSession();
3780 final SurfaceControl.Builder b = mService.makeSurfaceBuilder(s);
Robert Carrb1579c82017-09-05 14:54:47 -07003781 b.setSize(mSurfaceSize, mSurfaceSize);
Robert Carrf59b8dd2017-10-02 18:58:36 -07003782
3783 if (child == null) {
3784 return b;
3785 }
3786
Robert Carree4d4b92017-11-22 12:21:46 -08003787 return b.setName(child.getName())
3788 .setParent(mWindowingLayer);
Robert Carrb1579c82017-09-05 14:54:47 -07003789 }
3790
3791 /**
3792 * The makeSurface variants are for use by the window-container
3793 * hierarchy. makeOverlay here is a function for various non windowing
3794 * overlays like the ScreenRotation screenshot, the Strict Mode Flash
3795 * and other potpourii.
3796 */
3797 SurfaceControl.Builder makeOverlay() {
3798 return mService.makeSurfaceBuilder(mSession)
3799 .setParent(mOverlayLayer);
3800 }
3801
Daichi Hironoa1fb9be2017-12-18 17:02:54 +09003802 /**
3803 * Reparents the given surface to mOverlayLayer.
3804 */
3805 void reparentToOverlay(Transaction transaction, SurfaceControl surface) {
3806 transaction.reparent(surface, mOverlayLayer.getHandle());
3807 }
3808
Robert Carrb1579c82017-09-05 14:54:47 -07003809 void applyMagnificationSpec(MagnificationSpec spec) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07003810 applyMagnificationSpec(getPendingTransaction(), spec);
3811 getPendingTransaction().apply();
Robert Carrb1579c82017-09-05 14:54:47 -07003812 }
3813
3814 @Override
3815 void onParentSet() {
3816 // Since we are the top of the SurfaceControl hierarchy here
3817 // we create the root surfaces explicitly rather than chaining
3818 // up as the default implementation in onParentSet does. So we
3819 // explicitly do NOT call super here.
3820 }
3821
3822 @Override
3823 void assignChildLayers(SurfaceControl.Transaction t) {
Robert Carrb1579c82017-09-05 14:54:47 -07003824
3825 // These are layers as children of "mWindowingLayer"
3826 mBelowAppWindowsContainers.assignLayer(t, 0);
3827 mTaskStackContainers.assignLayer(t, 1);
3828 mAboveAppWindowsContainers.assignLayer(t, 2);
3829
3830 WindowState imeTarget = mService.mInputMethodTarget;
Robert Carree4d4b92017-11-22 12:21:46 -08003831 boolean needAssignIme = true;
Robert Carr1cafdf82017-11-22 13:56:43 -08003832
Robert Carree4d4b92017-11-22 12:21:46 -08003833 // In the case where we have an IME target that is not in split-screen
3834 // mode IME assignment is easy. We just need the IME to go directly above
3835 // the target. This way children of the target will naturally go above the IME
3836 // and everyone is happy.
Robert Carr1cafdf82017-11-22 13:56:43 -08003837 //
Robert Carree4d4b92017-11-22 12:21:46 -08003838 // In the case of split-screen windowing mode, we need to elevate the IME above the
3839 // docked divider while keeping the app itself below the docked divider, so instead
3840 // we use relative layering of the IME targets child windows, and place the
3841 // IME in the non-app layer (see {@link AboveAppWindowContainers#assignChildLayers}).
Robert Carr1cafdf82017-11-22 13:56:43 -08003842 //
Robert Carree4d4b92017-11-22 12:21:46 -08003843 // In the case where we have no IME target we assign it where it's base layer would
3844 // place it in the AboveAppWindowContainers.
3845 if (imeTarget != null && !imeTarget.inSplitScreenWindowingMode()
3846 && (imeTarget.getSurfaceControl() != null)) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +01003847 mImeWindowsContainers.assignRelativeLayer(t, imeTarget.getSurfaceControl(),
Robert Carrb1579c82017-09-05 14:54:47 -07003848 // TODO: We need to use an extra level on the app surface to ensure
3849 // this is always above SurfaceView but always below attached window.
3850 1);
Robert Carree4d4b92017-11-22 12:21:46 -08003851 needAssignIme = false;
Robert Carrb1579c82017-09-05 14:54:47 -07003852 }
3853
3854 // Above we have assigned layers to our children, now we ask them to assign
3855 // layers to their children.
3856 mBelowAppWindowsContainers.assignChildLayers(t);
3857 mTaskStackContainers.assignChildLayers(t);
Robert Carree4d4b92017-11-22 12:21:46 -08003858 mAboveAppWindowsContainers.assignChildLayers(t,
3859 needAssignIme == true ? mImeWindowsContainers : null);
Robert Carrb1579c82017-09-05 14:54:47 -07003860 mImeWindowsContainers.assignChildLayers(t);
3861 }
3862
3863 /**
3864 * Here we satisfy an unfortunate special case of the IME in split-screen mode. Imagine
3865 * that the IME target is one of the docked applications. We'd like the docked divider to be
3866 * above both of the applications, and we'd like the IME to be above the docked divider.
3867 * However we need child windows of the applications to be above the IME (Text drag handles).
3868 * This is a non-strictly hierarcical layering and we need to break out of the Z ordering
3869 * somehow. We do this by relatively ordering children of the target to the IME in cooperation
3870 * with {@link #WindowState#assignLayer}
3871 */
3872 void assignRelativeLayerForImeTargetChild(SurfaceControl.Transaction t, WindowContainer child) {
3873 t.setRelativeLayer(child.getSurfaceControl(), mImeWindowsContainers.getSurfaceControl(), 1);
3874 }
3875
3876 @Override
Chavi Weingarten38804382018-02-15 21:00:15 +00003877 public void destroyAfterPendingTransaction(SurfaceControl surface) {
3878 mPendingDestroyingSurfaces.add(surface);
3879 }
3880
3881 /**
3882 * Destroys any surfaces that have been put into the pending list with
3883 * {@link #destroyAfterPendingTransaction}.
3884 */
3885 void onPendingTransactionApplied() {
3886 for (int i = mPendingDestroyingSurfaces.size() - 1; i >= 0; i--) {
3887 mPendingDestroyingSurfaces.get(i).destroy();
3888 }
3889 mPendingDestroyingSurfaces.clear();
3890 }
3891
3892 @Override
Jorim Jaggi9af095b2017-12-12 17:18:57 +01003893 void prepareSurfaces() {
3894 final ScreenRotationAnimation screenRotationAnimation =
3895 mService.mAnimator.getScreenRotationAnimationLocked(mDisplayId);
3896 if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
3897 screenRotationAnimation.getEnterTransformation().getMatrix().getValues(mTmpFloats);
3898 mPendingTransaction.setMatrix(mWindowingLayer,
3899 mTmpFloats[Matrix.MSCALE_X], mTmpFloats[Matrix.MSKEW_Y],
3900 mTmpFloats[Matrix.MSKEW_X], mTmpFloats[Matrix.MSCALE_Y]);
3901 mPendingTransaction.setPosition(mWindowingLayer,
3902 mTmpFloats[Matrix.MTRANS_X], mTmpFloats[Matrix.MTRANS_Y]);
3903 mPendingTransaction.setAlpha(mWindowingLayer,
3904 screenRotationAnimation.getEnterTransformation().getAlpha());
3905 }
3906 super.prepareSurfaces();
3907 }
Robert Carr2f8aa392018-01-31 14:46:51 -08003908
3909 void assignStackOrdering(SurfaceControl.Transaction t) {
3910 mTaskStackContainers.assignStackOrdering(t);
3911 }
Craig Mautner59c00972012-07-30 12:10:24 -07003912}